Skip to content

Commit

Permalink
allow plain text response to be serialized with 'text/html' content-type
Browse files Browse the repository at this point in the history
  • Loading branch information
Conal-Tuohy committed Aug 26, 2019
1 parent f7e12ee commit fbc9ae6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/com/conaltuohy/xprocz/XProcZServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class XProcZServlet extends HttpServlet {
private static final String XPROC_Z_SYSTEM_PROPERTIES_NS = "tag:conaltuohy.com,2019:xproc-z-system-properties";

private static final String XPROC_STEP_NS = "http://www.w3.org/ns/xproc-step";
private static final String HTML_NS = "http://www.w3.org/1999/xhtml";

private final static SAXTransformerFactory transformerFactory = (SAXTransformerFactory) TransformerFactory.newInstance();
private final static DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Expand Down Expand Up @@ -473,8 +474,16 @@ private void respond(Processor processor, HttpServletResponse resp, XdmNode outp
if (isXMLMediaType(contentType)) {
serializer.setOutputProperty(Serializer.Property.METHOD, "xml");
} else if (isHTMLMediaType(contentType)) {
serializer.setOutputProperty(Serializer.Property.METHOD, "xhtml");
serializer.setOutputProperty(Serializer.Property.HTML_VERSION, "5");
// HTML content may be in the form of an element tree,
// or it may be text "<html>" etc.
QName htmlName = new QName(HTML_NS, "html");
XdmSequenceIterator htmlIterator = bodyElement.axisIterator(Axis.CHILD, htmlName);
if (htmlIterator.hasNext()) {
serializer.setOutputProperty(Serializer.Property.METHOD, "xhtml");
serializer.setOutputProperty(Serializer.Property.HTML_VERSION, "5");
} else {
serializer.setOutputProperty(Serializer.Property.METHOD, "text");
}
} else {
serializer.setOutputProperty(Serializer.Property.METHOD, "text");
}
Expand Down

0 comments on commit fbc9ae6

Please sign in to comment.