Skip to content

Commit

Permalink
Prepared for a separate rendering run for the preprint stage
Browse files Browse the repository at this point in the history
  • Loading branch information
thvitt committed Jul 25, 2017
1 parent 4ebefe4 commit 9ea33b4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
32 changes: 30 additions & 2 deletions pom.xml
Expand Up @@ -220,8 +220,10 @@

<profiles>
<profile>
<id>svg</id>
<activation><activeByDefault>true</activeByDefault></activation>
<id>svg-base</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>

Expand Down Expand Up @@ -284,7 +286,28 @@
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>svg-print</id>
<activation><activeByDefault>true</activeByDefault></activation>
<build>
<resources>
<resource>
<directory>svg_rendering/page</directory>
<filtering>false</filtering>
<targetPath>${project.build.directory}/preprint-rendering</targetPath>
</resource>
<resource>
<directory>src/main/preprint-web</directory>
<filtering>false</filtering>
<targetPath>${project.build.directory}/preprint-rendering</targetPath>
</resource>
</resources>

<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
Expand Down Expand Up @@ -314,7 +337,11 @@
<argument>-Dfaust.diplo.server=${faust.diplo.server}</argument>
<argument>-Dfaust.diplo.port=${faust.diplo.port}</argument>
<argument>-Dfaust.diplo.debug=${faust.diplo.debug}</argument>
<argument>-Dfaust.diplo.webapp=${project.build.directory}/preprint-rendering</argument>
<argument>-Dfaust.diplo.documentroot=document/faust/2</argument>
<argument>-Dfaust.diplo.transcript_www=www-preprint</argument>
<argument>net.faustedition.gen.DiplomaticConversion</argument>

</arguments>
</configuration>
</execution>
Expand All @@ -325,6 +352,7 @@
</build>
</profile>


<profile>
<id>sources</id>
<activation><activeByDefault>true</activeByDefault></activation>
Expand Down
23 changes: 15 additions & 8 deletions src/main/java/net/faustedition/gen/DiplomaticConversion.java
Expand Up @@ -51,12 +51,20 @@

public class DiplomaticConversion {


private static final String PROPERTY = System.getProperty("faust.diplo.documentroot", "document");

private static final URI cssURI = Paths.get(System.getProperty("faust.diplo.css", "src/main/web/css/document-transcript.css")).toAbsolutePath().toUri();

private static Logger logger = Logger.getLogger(DiplomaticConversion.class.getName());

public static Path root = Paths.get("data/xml/");
public static Path root = Paths.get(System.getProperty("faust.diplo.root", "data/xml/"));
public static Path target = Paths.get("target");

private static final Path prepared_svg = target.resolve(System.getProperty("faust.diplo.prepared-svg", "prepared-svg"));
public static Path profile = target.resolve("profile");
public static final Path diplomatic_path = target.resolve("www").resolve("transcript").resolve("diplomatic");
private static final File renderWebapp = new File(System.getProperty("faust.diplo.webapp", "svg_rendering/page"));
private static String serverURL;

private static boolean debugPhantomJS;
Expand Down Expand Up @@ -213,7 +221,7 @@ public static void main(final String[] args) throws IOException {
onlyWebServer = Boolean.valueOf((String) properties.getOrDefault("faust.diplo.server", "false"));
debugPhantomJS = Boolean.valueOf((String) properties.getOrDefault("faust.diplo.debug", "false"));
final int listeningPort = Integer.valueOf((String) properties.getOrDefault("faust.diplo.port", "0"));
final SimpleWebServer webServer = new SimpleWebServer("localhost", listeningPort, new File("svg_rendering/page"), true);
final SimpleWebServer webServer = new SimpleWebServer("localhost", listeningPort, renderWebapp, true);
webServer.start(60, true);
try {
serverURL = new URL("http", "localhost", webServer.getListeningPort(), "/transcript-generation.html").toString();
Expand Down Expand Up @@ -267,7 +275,7 @@ public static void main(final String[] args) throws IOException {
transcriptPages = failedConversions;
} while (failedPages > 0 && failedPages < totalPages);

addCssToSvgs(allPages);
postprocessPrintSVGs(allPages);


if (!failedConversions.isEmpty()) {
Expand Down Expand Up @@ -324,19 +332,18 @@ private static List<TranscriptPage> runSVGconversion(List<TranscriptPage> pages,
return failedConversions;
}

private static void addCssToSvgs(final List<TranscriptPage> transcripts) throws InterruptedException {
private static void postprocessPrintSVGs(final List<TranscriptPage> transcripts) throws InterruptedException {
logger.info("Creating SVGs with CSS ...");
final Processor processor = new Processor(false);
try {
final XsltExecutable xslt = processor.newXsltCompiler().compile(new StreamSource(new File("src/main/resources/add-svg-stylesheet.xsl")));
final URI cssURI = Paths.get("src", "main", "web", "css", "document-transcript.css").toAbsolutePath().toUri();
final XsltExecutable xslt = processor.newXsltCompiler().compile(new StreamSource(new File("src/main/resources/postprocess-svgs.xsl")));

for (final TranscriptPage page : transcripts)
try {
XsltTransformer transformer = xslt.load();
transformer.setParameter(new QName("css"), new XdmAtomicValue(cssURI));
transformer.setSource(new StreamSource(diplomatic_path.resolve(page.getPagePath("svg")).toFile()));
transformer.setDestination(processor.newSerializer(target.resolve("prepared-svg").resolve(page.getNewPagePath("svg")).toFile()));
transformer.setDestination(processor.newSerializer(prepared_svg.resolve(page.getNewPagePath("svg")).toFile()));
transformer.transform();
} catch (SaxonApiException e) {
logger.log(Level.WARNING, e, () -> MessageFormat.format("Failed to add CSS to {0}: {1}", page, e.getMessage()));
Expand All @@ -352,7 +359,7 @@ public static Path resolveFaustUri(final URI uri) {
}

private static Stream<Document> getDocuments() throws IOException {
return Files.walk(root.resolve("document")).filter(path -> path.toString().endsWith(".xml")).map(
return Files.walk(root.resolve(PROPERTY)).filter(path -> path.toString().endsWith(".xml")).map(
path -> new Document(path));
}
}
File renamed without changes.
1 change: 0 additions & 1 deletion svg_rendering/page/fonts

This file was deleted.

0 comments on commit 9ea33b4

Please sign in to comment.