12005
|
1 |
/*
|
42802
|
2 |
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
|
12005
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package com.sun.xml.internal.stream.events;
|
|
27 |
|
42802
|
28 |
import java.util.Iterator;
|
|
29 |
import javax.xml.namespace.NamespaceContext;
|
|
30 |
import javax.xml.namespace.QName;
|
12005
|
31 |
import javax.xml.stream.XMLEventFactory;
|
|
32 |
import javax.xml.stream.Location;
|
42802
|
33 |
import javax.xml.stream.events.Attribute;
|
|
34 |
import javax.xml.stream.events.Characters;
|
|
35 |
import javax.xml.stream.events.ProcessingInstruction;
|
12005
|
36 |
import javax.xml.stream.events.Namespace;
|
|
37 |
import javax.xml.stream.events.EntityDeclaration;
|
42802
|
38 |
import javax.xml.stream.events.EntityReference;
|
|
39 |
import javax.xml.stream.events.StartDocument;
|
|
40 |
import javax.xml.stream.events.StartElement;
|
12005
|
41 |
|
|
42 |
|
|
43 |
/**
|
|
44 |
*
|
48412
|
45 |
* @author Neeraj Bajaj, k venugopal
|
12005
|
46 |
*/
|
|
47 |
public class XMLEventFactoryImpl extends XMLEventFactory {
|
|
48 |
|
|
49 |
Location location = null;
|
|
50 |
/** Creates a new instance of XMLEventFactory */
|
|
51 |
public XMLEventFactoryImpl() {
|
|
52 |
}
|
|
53 |
|
42802
|
54 |
@Override
|
|
55 |
public Attribute createAttribute(String localName, String value) {
|
12005
|
56 |
AttributeImpl attr = new AttributeImpl(localName, value);
|
|
57 |
if(location != null)attr.setLocation(location);
|
|
58 |
return attr;
|
|
59 |
}
|
|
60 |
|
42802
|
61 |
@Override
|
|
62 |
public Attribute createAttribute(QName name, String value) {
|
12005
|
63 |
return createAttribute(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart(), value);
|
|
64 |
}
|
|
65 |
|
42802
|
66 |
@Override
|
|
67 |
public Attribute createAttribute(String prefix, String namespaceURI, String localName, String value) {
|
12005
|
68 |
AttributeImpl attr = new AttributeImpl(prefix, namespaceURI, localName, value, null);
|
|
69 |
if(location != null)attr.setLocation(location);
|
|
70 |
return attr;
|
|
71 |
}
|
|
72 |
|
42802
|
73 |
@Override
|
|
74 |
public Characters createCData(String content) {
|
12005
|
75 |
//stax doesn't have separate CDATA event. This is taken care by
|
|
76 |
//CHRACTERS event setting the cdata flag to true.
|
|
77 |
CharacterEvent charEvent = new CharacterEvent(content, true);
|
|
78 |
if(location != null)charEvent.setLocation(location);
|
|
79 |
return charEvent;
|
|
80 |
}
|
|
81 |
|
42802
|
82 |
@Override
|
|
83 |
public Characters createCharacters(String content) {
|
12005
|
84 |
CharacterEvent charEvent = new CharacterEvent(content);
|
|
85 |
if(location != null)charEvent.setLocation(location);
|
|
86 |
return charEvent;
|
|
87 |
}
|
|
88 |
|
42802
|
89 |
@Override
|
12005
|
90 |
public javax.xml.stream.events.Comment createComment(String text) {
|
|
91 |
CommentEvent charEvent = new CommentEvent(text);
|
|
92 |
if(location != null)charEvent.setLocation(location);
|
|
93 |
return charEvent;
|
|
94 |
}
|
|
95 |
|
42802
|
96 |
@Override
|
12005
|
97 |
public javax.xml.stream.events.DTD createDTD(String dtd) {
|
|
98 |
DTDEvent dtdEvent = new DTDEvent(dtd);
|
|
99 |
if(location != null)dtdEvent.setLocation(location);
|
|
100 |
return dtdEvent;
|
|
101 |
}
|
|
102 |
|
42802
|
103 |
@Override
|
12005
|
104 |
public javax.xml.stream.events.EndDocument createEndDocument() {
|
|
105 |
EndDocumentEvent event =new EndDocumentEvent();
|
|
106 |
if(location != null)event.setLocation(location);
|
|
107 |
return event;
|
|
108 |
}
|
|
109 |
|
42802
|
110 |
@Override
|
|
111 |
public javax.xml.stream.events.EndElement createEndElement(QName name,
|
|
112 |
Iterator<? extends Namespace> namespaces) {
|
12005
|
113 |
return createEndElement(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart());
|
|
114 |
}
|
|
115 |
|
42802
|
116 |
@Override
|
|
117 |
public javax.xml.stream.events.EndElement createEndElement(
|
|
118 |
String prefix, String namespaceUri, String localName) {
|
12005
|
119 |
EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName);
|
|
120 |
if(location != null)event.setLocation(location);
|
|
121 |
return event;
|
|
122 |
}
|
|
123 |
|
42802
|
124 |
@Override
|
|
125 |
public javax.xml.stream.events.EndElement createEndElement(String prefix, String namespaceUri,
|
|
126 |
String localName, Iterator<? extends Namespace> namespaces) {
|
12005
|
127 |
|
|
128 |
EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName);
|
|
129 |
if(namespaces!=null){
|
|
130 |
while(namespaces.hasNext())
|
42802
|
131 |
event.addNamespace(namespaces.next());
|
12005
|
132 |
}
|
|
133 |
if(location != null)event.setLocation(location);
|
|
134 |
return event;
|
|
135 |
}
|
|
136 |
|
42802
|
137 |
@Override
|
|
138 |
public EntityReference createEntityReference(String name, EntityDeclaration entityDeclaration) {
|
12005
|
139 |
EntityReferenceEvent event = new EntityReferenceEvent(name, entityDeclaration);
|
|
140 |
if(location != null)event.setLocation(location);
|
|
141 |
return event;
|
|
142 |
}
|
|
143 |
|
42802
|
144 |
@Override
|
|
145 |
public Characters createIgnorableSpace(String content) {
|
12005
|
146 |
CharacterEvent event = new CharacterEvent(content, false, true);
|
|
147 |
if(location != null)event.setLocation(location);
|
|
148 |
return event;
|
|
149 |
}
|
|
150 |
|
42802
|
151 |
@Override
|
|
152 |
public Namespace createNamespace(String namespaceURI) {
|
12005
|
153 |
NamespaceImpl event = new NamespaceImpl(namespaceURI);
|
|
154 |
if(location != null)event.setLocation(location);
|
|
155 |
return event;
|
|
156 |
}
|
|
157 |
|
42802
|
158 |
@Override
|
|
159 |
public Namespace createNamespace(String prefix, String namespaceURI) {
|
12005
|
160 |
NamespaceImpl event = new NamespaceImpl(prefix, namespaceURI);
|
|
161 |
if(location != null)event.setLocation(location);
|
|
162 |
return event;
|
|
163 |
}
|
|
164 |
|
42802
|
165 |
@Override
|
|
166 |
public ProcessingInstruction createProcessingInstruction(String target, String data) {
|
12005
|
167 |
ProcessingInstructionEvent event = new ProcessingInstructionEvent(target, data);
|
|
168 |
if(location != null)event.setLocation(location);
|
|
169 |
return event;
|
|
170 |
}
|
|
171 |
|
42802
|
172 |
@Override
|
|
173 |
public Characters createSpace(String content) {
|
12005
|
174 |
CharacterEvent event = new CharacterEvent(content);
|
|
175 |
if(location != null)event.setLocation(location);
|
|
176 |
return event;
|
|
177 |
}
|
|
178 |
|
42802
|
179 |
@Override
|
|
180 |
public StartDocument createStartDocument() {
|
12005
|
181 |
StartDocumentEvent event = new StartDocumentEvent();
|
|
182 |
if(location != null)event.setLocation(location);
|
|
183 |
return event;
|
|
184 |
}
|
|
185 |
|
42802
|
186 |
@Override
|
|
187 |
public StartDocument createStartDocument(String encoding) {
|
12005
|
188 |
StartDocumentEvent event = new StartDocumentEvent(encoding);
|
|
189 |
if(location != null)event.setLocation(location);
|
|
190 |
return event;
|
|
191 |
}
|
|
192 |
|
42802
|
193 |
@Override
|
|
194 |
public StartDocument createStartDocument(String encoding, String version) {
|
12005
|
195 |
StartDocumentEvent event = new StartDocumentEvent(encoding, version);
|
|
196 |
if(location != null)event.setLocation(location);
|
|
197 |
return event;
|
|
198 |
}
|
|
199 |
|
42802
|
200 |
@Override
|
|
201 |
public StartDocument createStartDocument(String encoding, String version, boolean standalone) {
|
12005
|
202 |
StartDocumentEvent event = new StartDocumentEvent(encoding, version, standalone);
|
|
203 |
if(location != null)event.setLocation(location);
|
|
204 |
return event;
|
|
205 |
}
|
|
206 |
|
42802
|
207 |
@Override
|
|
208 |
public StartElement createStartElement(QName name, Iterator<? extends Attribute> attributes,
|
|
209 |
Iterator<? extends Namespace> namespaces) {
|
|
210 |
return createStartElement(name.getPrefix(), name.getNamespaceURI(),
|
|
211 |
name.getLocalPart(), attributes, namespaces);
|
12005
|
212 |
}
|
|
213 |
|
42802
|
214 |
@Override
|
|
215 |
public StartElement createStartElement(String prefix, String namespaceUri, String localName) {
|
12005
|
216 |
StartElementEvent event = new StartElementEvent(prefix, namespaceUri, localName);
|
|
217 |
if(location != null)event.setLocation(location);
|
|
218 |
return event;
|
|
219 |
}
|
|
220 |
|
42802
|
221 |
@Override
|
|
222 |
public StartElement createStartElement(String prefix, String namespaceUri,
|
|
223 |
String localName, Iterator<? extends Attribute> attributes,
|
|
224 |
Iterator<? extends Namespace> namespaces) {
|
12005
|
225 |
return createStartElement(prefix, namespaceUri, localName, attributes, namespaces, null);
|
|
226 |
}
|
|
227 |
|
42802
|
228 |
@Override
|
|
229 |
public StartElement createStartElement(String prefix, String namespaceUri,
|
|
230 |
String localName, Iterator<? extends Attribute> attributes,
|
|
231 |
Iterator<? extends Namespace> namespaces, NamespaceContext context) {
|
12005
|
232 |
StartElementEvent elem = new StartElementEvent(prefix, namespaceUri, localName);
|
|
233 |
elem.addAttributes(attributes);
|
|
234 |
elem.addNamespaceAttributes(namespaces);
|
|
235 |
elem.setNamespaceContext(context);
|
|
236 |
if(location != null)elem.setLocation(location);
|
|
237 |
return elem;
|
|
238 |
}
|
|
239 |
|
42802
|
240 |
@Override
|
12005
|
241 |
public void setLocation(javax.xml.stream.Location location) {
|
|
242 |
this.location = location;
|
|
243 |
}
|
|
244 |
|
|
245 |
}
|