1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
package org.apache.maven.doxia.docrenderer.document.io.xpp3; |
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
import java.io.ByteArrayInputStream; |
12 | |
import java.io.IOException; |
13 | |
import java.io.InputStream; |
14 | |
import java.io.InputStreamReader; |
15 | |
import java.io.Reader; |
16 | |
import java.io.StringReader; |
17 | |
import java.io.StringWriter; |
18 | |
import java.text.DateFormat; |
19 | |
import java.text.ParsePosition; |
20 | |
import java.util.Locale; |
21 | |
import java.util.regex.Matcher; |
22 | |
import java.util.regex.Pattern; |
23 | |
import org.apache.maven.doxia.docrenderer.document.DocumentMeta; |
24 | |
import org.apache.maven.doxia.docrenderer.document.DocumentModel; |
25 | |
import org.apache.maven.doxia.docrenderer.document.DocumentTOC; |
26 | |
import org.apache.maven.doxia.docrenderer.document.DocumentTOCItem; |
27 | |
import org.codehaus.plexus.util.IOUtil; |
28 | |
import org.codehaus.plexus.util.ReaderFactory; |
29 | |
import org.codehaus.plexus.util.xml.pull.MXParser; |
30 | |
import org.codehaus.plexus.util.xml.pull.XmlPullParser; |
31 | |
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 1 | public class DocumentXpp3Reader { |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | 1 | private boolean addDefaultEntities = true; |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
public boolean getAddDefaultEntities() |
66 | |
{ |
67 | 0 | return addDefaultEntities; |
68 | |
} |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
public boolean getBooleanValue(String s, String attribute, XmlPullParser parser) |
78 | |
throws XmlPullParserException |
79 | |
{ |
80 | 0 | if ( s != null ) |
81 | |
{ |
82 | 0 | return Boolean.valueOf( s ).booleanValue(); |
83 | |
} |
84 | 0 | return false; |
85 | |
} |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public char getCharacterValue(String s, String attribute, XmlPullParser parser) |
95 | |
throws XmlPullParserException |
96 | |
{ |
97 | 0 | if ( s != null ) |
98 | |
{ |
99 | 0 | return s.charAt( 0 ); |
100 | |
} |
101 | 0 | return 0; |
102 | |
} |
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
public java.util.Date getDateValue(String s, String attribute, String dateFormat, XmlPullParser parser) |
113 | |
throws XmlPullParserException |
114 | |
{ |
115 | 0 | if ( s != null ) |
116 | |
{ |
117 | 0 | if ( dateFormat == null ) |
118 | |
{ |
119 | 0 | return new java.util.Date( Long.valueOf( s ).longValue() ); |
120 | |
} |
121 | |
else |
122 | |
{ |
123 | 0 | DateFormat dateParser = new java.text.SimpleDateFormat( dateFormat, Locale.US ); |
124 | |
try |
125 | |
{ |
126 | 0 | return dateParser.parse( s ); |
127 | |
} |
128 | 0 | catch ( java.text.ParseException e ) |
129 | |
{ |
130 | 0 | throw new XmlPullParserException( e.getMessage() ); |
131 | |
} |
132 | |
} |
133 | |
} |
134 | 0 | return null; |
135 | |
} |
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
public double getDoubleValue(String s, String attribute, XmlPullParser parser, boolean strict) |
146 | |
throws XmlPullParserException |
147 | |
{ |
148 | 0 | if ( s != null ) |
149 | |
{ |
150 | |
try |
151 | |
{ |
152 | 0 | return Double.valueOf( s ).doubleValue(); |
153 | |
} |
154 | 0 | catch ( NumberFormatException e ) |
155 | |
{ |
156 | 0 | if ( strict ) |
157 | |
{ |
158 | 0 | throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, null ); |
159 | |
} |
160 | |
} |
161 | |
} |
162 | 0 | return 0; |
163 | |
} |
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
public float getFloatValue(String s, String attribute, XmlPullParser parser, boolean strict) |
174 | |
throws XmlPullParserException |
175 | |
{ |
176 | 0 | if ( s != null ) |
177 | |
{ |
178 | |
try |
179 | |
{ |
180 | 0 | return Float.valueOf( s ).floatValue(); |
181 | |
} |
182 | 0 | catch ( NumberFormatException e ) |
183 | |
{ |
184 | 0 | if ( strict ) |
185 | |
{ |
186 | 0 | throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, null ); |
187 | |
} |
188 | |
} |
189 | |
} |
190 | 0 | return 0; |
191 | |
} |
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
public int getIntegerValue(String s, String attribute, XmlPullParser parser, boolean strict) |
202 | |
throws XmlPullParserException |
203 | |
{ |
204 | 0 | if ( s != null ) |
205 | |
{ |
206 | |
try |
207 | |
{ |
208 | 0 | return Integer.valueOf( s ).intValue(); |
209 | |
} |
210 | 0 | catch ( NumberFormatException e ) |
211 | |
{ |
212 | 0 | if ( strict ) |
213 | |
{ |
214 | 0 | throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be an integer", parser, null ); |
215 | |
} |
216 | |
} |
217 | |
} |
218 | 0 | return 0; |
219 | |
} |
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
public long getLongValue(String s, String attribute, XmlPullParser parser, boolean strict) |
230 | |
throws XmlPullParserException |
231 | |
{ |
232 | 0 | if ( s != null ) |
233 | |
{ |
234 | |
try |
235 | |
{ |
236 | 0 | return Long.valueOf( s ).longValue(); |
237 | |
} |
238 | 0 | catch ( NumberFormatException e ) |
239 | |
{ |
240 | 0 | if ( strict ) |
241 | |
{ |
242 | 0 | throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a long integer", parser, null ); |
243 | |
} |
244 | |
} |
245 | |
} |
246 | 0 | return 0; |
247 | |
} |
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
public String getRequiredAttributeValue(String s, String attribute, XmlPullParser parser, boolean strict) |
258 | |
throws XmlPullParserException |
259 | |
{ |
260 | 0 | if ( s == null ) |
261 | |
{ |
262 | 0 | if ( strict ) |
263 | |
{ |
264 | 0 | throw new XmlPullParserException( "Missing required value for attribute '" + attribute + "'", parser, null ); |
265 | |
} |
266 | |
} |
267 | 0 | return s; |
268 | |
} |
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
|
276 | |
|
277 | |
|
278 | |
public short getShortValue(String s, String attribute, XmlPullParser parser, boolean strict) |
279 | |
throws XmlPullParserException |
280 | |
{ |
281 | 0 | if ( s != null ) |
282 | |
{ |
283 | |
try |
284 | |
{ |
285 | 0 | return Short.valueOf( s ).shortValue(); |
286 | |
} |
287 | 0 | catch ( NumberFormatException e ) |
288 | |
{ |
289 | 0 | if ( strict ) |
290 | |
{ |
291 | 0 | throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a short integer", parser, null ); |
292 | |
} |
293 | |
} |
294 | |
} |
295 | 0 | return 0; |
296 | |
} |
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
|
303 | |
public String getTrimmedValue(String s) |
304 | |
{ |
305 | 5 | if ( s != null ) |
306 | |
{ |
307 | 5 | s = s.trim(); |
308 | |
} |
309 | 5 | return s; |
310 | |
} |
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
|
317 | |
|
318 | |
|
319 | |
private DocumentMeta parseDocumentMeta(String tagName, XmlPullParser parser, boolean strict) |
320 | |
throws IOException, XmlPullParserException |
321 | |
{ |
322 | 1 | DocumentMeta documentMeta = new DocumentMeta(); |
323 | 1 | java.util.Set parsed = new java.util.HashSet(); |
324 | 5 | while ( parser.nextTag() == XmlPullParser.START_TAG ) |
325 | |
{ |
326 | 4 | if ( parser.getName().equals( "title" ) ) |
327 | |
{ |
328 | 1 | if ( parsed.contains( "title" ) ) |
329 | |
{ |
330 | 0 | throw new XmlPullParserException( "Duplicated tag: '" + parser.getName() + "'", parser, null); |
331 | |
} |
332 | 1 | parsed.add( "title" ); |
333 | 1 | documentMeta.setTitle( getTrimmedValue( parser.nextText()) ); |
334 | |
} |
335 | 3 | else if ( parser.getName().equals( "author" ) ) |
336 | |
{ |
337 | 1 | if ( parsed.contains( "author" ) ) |
338 | |
{ |
339 | 0 | throw new XmlPullParserException( "Duplicated tag: '" + parser.getName() + "'", parser, null); |
340 | |
} |
341 | 1 | parsed.add( "author" ); |
342 | 1 | documentMeta.setAuthor( getTrimmedValue( parser.nextText()) ); |
343 | |
} |
344 | 2 | else if ( parser.getName().equals( "subject" ) ) |
345 | |
{ |
346 | 1 | if ( parsed.contains( "subject" ) ) |
347 | |
{ |
348 | 0 | throw new XmlPullParserException( "Duplicated tag: '" + parser.getName() + "'", parser, null); |
349 | |
} |
350 | 1 | parsed.add( "subject" ); |
351 | 1 | documentMeta.setSubject( getTrimmedValue( parser.nextText()) ); |
352 | |
} |
353 | 1 | else if ( parser.getName().equals( "keywords" ) ) |
354 | |
{ |
355 | 1 | if ( parsed.contains( "keywords" ) ) |
356 | |
{ |
357 | 0 | throw new XmlPullParserException( "Duplicated tag: '" + parser.getName() + "'", parser, null); |
358 | |
} |
359 | 1 | parsed.add( "keywords" ); |
360 | 1 | documentMeta.setKeywords( getTrimmedValue( parser.nextText()) ); |
361 | |
} |
362 | 0 | else if ( parser.getName().equals( "pageSize" ) ) |
363 | |
{ |
364 | 0 | if ( parsed.contains( "pageSize" ) ) |
365 | |
{ |
366 | 0 | throw new XmlPullParserException( "Duplicated tag: '" + parser.getName() + "'", parser, null); |
367 | |
} |
368 | 0 | parsed.add( "pageSize" ); |
369 | 0 | documentMeta.setPageSize( getTrimmedValue( parser.nextText()) ); |
370 | |
} |
371 | |
else |
372 | |
{ |
373 | 0 | if ( strict ) |
374 | |
{ |
375 | 0 | throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null); |
376 | |
} |
377 | |
else |
378 | |
{ |
379 | |
|
380 | 0 | while ( parser.next() != XmlPullParser.END_TAG ) {} |
381 | |
} |
382 | |
} |
383 | |
} |
384 | 1 | return documentMeta; |
385 | |
} |
386 | |
|
387 | |
|
388 | |
|
389 | |
|
390 | |
|
391 | |
|
392 | |
|
393 | |
|
394 | |
private DocumentModel parseDocumentModel(String tagName, XmlPullParser parser, boolean strict) |
395 | |
throws IOException, XmlPullParserException |
396 | |
{ |
397 | 1 | DocumentModel documentModel = new DocumentModel(); |
398 | 1 | documentModel.setOutputName( getTrimmedValue( parser.getAttributeValue( "", "outputName" )) ); |
399 | 1 | java.util.Set parsed = new java.util.HashSet(); |
400 | 1 | int eventType = parser.getEventType(); |
401 | 1 | boolean foundRoot = false; |
402 | 6 | while ( eventType != XmlPullParser.END_DOCUMENT ) |
403 | |
{ |
404 | 5 | if ( eventType == XmlPullParser.START_TAG ) |
405 | |
{ |
406 | 2 | if ( parser.getName().equals( tagName ) ) |
407 | |
{ |
408 | 1 | foundRoot = true; |
409 | |
} |
410 | 1 | else if ( parser.getName().equals( "meta" ) ) |
411 | |
{ |
412 | 1 | if ( parsed.contains( "meta" ) ) |
413 | |
{ |
414 | 0 | throw new XmlPullParserException( "Duplicated tag: '" + parser.getName() + "'", parser, null); |
415 | |
} |
416 | 1 | parsed.add( "meta" ); |
417 | 1 | documentModel.setMeta( parseDocumentMeta( "meta", parser, strict ) ); |
418 | |
} |
419 | 0 | else if ( parser.getName().equals( "toc" ) ) |
420 | |
{ |
421 | 0 | if ( parsed.contains( "toc" ) ) |
422 | |
{ |
423 | 0 | throw new XmlPullParserException( "Duplicated tag: '" + parser.getName() + "'", parser, null); |
424 | |
} |
425 | 0 | parsed.add( "toc" ); |
426 | 0 | documentModel.setToc( parseDocumentTOC( "toc", parser, strict ) ); |
427 | |
} |
428 | 0 | else if ( !foundRoot && strict ) |
429 | |
{ |
430 | 0 | throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null); |
431 | |
} |
432 | |
} |
433 | 5 | eventType = parser.next(); |
434 | |
} |
435 | 1 | return documentModel; |
436 | |
} |
437 | |
|
438 | |
|
439 | |
|
440 | |
|
441 | |
|
442 | |
|
443 | |
|
444 | |
|
445 | |
private DocumentTOC parseDocumentTOC(String tagName, XmlPullParser parser, boolean strict) |
446 | |
throws IOException, XmlPullParserException |
447 | |
{ |
448 | 0 | DocumentTOC documentTOC = new DocumentTOC(); |
449 | 0 | documentTOC.setName( getTrimmedValue( parser.getAttributeValue( "", "name" )) ); |
450 | 0 | java.util.Set parsed = new java.util.HashSet(); |
451 | 0 | while ( parser.nextTag() == XmlPullParser.START_TAG ) |
452 | |
{ |
453 | 0 | if ( parser.getName().equals( "item" ) ) |
454 | |
{ |
455 | 0 | java.util.List items = documentTOC.getItems(); |
456 | 0 | if ( items == null ) |
457 | |
{ |
458 | 0 | items = new java.util.ArrayList(); |
459 | 0 | documentTOC.setItems( items ); |
460 | |
} |
461 | 0 | items.add( parseDocumentTOCItem( "item", parser, strict ) ); |
462 | |
} |
463 | |
else |
464 | |
{ |
465 | 0 | if ( strict ) |
466 | |
{ |
467 | 0 | throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null); |
468 | |
} |
469 | |
else |
470 | |
{ |
471 | |
|
472 | 0 | while ( parser.next() != XmlPullParser.END_TAG ) {} |
473 | |
} |
474 | |
} |
475 | |
} |
476 | 0 | return documentTOC; |
477 | |
} |
478 | |
|
479 | |
|
480 | |
|
481 | |
|
482 | |
|
483 | |
|
484 | |
|
485 | |
|
486 | |
private DocumentTOCItem parseDocumentTOCItem(String tagName, XmlPullParser parser, boolean strict) |
487 | |
throws IOException, XmlPullParserException |
488 | |
{ |
489 | 0 | DocumentTOCItem documentTOCItem = new DocumentTOCItem(); |
490 | 0 | documentTOCItem.setName( getTrimmedValue( parser.getAttributeValue( "", "name" )) ); |
491 | 0 | documentTOCItem.setRef( getTrimmedValue( parser.getAttributeValue( "", "ref" )) ); |
492 | 0 | java.util.Set parsed = new java.util.HashSet(); |
493 | 0 | while ( parser.nextTag() == XmlPullParser.START_TAG ) |
494 | |
{ |
495 | 0 | if ( strict ) |
496 | |
{ |
497 | 0 | throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null); |
498 | |
} |
499 | |
else |
500 | |
{ |
501 | |
|
502 | 0 | while ( parser.next() != XmlPullParser.END_TAG ) {} |
503 | |
} |
504 | |
} |
505 | 0 | return documentTOCItem; |
506 | |
} |
507 | |
|
508 | |
|
509 | |
|
510 | |
|
511 | |
|
512 | |
|
513 | |
|
514 | |
public DocumentModel read(Reader reader, boolean strict) |
515 | |
throws IOException, XmlPullParserException |
516 | |
{ |
517 | 1 | XmlPullParser parser = new MXParser(); |
518 | |
|
519 | 1 | parser.setInput( reader ); |
520 | |
|
521 | 1 | if ( addDefaultEntities ) |
522 | |
{ |
523 | |
|
524 | |
|
525 | |
|
526 | |
|
527 | 1 | parser.defineEntityReplacementText( "nbsp", "\u00a0" ); |
528 | 1 | parser.defineEntityReplacementText( "iexcl", "\u00a1" ); |
529 | 1 | parser.defineEntityReplacementText( "cent", "\u00a2" ); |
530 | 1 | parser.defineEntityReplacementText( "pound", "\u00a3" ); |
531 | 1 | parser.defineEntityReplacementText( "curren", "\u00a4" ); |
532 | 1 | parser.defineEntityReplacementText( "yen", "\u00a5" ); |
533 | 1 | parser.defineEntityReplacementText( "brvbar", "\u00a6" ); |
534 | 1 | parser.defineEntityReplacementText( "sect", "\u00a7" ); |
535 | 1 | parser.defineEntityReplacementText( "uml", "\u00a8" ); |
536 | 1 | parser.defineEntityReplacementText( "copy", "\u00a9" ); |
537 | 1 | parser.defineEntityReplacementText( "ordf", "\u00aa" ); |
538 | 1 | parser.defineEntityReplacementText( "laquo", "\u00ab" ); |
539 | 1 | parser.defineEntityReplacementText( "not", "\u00ac" ); |
540 | 1 | parser.defineEntityReplacementText( "shy", "\u00ad" ); |
541 | 1 | parser.defineEntityReplacementText( "reg", "\u00ae" ); |
542 | 1 | parser.defineEntityReplacementText( "macr", "\u00af" ); |
543 | 1 | parser.defineEntityReplacementText( "deg", "\u00b0" ); |
544 | 1 | parser.defineEntityReplacementText( "plusmn", "\u00b1" ); |
545 | 1 | parser.defineEntityReplacementText( "sup2", "\u00b2" ); |
546 | 1 | parser.defineEntityReplacementText( "sup3", "\u00b3" ); |
547 | 1 | parser.defineEntityReplacementText( "acute", "\u00b4" ); |
548 | 1 | parser.defineEntityReplacementText( "micro", "\u00b5" ); |
549 | 1 | parser.defineEntityReplacementText( "para", "\u00b6" ); |
550 | 1 | parser.defineEntityReplacementText( "middot", "\u00b7" ); |
551 | 1 | parser.defineEntityReplacementText( "cedil", "\u00b8" ); |
552 | 1 | parser.defineEntityReplacementText( "sup1", "\u00b9" ); |
553 | 1 | parser.defineEntityReplacementText( "ordm", "\u00ba" ); |
554 | 1 | parser.defineEntityReplacementText( "raquo", "\u00bb" ); |
555 | 1 | parser.defineEntityReplacementText( "frac14", "\u00bc" ); |
556 | 1 | parser.defineEntityReplacementText( "frac12", "\u00bd" ); |
557 | 1 | parser.defineEntityReplacementText( "frac34", "\u00be" ); |
558 | 1 | parser.defineEntityReplacementText( "iquest", "\u00bf" ); |
559 | 1 | parser.defineEntityReplacementText( "Agrave", "\u00c0" ); |
560 | 1 | parser.defineEntityReplacementText( "Aacute", "\u00c1" ); |
561 | 1 | parser.defineEntityReplacementText( "Acirc", "\u00c2" ); |
562 | 1 | parser.defineEntityReplacementText( "Atilde", "\u00c3" ); |
563 | 1 | parser.defineEntityReplacementText( "Auml", "\u00c4" ); |
564 | 1 | parser.defineEntityReplacementText( "Aring", "\u00c5" ); |
565 | 1 | parser.defineEntityReplacementText( "AElig", "\u00c6" ); |
566 | 1 | parser.defineEntityReplacementText( "Ccedil", "\u00c7" ); |
567 | 1 | parser.defineEntityReplacementText( "Egrave", "\u00c8" ); |
568 | 1 | parser.defineEntityReplacementText( "Eacute", "\u00c9" ); |
569 | 1 | parser.defineEntityReplacementText( "Ecirc", "\u00ca" ); |
570 | 1 | parser.defineEntityReplacementText( "Euml", "\u00cb" ); |
571 | 1 | parser.defineEntityReplacementText( "Igrave", "\u00cc" ); |
572 | 1 | parser.defineEntityReplacementText( "Iacute", "\u00cd" ); |
573 | 1 | parser.defineEntityReplacementText( "Icirc", "\u00ce" ); |
574 | 1 | parser.defineEntityReplacementText( "Iuml", "\u00cf" ); |
575 | 1 | parser.defineEntityReplacementText( "ETH", "\u00d0" ); |
576 | 1 | parser.defineEntityReplacementText( "Ntilde", "\u00d1" ); |
577 | 1 | parser.defineEntityReplacementText( "Ograve", "\u00d2" ); |
578 | 1 | parser.defineEntityReplacementText( "Oacute", "\u00d3" ); |
579 | 1 | parser.defineEntityReplacementText( "Ocirc", "\u00d4" ); |
580 | 1 | parser.defineEntityReplacementText( "Otilde", "\u00d5" ); |
581 | 1 | parser.defineEntityReplacementText( "Ouml", "\u00d6" ); |
582 | 1 | parser.defineEntityReplacementText( "times", "\u00d7" ); |
583 | 1 | parser.defineEntityReplacementText( "Oslash", "\u00d8" ); |
584 | 1 | parser.defineEntityReplacementText( "Ugrave", "\u00d9" ); |
585 | 1 | parser.defineEntityReplacementText( "Uacute", "\u00da" ); |
586 | 1 | parser.defineEntityReplacementText( "Ucirc", "\u00db" ); |
587 | 1 | parser.defineEntityReplacementText( "Uuml", "\u00dc" ); |
588 | 1 | parser.defineEntityReplacementText( "Yacute", "\u00dd" ); |
589 | 1 | parser.defineEntityReplacementText( "THORN", "\u00de" ); |
590 | 1 | parser.defineEntityReplacementText( "szlig", "\u00df" ); |
591 | 1 | parser.defineEntityReplacementText( "agrave", "\u00e0" ); |
592 | 1 | parser.defineEntityReplacementText( "aacute", "\u00e1" ); |
593 | 1 | parser.defineEntityReplacementText( "acirc", "\u00e2" ); |
594 | 1 | parser.defineEntityReplacementText( "atilde", "\u00e3" ); |
595 | 1 | parser.defineEntityReplacementText( "auml", "\u00e4" ); |
596 | 1 | parser.defineEntityReplacementText( "aring", "\u00e5" ); |
597 | 1 | parser.defineEntityReplacementText( "aelig", "\u00e6" ); |
598 | 1 | parser.defineEntityReplacementText( "ccedil", "\u00e7" ); |
599 | 1 | parser.defineEntityReplacementText( "egrave", "\u00e8" ); |
600 | 1 | parser.defineEntityReplacementText( "eacute", "\u00e9" ); |
601 | 1 | parser.defineEntityReplacementText( "ecirc", "\u00ea" ); |
602 | 1 | parser.defineEntityReplacementText( "euml", "\u00eb" ); |
603 | 1 | parser.defineEntityReplacementText( "igrave", "\u00ec" ); |
604 | 1 | parser.defineEntityReplacementText( "iacute", "\u00ed" ); |
605 | 1 | parser.defineEntityReplacementText( "icirc", "\u00ee" ); |
606 | 1 | parser.defineEntityReplacementText( "iuml", "\u00ef" ); |
607 | 1 | parser.defineEntityReplacementText( "eth", "\u00f0" ); |
608 | 1 | parser.defineEntityReplacementText( "ntilde", "\u00f1" ); |
609 | 1 | parser.defineEntityReplacementText( "ograve", "\u00f2" ); |
610 | 1 | parser.defineEntityReplacementText( "oacute", "\u00f3" ); |
611 | 1 | parser.defineEntityReplacementText( "ocirc", "\u00f4" ); |
612 | 1 | parser.defineEntityReplacementText( "otilde", "\u00f5" ); |
613 | 1 | parser.defineEntityReplacementText( "ouml", "\u00f6" ); |
614 | 1 | parser.defineEntityReplacementText( "divide", "\u00f7" ); |
615 | 1 | parser.defineEntityReplacementText( "oslash", "\u00f8" ); |
616 | 1 | parser.defineEntityReplacementText( "ugrave", "\u00f9" ); |
617 | 1 | parser.defineEntityReplacementText( "uacute", "\u00fa" ); |
618 | 1 | parser.defineEntityReplacementText( "ucirc", "\u00fb" ); |
619 | 1 | parser.defineEntityReplacementText( "uuml", "\u00fc" ); |
620 | 1 | parser.defineEntityReplacementText( "yacute", "\u00fd" ); |
621 | 1 | parser.defineEntityReplacementText( "thorn", "\u00fe" ); |
622 | 1 | parser.defineEntityReplacementText( "yuml", "\u00ff" ); |
623 | |
|
624 | |
|
625 | |
|
626 | |
|
627 | |
|
628 | 1 | parser.defineEntityReplacementText( "OElig", "\u0152" ); |
629 | 1 | parser.defineEntityReplacementText( "oelig", "\u0153" ); |
630 | 1 | parser.defineEntityReplacementText( "Scaron", "\u0160" ); |
631 | 1 | parser.defineEntityReplacementText( "scaron", "\u0161" ); |
632 | 1 | parser.defineEntityReplacementText( "Yuml", "\u0178" ); |
633 | 1 | parser.defineEntityReplacementText( "circ", "\u02c6" ); |
634 | 1 | parser.defineEntityReplacementText( "tilde", "\u02dc" ); |
635 | 1 | parser.defineEntityReplacementText( "ensp", "\u2002" ); |
636 | 1 | parser.defineEntityReplacementText( "emsp", "\u2003" ); |
637 | 1 | parser.defineEntityReplacementText( "thinsp", "\u2009" ); |
638 | 1 | parser.defineEntityReplacementText( "zwnj", "\u200c" ); |
639 | 1 | parser.defineEntityReplacementText( "zwj", "\u200d" ); |
640 | 1 | parser.defineEntityReplacementText( "lrm", "\u200e" ); |
641 | 1 | parser.defineEntityReplacementText( "rlm", "\u200f" ); |
642 | 1 | parser.defineEntityReplacementText( "ndash", "\u2013" ); |
643 | 1 | parser.defineEntityReplacementText( "mdash", "\u2014" ); |
644 | 1 | parser.defineEntityReplacementText( "lsquo", "\u2018" ); |
645 | 1 | parser.defineEntityReplacementText( "rsquo", "\u2019" ); |
646 | 1 | parser.defineEntityReplacementText( "sbquo", "\u201a" ); |
647 | 1 | parser.defineEntityReplacementText( "ldquo", "\u201c" ); |
648 | 1 | parser.defineEntityReplacementText( "rdquo", "\u201d" ); |
649 | 1 | parser.defineEntityReplacementText( "bdquo", "\u201e" ); |
650 | 1 | parser.defineEntityReplacementText( "dagger", "\u2020" ); |
651 | 1 | parser.defineEntityReplacementText( "Dagger", "\u2021" ); |
652 | 1 | parser.defineEntityReplacementText( "permil", "\u2030" ); |
653 | 1 | parser.defineEntityReplacementText( "lsaquo", "\u2039" ); |
654 | 1 | parser.defineEntityReplacementText( "rsaquo", "\u203a" ); |
655 | 1 | parser.defineEntityReplacementText( "euro", "\u20ac" ); |
656 | |
|
657 | |
|
658 | |
|
659 | |
|
660 | |
|
661 | 1 | parser.defineEntityReplacementText( "fnof", "\u0192" ); |
662 | 1 | parser.defineEntityReplacementText( "Alpha", "\u0391" ); |
663 | 1 | parser.defineEntityReplacementText( "Beta", "\u0392" ); |
664 | 1 | parser.defineEntityReplacementText( "Gamma", "\u0393" ); |
665 | 1 | parser.defineEntityReplacementText( "Delta", "\u0394" ); |
666 | 1 | parser.defineEntityReplacementText( "Epsilon", "\u0395" ); |
667 | 1 | parser.defineEntityReplacementText( "Zeta", "\u0396" ); |
668 | 1 | parser.defineEntityReplacementText( "Eta", "\u0397" ); |
669 | 1 | parser.defineEntityReplacementText( "Theta", "\u0398" ); |
670 | 1 | parser.defineEntityReplacementText( "Iota", "\u0399" ); |
671 | 1 | parser.defineEntityReplacementText( "Kappa", "\u039a" ); |
672 | 1 | parser.defineEntityReplacementText( "Lambda", "\u039b" ); |
673 | 1 | parser.defineEntityReplacementText( "Mu", "\u039c" ); |
674 | 1 | parser.defineEntityReplacementText( "Nu", "\u039d" ); |
675 | 1 | parser.defineEntityReplacementText( "Xi", "\u039e" ); |
676 | 1 | parser.defineEntityReplacementText( "Omicron", "\u039f" ); |
677 | 1 | parser.defineEntityReplacementText( "Pi", "\u03a0" ); |
678 | 1 | parser.defineEntityReplacementText( "Rho", "\u03a1" ); |
679 | 1 | parser.defineEntityReplacementText( "Sigma", "\u03a3" ); |
680 | 1 | parser.defineEntityReplacementText( "Tau", "\u03a4" ); |
681 | 1 | parser.defineEntityReplacementText( "Upsilon", "\u03a5" ); |
682 | 1 | parser.defineEntityReplacementText( "Phi", "\u03a6" ); |
683 | 1 | parser.defineEntityReplacementText( "Chi", "\u03a7" ); |
684 | 1 | parser.defineEntityReplacementText( "Psi", "\u03a8" ); |
685 | 1 | parser.defineEntityReplacementText( "Omega", "\u03a9" ); |
686 | 1 | parser.defineEntityReplacementText( "alpha", "\u03b1" ); |
687 | 1 | parser.defineEntityReplacementText( "beta", "\u03b2" ); |
688 | 1 | parser.defineEntityReplacementText( "gamma", "\u03b3" ); |
689 | 1 | parser.defineEntityReplacementText( "delta", "\u03b4" ); |
690 | 1 | parser.defineEntityReplacementText( "epsilon", "\u03b5" ); |
691 | 1 | parser.defineEntityReplacementText( "zeta", "\u03b6" ); |
692 | 1 | parser.defineEntityReplacementText( "eta", "\u03b7" ); |
693 | 1 | parser.defineEntityReplacementText( "theta", "\u03b8" ); |
694 | 1 | parser.defineEntityReplacementText( "iota", "\u03b9" ); |
695 | 1 | parser.defineEntityReplacementText( "kappa", "\u03ba" ); |
696 | 1 | parser.defineEntityReplacementText( "lambda", "\u03bb" ); |
697 | 1 | parser.defineEntityReplacementText( "mu", "\u03bc" ); |
698 | 1 | parser.defineEntityReplacementText( "nu", "\u03bd" ); |
699 | 1 | parser.defineEntityReplacementText( "xi", "\u03be" ); |
700 | 1 | parser.defineEntityReplacementText( "omicron", "\u03bf" ); |
701 | 1 | parser.defineEntityReplacementText( "pi", "\u03c0" ); |
702 | 1 | parser.defineEntityReplacementText( "rho", "\u03c1" ); |
703 | 1 | parser.defineEntityReplacementText( "sigmaf", "\u03c2" ); |
704 | 1 | parser.defineEntityReplacementText( "sigma", "\u03c3" ); |
705 | 1 | parser.defineEntityReplacementText( "tau", "\u03c4" ); |
706 | 1 | parser.defineEntityReplacementText( "upsilon", "\u03c5" ); |
707 | 1 | parser.defineEntityReplacementText( "phi", "\u03c6" ); |
708 | 1 | parser.defineEntityReplacementText( "chi", "\u03c7" ); |
709 | 1 | parser.defineEntityReplacementText( "psi", "\u03c8" ); |
710 | 1 | parser.defineEntityReplacementText( "omega", "\u03c9" ); |
711 | 1 | parser.defineEntityReplacementText( "thetasym", "\u03d1" ); |
712 | 1 | parser.defineEntityReplacementText( "upsih", "\u03d2" ); |
713 | 1 | parser.defineEntityReplacementText( "piv", "\u03d6" ); |
714 | 1 | parser.defineEntityReplacementText( "bull", "\u2022" ); |
715 | 1 | parser.defineEntityReplacementText( "hellip", "\u2026" ); |
716 | 1 | parser.defineEntityReplacementText( "prime", "\u2032" ); |
717 | 1 | parser.defineEntityReplacementText( "Prime", "\u2033" ); |
718 | 1 | parser.defineEntityReplacementText( "oline", "\u203e" ); |
719 | 1 | parser.defineEntityReplacementText( "frasl", "\u2044" ); |
720 | 1 | parser.defineEntityReplacementText( "weierp", "\u2118" ); |
721 | 1 | parser.defineEntityReplacementText( "image", "\u2111" ); |
722 | 1 | parser.defineEntityReplacementText( "real", "\u211c" ); |
723 | 1 | parser.defineEntityReplacementText( "trade", "\u2122" ); |
724 | 1 | parser.defineEntityReplacementText( "alefsym", "\u2135" ); |
725 | 1 | parser.defineEntityReplacementText( "larr", "\u2190" ); |
726 | 1 | parser.defineEntityReplacementText( "uarr", "\u2191" ); |
727 | 1 | parser.defineEntityReplacementText( "rarr", "\u2192" ); |
728 | 1 | parser.defineEntityReplacementText( "darr", "\u2193" ); |
729 | 1 | parser.defineEntityReplacementText( "harr", "\u2194" ); |
730 | 1 | parser.defineEntityReplacementText( "crarr", "\u21b5" ); |
731 | 1 | parser.defineEntityReplacementText( "lArr", "\u21d0" ); |
732 | 1 | parser.defineEntityReplacementText( "uArr", "\u21d1" ); |
733 | 1 | parser.defineEntityReplacementText( "rArr", "\u21d2" ); |
734 | 1 | parser.defineEntityReplacementText( "dArr", "\u21d3" ); |
735 | 1 | parser.defineEntityReplacementText( "hArr", "\u21d4" ); |
736 | 1 | parser.defineEntityReplacementText( "forall", "\u2200" ); |
737 | 1 | parser.defineEntityReplacementText( "part", "\u2202" ); |
738 | 1 | parser.defineEntityReplacementText( "exist", "\u2203" ); |
739 | 1 | parser.defineEntityReplacementText( "empty", "\u2205" ); |
740 | 1 | parser.defineEntityReplacementText( "nabla", "\u2207" ); |
741 | 1 | parser.defineEntityReplacementText( "isin", "\u2208" ); |
742 | 1 | parser.defineEntityReplacementText( "notin", "\u2209" ); |
743 | 1 | parser.defineEntityReplacementText( "ni", "\u220b" ); |
744 | 1 | parser.defineEntityReplacementText( "prod", "\u220f" ); |
745 | 1 | parser.defineEntityReplacementText( "sum", "\u2211" ); |
746 | 1 | parser.defineEntityReplacementText( "minus", "\u2212" ); |
747 | 1 | parser.defineEntityReplacementText( "lowast", "\u2217" ); |
748 | 1 | parser.defineEntityReplacementText( "radic", "\u221a" ); |
749 | 1 | parser.defineEntityReplacementText( "prop", "\u221d" ); |
750 | 1 | parser.defineEntityReplacementText( "infin", "\u221e" ); |
751 | 1 | parser.defineEntityReplacementText( "ang", "\u2220" ); |
752 | 1 | parser.defineEntityReplacementText( "and", "\u2227" ); |
753 | 1 | parser.defineEntityReplacementText( "or", "\u2228" ); |
754 | 1 | parser.defineEntityReplacementText( "cap", "\u2229" ); |
755 | 1 | parser.defineEntityReplacementText( "cup", "\u222a" ); |
756 | 1 | parser.defineEntityReplacementText( "int", "\u222b" ); |
757 | 1 | parser.defineEntityReplacementText( "there4", "\u2234" ); |
758 | 1 | parser.defineEntityReplacementText( "sim", "\u223c" ); |
759 | 1 | parser.defineEntityReplacementText( "cong", "\u2245" ); |
760 | 1 | parser.defineEntityReplacementText( "asymp", "\u2248" ); |
761 | 1 | parser.defineEntityReplacementText( "ne", "\u2260" ); |
762 | 1 | parser.defineEntityReplacementText( "equiv", "\u2261" ); |
763 | 1 | parser.defineEntityReplacementText( "le", "\u2264" ); |
764 | 1 | parser.defineEntityReplacementText( "ge", "\u2265" ); |
765 | 1 | parser.defineEntityReplacementText( "sub", "\u2282" ); |
766 | 1 | parser.defineEntityReplacementText( "sup", "\u2283" ); |
767 | 1 | parser.defineEntityReplacementText( "nsub", "\u2284" ); |
768 | 1 | parser.defineEntityReplacementText( "sube", "\u2286" ); |
769 | 1 | parser.defineEntityReplacementText( "supe", "\u2287" ); |
770 | 1 | parser.defineEntityReplacementText( "oplus", "\u2295" ); |
771 | 1 | parser.defineEntityReplacementText( "otimes", "\u2297" ); |
772 | 1 | parser.defineEntityReplacementText( "perp", "\u22a5" ); |
773 | 1 | parser.defineEntityReplacementText( "sdot", "\u22c5" ); |
774 | 1 | parser.defineEntityReplacementText( "lceil", "\u2308" ); |
775 | 1 | parser.defineEntityReplacementText( "rceil", "\u2309" ); |
776 | 1 | parser.defineEntityReplacementText( "lfloor", "\u230a" ); |
777 | 1 | parser.defineEntityReplacementText( "rfloor", "\u230b" ); |
778 | 1 | parser.defineEntityReplacementText( "lang", "\u2329" ); |
779 | 1 | parser.defineEntityReplacementText( "rang", "\u232a" ); |
780 | 1 | parser.defineEntityReplacementText( "loz", "\u25ca" ); |
781 | 1 | parser.defineEntityReplacementText( "spades", "\u2660" ); |
782 | 1 | parser.defineEntityReplacementText( "clubs", "\u2663" ); |
783 | 1 | parser.defineEntityReplacementText( "hearts", "\u2665" ); |
784 | 1 | parser.defineEntityReplacementText( "diams", "\u2666" ); |
785 | |
|
786 | |
} |
787 | |
|
788 | 1 | parser.next(); |
789 | 1 | return parseDocumentModel( "document", parser, strict ); |
790 | |
} |
791 | |
|
792 | |
|
793 | |
|
794 | |
|
795 | |
|
796 | |
|
797 | |
public DocumentModel read(Reader reader) |
798 | |
throws IOException, XmlPullParserException |
799 | |
{ |
800 | 1 | return read( reader, true ); |
801 | |
} |
802 | |
|
803 | |
|
804 | |
|
805 | |
|
806 | |
|
807 | |
|
808 | |
|
809 | |
public DocumentModel read(InputStream in, boolean strict) |
810 | |
throws IOException, XmlPullParserException |
811 | |
{ |
812 | 0 | Reader reader = ReaderFactory.newXmlReader( in ); |
813 | |
|
814 | 0 | return read( reader, strict ); |
815 | |
} |
816 | |
|
817 | |
|
818 | |
|
819 | |
|
820 | |
|
821 | |
|
822 | |
public DocumentModel read(InputStream in) |
823 | |
throws IOException, XmlPullParserException |
824 | |
{ |
825 | 0 | Reader reader = ReaderFactory.newXmlReader( in ); |
826 | |
|
827 | 0 | return read( reader ); |
828 | |
} |
829 | |
|
830 | |
|
831 | |
|
832 | |
|
833 | |
|
834 | |
|
835 | |
public void setAddDefaultEntities(boolean addDefaultEntities) |
836 | |
{ |
837 | 0 | this.addDefaultEntities = addDefaultEntities; |
838 | 0 | } |
839 | |
|
840 | |
|
841 | |
} |