1 51 package org.apache.fop.fo; 52 53 import org.apache.fop.layout.Area; 55 import org.apache.fop.apps.FOPException; 56 import org.apache.fop.layout.LinkSet; 57 import org.apache.fop.datatypes.IDReferences; 58 59 import org.w3c.dom.*; 60 import org.xml.sax.Attributes ; 61 62 import java.util.ArrayList ; 63 import java.util.HashMap ; 64 65 70 public abstract class XMLObj extends FObj { 71 72 protected String tagName; 73 74 protected Element element; 75 protected Document doc; 76 77 82 public XMLObj(FObj parent, PropertyList propertyList, String tag, 83 String systemId, int line, int column) { 84 super(parent, propertyList, systemId, line, column); 85 tagName = tag; 86 } 87 88 public abstract String getNameSpace(); 89 90 protected static HashMap ns = new HashMap (); 91 92 public void addGraphic(Document doc, Element parent) { 93 this.doc = doc; 94 element = doc.createElementNS(getNameSpace(), tagName); 95 96 if(this.properties instanceof DirectPropertyListBuilder.AttrPropertyList) { 97 Attributes attr = ((DirectPropertyListBuilder.AttrPropertyList)this.properties).getAttributes(); 98 for (int count = 0; count < attr.getLength(); count++) { 99 String rf = attr.getValue(count); 100 String qname = attr.getQName(count); 101 if (qname.indexOf(":") == -1) { 102 element.setAttribute(qname, rf); 103 } else { 104 String pref = 105 qname.substring(0, qname.indexOf(":")); 106 if (pref.equals("xmlns")) { 107 ns.put(qname.substring(qname.indexOf(":") 108 + 1), rf); 109 } 110 ns.put("xlink", "http://www.w3.org/1999/xlink"); 111 element.setAttributeNS((String )ns.get(pref), 112 qname, rf); 113 } 114 } 115 } else { 116 } 117 118 parent.appendChild(element); 119 } 120 121 public void buildTopLevel(Document doc, Element svgRoot) { 122 if(this.properties instanceof DirectPropertyListBuilder.AttrPropertyList) { 124 Attributes attr = ((DirectPropertyListBuilder.AttrPropertyList)this.properties).getAttributes(); 125 for (int count = 0; count < attr.getLength(); count++) { 126 String rf = attr.getValue(count); 127 String qname = attr.getQName(count); 128 if (qname.indexOf(":") == -1) { 129 element.setAttribute(qname, rf); 130 } else { 131 String pref = 132 qname.substring(0, qname.indexOf(":")); 133 if (pref.equals("xmlns")) { 134 ns.put(qname.substring(qname.indexOf(":") 135 + 1), rf); 136 } 137 ns.put("xlink", "http://www.w3.org/1999/xlink"); 138 element.setAttributeNS((String )ns.get(pref), 139 qname, rf); 140 } 141 } 142 } else { 143 } 144 } 145 146 public Document createBasicDocument() { 147 doc = null; 148 149 element = null; 150 try { 151 doc = 155 javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); 156 Element el = doc.createElement("graph"); 157 doc.appendChild(el); 158 159 element = doc.getDocumentElement(); 160 buildTopLevel(doc, element); 161 } catch (Exception e) { 162 e.printStackTrace(); 163 } 164 return doc; 165 } 166 167 protected void addChild(FONode child) { 168 if (child instanceof XMLObj) { 169 ((XMLObj)child).addGraphic(doc, element); 170 } 171 } 172 173 protected void addCharacters(char data[], int start, int length) { 174 String str = new String (data, start, length); 175 org.w3c.dom.Text text = doc.createTextNode(str); 176 element.appendChild(text); 177 } 178 179 185 public int layout(Area area) throws FOPException { 186 187 log.error("" + this.tagName + " outside foreign xml"); 188 189 190 return Status.OK; 191 } 192 193 public void removeID(IDReferences idReferences) {} 194 195 198 public void setIsInTableCell() {} 199 200 public void forceStartOffset(int offset) {} 201 202 public void forceWidth(int width) {} 203 204 public void resetMarker() {} 205 206 public void setLinkSet(LinkSet linkSet) {} 207 208 public ArrayList getMarkerSnapshot(ArrayList snapshot) { 209 return snapshot; 210 } 211 212 public void rollback(ArrayList snapshot) {} 213 214 protected void setWritingMode() {} 215 } 216 217 | Popular Tags |