@@ -105,5 +105,119 @@ public void testWriteToFile() throws Exception
105105
106106 assertEquals ("<IntWrapper><i>42</i></IntWrapper>" , xml );
107107 f .delete ();
108- }
108+ }
109+
110+ public void testRawSimpleValue () throws Exception
111+ {
112+ XmlFactory f = new XmlFactory ();
113+ StringWriter out = new StringWriter ();
114+ ToXmlGenerator gen = f .createGenerator (out );
115+ // root name is special, need to be fed first:
116+ gen .setNextName (new QName ("root" ));
117+ gen .writeStartObject ();
118+ gen .writeFieldName ("elem" );
119+ gen .writeRawValue ("value" );
120+ gen .writeEndObject ();
121+ gen .close ();
122+ String xml = out .toString ();
123+ // one more thing: remove that annoying 'xmlns' decl, if it's there:
124+ xml = removeSjsxpNamespace (xml );
125+ assertEquals ("<root><elem>value</elem></root>" , xml );
126+ }
127+
128+ public void testRawOffsetValue () throws Exception
129+ {
130+ XmlFactory f = new XmlFactory ();
131+ StringWriter out = new StringWriter ();
132+ ToXmlGenerator gen = f .createGenerator (out );
133+ // root name is special, need to be fed first:
134+ gen .setNextName (new QName ("root" ));
135+ gen .writeStartObject ();
136+ gen .writeFieldName ("elem" );
137+ gen .writeRawValue ("NotAValue_value_NotAValue" , 10 , 5 );
138+ gen .writeEndObject ();
139+ gen .close ();
140+ String xml = out .toString ();
141+ // one more thing: remove that annoying 'xmlns' decl, if it's there:
142+ xml = removeSjsxpNamespace (xml );
143+ assertEquals ("<root><elem>value</elem></root>" , xml );
144+ }
145+
146+ public void testRawCharArrayValue () throws Exception
147+ {
148+ XmlFactory f = new XmlFactory ();
149+ StringWriter out = new StringWriter ();
150+ ToXmlGenerator gen = f .createGenerator (out );
151+ // root name is special, need to be fed first:
152+ gen .setNextName (new QName ("root" ));
153+ gen .writeStartObject ();
154+ gen .writeFieldName ("elem" );
155+ gen .writeRawValue (new char [] {'!' , 'v' , 'a' , 'l' , 'u' , 'e' , '!' }, 1 , 5 );
156+ gen .writeEndObject ();
157+ gen .close ();
158+ String xml = out .toString ();
159+ // one more thing: remove that annoying 'xmlns' decl, if it's there:
160+ xml = removeSjsxpNamespace (xml );
161+ assertEquals ("<root><elem>value</elem></root>" , xml );
162+ }
163+
164+ public void testRawSimpleAttribute () throws Exception
165+ {
166+ XmlFactory f = new XmlFactory ();
167+ StringWriter out = new StringWriter ();
168+ ToXmlGenerator gen = f .createGenerator (out );
169+ // root name is special, need to be fed first:
170+ gen .setNextName (new QName ("root" ));
171+ gen .writeStartObject ();
172+ // and also need to force attribute
173+ gen .setNextIsAttribute (true );
174+ gen .writeFieldName ("attr" );
175+ gen .writeRawValue ("value" );
176+ gen .writeEndObject ();
177+ gen .close ();
178+ String xml = out .toString ();
179+ // one more thing: remove that annoying 'xmlns' decl, if it's there:
180+ xml = removeSjsxpNamespace (xml );
181+ assertEquals ("<root attr=\" value\" />" , xml );
182+ }
183+
184+ public void testRawOffsetAttribute () throws Exception
185+ {
186+ XmlFactory f = new XmlFactory ();
187+ StringWriter out = new StringWriter ();
188+ ToXmlGenerator gen = f .createGenerator (out );
189+ // root name is special, need to be fed first:
190+ gen .setNextName (new QName ("root" ));
191+ gen .writeStartObject ();
192+ // and also need to force attribute
193+ gen .setNextIsAttribute (true );
194+ gen .writeFieldName ("attr" );
195+ gen .writeRawValue ("NotAValue_value_NotAValue" , 10 , 5 );
196+ gen .writeEndObject ();
197+ gen .close ();
198+ String xml = out .toString ();
199+ // one more thing: remove that annoying 'xmlns' decl, if it's there:
200+ xml = removeSjsxpNamespace (xml );
201+ assertEquals ("<root attr=\" value\" />" , xml );
202+ }
203+
204+ public void testRawCharArratAttribute () throws Exception
205+ {
206+ XmlFactory f = new XmlFactory ();
207+ StringWriter out = new StringWriter ();
208+ ToXmlGenerator gen = f .createGenerator (out );
209+ // root name is special, need to be fed first:
210+ gen .setNextName (new QName ("root" ));
211+ gen .writeStartObject ();
212+ // and also need to force attribute
213+ gen .setNextIsAttribute (true );
214+ gen .writeFieldName ("attr" );
215+ gen .writeRawValue (new char []{'!' , 'v' , 'a' , 'l' , 'u' , 'e' , '!' }, 1 , 5 );
216+ gen .writeEndObject ();
217+ gen .close ();
218+ String xml = out .toString ();
219+ // one more thing: remove that annoying 'xmlns' decl, if it's there:
220+ xml = removeSjsxpNamespace (xml );
221+ assertEquals ("<root attr=\" value\" />" , xml );
222+ }
109223}
0 commit comments