diff options
author | Jeremias Maerki <jeremias@apache.org> | 2006-02-17 10:57:15 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2006-02-17 10:57:15 +0000 |
commit | c939529a9baf1a9ac1d16f935e8f11c89ca77be2 (patch) | |
tree | 1c6f827ad2421ba2ded81d2c8f4e15f196c9075e /src/java/org/apache/fop/render/xml/XMLXMLHandler.java | |
parent | 90a82aaadad9c950b0c12c33ffb8b4d7201df286 (diff) | |
download | xmlgraphics-fop-c939529a9baf1a9ac1d16f935e8f11c89ca77be2.tar.gz xmlgraphics-fop-c939529a9baf1a9ac1d16f935e8f11c89ca77be2.zip |
Initial support for XMP metadata (PDF 1.4) under fo:declarations. Both xmpmeta and RDF elements can be used as root elements for XMP metadata.
Extracted DOM2SAX functionality from XMLXMLHandler into utility class since it is now reused elsewhere.
New DOMBuilderContentHandlerFactory is used to create ContentHandlers that build generic DOMs.
New DelegatingContentHandler is a convenience base class modelled after XMLFilterImpl but as passive SAX receiver. It is used by DOMBuilderContentHandlerFactory.
Refactored FOTreeBuilder. FO tree building is now in a special ContentHandler which can be replaced temporarily when handling foreign XML like SVG or XMP. Extension Elements wanting the set their own ContentHandlers (instead of using the standard FO tree building mechanism) return a non-null value in getContentHandlerFactory(). The old mechanism is still supported (MathML, Plan and Barcode4J still use that). However, SVG support is changed to use a ContentHandlerFactory.
Extension elements for xmpmeta and RDF elements making use of the new DOM build-up using ContentHandlerFactory.
XMP metadata is passed to the renderer as ExtensionAttachment to the document. Only PDFRenderer uses the XMP extension attachment at this time.
The PDFRenderer automatically builds XMP metadata based on the basic metadata information in the PDFInfo object if no explicit XMP metadata has been added to the XSL-FO document.
XMP metadata merging is not implemented because this would involve a more sophisticated XMP infrastructure. That also means that XMP metadata is not validated. It's passed into the PDF as is.
The PDF library now provides the PDFMetadata class to embed XMP metadata in PDFs version >=1.4. stream contents use a special filter list which is initially empty, so non-PDF-aware XMP readers can extract (and optionally modify) the XMP metadata.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@378482 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render/xml/XMLXMLHandler.java')
-rw-r--r-- | src/java/org/apache/fop/render/xml/XMLXMLHandler.java | 104 |
1 files changed, 2 insertions, 102 deletions
diff --git a/src/java/org/apache/fop/render/xml/XMLXMLHandler.java b/src/java/org/apache/fop/render/xml/XMLXMLHandler.java index eb1f4946b..da44bc725 100644 --- a/src/java/org/apache/fop/render/xml/XMLXMLHandler.java +++ b/src/java/org/apache/fop/render/xml/XMLXMLHandler.java @@ -18,20 +18,12 @@ package org.apache.fop.render.xml; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.apache.fop.render.Renderer; import org.apache.fop.render.XMLHandler; import org.apache.fop.render.RendererContext; +import org.apache.fop.util.DOM2SAX; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Attr; -import org.xml.sax.SAXException; import org.xml.sax.ContentHandler; -import org.xml.sax.ext.LexicalHandler; -import org.xml.sax.helpers.AttributesImpl; /** * XML handler for the XML renderer. @@ -41,104 +33,12 @@ public class XMLXMLHandler implements XMLHandler { /** Key for getting the TransformerHandler from the RendererContext */ public static final String HANDLER = "handler"; - /** Logging instance */ - private static Log log = LogFactory.getLog(XMLXMLHandler.class); - - private AttributesImpl atts = new AttributesImpl(); - /** @see org.apache.fop.render.XMLHandler */ public void handleXML(RendererContext context, org.w3c.dom.Document doc, String ns) throws Exception { ContentHandler handler = (ContentHandler) context.getProperty(HANDLER); - writeDocument(doc, handler); - } - - /** - * Writes the given document using the given TransformerHandler. - * @param doc DOM document - * @param handler TransformerHandler to write to - * @throws SAXException In case of a problem while writing XML - */ - public void writeDocument(Document doc, - ContentHandler handler) throws SAXException { - for (Node n = doc.getFirstChild(); n != null; - n = n.getNextSibling()) { - writeNode(n, handler); - } - } - - /** - * Writes a node using the given writer. - * @param node node to serialize - * @param handler ContentHandler to write to - * @throws SAXException In case of a problem while writing XML - */ - public void writeNode(Node node, ContentHandler handler) throws SAXException { - char[] ca; - switch (node.getNodeType()) { - case Node.ELEMENT_NODE: - atts.clear(); - - if (node.hasAttributes()) { - NamedNodeMap attr = node.getAttributes(); - int len = attr.getLength(); - for (int i = 0; i < len; i++) { - Attr a = (Attr) attr.item(i); - atts.addAttribute("", a.getNodeName(), a.getNodeName(), - "CDATA", a.getNodeValue()); - } - } - handler.startElement(node.getNamespaceURI(), - node.getLocalName(), node.getLocalName(), atts); - - Node c = node.getFirstChild(); - if (c != null) { - for (; c != null; c = c.getNextSibling()) { - writeNode(c, handler); - } - } - handler.endElement(node.getNamespaceURI(), node.getNodeName(), node.getNodeName()); - break; - case Node.TEXT_NODE: - ca = node.getNodeValue().toCharArray(); - handler.characters(ca, 0, ca.length); - break; - case Node.CDATA_SECTION_NODE: - ca = node.getNodeValue().toCharArray(); - if (handler instanceof LexicalHandler) { - LexicalHandler lh = (LexicalHandler)handler; - lh.startCDATA(); - handler.characters(ca, 0, ca.length); - lh.endCDATA(); - } else { - handler.characters(ca, 0, ca.length); - } - break; - case Node.ENTITY_REFERENCE_NODE: - log.warn("Ignoring ENTITY_REFERENCE_NODE. NYI"); - /* - writer.write("&"); - writer.write(); - writer.write(";"); - */ - break; - case Node.PROCESSING_INSTRUCTION_NODE: - handler.processingInstruction(node.getNodeName(), node.getNodeValue()); - break; - case Node.COMMENT_NODE: - ca = node.getNodeValue().toCharArray(); - if (handler instanceof LexicalHandler) { - LexicalHandler lh = (LexicalHandler)handler; - lh.comment(ca, 0, ca.length); - } - break; - case Node.DOCUMENT_TYPE_NODE: - break; - default: - throw new IllegalArgumentException("Unexpected node type (" - + node.getNodeType() + ")"); - } + DOM2SAX.writeDocument(doc, handler); } /** @see org.apache.fop.render.XMLHandler#supportsRenderer(org.apache.fop.render.Renderer) */ |