1 38 39 40 package com.sun.xml.fastinfoset.stax; 41 42 import javax.xml.namespace.QName ; 43 import javax.xml.namespace.NamespaceContext ; 44 import javax.xml.stream.Location; 45 import javax.xml.stream.XMLEventFactory; 46 import javax.xml.stream.events.*; 47 import java.util.Iterator ; 48 import com.sun.xml.fastinfoset.stax.events.*; 49 50 51 public class StAXEventFactory extends XMLEventFactory { 52 Location location = null; 53 54 55 public StAXEventFactory() { 56 } 57 64 public void setLocation(Location location) { 65 this.location = location; 66 } 67 68 76 public Attribute createAttribute(String prefix, String namespaceURI, String localName, String value) { 77 AttributeBase attr = new AttributeBase(prefix, namespaceURI, localName, value, null); 78 if(location != null)attr.setLocation(location); 79 return attr; 80 } 81 82 88 public Attribute createAttribute(String localName, String value) { 89 AttributeBase attr = new AttributeBase(localName, value); 90 if(location != null)attr.setLocation(location); 91 return attr; 92 } 93 94 public Attribute createAttribute(QName name, String value) { 95 AttributeBase attr = new AttributeBase(name, value); 96 if(location != null)attr.setLocation(location); 97 return attr; 98 } 99 100 105 public Namespace createNamespace(String namespaceURI) { 106 NamespaceBase event = new NamespaceBase(namespaceURI); 107 if(location != null)event.setLocation(location); 108 return event; 109 } 110 111 117 public Namespace createNamespace(String prefix, String namespaceURI) { 118 NamespaceBase event = new NamespaceBase(prefix, namespaceURI); 119 if(location != null)event.setLocation(location); 120 return event; 121 } 122 123 132 public StartElement createStartElement(QName name, Iterator attributes, Iterator namespaces) { 133 return createStartElement(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart(), attributes, namespaces); 134 } 135 136 public StartElement createStartElement(String prefix, String namespaceUri, String localName) { 137 StartElementEvent event = new StartElementEvent(prefix, namespaceUri, localName); 138 if(location != null)event.setLocation(location); 139 return event; 140 } 141 142 public StartElement createStartElement(String prefix, String namespaceUri, String localName, Iterator attributes, Iterator namespaces) { 143 return createStartElement(prefix, namespaceUri, localName, attributes, namespaces, null); 144 } 145 146 public StartElement createStartElement(String prefix, String namespaceUri, String localName, Iterator attributes, Iterator namespaces, NamespaceContext context) { 147 StartElementEvent elem = new StartElementEvent(prefix, namespaceUri, localName); 148 elem.addAttributes(attributes); 149 elem.addNamespaces(namespaces); 150 elem.setNamespaceContext(context); 151 if(location != null)elem.setLocation(location); 152 return elem; 153 } 154 155 162 public EndElement createEndElement(QName name, Iterator namespaces) { 163 return createEndElement(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart(), namespaces); 164 } 165 166 173 public EndElement createEndElement(String prefix, String namespaceUri, String localName) { 174 EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName); 175 if(location != null)event.setLocation(location); 176 return event; 177 } 178 179 188 public EndElement createEndElement(String prefix, String namespaceUri, String localName, Iterator namespaces) { 189 190 EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName); 191 if(namespaces!=null){ 192 while(namespaces.hasNext()) 193 event.addNamespace((Namespace)namespaces.next()); 194 } 195 if(location != null)event.setLocation(location); 196 return event; 197 } 198 199 205 public Characters createCharacters(String content) { 206 CharactersEvent charEvent = new CharactersEvent(content); 207 if(location != null)charEvent.setLocation(location); 208 return charEvent; 209 } 210 211 216 public Characters createCData(String content) { 217 CharactersEvent charEvent = new CharactersEvent(content, true); 218 if(location != null)charEvent.setLocation(location); 219 return charEvent; 220 } 221 222 227 public Characters createSpace(String content) { 228 CharactersEvent event = new CharactersEvent(content); 229 event.setSpace(true); 230 if(location != null)event.setLocation(location); 231 return event; 232 } 233 238 public Characters createIgnorableSpace(String content) { 239 CharactersEvent event = new CharactersEvent(content, false); 240 event.setSpace(true); 241 event.setIgnorable(true); 242 if(location != null)event.setLocation(location); 243 return event; 244 } 245 249 public StartDocument createStartDocument() { 250 StartDocumentEvent event = new StartDocumentEvent(); 251 if(location != null)event.setLocation(location); 252 return event; 253 } 254 255 261 public StartDocument createStartDocument(String encoding) { 262 StartDocumentEvent event = new StartDocumentEvent(encoding); 263 if(location != null)event.setLocation(location); 264 return event; 265 } 266 267 274 public StartDocument createStartDocument(String encoding, String version) { 275 StartDocumentEvent event = new StartDocumentEvent(encoding, version); 276 if(location != null)event.setLocation(location); 277 return event; 278 } 279 280 288 public StartDocument createStartDocument(String encoding, String version, boolean standalone) { 289 StartDocumentEvent event = new StartDocumentEvent(encoding, version); 290 event.setStandalone(standalone); 291 if(location != null)event.setLocation(location); 292 return event; 293 } 294 295 public EndDocument createEndDocument() { 296 EndDocumentEvent event =new EndDocumentEvent(); 297 if(location != null)event.setLocation(location); 298 return event; 299 } 300 301 307 public EntityReference createEntityReference(String name, EntityDeclaration entityDeclaration) { 308 EntityReferenceEvent event = new EntityReferenceEvent(name, entityDeclaration); 309 if(location != null)event.setLocation(location); 310 return event; 311 } 312 313 318 public Comment createComment(String text) { 319 CommentEvent charEvent = new CommentEvent(text); 320 if(location != null)charEvent.setLocation(location); 321 return charEvent; 322 } 323 324 331 public DTD createDTD(String dtd) { 332 DTDEvent dtdEvent = new DTDEvent(dtd); 333 if(location != null)dtdEvent.setLocation(location); 334 return dtdEvent; 335 } 336 337 338 344 public ProcessingInstruction createProcessingInstruction(String target, String data) { 345 ProcessingInstructionEvent event = new ProcessingInstructionEvent(target, data); 346 if(location != null)event.setLocation(location); 347 return event; 348 } 349 350 351 352 353 354 } 355 | Popular Tags |