1 |
14 |
jlechner |
/* XMLEventFactoryImpl.java --
|
2 |
|
|
Copyright (C) 2005 Free Software Foundation, Inc.
|
3 |
|
|
|
4 |
|
|
This file is part of GNU Classpath.
|
5 |
|
|
|
6 |
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
7 |
|
|
it under the terms of the GNU General Public License as published by
|
8 |
|
|
the Free Software Foundation; either version 2, or (at your option)
|
9 |
|
|
any later version.
|
10 |
|
|
|
11 |
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
12 |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
|
|
General Public License for more details.
|
15 |
|
|
|
16 |
|
|
You should have received a copy of the GNU General Public License
|
17 |
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
18 |
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
|
|
02110-1301 USA.
|
20 |
|
|
|
21 |
|
|
Linking this library statically or dynamically with other modules is
|
22 |
|
|
making a combined work based on this library. Thus, the terms and
|
23 |
|
|
conditions of the GNU General Public License cover the whole
|
24 |
|
|
combination.
|
25 |
|
|
|
26 |
|
|
As a special exception, the copyright holders of this library give you
|
27 |
|
|
permission to link this library with independent modules to produce an
|
28 |
|
|
executable, regardless of the license terms of these independent
|
29 |
|
|
modules, and to copy and distribute the resulting executable under
|
30 |
|
|
terms of your choice, provided that you also meet, for each linked
|
31 |
|
|
independent module, the terms and conditions of the license of that
|
32 |
|
|
module. An independent module is a module which is not derived from
|
33 |
|
|
or based on this library. If you modify this library, you may extend
|
34 |
|
|
this exception to your version of the library, but you are not
|
35 |
|
|
obligated to do so. If you do not wish to do so, delete this
|
36 |
|
|
exception statement from your version. */
|
37 |
|
|
|
38 |
|
|
package gnu.xml.stream;
|
39 |
|
|
|
40 |
|
|
import java.util.Collections;
|
41 |
|
|
import java.util.Iterator;
|
42 |
|
|
import java.util.LinkedList;
|
43 |
|
|
import javax.xml.XMLConstants;
|
44 |
|
|
import javax.xml.namespace.NamespaceContext;
|
45 |
|
|
import javax.xml.namespace.QName;
|
46 |
|
|
import javax.xml.stream.Location;
|
47 |
|
|
import javax.xml.stream.XMLEventFactory;
|
48 |
|
|
import javax.xml.stream.events.Attribute;
|
49 |
|
|
import javax.xml.stream.events.Characters;
|
50 |
|
|
import javax.xml.stream.events.Comment;
|
51 |
|
|
import javax.xml.stream.events.DTD;
|
52 |
|
|
import javax.xml.stream.events.EndDocument;
|
53 |
|
|
import javax.xml.stream.events.EndElement;
|
54 |
|
|
import javax.xml.stream.events.EntityDeclaration;
|
55 |
|
|
import javax.xml.stream.events.EntityReference;
|
56 |
|
|
import javax.xml.stream.events.Namespace;
|
57 |
|
|
import javax.xml.stream.events.ProcessingInstruction;
|
58 |
|
|
import javax.xml.stream.events.StartDocument;
|
59 |
|
|
import javax.xml.stream.events.StartElement;
|
60 |
|
|
|
61 |
|
|
/**
|
62 |
|
|
* Factory for XML events.
|
63 |
|
|
*
|
64 |
|
|
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
65 |
|
|
*/
|
66 |
|
|
public class XMLEventFactoryImpl
|
67 |
|
|
extends XMLEventFactory
|
68 |
|
|
{
|
69 |
|
|
|
70 |
|
|
protected Location location;
|
71 |
|
|
|
72 |
|
|
public void setLocation(Location location)
|
73 |
|
|
{
|
74 |
|
|
this.location = location;
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
public Attribute createAttribute(String prefix, String namespaceURI,
|
78 |
|
|
String localName, String value)
|
79 |
|
|
{
|
80 |
|
|
return new AttributeImpl(location,
|
81 |
|
|
new QName(namespaceURI, localName, prefix),
|
82 |
|
|
value, QName.valueOf("CDATA"), true);
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
public Attribute createAttribute(String localName, String value)
|
86 |
|
|
{
|
87 |
|
|
return new AttributeImpl(location,
|
88 |
|
|
new QName(localName),
|
89 |
|
|
value, QName.valueOf("CDATA"), true);
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
public Attribute createAttribute(QName name, String value)
|
93 |
|
|
{
|
94 |
|
|
return new AttributeImpl(location, name, value,
|
95 |
|
|
QName.valueOf("CDATA"), true);
|
96 |
|
|
}
|
97 |
|
|
|
98 |
|
|
public Namespace createNamespace(String namespaceURI)
|
99 |
|
|
{
|
100 |
|
|
return new NamespaceImpl(location,
|
101 |
|
|
XMLConstants.DEFAULT_NS_PREFIX, namespaceURI);
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
public Namespace createNamespace(String prefix, String namespaceUri)
|
105 |
|
|
{
|
106 |
|
|
return new NamespaceImpl(location, prefix, namespaceUri);
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
public StartElement createStartElement(QName name,
|
110 |
|
|
Iterator attributes,
|
111 |
|
|
Iterator namespaces)
|
112 |
|
|
{
|
113 |
|
|
return new StartElementImpl(location, name,
|
114 |
|
|
createLinkedList(attributes),
|
115 |
|
|
createLinkedList(namespaces),
|
116 |
|
|
null);
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
public StartElement createStartElement(String prefix,
|
120 |
|
|
String namespaceUri,
|
121 |
|
|
String localName)
|
122 |
|
|
{
|
123 |
|
|
return new StartElementImpl(location,
|
124 |
|
|
new QName(namespaceUri, localName, prefix),
|
125 |
|
|
Collections.EMPTY_LIST,
|
126 |
|
|
Collections.EMPTY_LIST,
|
127 |
|
|
null);
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
public StartElement createStartElement(String prefix,
|
131 |
|
|
String namespaceUri,
|
132 |
|
|
String localName,
|
133 |
|
|
Iterator attributes,
|
134 |
|
|
Iterator namespaces)
|
135 |
|
|
{
|
136 |
|
|
return new StartElementImpl(location,
|
137 |
|
|
new QName(namespaceUri, localName, prefix),
|
138 |
|
|
createLinkedList(attributes),
|
139 |
|
|
createLinkedList(namespaces),
|
140 |
|
|
null);
|
141 |
|
|
}
|
142 |
|
|
|
143 |
|
|
public StartElement createStartElement(String prefix,
|
144 |
|
|
String namespaceUri,
|
145 |
|
|
String localName,
|
146 |
|
|
Iterator attributes,
|
147 |
|
|
Iterator namespaces,
|
148 |
|
|
NamespaceContext context)
|
149 |
|
|
{
|
150 |
|
|
return new StartElementImpl(location,
|
151 |
|
|
new QName(namespaceUri, localName, prefix),
|
152 |
|
|
createLinkedList(attributes),
|
153 |
|
|
createLinkedList(namespaces),
|
154 |
|
|
context);
|
155 |
|
|
}
|
156 |
|
|
|
157 |
|
|
public EndElement createEndElement(QName name,
|
158 |
|
|
Iterator namespaces)
|
159 |
|
|
{
|
160 |
|
|
return new EndElementImpl(location, name,
|
161 |
|
|
createLinkedList(namespaces));
|
162 |
|
|
}
|
163 |
|
|
|
164 |
|
|
public EndElement createEndElement(String prefix,
|
165 |
|
|
String namespaceUri,
|
166 |
|
|
String localName)
|
167 |
|
|
{
|
168 |
|
|
return new EndElementImpl(location,
|
169 |
|
|
new QName(namespaceUri, localName, prefix),
|
170 |
|
|
Collections.EMPTY_LIST);
|
171 |
|
|
}
|
172 |
|
|
|
173 |
|
|
public EndElement createEndElement(String prefix,
|
174 |
|
|
String namespaceUri,
|
175 |
|
|
String localName,
|
176 |
|
|
Iterator namespaces)
|
177 |
|
|
{
|
178 |
|
|
return new EndElementImpl(location,
|
179 |
|
|
new QName(namespaceUri, localName, prefix),
|
180 |
|
|
createLinkedList(namespaces));
|
181 |
|
|
}
|
182 |
|
|
|
183 |
|
|
public Characters createCharacters(String content)
|
184 |
|
|
{
|
185 |
|
|
return new CharactersImpl(location, content, false, false, false);
|
186 |
|
|
}
|
187 |
|
|
|
188 |
|
|
public Characters createCData(String content)
|
189 |
|
|
{
|
190 |
|
|
return new CharactersImpl(location, content, false, true, false);
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
public Characters createSpace(String content)
|
194 |
|
|
{
|
195 |
|
|
return new CharactersImpl(location, content, true, false, false);
|
196 |
|
|
}
|
197 |
|
|
|
198 |
|
|
public Characters createIgnorableSpace(String content)
|
199 |
|
|
{
|
200 |
|
|
return new CharactersImpl(location, content, true, false, true);
|
201 |
|
|
}
|
202 |
|
|
|
203 |
|
|
public StartDocument createStartDocument()
|
204 |
|
|
{
|
205 |
|
|
return new StartDocumentImpl(location, null, "UTF-8", "1.0",
|
206 |
|
|
false, false, false);
|
207 |
|
|
}
|
208 |
|
|
|
209 |
|
|
public StartDocument createStartDocument(String encoding,
|
210 |
|
|
String version,
|
211 |
|
|
boolean standalone)
|
212 |
|
|
{
|
213 |
|
|
return new StartDocumentImpl(location, null, encoding, version,
|
214 |
|
|
standalone, true, true);
|
215 |
|
|
}
|
216 |
|
|
|
217 |
|
|
public StartDocument createStartDocument(String encoding,
|
218 |
|
|
String version)
|
219 |
|
|
{
|
220 |
|
|
return new StartDocumentImpl(location, null, encoding, version,
|
221 |
|
|
false, false, true);
|
222 |
|
|
}
|
223 |
|
|
|
224 |
|
|
public StartDocument createStartDocument(String encoding)
|
225 |
|
|
{
|
226 |
|
|
return new StartDocumentImpl(location, null, encoding, "1.0",
|
227 |
|
|
false, false, true);
|
228 |
|
|
}
|
229 |
|
|
|
230 |
|
|
public EndDocument createEndDocument()
|
231 |
|
|
{
|
232 |
|
|
return new EndDocumentImpl(location);
|
233 |
|
|
}
|
234 |
|
|
|
235 |
|
|
public EntityReference createEntityReference(String name,
|
236 |
|
|
//EntityDeclaration declaration)
|
237 |
|
|
String replacementText)
|
238 |
|
|
{
|
239 |
|
|
//return new EntityReferenceImpl(location, declaration, name);
|
240 |
|
|
return new EntityReferenceImpl(location, name, null, null, null,
|
241 |
|
|
replacementText);
|
242 |
|
|
}
|
243 |
|
|
|
244 |
|
|
public Comment createComment(String text)
|
245 |
|
|
{
|
246 |
|
|
return new CommentImpl(location, text);
|
247 |
|
|
}
|
248 |
|
|
|
249 |
|
|
public ProcessingInstruction createProcessingInstruction(String target,
|
250 |
|
|
String data)
|
251 |
|
|
{
|
252 |
|
|
return new ProcessingInstructionImpl(location, target, data);
|
253 |
|
|
}
|
254 |
|
|
|
255 |
|
|
public DTD createDTD(String dtd)
|
256 |
|
|
{
|
257 |
|
|
return new DTDImpl(location, dtd, null,
|
258 |
|
|
Collections.EMPTY_LIST,
|
259 |
|
|
Collections.EMPTY_LIST);
|
260 |
|
|
}
|
261 |
|
|
|
262 |
|
|
LinkedList createLinkedList(Iterator i)
|
263 |
|
|
{
|
264 |
|
|
LinkedList ret = new LinkedList();
|
265 |
|
|
while (i.hasNext())
|
266 |
|
|
ret.add(i.next());
|
267 |
|
|
return ret;
|
268 |
|
|
}
|
269 |
|
|
|
270 |
|
|
}
|
271 |
|
|
|