Revision 3045 tmp/org.txm.core/src/java/org/txm/scripts/importer/StaxStackWriter.groovy

StaxStackWriter.groovy (revision 3045)
8 8
import org.eclipse.core.runtime.Platform;
9 9

  
10 10
public class StaxStackWriter implements XMLStreamWriter {
11

  
11
	
12 12
	XMLStreamWriter writer;
13 13
	OutputStream output;
14 14
	def events = [];
......
31 31
		this.output = output
32 32
		this.writer = factory.createXMLStreamWriter(output, encoding);//create a new file
33 33
	}
34

  
34
	
35 35
	Charset UTF8 = Charset.forName("UTF-8");
36 36
	public void write(String txt) {
37 37
		output.write(txt.getBytes(UTF8))
......
44 44
		}
45 45
		events = [];
46 46
	}
47

  
47
	
48 48
	public void writeStartElements(def tagsToWrite) {
49 49
		for (String tag : tagsToWrite)
50 50
			writeStartElement(tag);
51 51
	}
52

  
52
	
53 53
	public def getTagStack() {
54 54
		return events;
55 55
	}
56

  
56
	
57 57
	@Override
58 58
	public void close () throws XMLStreamException {
59 59
		writer.close();
60 60
		output.close();
61 61
	}
62

  
62
	
63 63
	@Override
64 64
	public void flush () throws XMLStreamException {
65 65
		writer.flush();
66

  
67 66
	}
68

  
67
	
69 68
	@Override
70 69
	public NamespaceContext getNamespaceContext() {
71 70
		return writer.getNamespaceContext();
72 71
	}
73

  
72
	
74 73
	@Override
75 74
	public String getPrefix (String uri) throws XMLStreamException {
76 75
		return writer.getPrefix(uri);
77 76
	}
78

  
77
	
79 78
	@Override
80 79
	public Object getProperty (String name) throws IllegalArgumentException {
81 80
		return writer.getProperty(name);
82 81
	}
83

  
82
	
84 83
	@Override
85 84
	public void setDefaultNamespace (String uri) throws XMLStreamException {
86 85
		writer.setDefaultNamespace(uri);
87 86
	}
88

  
87
	
89 88
	@Override
90 89
	public void setNamespaceContext(NamespaceContext context)
91 90
	throws XMLStreamException {
92 91
		writer.setNamespaceContext(context);
93 92
	}
94

  
93
	
95 94
	@Override
96 95
	public void setPrefix (String prefix, String uri) throws XMLStreamException {
97 96
		writer.setPrefix(prefix, uri);
98 97
	}
99

  
98
	
100 99
	@Override
101 100
	public void writeAttribute (String localName, String value) throws XMLStreamException {
102 101
		writer.writeAttribute(localName, value);
103 102
	}
104

  
103
	
105 104
	@Override
106 105
	public void writeAttribute (String namespaceURI, String localName, String value) throws XMLStreamException {
107 106
		writer.writeAttribute(namespaceURI, localName, value);
108 107
	}
109

  
108
	
110 109
	@Override
111 110
	public void writeAttribute (String prefix, String namespaceURI, String localName, String value) throws XMLStreamException {
112 111
		writer.writeAttribute(prefix, namespaceURI, localName, value);
113 112
	}
114

  
113
	
115 114
	@Override
116 115
	public void writeCData (String data) throws XMLStreamException {
117 116
		writer.writeCData(data);
118 117
	}
119

  
118
	
120 119
	@Override
121 120
	public void writeCharacters (String text) throws XMLStreamException {
122 121
		writer.writeCharacters(text);
123 122
	}
124

  
123
	
125 124
	@Override
126 125
	public void writeCharacters (char[] text, int start, int len) throws XMLStreamException {
127 126
		writer.writeCharacters(text, start, len);
128 127
	}
129

  
128
	
130 129
	@Override
131 130
	public void writeComment (String data) throws XMLStreamException {
132 131
		writer.writeComment(data);
133 132
	}
134

  
133
	
135 134
	@Override
136 135
	public void writeDTD (String dtd) throws XMLStreamException {
137 136
		writer.writeDTD(dtd);
138 137
	}
139

  
138
	
140 139
	@Override
141 140
	public void writeDefaultNamespace(String namespaceURI)
142 141
	throws XMLStreamException {
143 142
		writer.writeDefaultNamespace(namespaceURI);
144 143
	}
145

  
144
	
145
	/**
146
	 * WARNING THE ELEMENT IS CLOSED
147
	 * @param localName
148
	 * @param text
149
	 * @throws XMLStreamException
150
	 */
146 151
	public void writeElement (String localName, String text) throws XMLStreamException {
147 152
		writer.writeStartElement(localName);
148 153
		writer.writeCharacters(text);
......
155 160
		writer.writeCharacters(text);
156 161
		writer.writeEndElement();
157 162
	}
158

  
163
	
159 164
	@Override
160 165
	public void writeEmptyElement (String localName) throws XMLStreamException {
161 166
		writer.writeEmptyElement(localName);
162 167
	}
163

  
168
	
164 169
	public void writeEmptyElement (String localName, def map) throws XMLStreamException {
165 170
		writer.writeEmptyElement(localName);
166 171
		for (def key : map.keySet())
167 172
			writeAttribute(key.toString(), map[key].toString());
168 173
	}
169

  
174
	
170 175
	@Override
171 176
	public void writeEmptyElement(String namespaceURI, String localName)
172 177
	throws XMLStreamException {
173 178
		writer.writeEmptyElement(namespaceURI, localName);
174 179
	}
175

  
180
	
176 181
	@Override
177 182
	public void writeEmptyElement (String prefix, String localName, String namespaceURI) throws XMLStreamException {
178 183
		writer.writeEmptyElement(prefix, localName, namespaceURI);
179 184
	}
180

  
185
	
181 186
	@Override
182 187
	public void writeEndDocument () throws XMLStreamException {
183 188
		writer.writeEndDocument();
184 189
	}
185

  
190
	
186 191
	@Override
187 192
	public void writeEndElement () throws XMLStreamException {
188 193
		writer.writeEndElement();
189 194
		events.remove(events.size()-1)
190 195
		if (debug) println "END: $events"
191

  
192 196
	}
193

  
197
	
194 198
	@Override
195 199
	public void writeEntityRef (String name) throws XMLStreamException {
196 200
		writer.writeEntityRef(name);
197 201
	}
198

  
202
	
199 203
	@Override
200 204
	public void writeNamespace(String prefix, String namespaceURI)
201 205
	throws XMLStreamException {
202 206
		writer.writeNamespace(prefix, namespaceURI);
203 207
	}
204

  
208
	
205 209
	@Override
206 210
	public void writeProcessingInstruction(String target)
207 211
	throws XMLStreamException {
208 212
		writer.writeProcessingInstruction(target);
209 213
	}
210

  
214
	
211 215
	@Override
212 216
	public void writeProcessingInstruction(String target, String data)
213 217
	throws XMLStreamException {
214 218
		writer.writeProcessingInstruction(target, data);
215 219
	}
216

  
220
	
217 221
	@Override
218 222
	public void writeStartDocument () throws XMLStreamException {
219 223
		writer.writeStartDocument();
220

  
221 224
	}
222

  
225
	
223 226
	@Override
224 227
	public void writeStartDocument (String version) throws XMLStreamException {
225 228
		writer.writeStartDocument(version);
226 229
	}
227

  
230
	
228 231
	@Override
229 232
	public void writeStartDocument(String encoding, String version)
230 233
	throws XMLStreamException {
231 234
		writer.writeStartDocument(encoding, version);
232 235
	}
233

  
236
	
234 237
	@Override
235 238
	public void writeStartElement (String localName) throws XMLStreamException {
236 239
		writer.writeStartElement(localName);
237 240
		events << localName
238 241
		if (debug) println "START $localName $events"
239

  
240 242
	}
241 243
	
242 244
	public void writeStartElement (String localName, def map) throws XMLStreamException {
......
245 247
			writeAttribute(key.toString(), map[key].toString());
246 248
		}
247 249
	}
248

  
250
	
249 251
	@Override
250 252
	public void writeStartElement(String namespaceURI, String localName)
251 253
	throws XMLStreamException {
......
253 255
		events << localName
254 256
		if (debug) println "START $localName $events"
255 257
	}
256

  
258
	
257 259
	@Override
258 260
	public void writeStartElement(String prefix, String localName,
259
	String namespaceURI) throws XMLStreamException {
261
			String namespaceURI) throws XMLStreamException {
260 262
		writer.writeStartElement(prefix, localName, namespaceURI);
261 263
		events << localName
262 264
		if (debug) println "START $localName $prefix $events"

Also available in: Unified diff