1:
37:
38: package ;
39:
40: import ;
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56:
57:
62: public class XMLEventWriterImpl
63: implements XMLEventWriter
64: {
65:
66: protected final XMLStreamWriter writer;
67:
68: protected XMLEventWriterImpl(XMLStreamWriter writer)
69: {
70: this.writer = writer;
71: }
72:
73: public void flush()
74: throws XMLStreamException
75: {
76: writer.flush();
77: }
78:
79: public void close()
80: throws XMLStreamException
81: {
82: writer.close();
83: }
84:
85: public void add(XMLEvent event)
86: throws XMLStreamException
87: {
88: QName name;
89: String uri;
90: switch (event.getEventType())
91: {
92: case XMLStreamConstants.START_ELEMENT:
93: StartElement startElement = event.asStartElement();
94: name = startElement.getName();
95: uri = name.getNamespaceURI();
96: if (uri != null && !"".equals(uri))
97: writer.writeStartElement(name.getPrefix(), name.getLocalPart(), uri);
98: else
99: writer.writeStartElement(name.getLocalPart());
100: break;
101: case XMLStreamConstants.END_ELEMENT:
102: writer.writeEndElement();
103: break;
104: case XMLStreamConstants.ATTRIBUTE:
105: Attribute attribute = (Attribute) event;
106: name = attribute.getName();
107: uri = name.getNamespaceURI();
108: if (uri != null && !"".equals(uri))
109: writer.writeAttribute(name.getPrefix(), uri, name.getLocalPart(),
110: attribute.getValue());
111: else
112: writer.writeAttribute(name.getLocalPart(), attribute.getValue());
113: break;
114: case XMLStreamConstants.NAMESPACE:
115: Namespace namespace = (Namespace) event;
116: uri = namespace.getNamespaceURI();
117: writer.writeNamespace(namespace.getPrefix(), uri);
118: break;
119: case XMLStreamConstants.PROCESSING_INSTRUCTION:
120: ProcessingInstruction pi = (ProcessingInstruction) event;
121: String data = pi.getData();
122: if (data == null)
123: writer.writeProcessingInstruction(pi.getTarget());
124: else
125: writer.writeProcessingInstruction(pi.getTarget(), data);
126: break;
127: case XMLStreamConstants.COMMENT:
128: Comment comment = (Comment) event;
129: writer.writeComment(comment.getText());
130: break;
131: case XMLStreamConstants.START_DOCUMENT:
132: StartDocument startDocument = (StartDocument) event;
133: writer.writeStartDocument(startDocument.getVersion());
134: break;
135: case XMLStreamConstants.END_DOCUMENT:
136: writer.writeEndDocument();
137: break;
138: case XMLStreamConstants.DTD:
139: DTD dtd = (DTD) event;
140: writer.writeDTD(dtd.getDocumentTypeDeclaration());
141: break;
142: case XMLStreamConstants.CHARACTERS:
143: case XMLStreamConstants.SPACE:
144: Characters characters = event.asCharacters();
145: writer.writeCharacters(characters.getData());
146: break;
147: case XMLStreamConstants.CDATA:
148: Characters cdata = event.asCharacters();
149: writer.writeCData(cdata.getData());
150: break;
151: }
152: }
153:
154: public void add(XMLEventReader reader)
155: throws XMLStreamException
156: {
157: while (reader.hasNext())
158: add(reader.nextEvent());
159: }
160:
161: public String getPrefix(String uri)
162: throws XMLStreamException
163: {
164: return writer.getPrefix(uri);
165: }
166:
167: public void setPrefix(String prefix, String uri)
168: throws XMLStreamException
169: {
170: writer.setPrefix(prefix, uri);
171: }
172:
173: public void setDefaultNamespace(String uri)
174: throws XMLStreamException
175: {
176: writer.setDefaultNamespace(uri);
177: }
178:
179: public void setNamespaceContext(NamespaceContext context)
180: throws XMLStreamException
181: {
182: writer.setNamespaceContext(context);
183: }
184:
185: public NamespaceContext getNamespaceContext()
186: {
187: return writer.getNamespaceContext();
188: }
189:
190: }