Skip to content
Snippets Groups Projects
Commit db2fd0e1 authored by Thorsten Vitt's avatar Thorsten Vitt
Browse files

Added support for the embedded parameter

parent adc8430d
Branches
Tags
No related merge requests found
...@@ -209,6 +209,7 @@ public StreamingOutput get( ...@@ -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("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") @Description("Session ID to access protected resources")
@QueryParam("sid") final String sid, @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") @Description("URL of the CSS that should be referenced in the HTML that is created")
@QueryParam("css") final URI css) throws ObjectNotFoundFault, @QueryParam("css") final URI css) throws ObjectNotFoundFault,
MetadataParseFault, IoFault, AuthFault, MetadataParseFault, IoFault, AuthFault,
...@@ -216,9 +217,8 @@ public StreamingOutput get( ...@@ -216,9 +217,8 @@ public StreamingOutput get(
SaxonApiException, ExecutionException { SaxonApiException, ExecutionException {
logger.fine("HTML called for root object: " + uri); logger.fine("HTML called for root object: " + uri);
final HTMLWriter writer = new HTMLWriter(this, uri).stylesheet(xsluri) final HTMLWriter writer = new HTMLWriter(this, uri, xsluri,
.embedded(pi) refreshStylesheet, pi, embedded, css, sid);
.sid(sid).refresh(refreshStylesheet).css(css);
writer.loadSource(); writer.loadSource();
writer.loadStylesheet(); writer.loadStylesheet();
return writer; return writer;
......
...@@ -84,8 +84,11 @@ public class HTMLWriter implements StreamingOutput { ...@@ -84,8 +84,11 @@ public class HTMLWriter implements StreamingOutput {
private final URI rootURI; private final URI rootURI;
private Optional<URI> stylesheetURI = Optional.absent(); private Optional<URI> stylesheetURI = Optional.absent();
private boolean refreshStylesheet = false; private boolean refreshStylesheet = false;
private boolean tryEmbeddedStylesheet = false; private boolean readStylesheetPI = false;
private boolean embedded = false;
private Optional<URI> css = Optional.absent(); private Optional<URI> css = Optional.absent();
private Optional<String> sid;
// detected and extracted // detected and extracted
private enum SourceType { private enum SourceType {
...@@ -96,8 +99,6 @@ private enum SourceType { ...@@ -96,8 +99,6 @@ private enum SourceType {
private final ITextGridRep repository; private final ITextGridRep repository;
private Optional<String> sid;
private ObjectType metadata; private ObjectType metadata;
private Optional<URI> associatedStylesheet = Optional.absent(); private Optional<URI> associatedStylesheet = Optional.absent();
...@@ -106,7 +107,7 @@ private enum SourceType { ...@@ -106,7 +107,7 @@ private enum SourceType {
private XsltTransformer transformer; private XsltTransformer transformer;
private Stopwatch stopwatch; private final Stopwatch stopwatch;
private String actualStylesheet; private String actualStylesheet;
...@@ -121,6 +122,21 @@ public HTMLWriter(final HTML service, final URI rootURI) { ...@@ -121,6 +122,21 @@ public HTMLWriter(final HTML service, final URI rootURI) {
this.repository = service.repository; 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) { public HTMLWriter sid(final String sid) {
if (sid == null || sid.isEmpty()) { if (sid == null || sid.isEmpty()) {
this.sid = Optional.absent(); this.sid = Optional.absent();
...@@ -141,7 +157,7 @@ public HTMLWriter refresh(final boolean refresh) { ...@@ -141,7 +157,7 @@ public HTMLWriter refresh(final boolean refresh) {
} }
public HTMLWriter embedded(final boolean embedded) { public HTMLWriter embedded(final boolean embedded) {
this.tryEmbeddedStylesheet = embedded; this.readStylesheetPI = embedded;
if (embedded) { if (embedded) {
this.sourceType = SourceType.XML; this.sourceType = SourceType.XML;
} }
...@@ -183,7 +199,7 @@ protected HTMLWriter loadSource() throws ObjectNotFoundFault, ...@@ -183,7 +199,7 @@ protected HTMLWriter loadSource() throws ObjectNotFoundFault,
corpusBuffer.close(); corpusBuffer.close();
this.source = new StreamSource(corpusBuffer.getSupplier() this.source = new StreamSource(corpusBuffer.getSupplier()
.getInput()); .getInput());
} else if (sourceType == SourceType.XML && tryEmbeddedStylesheet) { } else if (sourceType == SourceType.XML && readStylesheetPI) {
final FileBackedOutputStream xmlBuffer = new FileBackedOutputStream( final FileBackedOutputStream xmlBuffer = new FileBackedOutputStream(
1024 * 1024, true); 1024 * 1024, true);
ByteStreams.copy(content, xmlBuffer); ByteStreams.copy(content, xmlBuffer);
...@@ -252,6 +268,9 @@ protected HTMLWriter loadStylesheet() throws SaxonApiException, ...@@ -252,6 +268,9 @@ protected HTMLWriter loadStylesheet() throws SaxonApiException,
transformer.setParameter(new QName("cssFile"), new XdmAtomicValue( transformer.setParameter(new QName("cssFile"), new XdmAtomicValue(
css.get())); css.get()));
} }
transformer.setParameter(new QName("embedded"), new XdmAtomicValue(
embedded));
transformer.setSource(source); transformer.setSource(source);
this.transformer = transformer; this.transformer = transformer;
logger.log(Level.INFO, MessageFormat.format("Prepared XSLT stylesheet {1} for {0} after {2}", rootURI, actualStylesheet, stopwatch.toString())); logger.log(Level.INFO, MessageFormat.format("Prepared XSLT stylesheet {1} for {0} after {2}", rootURI, actualStylesheet, stopwatch.toString()));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment