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

Encapsulated sid and logger

parent 0cf1cd4a
No related branches found
No related tags found
No related merge requests found
......@@ -67,9 +67,21 @@
*/
public abstract class AbstractExporter implements StreamingOutput {
protected static final Logger logger = Logger
private static final Logger logger = Logger
.getLogger(AbstractExporter.class.getCanonicalName());
protected Optional<String> sid = Optional.absent();
private Optional<String> sid = Optional.absent();
protected Optional<String> getSid() {
return sid;
}
public SourceType getSourceType() {
return sourceType;
}
public URI[] getRootURIs() {
return rootURIs;
}
// detected and extracted
protected enum SourceType {
......
......@@ -12,6 +12,7 @@
import java.io.InputStream;
import java.text.MessageFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Request;
......@@ -25,6 +26,7 @@
public abstract class CorpusBasedExporter extends AbstractExporter {
private static final Logger logger = Logger.getLogger(CorpusBasedExporter.class.getCanonicalName());
protected boolean readStylesheetPI = false;
private InputSupplier<InputStream> sourceBuffer = null;
......@@ -80,7 +82,7 @@ protected Source loadSource(final boolean bufferRequired)
if (sourceType == SourceType.AGGREGATION
|| sourceType == SourceType.BASKET) {
final TEICorpusSerializer corpusSerializer =
new TEICorpusSerializer(getRootObjects(), false, sid.orNull());
new TEICorpusSerializer(getRootObjects(), false, getSid().orNull());
final FileBackedOutputStream corpusBuffer = new FileBackedOutputStream(
1024 * 1024, true);
corpusSerializer.write(corpusBuffer);
......
......@@ -18,6 +18,7 @@
import java.text.MessageFormat;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
......@@ -94,6 +95,7 @@ public class HTMLWriter extends CorpusBasedExporter implements StreamingOutput {
private Source source;
private StylesheetManager stylesheetManager;
private static final Logger logger = Logger.getLogger(HTMLWriter.class.getCanonicalName());
......@@ -120,6 +122,7 @@ public HTMLWriter(final ITextGridRep repository, final StylesheetManager stylesh
this.refreshStylesheet = refreshStylesheet;
this.readStylesheetPI = readStylesheetPI;
this.embedded = embedded;
this.css = Optional.fromNullable(css);
this.sid(sid);
this.requestedMediaType = Optional.fromNullable(mediaType);
......@@ -169,15 +172,15 @@ private XsltExecutable getStylesheet() throws SaxonApiException,
IOException {
if (explicitStylesheetURI.isPresent()) {
actualStylesheetLabel = explicitStylesheetURI.get().toString() + " (explicit)";
return stylesheetManager.getStylesheet(explicitStylesheetURI.get(), sid,
return stylesheetManager.getStylesheet(explicitStylesheetURI.get(), getSid(),
refreshStylesheet, false);
} else if (associatedStylesheetURI.isPresent()) {
actualStylesheetLabel = associatedStylesheetURI.get().toString() + " (associated)";
return stylesheetManager.getStylesheet(associatedStylesheetURI.get(), sid,
return stylesheetManager.getStylesheet(associatedStylesheetURI.get(), getSid(),
refreshStylesheet, false);
} else {
actualStylesheetLabel = "(internal)";
return stylesheetManager.getStylesheet(TO_HTML_XSL, sid, false, true);
return stylesheetManager.getStylesheet(TO_HTML_XSL, getSid(), false, true);
}
}
......@@ -197,14 +200,13 @@ public XsltTransformer getTransformer() throws SaxonApiException, IOException {
return transformer;
final XsltTransformer transformer = getStylesheet().load();
if (sid.isPresent()) {
transformer.setURIResolver(new TGUriResolver(repository, sid));
if (getSid().isPresent()) {
transformer.setURIResolver(new TGUriResolver(repository, getSid()));
}
transformer.setParameter(new QName("graphicsURLPattern"),
new XdmAtomicValue(repository.getCRUDRestEndpoint()
+ "/@URI@/data"
+ ((sid == null || "".equals(sid)) ? ""
: ("?sessionId=" + sid))));
+ (getSid().isPresent()? "?sessionId=" + getSid().get() : "")));
if (css.isPresent()) {
transformer.setParameter(new QName("cssFile"), new XdmAtomicValue(
css.get()));
......@@ -231,7 +233,7 @@ public void write(final OutputStream out) throws IOException,
logger.log(Level.INFO, MessageFormat.format("Ready for transformation of {0} after {1}", rootURIs, stopwatch.toString()));
final Serializer serializer = stylesheetManager.xsltProcessor.newSerializer(out);
if (embedded) {
final XsltTransformer extractBody = stylesheetManager.getStylesheet(EXTRACT_BODY_XSL, sid, false, true).load();
final XsltTransformer extractBody = stylesheetManager.getStylesheet(EXTRACT_BODY_XSL, getSid(), false, true).load();
extractBody.setDestination(serializer);
getTransformer().setDestination(extractBody);
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment