Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

XMLObj.java 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * $Id$
  3. * ============================================================================
  4. * The Apache Software License, Version 1.1
  5. * ============================================================================
  6. *
  7. * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modifica-
  10. * tion, are permitted provided that the following conditions are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if any, must
  20. * include the following acknowledgment: "This product includes software
  21. * developed by the Apache Software Foundation (http://www.apache.org/)."
  22. * Alternately, this acknowledgment may appear in the software itself, if
  23. * and wherever such third-party acknowledgments normally appear.
  24. *
  25. * 4. The names "FOP" and "Apache Software Foundation" must not be used to
  26. * endorse or promote products derived from this software without prior
  27. * written permission. For written permission, please contact
  28. * apache@apache.org.
  29. *
  30. * 5. Products derived from this software may not be called "Apache", nor may
  31. * "Apache" appear in their name, without prior written permission of the
  32. * Apache Software Foundation.
  33. *
  34. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  35. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  36. * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  37. * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  38. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  39. * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  40. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  41. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  42. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  43. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44. * ============================================================================
  45. *
  46. * This software consists of voluntary contributions made by many individuals
  47. * on behalf of the Apache Software Foundation and was originally created by
  48. * James Tauber <jtauber@jtauber.com>. For more information on the Apache
  49. * Software Foundation, please see <http://www.apache.org/>.
  50. */
  51. package org.apache.fop.fo;
  52. // FOP
  53. import org.apache.fop.layout.Area;
  54. import org.apache.fop.apps.FOPException;
  55. import org.apache.fop.layout.LinkSet;
  56. import org.apache.fop.datatypes.IDReferences;
  57. import org.w3c.dom.Element;
  58. import org.w3c.dom.Document;
  59. import org.xml.sax.Attributes;
  60. import java.util.ArrayList;
  61. import java.util.HashMap;
  62. /**
  63. * Since SVG objects are not layed out then this class checks
  64. * that this element is not being layed out inside some incorrect
  65. * element.
  66. */
  67. public abstract class XMLObj extends FObj {
  68. protected String tagName;
  69. protected Element element;
  70. protected Document doc;
  71. /**
  72. *
  73. * @param parent the parent formatting object
  74. * @param propertyList the explicit properties of this object
  75. */
  76. public XMLObj(FObj parent, PropertyList propertyList, String tag,
  77. String systemId, int line, int column) {
  78. super(parent, propertyList, systemId, line, column);
  79. tagName = tag;
  80. }
  81. public abstract String getNameSpace();
  82. protected static HashMap ns = new HashMap();
  83. public void addGraphic(Document doc, Element parent) {
  84. this.doc = doc;
  85. element = doc.createElementNS(getNameSpace(), tagName);
  86. if(this.properties instanceof DirectPropertyListBuilder.AttrPropertyList) {
  87. Attributes attr = ((DirectPropertyListBuilder.AttrPropertyList)this.properties).getAttributes();
  88. for (int count = 0; count < attr.getLength(); count++) {
  89. String rf = attr.getValue(count);
  90. String qname = attr.getQName(count);
  91. if (qname.indexOf(":") == -1) {
  92. element.setAttribute(qname, rf);
  93. } else {
  94. String pref =
  95. qname.substring(0, qname.indexOf(":"));
  96. if (pref.equals("xmlns")) {
  97. ns.put(qname.substring(qname.indexOf(":")
  98. + 1), rf);
  99. }
  100. ns.put("xlink", "http://www.w3.org/1999/xlink");
  101. element.setAttributeNS((String)ns.get(pref),
  102. qname, rf);
  103. }
  104. }
  105. } else {
  106. }
  107. parent.appendChild(element);
  108. }
  109. public void buildTopLevel(Document doc, Element svgRoot) {
  110. // build up the info for the top level element
  111. if(this.properties instanceof DirectPropertyListBuilder.AttrPropertyList) {
  112. Attributes attr = ((DirectPropertyListBuilder.AttrPropertyList)this.properties).getAttributes();
  113. for (int count = 0; count < attr.getLength(); count++) {
  114. String rf = attr.getValue(count);
  115. String qname = attr.getQName(count);
  116. if (qname.indexOf(":") == -1) {
  117. element.setAttribute(qname, rf);
  118. } else {
  119. String pref =
  120. qname.substring(0, qname.indexOf(":"));
  121. if (pref.equals("xmlns")) {
  122. ns.put(qname.substring(qname.indexOf(":")
  123. + 1), rf);
  124. }
  125. ns.put("xlink", "http://www.w3.org/1999/xlink");
  126. element.setAttributeNS((String)ns.get(pref),
  127. qname, rf);
  128. }
  129. }
  130. } else {
  131. }
  132. }
  133. public Document createBasicDocument() {
  134. doc = null;
  135. element = null;
  136. try {
  137. // DOMImplementation impl = javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
  138. // String ns = GraphElementMapping.URI;
  139. // doc = impl.createDocument(ns, "graph", null);
  140. doc =
  141. javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
  142. Element el = doc.createElement("graph");
  143. doc.appendChild(el);
  144. element = doc.getDocumentElement();
  145. buildTopLevel(doc, element);
  146. } catch (Exception e) {
  147. e.printStackTrace();
  148. }
  149. return doc;
  150. }
  151. protected void addChild(FONode child) {
  152. if (child instanceof XMLObj) {
  153. ((XMLObj)child).addGraphic(doc, element);
  154. }
  155. }
  156. protected void addCharacters(char data[], int start, int length) {
  157. String str = new String(data, start, length);
  158. org.w3c.dom.Text text = doc.createTextNode(str);
  159. element.appendChild(text);
  160. }
  161. /**
  162. * layout this formatting object.
  163. *
  164. * @param area the area to layout the object into
  165. * @return the status of the layout
  166. */
  167. public int layout(Area area) throws FOPException {
  168. /* generate a warning */
  169. log.error("" + this.tagName + " outside foreign xml");
  170. /* return status */
  171. return Status.OK;
  172. }
  173. public void removeID(IDReferences idReferences) {}
  174. /**
  175. * These method overrides prevent problems with the different types.
  176. */
  177. public void setIsInTableCell() {}
  178. public void forceStartOffset(int offset) {}
  179. public void forceWidth(int width) {}
  180. public void resetMarker() {}
  181. public void setLinkSet(LinkSet linkSet) {}
  182. public ArrayList getMarkerSnapshot(ArrayList snapshot) {
  183. return snapshot;
  184. }
  185. public void rollback(ArrayList snapshot) {}
  186. protected void setWritingMode() {}
  187. }