001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Adam Megacz
028: */
029:
030: package com.caucho.xml.stream;
031:
032: import javax.xml.namespace.NamespaceContext;
033: import javax.xml.namespace.QName;
034: import javax.xml.stream.Location;
035: import javax.xml.stream.XMLEventFactory;
036: import javax.xml.stream.events.*;
037: import java.util.Iterator;
038: import java.util.HashMap;
039:
040: import com.caucho.xml.stream.events.*;
041:
042: public class XMLEventFactoryImpl extends XMLEventFactory {
043:
044: public XMLEventFactoryImpl() {
045: }
046:
047: public Attribute createAttribute(QName name, String value) {
048: return new AttributeImpl(name, value);
049: }
050:
051: public Attribute createAttribute(String localName, String value) {
052: return new AttributeImpl(new QName(localName), value);
053: }
054:
055: public Attribute createAttribute(String prefix,
056: String namespaceURI, String localName, String value) {
057: return new AttributeImpl(new QName(namespaceURI, localName,
058: prefix), value);
059: }
060:
061: public Characters createCData(String content) {
062: return new CharactersImpl(content, true, false, false);
063: }
064:
065: public Characters createCharacters(String content) {
066: return new CharactersImpl(content, false, false, false);
067: }
068:
069: public Comment createComment(String text) {
070: return new CommentImpl(text);
071: }
072:
073: public DTD createDTD(String dtd) {
074: return new DTDImpl(dtd);
075: }
076:
077: public EndDocument createEndDocument() {
078: return new EndDocumentImpl();
079: }
080:
081: public EndElement createEndElement(QName name, Iterator namespaces) {
082: return new EndElementImpl(name, namespaces);
083: }
084:
085: public EndElement createEndElement(String prefix,
086: String namespaceUri, String localName) {
087: return new EndElementImpl(new QName(namespaceUri, localName,
088: prefix));
089: }
090:
091: public EndElement createEndElement(String prefix,
092: String namespaceUri, String localName, Iterator namespaces) {
093: return new EndElementImpl(new QName(namespaceUri, localName,
094: prefix), namespaces);
095: }
096:
097: public EntityReference createEntityReference(String name,
098: EntityDeclaration declaration) {
099: return new EntityReferenceImpl(name, declaration);
100: }
101:
102: public Characters createIgnorableSpace(String content) {
103: return new CharactersImpl(content, false, true, false);
104: }
105:
106: public Namespace createNamespace(String namespaceURI) {
107: return new NamespaceImpl(namespaceURI, null);
108: }
109:
110: public Namespace createNamespace(String prefix, String namespaceUri) {
111: return new NamespaceImpl(namespaceUri, prefix);
112: }
113:
114: public ProcessingInstruction createProcessingInstruction(
115: String target, String data) {
116: return new ProcessingInstructionImpl(target, data);
117: }
118:
119: public Characters createSpace(String content) {
120: return new CharactersImpl(content, false, false, true);
121: }
122:
123: public StartDocument createStartDocument() {
124: return new StartDocumentImpl();
125: }
126:
127: public StartDocument createStartDocument(String encoding) {
128: return new StartDocumentImpl(true, encoding, null, "1.0",
129: false, false);
130: }
131:
132: public StartDocument createStartDocument(String encoding,
133: String version) {
134: return new StartDocumentImpl(true, encoding, null, version,
135: false, false);
136: }
137:
138: public StartDocument createStartDocument(String encoding,
139: String version, boolean standalone) {
140: return new StartDocumentImpl(true, encoding, null, version,
141: standalone, true);
142: }
143:
144: public StartElement createStartElement(QName name,
145: Iterator attributes, Iterator namespaces) {
146: return createStartElement(name, attributes, namespaces, null);
147: }
148:
149: public StartElement createStartElement(String prefix,
150: String namespaceUri, String localName) {
151: return createStartElement(prefix, namespaceUri, localName,
152: null, null);
153: }
154:
155: public StartElement createStartElement(String prefix,
156: String namespaceUri, String localName, Iterator attributes,
157: Iterator namespaces) {
158: return createStartElement(prefix, namespaceUri, localName,
159: attributes, namespaces, null);
160: }
161:
162: public StartElement createStartElement(String prefix,
163: String namespaceUri, String localName, Iterator attributes,
164: Iterator namespaces, NamespaceContext context) {
165: return createStartElement(new QName(namespaceUri, localName,
166: prefix), attributes, namespaces, context);
167: }
168:
169: private StartElement createStartElement(QName name,
170: Iterator attributes, Iterator namespaces,
171: NamespaceContext context) {
172: HashMap<QName, Attribute> attributeMap = new HashMap<QName, Attribute>();
173: HashMap<String, Namespace> namespaceMap = new HashMap<String, Namespace>();
174:
175: if (attributes != null) {
176: while (attributes.hasNext()) {
177: Attribute attribute = (Attribute) attributes.next();
178: attributeMap.put(attribute.getName(), attribute);
179: }
180: }
181:
182: if (namespaces != null) {
183: while (namespaces.hasNext()) {
184: Namespace namespace = (Namespace) namespaces.next();
185: namespaceMap.put(namespace.getPrefix(), namespace);
186: }
187: }
188:
189: return new StartElementImpl(name, attributeMap, namespaceMap,
190: context);
191: }
192:
193: public void setLocation(Location location) {
194: throw new UnsupportedOperationException();
195: }
196:
197: }
|