From db2fd0e1366f673e2e65d99bf1258d6326bc3e11 Mon Sep 17 00:00:00 2001 From: Thorsten Vitt <thorsten.vitt@uni-wuerzburg.de> Date: Wed, 4 Sep 2013 17:40:48 +0200 Subject: [PATCH] Added support for the embedded parameter --- .../services/aggregator/html/HTML.java | 6 ++-- .../services/aggregator/html/HTMLWriter.java | 31 +++++++++++++++---- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/main/java/info/textgrid/services/aggregator/html/HTML.java b/src/main/java/info/textgrid/services/aggregator/html/HTML.java index 7c7f3cd..1d87502 100644 --- a/src/main/java/info/textgrid/services/aggregator/html/HTML.java +++ b/src/main/java/info/textgrid/services/aggregator/html/HTML.java @@ -209,6 +209,7 @@ public StreamingOutput get( @Description("If true and a stylesheet has been given, force reloading the stylesheet, do not cache") @QueryParam("refreshStylesheet") final boolean refreshStylesheet, @Description("Session ID to access protected resources") @QueryParam("sid") final String sid, + @Description("If true, pass the information the stylesheet that its result will be embedded into some website") @QueryParam("embedded") final boolean embedded, @Description("URL of the CSS that should be referenced in the HTML that is created") @QueryParam("css") final URI css) throws ObjectNotFoundFault, MetadataParseFault, IoFault, AuthFault, @@ -216,9 +217,8 @@ public StreamingOutput get( SaxonApiException, ExecutionException { logger.fine("HTML called for root object: " + uri); - final HTMLWriter writer = new HTMLWriter(this, uri).stylesheet(xsluri) - .embedded(pi) - .sid(sid).refresh(refreshStylesheet).css(css); + final HTMLWriter writer = new HTMLWriter(this, uri, xsluri, + refreshStylesheet, pi, embedded, css, sid); writer.loadSource(); writer.loadStylesheet(); return writer; diff --git a/src/main/java/info/textgrid/services/aggregator/html/HTMLWriter.java b/src/main/java/info/textgrid/services/aggregator/html/HTMLWriter.java index 5500393..0b6241a 100644 --- a/src/main/java/info/textgrid/services/aggregator/html/HTMLWriter.java +++ b/src/main/java/info/textgrid/services/aggregator/html/HTMLWriter.java @@ -84,8 +84,11 @@ public class HTMLWriter implements StreamingOutput { private final URI rootURI; private Optional<URI> stylesheetURI = Optional.absent(); private boolean refreshStylesheet = false; - private boolean tryEmbeddedStylesheet = false; + private boolean readStylesheetPI = false; + private boolean embedded = false; + private Optional<URI> css = Optional.absent(); + private Optional<String> sid; // detected and extracted private enum SourceType { @@ -96,8 +99,6 @@ private enum SourceType { private final ITextGridRep repository; - private Optional<String> sid; - private ObjectType metadata; private Optional<URI> associatedStylesheet = Optional.absent(); @@ -106,7 +107,7 @@ private enum SourceType { private XsltTransformer transformer; - private Stopwatch stopwatch; + private final Stopwatch stopwatch; private String actualStylesheet; @@ -121,6 +122,21 @@ public HTMLWriter(final HTML service, final URI rootURI) { this.repository = service.repository; } + public HTMLWriter(final HTML service, final URI rootURI, + final URI stylesheetURI, final boolean refreshStylesheet, + final boolean readStylesheetPI, final boolean embedded, + final URI css, final String sid) { + + this(service, rootURI); + + this.stylesheetURI = Optional.fromNullable(stylesheetURI); + this.refreshStylesheet = refreshStylesheet; + this.readStylesheetPI = readStylesheetPI; + this.embedded = embedded; + this.css = Optional.fromNullable(css); + this.sid(sid); + } + public HTMLWriter sid(final String sid) { if (sid == null || sid.isEmpty()) { this.sid = Optional.absent(); @@ -141,7 +157,7 @@ public HTMLWriter refresh(final boolean refresh) { } public HTMLWriter embedded(final boolean embedded) { - this.tryEmbeddedStylesheet = embedded; + this.readStylesheetPI = embedded; if (embedded) { this.sourceType = SourceType.XML; } @@ -183,7 +199,7 @@ protected HTMLWriter loadSource() throws ObjectNotFoundFault, corpusBuffer.close(); this.source = new StreamSource(corpusBuffer.getSupplier() .getInput()); - } else if (sourceType == SourceType.XML && tryEmbeddedStylesheet) { + } else if (sourceType == SourceType.XML && readStylesheetPI) { final FileBackedOutputStream xmlBuffer = new FileBackedOutputStream( 1024 * 1024, true); ByteStreams.copy(content, xmlBuffer); @@ -252,6 +268,9 @@ protected HTMLWriter loadStylesheet() throws SaxonApiException, transformer.setParameter(new QName("cssFile"), new XdmAtomicValue( css.get())); } + transformer.setParameter(new QName("embedded"), new XdmAtomicValue( + embedded)); + transformer.setSource(source); this.transformer = transformer; logger.log(Level.INFO, MessageFormat.format("Prepared XSLT stylesheet {1} for {0} after {2}", rootURI, actualStylesheet, stopwatch.toString())); -- GitLab