You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XMLObj.java 6.8KB

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
18 years ago
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
18 years ago
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
18 years ago
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
18 years ago
Merged revisions 670689,670723,670760-670761,670763,670765-670767,670770,670773,670777,671145,672010,672026 via svnmerge from https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk ........ r670689 | adelmelle | 2008-06-23 19:01:25 +0100 (Mon, 23 Jun 2008) | 1 line Fix XMLObj.addCharacters(): incorrect after r670341 ........ r670723 | adelmelle | 2008-06-23 20:56:51 +0100 (Mon, 23 Jun 2008) | 1 line Javadoc modification + addition of clarifying comments ........ r670760 | adelmelle | 2008-06-23 22:18:45 +0100 (Mon, 23 Jun 2008) | 1 line Javadoc fixup ........ r670761 | adelmelle | 2008-06-23 22:21:09 +0100 (Mon, 23 Jun 2008) | 1 line Minor cleanup: remove unused parameter from method signature ........ r670763 | adelmelle | 2008-06-23 22:22:48 +0100 (Mon, 23 Jun 2008) | 1 line Minor cleanup: remove double storage of the FObj ........ r670765 | adelmelle | 2008-06-23 22:24:46 +0100 (Mon, 23 Jun 2008) | 1 line Minor cleanup: remove redundant cast ........ r670766 | adelmelle | 2008-06-23 22:25:30 +0100 (Mon, 23 Jun 2008) | 1 line Minor cleanup: remove redundant cast ........ r670767 | adelmelle | 2008-06-23 22:26:56 +0100 (Mon, 23 Jun 2008) | 1 line Javadoc fixup ........ r670770 | adelmelle | 2008-06-23 22:29:53 +0100 (Mon, 23 Jun 2008) | 1 line Minor cleanup: simplified conditional ........ r670773 | adelmelle | 2008-06-23 22:32:31 +0100 (Mon, 23 Jun 2008) | 1 line A nit... ........ r670777 | adelmelle | 2008-06-23 22:39:19 +0100 (Mon, 23 Jun 2008) | 1 line Fix imports... ........ r671145 | maxberger | 2008-06-24 12:59:33 +0100 (Tue, 24 Jun 2008) | 2 lines Another character handling problem, replaced end-start by length ........ r672010 | adelmelle | 2008-06-26 20:44:20 +0100 (Thu, 26 Jun 2008) | 1 line Fixed a possible NullPointerException: if the citation appears in a fo:marker, the property will only be parsed if the marker is retrieved... ........ r672026 | acumiskey | 2008-06-26 21:49:11 +0100 (Thu, 26 Jun 2008) | 5 lines Some basic cleanup. * Duplicated/redundant PSDictionary, PSPageDeviceDictionary and PSDictionaryFormatException removed and now referenced from xmlgraphics commons. * Updated xmlgraphics commons jar containing migrated PSPageDeviceDictionary class. ........ git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@672235 13f79535-47bb-0310-9956-ffa450edef68
16 years ago
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
18 years ago
Merged revisions 719616,719629,719646,719654 via svnmerge from https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk ........ r719616 | jeremias | 2008-11-21 16:07:58 +0000 (Fri, 21 Nov 2008) | 1 line Added support for SVG 1.2 inside fo:instream-foreign-object. The code just used the basic SVGDOMImplementation for SVG 1.1. Now it delegates the DOM building to Batik code instead of to a normal DOM builder. ........ r719629 | jeremias | 2008-11-21 16:33:33 +0000 (Fri, 21 Nov 2008) | 2 lines Fix for unit test failure in transcoder tests (NullPointerException): Have to pass the root PSGraphics2D to NativeTextHandler instead of the PSGenerator as this one hasn't been initialized in PSGraphics2D when the NativeTextHandler is built in AbstractPSTranscoder. ........ r719646 | jeremias | 2008-11-21 17:24:32 +0000 (Fri, 21 Nov 2008) | 1 line Fixed possible ClassCastException that was caused by my earlier attempt to support SVG 1.2. Batik's SAXSVGDocumentFactory doesn't currently deal well with the case when namespaces are declared outside of its scope. Worked around that by doing the SVG version detection in FOP code. SVG12DOMImplementation is obtained by reflection in order to keep backwards compatilibility with earlier Batik versions that don't support SVG 1.2. ........ r719654 | jeremias | 2008-11-21 17:44:08 +0000 (Fri, 21 Nov 2008) | 1 line This actually fixes a bug. ........ git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@720850 13f79535-47bb-0310-9956-ffa450edef68
15 years ago
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
18 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.fo;
  19. // Java
  20. import java.awt.geom.Point2D;
  21. import java.util.HashMap;
  22. import javax.xml.parsers.DocumentBuilderFactory;
  23. import org.w3c.dom.Document;
  24. import org.w3c.dom.Element;
  25. import org.xml.sax.Attributes;
  26. import org.xml.sax.Locator;
  27. import org.apache.fop.apps.FOPException;
  28. import org.apache.fop.datatypes.Length;
  29. import org.apache.fop.util.ContentHandlerFactory.ObjectBuiltListener;
  30. /**
  31. * Abstract class modelling generic, non-XSL-FO XML objects. Such objects are
  32. * stored in a DOM.
  33. */
  34. public abstract class XMLObj extends FONode implements ObjectBuiltListener {
  35. private static final String XMLNS_NAMESPACE_URI = "http://www.w3.org/2000/xmlns/";
  36. // temp reference for attributes
  37. private Attributes attr = null;
  38. /** DOM element representing this node */
  39. protected Element element;
  40. /** DOM document containing this node */
  41. protected Document doc;
  42. /** Name of the node */
  43. protected String name;
  44. /**
  45. * Base constructor
  46. *
  47. * @param parent {@link FONode} that is the parent of this object
  48. */
  49. public XMLObj(FONode parent) {
  50. super(parent);
  51. }
  52. /**
  53. * {@inheritDoc}
  54. * <br>Here, blocks XSL-FO's from having non-FO parents.
  55. */
  56. protected void validateChildNode(Locator loc, String nsURI, String localName)
  57. throws ValidationException {
  58. if (FO_URI.equals(nsURI)) {
  59. invalidChildError(loc, nsURI, localName);
  60. }
  61. }
  62. /** {@inheritDoc} */
  63. public void processNode(String elementName, Locator locator,
  64. Attributes attlist, PropertyList propertyList) throws FOPException {
  65. setLocator(locator);
  66. name = elementName;
  67. attr = attlist;
  68. }
  69. /**
  70. * @return DOM document representing this foreign XML
  71. */
  72. public Document getDOMDocument() {
  73. return doc;
  74. }
  75. /**
  76. * Returns the dimensions of the generated area in pts.
  77. *
  78. * @param view Point2D instance to receive the dimensions
  79. * @return the requested dimensions in pts.
  80. */
  81. public Point2D getDimension(Point2D view) {
  82. return null;
  83. }
  84. /**
  85. * Retrieve the intrinsic alignment-adjust of the child element.
  86. *
  87. * @return the intrinsic alignment-adjust.
  88. */
  89. public Length getIntrinsicAlignmentAdjust() {
  90. return null;
  91. }
  92. /** {@inheritDoc} */
  93. public String getLocalName() {
  94. return name;
  95. }
  96. private static HashMap ns = new HashMap();
  97. static {
  98. ns.put("xlink", "http://www.w3.org/1999/xlink");
  99. }
  100. /**
  101. * Add an element to the DOM document
  102. * @param doc DOM document to which to add an element
  103. * @param parent the parent element of the element that is being added
  104. */
  105. public void addElement(Document doc, Element parent) {
  106. this.doc = doc;
  107. element = doc.createElementNS(getNamespaceURI(), name);
  108. setAttributes(element, attr);
  109. attr = null;
  110. parent.appendChild(element);
  111. }
  112. private static void setAttributes(Element element, Attributes attr) {
  113. for (int count = 0; count < attr.getLength(); count++) {
  114. String rf = attr.getValue(count);
  115. String qname = attr.getQName(count);
  116. int idx = qname.indexOf(":");
  117. if (idx == -1) {
  118. element.setAttribute(qname, rf);
  119. } else {
  120. String pref = qname.substring(0, idx);
  121. String tail = qname.substring(idx + 1);
  122. if (pref.equals("xmlns")) {
  123. ns.put(tail, rf);
  124. } else {
  125. element.setAttributeNS((String)ns.get(pref), tail, rf);
  126. }
  127. }
  128. }
  129. }
  130. /**
  131. * Add the top-level element to the DOM document
  132. *
  133. * @param doc DOM document
  134. * @param svgRoot non-XSL-FO element to be added as the root of this document
  135. */
  136. public void buildTopLevel(Document doc, Element svgRoot) {
  137. // build up the info for the top level element
  138. setAttributes(element, attr);
  139. }
  140. /**
  141. * Create an empty DOM document
  142. *
  143. * @return DOM document
  144. */
  145. public Document createBasicDocument() {
  146. doc = null;
  147. element = null;
  148. try {
  149. DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
  150. fact.setNamespaceAware(true);
  151. doc = fact.newDocumentBuilder().newDocument();
  152. Element el = doc.createElementNS(getNamespaceURI(), name);
  153. doc.appendChild(el);
  154. element = doc.getDocumentElement();
  155. buildTopLevel(doc, element);
  156. if (!element.hasAttributeNS(XMLNS_NAMESPACE_URI, "xmlns")) {
  157. element.setAttributeNS(XMLNS_NAMESPACE_URI, "xmlns",
  158. getNamespaceURI());
  159. }
  160. } catch (Exception e) {
  161. //TODO this is ugly because there may be subsequent failures like NPEs
  162. log.error("Error while trying to instantiate a DOM Document", e);
  163. }
  164. return doc;
  165. }
  166. /** {@inheritDoc} */
  167. protected void addChildNode(FONode child) {
  168. if (child instanceof XMLObj) {
  169. ((XMLObj)child).addElement(doc, element);
  170. } else {
  171. // in theory someone might want to embed some defined
  172. // xml (eg. fo) inside the foreign xml
  173. // they could use a different namespace
  174. log.debug("Invalid element: " + child.getName() + " inside foreign xml markup");
  175. }
  176. }
  177. /** {@inheritDoc} */
  178. protected void characters(char[] data, int start, int length,
  179. PropertyList pList, Locator locator) throws FOPException {
  180. super.characters(data, start, length, pList, locator);
  181. String str = new String(data, start, length);
  182. org.w3c.dom.Text text = doc.createTextNode(str);
  183. element.appendChild(text);
  184. }
  185. /** {@inheritDoc} */
  186. public void notifyObjectBuilt(Object obj) {
  187. this.doc = (Document)obj;
  188. this.element = this.doc.getDocumentElement();
  189. }
  190. }