From: Simon Pepping Date: Fri, 27 Jan 2006 20:24:15 +0000 (+0000) Subject: Change TransformerHandler to ContentHandler. Use comment method when X-Git-Tag: fop-0_92-beta~164 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8f160a6bf6550761eaddaca0bccbfe0380ee6876;p=xmlgraphics-fop.git Change TransformerHandler to ContentHandler. Use comment method when available. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@372971 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/render/xml/XMLRenderer.java b/src/java/org/apache/fop/render/xml/XMLRenderer.java index c51c33522..833f3df8a 100644 --- a/src/java/org/apache/fop/render/xml/XMLRenderer.java +++ b/src/java/org/apache/fop/render/xml/XMLRenderer.java @@ -36,6 +36,7 @@ import org.apache.avalon.framework.configuration.ConfigurationException; import org.w3c.dom.Document; import org.xml.sax.Attributes; import org.xml.sax.SAXException; +import org.xml.sax.ext.LexicalHandler; import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.ContentHandler; @@ -111,7 +112,7 @@ public class XMLRenderer extends PrintRenderer { /** If not null, the XMLRenderer will mimic another renderer by using its font setup. */ protected Renderer mimic; - /** TransformerHandler that the generated XML is written to */ + /** ContentHandler that the generated XML is written to */ protected ContentHandler handler; /** AttributesImpl instance that can be used during XML generation. */ @@ -196,6 +197,20 @@ public class XMLRenderer extends PrintRenderer { throw new RuntimeException(saxe.getMessage()); } + /** + * Writes a comment to the generated XML. + * @param comment the comment + */ + protected void comment(String comment) { + if (handler instanceof LexicalHandler) { + try { + ((LexicalHandler) handler).comment(comment.toCharArray(), 0, comment.length()); + } catch (SAXException saxe) { + handleSAXException(saxe); + } + } + } + /** * Starts a new element (without attributes). * @param tagName tag name of the element @@ -406,6 +421,9 @@ public class XMLRenderer extends PrintRenderer { } catch (SAXException saxe) { handleSAXException(saxe); } + if (userAgent.getProducer() != null) { + comment("Produced by " + userAgent.getProducer()); + } startElement("areaTree"); } diff --git a/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java b/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java index 637966580..245dc25eb 100644 --- a/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java +++ b/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java @@ -192,7 +192,7 @@ public class AreaTreeParserTestCase extends XMLTestCase { XMLRenderer renderer = new XMLRenderer(); renderer.mimicRenderer(targetRenderer); - renderer.setTransformerHandler(handler); + renderer.setContentHandler(handler); renderer.setUserAgent(userAgent); userAgent.setRendererOverride(renderer); @@ -223,7 +223,7 @@ public class AreaTreeParserTestCase extends XMLTestCase { DOMResult domResult = new DOMResult(); handler.setResult(domResult); XMLRenderer renderer = new XMLRenderer(); - renderer.setTransformerHandler(handler); + renderer.setContentHandler(handler); FOUserAgent userAgent = createUserAgent(); userAgent.setRendererOverride(renderer);