Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
philipru committed Dec 6, 2021
2 parents afb921d + 4e8fecd commit 5809c93
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 44 deletions.
31 changes: 18 additions & 13 deletions pso-docx-ant/src/main/java/org/pageseeder/docx/ant/ExportTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
*/
public final class ExportTask extends Task {

/**
* Used to prefix filenames of template images to avoid clashes with PSML images.
*/
public static String MEDIA_PREFIX = "kwo5nu83zotp2-";

/**
* The PageSeeder documents to export.
*
Expand Down Expand Up @@ -186,13 +191,13 @@ public void execute() throws BuildException {
}

// 1. Let's unzip the dotx
log("Extracting DOTX: " + this.dotx.getName());
log("Extracting template: " + this.dotx.getName());
File dotx = new File(this.working, "dotx");
dotx.mkdirs();
ZipUtils.unzip(this.dotx, dotx);

// 2. Sanity check
log("Checking DOTX");
log("Checking template");
File contentTypes = new File(dotx, "[Content_Types].xml");
File relationships = new File(dotx, "_rels/.rels");
if (!contentTypes.exists()) { throw new BuildException("Not a valid DOTX: unable to find [Content_Types].xml"); }
Expand All @@ -204,27 +209,28 @@ public void execute() throws BuildException {
ZipUtils.unzip(this.dotx, prepacked);
File document = new File(prepacked, "word/document.xml");
Files.ensureDirectoryExists(document.getParentFile());
// prefix template media files with a random string to avoid clashes with PSML images
File mediaFolder = new File(prepacked, "word/media");
String mediaPrefix = "kwo5nu83zotp2-";
Files.renameFiles(mediaFolder, mediaPrefix);
// for backward compatibility don't prefix when PSML images already copied to media folder
String mediaPrefix = "";

// 4. (extra) copy everything from the media folder to prepacked folder
if (this.media != null) {
log("Copy media files");
log("Copying media files");
if (!mediaFolder.exists()) {
mediaFolder.mkdirs();
}
// prefix template media files with a random string to avoid clashes with PSML images
mediaPrefix = MEDIA_PREFIX;
Files.renameFiles(mediaFolder, mediaPrefix);
try {
Files.copyDirectory(this.media, mediaFolder);
} catch (IOException e) {
// FIXME store to somewhere for debug.
e.printStackTrace();
log("Failed to copy media files: " + e.getMessage());
}
}

// 5. Unnest the files
log("Unnest");
log("Unnesting");
Templates unnest = XSLT.getTemplatesFromResource("org/pageseeder/docx/xslt/export-unnest.xsl");
File sourceDocument = this.source;
File newSourceDocument = new File(this.working, "unnested/document-unnested.psml");
Expand All @@ -233,7 +239,7 @@ public void execute() throws BuildException {
XSLT.transform(sourceDocument, newSourceDocument, unnest, noParameters);

// 6. Process the files
log("Process with XSLT");
log("Processing with XSLT");

// Parse templates
Templates templates = XSLT.getTemplatesFromResource("org/pageseeder/docx/xslt/export.xsl");
Expand Down Expand Up @@ -262,13 +268,12 @@ public void execute() throws BuildException {
prepacked.renameTo(this.destination);
// for backward compatibility
} else if (parameters.containsKey("generate-processed-psml") && parameters.get("generate-processed-psml").equals("true")) {
log("Debug Mode");
log("Copying processed PSML");
File newDestinationDocument = new File(this.destination.getParentFile() + "/document.xml");
try {
Files.copy(document, newDestinationDocument);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
log("Failed to copy processed PSML: " + e.getMessage());
}
this.destination.getParentFile().mkdirs();
ZipUtils.zip(prepacked, this.destination);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,11 @@ private static void copyMedia(File from, File to, String folder) {
try {
Files.ensureDirectoryExists(mediaOut);
for (File m : media.listFiles()) {
// decode filename because the image/@src will be decoded by PageSeeder
Files.copy(m, new File(mediaOut, URLDecoder.decode(m.getName(), "UTF-8").toLowerCase()));
// don't import template images
if (!m.getName().startsWith(ExportTask.MEDIA_PREFIX)) {
// decode filename because the image/@src will be decoded by PageSeeder
Files.copy(m, new File(mediaOut, URLDecoder.decode(m.getName(), "UTF-8").toLowerCase()));
}
}
} catch (IOException ex) {
// TODO clean up files
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:bookmarkStart w:name="f-186971" w:id="0"/><w:bookmarkEnd w:id="0"/><w:bookmarkStart w:name="f-title" w:id="1"/><w:p><w:pPr><w:pStyle w:val="BodyText"/></w:pPr><w:bookmarkStart w:name="h-title" w:id="2"/><w:r><w:rPr/><w:t xml:space="preserve">Block whitespace</w:t></w:r><w:bookmarkEnd w:id="2"/></w:p><w:bookmarkEnd w:id="1"/><w:bookmarkStart w:name="f-1" w:id="3"/><w:p><w:pPr><w:pStyle w:val="ListNumber"/></w:pPr><w:r><w:rPr/><w:t xml:space="preserve">Some text 1</w:t></w:r></w:p><w:p><w:pPr><w:pStyle w:val="ListNumber"/></w:pPr><w:r><w:rPr/><w:t xml:space="preserve">Some text 2</w:t></w:r></w:p><w:p><w:pPr><w:pStyle w:val="ListNumber"/></w:pPr><w:r><w:rPr/><w:t xml:space="preserve">Some </w:t></w:r><w:r><w:rPr><w:b/></w:rPr><w:t xml:space="preserve">bold</w:t></w:r><w:r><w:rPr/><w:t xml:space="preserve"> </w:t></w:r><w:r><w:rPr><w:i/></w:rPr><w:t xml:space="preserve">text</w:t></w:r><w:r><w:rPr/><w:t xml:space="preserve"> 3</w:t></w:r></w:p><w:p><w:pPr><w:pStyle w:val="BodyText"/></w:pPr><w:r><w:rPr/><w:t xml:space="preserve">pre</w:t></w:r></w:p><w:p><w:pPr><w:pStyle w:val="ListNumber"/></w:pPr><w:r><w:rPr/><w:t xml:space="preserve">Some </w:t></w:r><w:r><w:rPr><w:b/></w:rPr><w:t xml:space="preserve">bold</w:t></w:r><w:r><w:rPr/><w:t xml:space="preserve"> </w:t></w:r><w:r><w:rPr><w:i/></w:rPr><w:t xml:space="preserve">text</w:t></w:r><w:r><w:rPr/><w:t xml:space="preserve"> 4</w:t></w:r></w:p><w:p><w:pPr><w:pStyle w:val="BodyText"/></w:pPr><w:r><w:rPr/><w:t xml:space="preserve">pre</w:t></w:r></w:p><w:p><w:pPr><w:pStyle w:val="ListNumber"/></w:pPr><w:r><w:rPr/><w:t xml:space="preserve">Some </w:t></w:r><w:r><w:rPr><w:b/></w:rPr><w:t xml:space="preserve">bold</w:t></w:r><w:r><w:rPr/><w:t xml:space="preserve"> </w:t></w:r><w:r><w:rPr><w:i/></w:rPr><w:t xml:space="preserve">text</w:t></w:r></w:p><w:p><w:pPr><w:pStyle w:val="BodyText"/></w:pPr><w:r><w:rPr/><w:t xml:space="preserve">pre</w:t></w:r></w:p><w:p><w:pPr><w:pStyle w:val="ListNumber"/></w:pPr><w:r><w:rPr/><w:t xml:space="preserve">and </w:t></w:r><w:r><w:rPr><w:u w:val="single"/></w:rPr><w:t xml:space="preserve">more</w:t></w:r><w:r><w:rPr/><w:t xml:space="preserve"> 4</w:t></w:r></w:p><w:p><w:pPr><w:pStyle w:val="ListNumber"/></w:pPr><w:r><w:rPr/><w:t xml:space="preserve"/></w:r><w:r><w:rPr><w:b/></w:rPr><w:t xml:space="preserve"> </w:t></w:r><w:r><w:rPr/><w:t xml:space="preserve"> </w:t></w:r><w:r><w:rPr><w:i/></w:rPr><w:t xml:space="preserve"> </w:t></w:r><w:r><w:rPr/><w:t xml:space="preserve"/></w:r></w:p><w:p><w:pPr><w:pStyle w:val="ListNumber"/></w:pPr></w:p><w:p><w:pPr><w:pStyle w:val="ListNumber"/></w:pPr><w:r><w:pPr><w:rStyle w:val="DefaultParagraphFont"/></w:pPr><w:drawing><wp:inline xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" distT="0" distB="0" distL="0" distR="0"><wp:extent cx="190500" cy="190500"/><wp:docPr id="1" name="ico-url" descr="" title=""/><a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"><pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"><pic:nvPicPr><pic:cNvPr id="0" name="whatever"/><pic:cNvPicPr/></pic:nvPicPr><pic:blipFill><a:blip xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed="rId17"/><a:stretch><a:fillRect/></a:stretch></pic:blipFill><pic:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="190500" cy="190500"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></pic:spPr></pic:pic></a:graphicData></a:graphic></wp:inline></w:drawing></w:r></w:p><w:bookmarkEnd w:id="3"/><w:sectPr xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" w:rsidR="00125F2B"><w:headerReference w:type="even" r:id="rId8"/><w:headerReference w:type="default" r:id="rId9"/><w:footerReference w:type="even" r:id="rId10"/><w:footerReference w:type="default" r:id="rId11"/><w:headerReference w:type="first" r:id="rId12"/><w:footerReference w:type="first" r:id="rId13"/><w:pgSz w:w="11906" w:h="16838"/><w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/><w:cols w:space="708"/><w:docGrid w:linePitch="360"/></w:sectPr></w:body></w:document>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:bookmarkStart w:name="f-186971" w:id="0"/><w:bookmarkEnd w:id="0"/><w:bookmarkStart w:name="f-title" w:id="1"/><w:p><w:pPr><w:pStyle w:val="BodyText"/></w:pPr><w:bookmarkStart w:name="h-title" w:id="2"/><w:r><w:rPr/><w:t xml:space="preserve">Block whitespace</w:t></w:r><w:bookmarkEnd w:id="2"/></w:p><w:bookmarkEnd w:id="1"/><w:bookmarkStart w:name="f-1" w:id="3"/><w:p><w:pPr><w:pStyle w:val="ListNumber"/></w:pPr><w:r><w:rPr/><w:t xml:space="preserve">Some text 1</w:t></w:r></w:p><w:p><w:pPr><w:pStyle w:val="ListNumber"/></w:pPr><w:r><w:rPr/><w:t xml:space="preserve">Some text 2</w:t></w:r></w:p><w:p><w:pPr><w:pStyle w:val="ListNumber"/></w:pPr><w:r><w:rPr/><w:t xml:space="preserve">Some </w:t></w:r><w:r><w:rPr><w:b/></w:rPr><w:t xml:space="preserve">bold</w:t></w:r><w:r><w:rPr/><w:t xml:space="preserve"> </w:t></w:r><w:r><w:rPr><w:i/></w:rPr><w:t xml:space="preserve">text</w:t></w:r><w:r><w:rPr/><w:t xml:space="preserve"> 3</w:t></w:r></w:p><w:p><w:pPr><w:pStyle w:val="BodyText"/></w:pPr><w:r><w:rPr/><w:t xml:space="preserve">pre</w:t></w:r></w:p><w:p><w:pPr><w:pStyle w:val="ListNumber"/></w:pPr><w:r><w:rPr/><w:t xml:space="preserve">Some </w:t></w:r><w:r><w:rPr><w:b/></w:rPr><w:t xml:space="preserve">bold</w:t></w:r><w:r><w:rPr/><w:t xml:space="preserve"> </w:t></w:r><w:r><w:rPr><w:i/></w:rPr><w:t xml:space="preserve">text</w:t></w:r><w:r><w:rPr/><w:t xml:space="preserve"> 4</w:t></w:r></w:p><w:p><w:pPr><w:pStyle w:val="BodyText"/></w:pPr><w:r><w:rPr/><w:t xml:space="preserve">pre</w:t></w:r></w:p><w:p><w:pPr><w:pStyle w:val="ListNumber"/></w:pPr><w:r><w:rPr/><w:t xml:space="preserve">Some </w:t></w:r><w:r><w:rPr><w:b/></w:rPr><w:t xml:space="preserve">bold</w:t></w:r><w:r><w:rPr/><w:t xml:space="preserve"> </w:t></w:r><w:r><w:rPr><w:i/></w:rPr><w:t xml:space="preserve">text</w:t></w:r></w:p><w:p><w:pPr><w:pStyle w:val="BodyText"/></w:pPr><w:r><w:rPr/><w:t xml:space="preserve">pre</w:t></w:r></w:p><w:p><w:pPr><w:pStyle w:val="ListNumber"/></w:pPr><w:r><w:rPr/><w:t xml:space="preserve">and </w:t></w:r><w:r><w:rPr><w:u w:val="single"/></w:rPr><w:t xml:space="preserve">more</w:t></w:r><w:r><w:rPr/><w:t xml:space="preserve"> 4</w:t></w:r></w:p><w:p><w:pPr><w:pStyle w:val="ListNumber"/></w:pPr><w:r><w:rPr/><w:t xml:space="preserve"/></w:r><w:r><w:rPr><w:b/></w:rPr><w:t xml:space="preserve"> </w:t></w:r><w:r><w:rPr/><w:t xml:space="preserve"> </w:t></w:r><w:r><w:rPr><w:i/></w:rPr><w:t xml:space="preserve"> </w:t></w:r><w:r><w:rPr/><w:t xml:space="preserve"/></w:r></w:p><w:p><w:pPr><w:pStyle w:val="ListNumber"/></w:pPr></w:p><w:p><w:pPr><w:pStyle w:val="ListNumber"/></w:pPr><w:r><w:pPr><w:rStyle w:val="DefaultParagraphFont"/></w:pPr><w:drawing><wp:inline xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" distT="0" distB="0" distL="0" distR="0"><wp:extent cx="190500" cy="190500"/><wp:docPr id="100" name="ico-url" descr="" title=""/><a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"><pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"><pic:nvPicPr><pic:cNvPr id="0" name="whatever"/><pic:cNvPicPr/></pic:nvPicPr><pic:blipFill><a:blip xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed="rId17"/><a:stretch><a:fillRect/></a:stretch></pic:blipFill><pic:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="190500" cy="190500"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></pic:spPr></pic:pic></a:graphicData></a:graphic></wp:inline></w:drawing></w:r></w:p><w:bookmarkEnd w:id="3"/><w:sectPr xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" w:rsidR="00125F2B"><w:headerReference w:type="even" r:id="rId8"/><w:headerReference w:type="default" r:id="rId9"/><w:footerReference w:type="even" r:id="rId10"/><w:footerReference w:type="default" r:id="rId11"/><w:headerReference w:type="first" r:id="rId12"/><w:footerReference w:type="first" r:id="rId13"/><w:pgSz w:w="11906" w:h="16838"/><w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/><w:cols w:space="708"/><w:docGrid w:linePitch="360"/></w:sectPr></w:body></w:document>
Loading

0 comments on commit 5809c93

Please sign in to comment.