/
XMLStreamWriter2.java
240 lines (218 loc) · 9.5 KB
/
XMLStreamWriter2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
package org.codehaus.stax2;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.codehaus.stax2.typed.TypedXMLStreamWriter;
import org.codehaus.stax2.validation.Validatable;
/**
* Extended interface that implements functionality that is necessary
* to properly build event API on top of {@link XMLStreamWriter},
* as well as to configure individual instances.
* It also adds limited number of methods that are important for
* efficient pass-through processing (such as one needed when routing
* SOAP-messages).
*<p>
* Since version 3.0, stream writer will also implement "Typed Access API"
* on output side.
*
* @version 3.0.1 06-Nov-2008
* @author Tatu Saloranta (tatu.saloranta@iki.fi)
*/
public interface XMLStreamWriter2
extends TypedXMLStreamWriter,
Validatable
{
/*
/**********************************************************************
/* Configuration
/**********************************************************************
*/
/**
* Method similar to {@link javax.xml.stream.XMLOutputFactory#isPropertySupported}, used
* to determine whether a property is supported by the Writer
* <b>instance</b>. This means that this method may return false
* for some properties that the output factory does support: specifically,
* it should only return true if the value is mutable on per-instance
* basis. False means that either the property is not recognized, or
* is not mutable via writer instance.
*/
public boolean isPropertySupported(String name);
/**
* Method that can be used to set per-writer properties; a subset of
* properties one can set via matching
* {@link org.codehaus.stax2.XMLOutputFactory2}
* instance. Exactly which methods are mutable is implementation
* specific.
*
* @param name Name of the property to set
* @param value Value to set property to.
*
* @return True, if the specified property was <b>succesfully</b>
* set to specified value; false if its value was not changed
*
* @throws IllegalArgumentException if the property is not supported
* (or recognized) by the stream writer implementation
*/
public boolean setProperty(String name, Object value);
/*
/**********************************************************************
/* Other accessors, mutators
/**********************************************************************
*/
/**
* Method that should return current output location, if the writer
* keeps track of it; null if it does not.
*/
public XMLStreamLocation2 getLocation();
/**
* Method that can be called to get information about encoding that
* this writer is using (or at least claims is using). That is,
* it returns name of encoding specified when (in order of priority):
*<ul>
* <li>Passed to one of factory methods of
* {@link javax.xml.stream.XMLOutputFactory}
* </li>
* <li>Passed to <code>writeStartDocument</code> method (explicitly
* or implicity; latter in cases where defaults are imposed
* by Stax specification)
* </li>
* </ul>
*/
public String getEncoding();
/*
/**********************************************************************
/* Write methods base interface is missing
/**********************************************************************
*/
public void writeCData(char[] text, int start, int len)
throws XMLStreamException;
public void writeDTD(String rootName, String systemId, String publicId,
String internalSubset)
throws XMLStreamException;
/**
* Method similar to {@link #writeEndElement}, but that will always
* write the full end element, instead of empty element. This only
* matters for cases where the element itself has no content, and
* if writer is allowed to write empty elements when it encounters
* such start/end element write pairs.
*/
public void writeFullEndElement() throws XMLStreamException;
public void writeStartDocument(String version, String encoding,
boolean standAlone)
throws XMLStreamException;
/**
* Method that can be called to write whitespace-only content.
* If so, it is to be written as is (with no escaping), and does
* not contain non-whitespace characters (writer may validate this,
* and throw an exception if it does).
*<p>
* This method is useful for things like outputting indentation.
*
* @since 3.0
*/
public void writeSpace(String text)
throws XMLStreamException;
/**
* Method that can be called to write whitespace-only content.
* If so, it is to be written as is (with no escaping), and does
* not contain non-whitespace characters (writer may validate this,
* and throw an exception if it does).
*<p>
* This method is useful for things like outputting indentation.
*
* @since 3.0
*/
public void writeSpace(char[] text, int offset, int length)
throws XMLStreamException;
/*
/**********************************************************************
/* Pass-through methods
/**********************************************************************
*/
/**
* Method that writes specified content as is, without encoding or
* deciphering it in any way. It will not update state of the writer
* (except by possibly flushing output of previous writes, like
* finishing a start element),
* nor be validated in any way. As such, care must be taken, if this
* method is used.
*<p>
* Method is usually used when encapsulating output from another writer
* as a sub-tree, or when passing through XML fragments.
*<p>
* NOTE: since text to be written may be anything, including markup,
* it can not be reliably validated. Because of this, validator(s)
* attached to the writer will NOT be informed about writes.
*/
public void writeRaw(String text) throws XMLStreamException;
/**
* Method that writes specified content as is, without encoding or
* deciphering it in any way. It will not update state of the writer
* (except by possibly flushing output of previous writes, like
* finishing a start element),
* nor be validated in any way. As such, care must be taken, if this
* method is used.
*<p>
* Method is usually used when encapsulating output from another writer
* as a sub-tree, or when passing through XML fragments.
*<p>
* NOTE: since text to be written may be anything, including markup,
* it can not be reliably validated. Because of this, validator(s)
* attached to the writer will NOT be informed about writes.
*/
public void writeRaw(String text, int offset, int length)
throws XMLStreamException;
/**
* Method that writes specified content as is, without encoding or
* deciphering it in any way. It will not update state of the writer
* (except by possibly flushing output of previous writes, like
* finishing a start element),
* nor be validated in any way. As such, care must be taken, if this
* method is used.
*<p>
* Method is usually used when encapsulating output from another writer
* as a sub-tree, or when passing through XML fragments.
*<p>
* NOTE: since text to be written may be anything, including markup,
* it can not be reliably validated. Because of this, validator(s)
* attached to the writer will NOT be informed about writes.
*/
public void writeRaw(char[] text, int offset, int length)
throws XMLStreamException;
/**
* Method that essentially copies
* event that the specified reader has just read.
* This can be both more convenient
* (no need to worry about details) and more efficient
* than separately calling access methods of the reader and
* write methods of the writer, since writer may know more
* about reader than the application (and may be able to use
* non-public methods)
*
* @param r Reader to use for accessing event to copy
* @param preserveEventData If true, writer is not allowed to change
* the state of the reader (so that all the data associated with the
* current event has to be preserved); if false, writer is allowed
* to use methods that may cause some data to be discarded. Setting
* this to false may improve the performance, since it may allow
* full no-copy streaming of data, especially textual contents.
*/
public void copyEventFromReader(XMLStreamReader2 r, boolean preserveEventData)
throws XMLStreamException;
/*
/**********************************************************************
/* Output handling
/**********************************************************************
*/
/**
* Method similar to
* {@link javax.xml.stream.XMLStreamWriter#close()},
* except that this method also does close the underlying output
* destination (stream) if it has not yet been closed.
* It is specifically necessary to call this method if the parsing ends
* in an exception to ensure that the output destination does get
* properly closed, even if the stream writer would otherwise close
* it (as is the case for destinations it manages where calling
* application has no access)
*/
public void closeCompletely() throws XMLStreamException;
}