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 |
| package org.w3c.tidy; |
55 |
| |
56 |
| import java.io.FileInputStream; |
57 |
| import java.io.IOException; |
58 |
| import java.io.Serializable; |
59 |
| import java.io.Writer; |
60 |
| import java.lang.reflect.Field; |
61 |
| import java.util.ArrayList; |
62 |
| import java.util.Collections; |
63 |
| import java.util.Enumeration; |
64 |
| import java.util.HashMap; |
65 |
| import java.util.Iterator; |
66 |
| import java.util.List; |
67 |
| import java.util.Map; |
68 |
| import java.util.Properties; |
69 |
| |
70 |
| |
71 |
| |
72 |
| |
73 |
| |
74 |
| |
75 |
| |
76 |
| |
77 |
| |
78 |
| |
79 |
| public class Configuration implements Serializable |
80 |
| { |
81 |
| |
82 |
| |
83 |
| |
84 |
| |
85 |
| |
86 |
| public static final int RAW = 0; |
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
| |
92 |
| public static final int ASCII = 1; |
93 |
| |
94 |
| |
95 |
| |
96 |
| |
97 |
| |
98 |
| public static final int LATIN1 = 2; |
99 |
| |
100 |
| |
101 |
| |
102 |
| |
103 |
| |
104 |
| public static final int UTF8 = 3; |
105 |
| |
106 |
| |
107 |
| |
108 |
| |
109 |
| |
110 |
| public static final int ISO2022 = 4; |
111 |
| |
112 |
| |
113 |
| |
114 |
| |
115 |
| |
116 |
| public static final int MACROMAN = 5; |
117 |
| |
118 |
| |
119 |
| |
120 |
| |
121 |
| |
122 |
| public static final int UTF16LE = 6; |
123 |
| |
124 |
| |
125 |
| |
126 |
| |
127 |
| |
128 |
| public static final int UTF16BE = 7; |
129 |
| |
130 |
| |
131 |
| |
132 |
| |
133 |
| |
134 |
| public static final int UTF16 = 8; |
135 |
| |
136 |
| |
137 |
| |
138 |
| |
139 |
| |
140 |
| public static final int WIN1252 = 9; |
141 |
| |
142 |
| |
143 |
| |
144 |
| |
145 |
| |
146 |
| public static final int BIG5 = 10; |
147 |
| |
148 |
| |
149 |
| |
150 |
| |
151 |
| |
152 |
| public static final int SHIFTJIS = 11; |
153 |
| |
154 |
| |
155 |
| |
156 |
| |
157 |
| private final String[] ENCODING_NAMES = new String[]{ |
158 |
| "raw", |
159 |
| "ASCII", |
160 |
| "ISO8859_1", |
161 |
| "UTF8", |
162 |
| "JIS", |
163 |
| "MacRoman", |
164 |
| "UnicodeLittle", |
165 |
| "UnicodeBig", |
166 |
| "Unicode", |
167 |
| "Cp1252", |
168 |
| "Big5", |
169 |
| "SJIS"}; |
170 |
| |
171 |
| |
172 |
| |
173 |
| |
174 |
| |
175 |
| public static final int DOCTYPE_OMIT = 0; |
176 |
| |
177 |
| |
178 |
| |
179 |
| |
180 |
| public static final int DOCTYPE_AUTO = 1; |
181 |
| |
182 |
| |
183 |
| |
184 |
| |
185 |
| public static final int DOCTYPE_STRICT = 2; |
186 |
| |
187 |
| |
188 |
| |
189 |
| |
190 |
| public static final int DOCTYPE_LOOSE = 3; |
191 |
| |
192 |
| |
193 |
| |
194 |
| |
195 |
| public static final int DOCTYPE_USER = 4; |
196 |
| |
197 |
| |
198 |
| |
199 |
| |
200 |
| |
201 |
| public static final int KEEP_LAST = 0; |
202 |
| |
203 |
| |
204 |
| |
205 |
| |
206 |
| public static final int KEEP_FIRST = 1; |
207 |
| |
208 |
| |
209 |
| |
210 |
| |
211 |
| |
212 |
| private static final Map OPTIONS = new HashMap(); |
213 |
| |
214 |
| |
215 |
| |
216 |
| |
217 |
| private static final long serialVersionUID = -4955155037138560842L; |
218 |
| |
219 |
| static |
220 |
| { |
221 |
13
| addConfigOption(new Flag("indent-spaces", "spaces", ParsePropertyImpl.INT));
|
222 |
13
| addConfigOption(new Flag("wrap", "wraplen", ParsePropertyImpl.INT));
|
223 |
13
| addConfigOption(new Flag("show-errors", "showErrors", ParsePropertyImpl.INT));
|
224 |
13
| addConfigOption(new Flag("tab-size", "tabsize", ParsePropertyImpl.INT));
|
225 |
| |
226 |
13
| addConfigOption(new Flag("wrap-attributes", "wrapAttVals", ParsePropertyImpl.BOOL));
|
227 |
13
| addConfigOption(new Flag("wrap-script-literals", "wrapScriptlets", ParsePropertyImpl.BOOL));
|
228 |
13
| addConfigOption(new Flag("wrap-sections", "wrapSection", ParsePropertyImpl.BOOL));
|
229 |
13
| addConfigOption(new Flag("wrap-asp", "wrapAsp", ParsePropertyImpl.BOOL));
|
230 |
13
| addConfigOption(new Flag("wrap-jste", "wrapJste", ParsePropertyImpl.BOOL));
|
231 |
13
| addConfigOption(new Flag("wrap-php", "wrapPhp", ParsePropertyImpl.BOOL));
|
232 |
13
| addConfigOption(new Flag("literal-attributes", "literalAttribs", ParsePropertyImpl.BOOL));
|
233 |
13
| addConfigOption(new Flag("show-body-only", "bodyOnly", ParsePropertyImpl.BOOL));
|
234 |
13
| addConfigOption(new Flag("fix-uri", "fixUri", ParsePropertyImpl.BOOL));
|
235 |
13
| addConfigOption(new Flag("lower-literals", "lowerLiterals", ParsePropertyImpl.BOOL));
|
236 |
13
| addConfigOption(new Flag("hide-comments", "hideComments", ParsePropertyImpl.BOOL));
|
237 |
13
| addConfigOption(new Flag("indent-cdata", "indentCdata", ParsePropertyImpl.BOOL));
|
238 |
13
| addConfigOption(new Flag("force-output", "forceOutput", ParsePropertyImpl.BOOL));
|
239 |
13
| addConfigOption(new Flag("ascii-chars", "asciiChars", ParsePropertyImpl.BOOL));
|
240 |
13
| addConfigOption(new Flag("join-classes", "joinClasses", ParsePropertyImpl.BOOL));
|
241 |
13
| addConfigOption(new Flag("join-styles", "joinStyles", ParsePropertyImpl.BOOL));
|
242 |
13
| addConfigOption(new Flag("escape-cdata", "escapeCdata", ParsePropertyImpl.BOOL));
|
243 |
13
| addConfigOption(new Flag("replace-color", "replaceColor", ParsePropertyImpl.BOOL));
|
244 |
13
| addConfigOption(new Flag("quiet", "quiet", ParsePropertyImpl.BOOL));
|
245 |
13
| addConfigOption(new Flag("tidy-mark", "tidyMark", ParsePropertyImpl.BOOL));
|
246 |
13
| addConfigOption(new Flag("indent-attributes", "indentAttributes", ParsePropertyImpl.BOOL));
|
247 |
13
| addConfigOption(new Flag("hide-endtags", "hideEndTags", ParsePropertyImpl.BOOL));
|
248 |
13
| addConfigOption(new Flag("input-xml", "xmlTags", ParsePropertyImpl.BOOL));
|
249 |
13
| addConfigOption(new Flag("output-xml", "xmlOut", ParsePropertyImpl.BOOL));
|
250 |
13
| addConfigOption(new Flag("output-html", "htmlOut", ParsePropertyImpl.BOOL));
|
251 |
13
| addConfigOption(new Flag("output-xhtml", "xHTML", ParsePropertyImpl.BOOL));
|
252 |
13
| addConfigOption(new Flag("add-xml-pi", "xmlPi", ParsePropertyImpl.BOOL));
|
253 |
13
| addConfigOption(new Flag("add-xml-decl", "xmlPi", ParsePropertyImpl.BOOL));
|
254 |
13
| addConfigOption(new Flag("assume-xml-procins", "xmlPIs", ParsePropertyImpl.BOOL));
|
255 |
13
| addConfigOption(new Flag("uppercase-tags", "upperCaseTags", ParsePropertyImpl.BOOL));
|
256 |
13
| addConfigOption(new Flag("uppercase-attributes", "upperCaseAttrs", ParsePropertyImpl.BOOL));
|
257 |
13
| addConfigOption(new Flag("bare", "makeBare", ParsePropertyImpl.BOOL));
|
258 |
13
| addConfigOption(new Flag("clean", "makeClean", ParsePropertyImpl.BOOL));
|
259 |
13
| addConfigOption(new Flag("logical-emphasis", "logicalEmphasis", ParsePropertyImpl.BOOL));
|
260 |
13
| addConfigOption(new Flag("word-2000", "word2000", ParsePropertyImpl.BOOL));
|
261 |
13
| addConfigOption(new Flag("drop-empty-paras", "dropEmptyParas", ParsePropertyImpl.BOOL));
|
262 |
13
| addConfigOption(new Flag("drop-font-tags", "dropFontTags", ParsePropertyImpl.BOOL));
|
263 |
13
| addConfigOption(new Flag("drop-proprietary-attributes", "dropProprietaryAttributes", ParsePropertyImpl.BOOL));
|
264 |
13
| addConfigOption(new Flag("enclose-text", "encloseBodyText", ParsePropertyImpl.BOOL));
|
265 |
13
| addConfigOption(new Flag("enclose-block-text", "encloseBlockText", ParsePropertyImpl.BOOL));
|
266 |
13
| addConfigOption(new Flag("add-xml-space", "xmlSpace", ParsePropertyImpl.BOOL));
|
267 |
13
| addConfigOption(new Flag("fix-bad-comments", "fixComments", ParsePropertyImpl.BOOL));
|
268 |
13
| addConfigOption(new Flag("split", "burstSlides", ParsePropertyImpl.BOOL));
|
269 |
13
| addConfigOption(new Flag("break-before-br", "breakBeforeBR", ParsePropertyImpl.BOOL));
|
270 |
13
| addConfigOption(new Flag("numeric-entities", "numEntities", ParsePropertyImpl.BOOL));
|
271 |
13
| addConfigOption(new Flag("quote-marks", "quoteMarks", ParsePropertyImpl.BOOL));
|
272 |
13
| addConfigOption(new Flag("quote-nbsp", "quoteNbsp", ParsePropertyImpl.BOOL));
|
273 |
13
| addConfigOption(new Flag("quote-ampersand", "quoteAmpersand", ParsePropertyImpl.BOOL));
|
274 |
13
| addConfigOption(new Flag("write-back", "writeback", ParsePropertyImpl.BOOL));
|
275 |
13
| addConfigOption(new Flag("keep-time", "keepFileTimes", ParsePropertyImpl.BOOL));
|
276 |
13
| addConfigOption(new Flag("show-warnings", "showWarnings", ParsePropertyImpl.BOOL));
|
277 |
13
| addConfigOption(new Flag("ncr", "ncr", ParsePropertyImpl.BOOL));
|
278 |
13
| addConfigOption(new Flag("fix-backslash", "fixBackslash", ParsePropertyImpl.BOOL));
|
279 |
13
| addConfigOption(new Flag("gnu-emacs", "emacs", ParsePropertyImpl.BOOL));
|
280 |
13
| addConfigOption(new Flag("only-errors", "onlyErrors", ParsePropertyImpl.BOOL));
|
281 |
13
| addConfigOption(new Flag("output-raw", "rawOut", ParsePropertyImpl.BOOL));
|
282 |
13
| addConfigOption(new Flag("trim-empty-elements", "trimEmpty", ParsePropertyImpl.BOOL));
|
283 |
| |
284 |
13
| addConfigOption(new Flag("markup", "onlyErrors", ParsePropertyImpl.INVBOOL));
|
285 |
| |
286 |
13
| addConfigOption(new Flag("char-encoding", null, ParsePropertyImpl.CHAR_ENCODING));
|
287 |
13
| addConfigOption(new Flag("input-encoding", null, ParsePropertyImpl.CHAR_ENCODING));
|
288 |
13
| addConfigOption(new Flag("output-encoding", null, ParsePropertyImpl.CHAR_ENCODING));
|
289 |
| |
290 |
13
| addConfigOption(new Flag("error-file", "errfile", ParsePropertyImpl.NAME));
|
291 |
13
| addConfigOption(new Flag("slide-style", "slidestyle", ParsePropertyImpl.NAME));
|
292 |
13
| addConfigOption(new Flag("language", "language", ParsePropertyImpl.NAME));
|
293 |
| |
294 |
13
| addConfigOption(new Flag("new-inline-tags", null, ParsePropertyImpl.TAGNAMES));
|
295 |
13
| addConfigOption(new Flag("new-blocklevel-tags", null, ParsePropertyImpl.TAGNAMES));
|
296 |
13
| addConfigOption(new Flag("new-empty-tags", null, ParsePropertyImpl.TAGNAMES));
|
297 |
13
| addConfigOption(new Flag("new-pre-tags", null, ParsePropertyImpl.TAGNAMES));
|
298 |
| |
299 |
13
| addConfigOption(new Flag("doctype", "docTypeStr", ParsePropertyImpl.DOCTYPE));
|
300 |
| |
301 |
13
| addConfigOption(new Flag("repeated-attributes", "duplicateAttrs", ParsePropertyImpl.REPEATED_ATTRIBUTES));
|
302 |
| |
303 |
13
| addConfigOption(new Flag("alt-text", "altText", ParsePropertyImpl.STRING));
|
304 |
| |
305 |
13
| addConfigOption(new Flag("indent", "indentContent", ParsePropertyImpl.INDENT));
|
306 |
| |
307 |
13
| addConfigOption(new Flag("css-prefix", "cssPrefix", ParsePropertyImpl.CSS1SELECTOR));
|
308 |
| |
309 |
13
| addConfigOption(new Flag("newline", null, ParsePropertyImpl.NEWLINE));
|
310 |
| } |
311 |
| |
312 |
| |
313 |
| |
314 |
| |
315 |
| protected int spaces = 2; |
316 |
| |
317 |
| |
318 |
| |
319 |
| |
320 |
| protected int wraplen = 68; |
321 |
| |
322 |
| |
323 |
| |
324 |
| |
325 |
| protected int tabsize = 8; |
326 |
| |
327 |
| |
328 |
| |
329 |
| |
330 |
| protected int docTypeMode = DOCTYPE_AUTO; |
331 |
| |
332 |
| |
333 |
| |
334 |
| |
335 |
| protected int duplicateAttrs = KEEP_LAST; |
336 |
| |
337 |
| |
338 |
| |
339 |
| |
340 |
| protected String altText; |
341 |
| |
342 |
| |
343 |
| |
344 |
| |
345 |
| |
346 |
| protected String slidestyle; |
347 |
| |
348 |
| |
349 |
| |
350 |
| |
351 |
| protected String language; |
352 |
| |
353 |
| |
354 |
| |
355 |
| |
356 |
| protected String docTypeStr; |
357 |
| |
358 |
| |
359 |
| |
360 |
| |
361 |
| protected String errfile; |
362 |
| |
363 |
| |
364 |
| |
365 |
| |
366 |
| protected boolean writeback; |
367 |
| |
368 |
| |
369 |
| |
370 |
| |
371 |
| protected boolean onlyErrors; |
372 |
| |
373 |
| |
374 |
| |
375 |
| |
376 |
| protected boolean showWarnings = true; |
377 |
| |
378 |
| |
379 |
| |
380 |
| |
381 |
| protected boolean quiet; |
382 |
| |
383 |
| |
384 |
| |
385 |
| |
386 |
| protected boolean indentContent; |
387 |
| |
388 |
| |
389 |
| |
390 |
| |
391 |
| protected boolean smartIndent; |
392 |
| |
393 |
| |
394 |
| |
395 |
| |
396 |
| protected boolean hideEndTags; |
397 |
| |
398 |
| |
399 |
| |
400 |
| |
401 |
| protected boolean xmlTags; |
402 |
| |
403 |
| |
404 |
| |
405 |
| |
406 |
| protected boolean xmlOut; |
407 |
| |
408 |
| |
409 |
| |
410 |
| |
411 |
| protected boolean xHTML; |
412 |
| |
413 |
| |
414 |
| |
415 |
| |
416 |
| protected boolean htmlOut; |
417 |
| |
418 |
| |
419 |
| |
420 |
| |
421 |
| protected boolean xmlPi; |
422 |
| |
423 |
| |
424 |
| |
425 |
| |
426 |
| protected boolean upperCaseTags; |
427 |
| |
428 |
| |
429 |
| |
430 |
| |
431 |
| protected boolean upperCaseAttrs; |
432 |
| |
433 |
| |
434 |
| |
435 |
| |
436 |
| protected boolean makeClean; |
437 |
| |
438 |
| |
439 |
| |
440 |
| |
441 |
| protected boolean makeBare; |
442 |
| |
443 |
| |
444 |
| |
445 |
| |
446 |
| protected boolean logicalEmphasis; |
447 |
| |
448 |
| |
449 |
| |
450 |
| |
451 |
| protected boolean dropFontTags; |
452 |
| |
453 |
| |
454 |
| |
455 |
| |
456 |
| protected boolean dropProprietaryAttributes; |
457 |
| |
458 |
| |
459 |
| |
460 |
| |
461 |
| protected boolean dropEmptyParas = true; |
462 |
| |
463 |
| |
464 |
| |
465 |
| |
466 |
| protected boolean fixComments = true; |
467 |
| |
468 |
| |
469 |
| |
470 |
| |
471 |
| protected boolean trimEmpty = true; |
472 |
| |
473 |
| |
474 |
| |
475 |
| |
476 |
| protected boolean breakBeforeBR; |
477 |
| |
478 |
| |
479 |
| |
480 |
| |
481 |
| protected boolean burstSlides; |
482 |
| |
483 |
| |
484 |
| |
485 |
| |
486 |
| protected boolean numEntities; |
487 |
| |
488 |
| |
489 |
| |
490 |
| |
491 |
| protected boolean quoteMarks; |
492 |
| |
493 |
| |
494 |
| |
495 |
| |
496 |
| protected boolean quoteNbsp = true; |
497 |
| |
498 |
| |
499 |
| |
500 |
| |
501 |
| protected boolean quoteAmpersand = true; |
502 |
| |
503 |
| |
504 |
| |
505 |
| |
506 |
| protected boolean wrapAttVals; |
507 |
| |
508 |
| |
509 |
| |
510 |
| |
511 |
| protected boolean wrapScriptlets; |
512 |
| |
513 |
| |
514 |
| |
515 |
| |
516 |
| protected boolean wrapSection = true; |
517 |
| |
518 |
| |
519 |
| |
520 |
| |
521 |
| protected boolean wrapAsp = true; |
522 |
| |
523 |
| |
524 |
| |
525 |
| |
526 |
| protected boolean wrapJste = true; |
527 |
| |
528 |
| |
529 |
| |
530 |
| |
531 |
| protected boolean wrapPhp = true; |
532 |
| |
533 |
| |
534 |
| |
535 |
| |
536 |
| protected boolean fixBackslash = true; |
537 |
| |
538 |
| |
539 |
| |
540 |
| |
541 |
| protected boolean indentAttributes; |
542 |
| |
543 |
| |
544 |
| |
545 |
| |
546 |
| protected boolean xmlPIs; |
547 |
| |
548 |
| |
549 |
| |
550 |
| |
551 |
| protected boolean xmlSpace; |
552 |
| |
553 |
| |
554 |
| |
555 |
| |
556 |
| protected boolean encloseBodyText; |
557 |
| |
558 |
| |
559 |
| |
560 |
| |
561 |
| protected boolean encloseBlockText; |
562 |
| |
563 |
| |
564 |
| |
565 |
| |
566 |
| protected boolean keepFileTimes = true; |
567 |
| |
568 |
| |
569 |
| |
570 |
| |
571 |
| protected boolean word2000; |
572 |
| |
573 |
| |
574 |
| |
575 |
| |
576 |
| protected boolean tidyMark = true; |
577 |
| |
578 |
| |
579 |
| |
580 |
| |
581 |
| protected boolean emacs; |
582 |
| |
583 |
| |
584 |
| |
585 |
| |
586 |
| protected boolean literalAttribs; |
587 |
| |
588 |
| |
589 |
| |
590 |
| |
591 |
| protected boolean bodyOnly; |
592 |
| |
593 |
| |
594 |
| |
595 |
| |
596 |
| protected boolean fixUri = true; |
597 |
| |
598 |
| |
599 |
| |
600 |
| |
601 |
| protected boolean lowerLiterals = true; |
602 |
| |
603 |
| |
604 |
| |
605 |
| |
606 |
| protected boolean replaceColor; |
607 |
| |
608 |
| |
609 |
| |
610 |
| |
611 |
| protected boolean hideComments; |
612 |
| |
613 |
| |
614 |
| |
615 |
| |
616 |
| protected boolean indentCdata; |
617 |
| |
618 |
| |
619 |
| |
620 |
| |
621 |
| protected boolean forceOutput; |
622 |
| |
623 |
| |
624 |
| |
625 |
| |
626 |
| protected int showErrors = 6; |
627 |
| |
628 |
| |
629 |
| |
630 |
| |
631 |
| protected boolean asciiChars = true; |
632 |
| |
633 |
| |
634 |
| |
635 |
| |
636 |
| protected boolean joinClasses; |
637 |
| |
638 |
| |
639 |
| |
640 |
| |
641 |
| protected boolean joinStyles = true; |
642 |
| |
643 |
| |
644 |
| |
645 |
| |
646 |
| protected boolean escapeCdata = true; |
647 |
| |
648 |
| |
649 |
| |
650 |
| |
651 |
| protected boolean ncr = true; |
652 |
| |
653 |
| |
654 |
| |
655 |
| |
656 |
| protected String cssPrefix; |
657 |
| |
658 |
| |
659 |
| |
660 |
| |
661 |
| protected int replacementCharEncoding = WIN1252; |
662 |
| |
663 |
| |
664 |
| |
665 |
| |
666 |
| protected TagTable tt; |
667 |
| |
668 |
| |
669 |
| |
670 |
| |
671 |
| protected Report report; |
672 |
| |
673 |
| |
674 |
| |
675 |
| |
676 |
| protected int definedTags; |
677 |
| |
678 |
| |
679 |
| |
680 |
| |
681 |
| protected char[] newline = (System.getProperty("line.separator")).toCharArray(); |
682 |
| |
683 |
| |
684 |
| |
685 |
| |
686 |
| private int inCharEncoding = LATIN1; |
687 |
| |
688 |
| |
689 |
| |
690 |
| |
691 |
| private String inCharEncodingName = "ISO8859_1"; |
692 |
| |
693 |
| |
694 |
| |
695 |
| |
696 |
| private int outCharEncoding = ASCII; |
697 |
| |
698 |
| |
699 |
| |
700 |
| |
701 |
| private String outCharEncodingName = "ASCII"; |
702 |
| |
703 |
| |
704 |
| |
705 |
| |
706 |
| protected boolean rawOut; |
707 |
| |
708 |
| |
709 |
| |
710 |
| |
711 |
| private transient Properties properties = new Properties(); |
712 |
| |
713 |
| |
714 |
| |
715 |
| |
716 |
| |
717 |
299
| protected Configuration(Report report)
|
718 |
| { |
719 |
299
| this.report = report;
|
720 |
| } |
721 |
| |
722 |
| |
723 |
| |
724 |
| |
725 |
| |
726 |
1014
| private static void addConfigOption(Flag flag)
|
727 |
| { |
728 |
1014
| OPTIONS.put(flag.getName(), flag);
|
729 |
| } |
730 |
| |
731 |
| |
732 |
| |
733 |
| |
734 |
| |
735 |
230
| public void addProps(Properties p)
|
736 |
| { |
737 |
230
| Enumeration propEnum = p.propertyNames();
|
738 |
230
| while (propEnum.hasMoreElements())
|
739 |
| { |
740 |
616
| String key = (String) propEnum.nextElement();
|
741 |
616
| String value = p.getProperty(key);
|
742 |
616
| properties.put(key, value);
|
743 |
| } |
744 |
230
| parseProps();
|
745 |
| } |
746 |
| |
747 |
| |
748 |
| |
749 |
| |
750 |
| |
751 |
0
| public void parseFile(String filename)
|
752 |
| { |
753 |
0
| try
|
754 |
| { |
755 |
0
| properties.load(new FileInputStream(filename));
|
756 |
| } |
757 |
| catch (IOException e) |
758 |
| { |
759 |
0
| System.err.println(filename + " " + e.toString());
|
760 |
0
| return;
|
761 |
| } |
762 |
0
| parseProps();
|
763 |
| } |
764 |
| |
765 |
| |
766 |
| |
767 |
| |
768 |
| |
769 |
| |
770 |
1
| public static boolean isKnownOption(String name)
|
771 |
| { |
772 |
1
| return name != null && OPTIONS.containsKey(name);
|
773 |
| } |
774 |
| |
775 |
| |
776 |
| |
777 |
| |
778 |
230
| private void parseProps()
|
779 |
| { |
780 |
230
| Iterator iterator = properties.keySet().iterator();
|
781 |
| |
782 |
230
| while (iterator.hasNext())
|
783 |
| { |
784 |
616
| String key = (String) iterator.next();
|
785 |
616
| Flag flag = (Flag) OPTIONS.get(key);
|
786 |
616
| if (flag == null)
|
787 |
| { |
788 |
0
| report.unknownOption(key);
|
789 |
0
| continue;
|
790 |
| } |
791 |
| |
792 |
616
| String stringValue = properties.getProperty(key);
|
793 |
616
| Object value = flag.getParser().parse(stringValue, key, this);
|
794 |
616
| if (flag.getLocation() != null)
|
795 |
| { |
796 |
587
| try
|
797 |
| { |
798 |
587
| flag.getLocation().set(this, value);
|
799 |
| } |
800 |
| catch (IllegalArgumentException e) |
801 |
| { |
802 |
0
| throw new RuntimeException("IllegalArgumentException during config initialization for field "
|
803 |
| + key |
804 |
| + "with value [" |
805 |
| + value |
806 |
| + "]: " |
807 |
| + e.getMessage()); |
808 |
| } |
809 |
| catch (IllegalAccessException e) |
810 |
| { |
811 |
0
| throw new RuntimeException("IllegalArgumentException during config initialization for field "
|
812 |
| + key |
813 |
| + "with value [" |
814 |
| + value |
815 |
| + "]: " |
816 |
| + e.getMessage()); |
817 |
| } |
818 |
| } |
819 |
| } |
820 |
| } |
821 |
| |
822 |
| |
823 |
| |
824 |
| |
825 |
236
| public void adjust()
|
826 |
| { |
827 |
236
| if (encloseBlockText)
|
828 |
| { |
829 |
1
| encloseBodyText = true;
|
830 |
| } |
831 |
| |
832 |
| |
833 |
236
| if (smartIndent)
|
834 |
| { |
835 |
12
| indentContent = true;
|
836 |
| } |
837 |
| |
838 |
| |
839 |
236
| if (wraplen == 0)
|
840 |
| { |
841 |
161
| wraplen = 0x7FFFFFFF;
|
842 |
| } |
843 |
| |
844 |
| |
845 |
236
| if (word2000)
|
846 |
| { |
847 |
8
| definedTags |= Dict.TAGTYPE_INLINE;
|
848 |
8
| tt.defineTag(Dict.TAGTYPE_INLINE, "o:p");
|
849 |
| } |
850 |
| |
851 |
| |
852 |
236
| if (xmlTags)
|
853 |
| { |
854 |
17
| xHTML = false;
|
855 |
| } |
856 |
| |
857 |
| |
858 |
236
| if (xHTML)
|
859 |
| { |
860 |
33
| xmlOut = true;
|
861 |
33
| upperCaseTags = false;
|
862 |
33
| upperCaseAttrs = false;
|
863 |
| } |
864 |
| |
865 |
| |
866 |
236
| if (xmlTags)
|
867 |
| { |
868 |
17
| xmlOut = true;
|
869 |
17
| xmlPIs = true;
|
870 |
| } |
871 |
| |
872 |
| |
873 |
| |
874 |
236
| if (getOutCharEncoding() != UTF8 && getOutCharEncoding() != ASCII && xmlOut)
|
875 |
| { |
876 |
9
| xmlPi = true;
|
877 |
| } |
878 |
| |
879 |
| |
880 |
236
| if (xmlOut)
|
881 |
| { |
882 |
54
| quoteAmpersand = true;
|
883 |
54
| hideEndTags = false;
|
884 |
| } |
885 |
| } |
886 |
| |
887 |
| |
888 |
| |
889 |
| |
890 |
| |
891 |
| |
892 |
2
| void printConfigOptions(Writer errout, boolean showActualConfiguration)
|
893 |
| { |
894 |
2
| String pad = " ";
|
895 |
2
| try
|
896 |
| { |
897 |
2
| errout.write("\nConfiguration File Settings:\n\n");
|
898 |
| |
899 |
2
| if (showActualConfiguration)
|
900 |
| { |
901 |
1
| errout.write("Name Type Current Value\n");
|
902 |
| } |
903 |
| else |
904 |
| { |
905 |
1
| errout.write("Name Type Allowable values\n");
|
906 |
| } |
907 |
| |
908 |
2
| errout.write("=========================== ========= ========================================\n");
|
909 |
| |
910 |
2
| Flag configItem;
|
911 |
| |
912 |
| |
913 |
2
| List values = new ArrayList(OPTIONS.values());
|
914 |
2
| Collections.sort(values);
|
915 |
| |
916 |
2
| Iterator iterator = values.iterator();
|
917 |
| |
918 |
2
| while (iterator.hasNext())
|
919 |
| { |
920 |
156
| configItem = (Flag) iterator.next();
|
921 |
| |
922 |
156
| errout.write(configItem.getName());
|
923 |
156
| errout.write(pad, 0, 28 - configItem.getName().length());
|
924 |
| |
925 |
156
| errout.write(configItem.getParser().getType());
|
926 |
156
| errout.write(pad, 0, 11 - configItem.getParser().getType().length());
|
927 |
| |
928 |
156
| if (showActualConfiguration)
|
929 |
| { |
930 |
78
| Field field = configItem.getLocation();
|
931 |
78
| Object actualValue = null;
|
932 |
| |
933 |
78
| if (field != null)
|
934 |
| { |
935 |
70
| try
|
936 |
| { |
937 |
70
| actualValue = field.get(this);
|
938 |
| } |
939 |
| catch (IllegalArgumentException e1) |
940 |
| { |
941 |
| |
942 |
0
| throw new RuntimeException("IllegalArgument when reading field " + field.getName());
|
943 |
| } |
944 |
| catch (IllegalAccessException e1) |
945 |
| { |
946 |
| |
947 |
0
| throw new RuntimeException("IllegalAccess when reading field " + field.getName());
|
948 |
| } |
949 |
| } |
950 |
| |
951 |
78
| errout.write(configItem.getParser().getFriendlyName(configItem.getName(), actualValue, this));
|
952 |
| } |
953 |
| else |
954 |
| { |
955 |
78
| errout.write(configItem.getParser().getOptionValues());
|
956 |
| } |
957 |
| |
958 |
156
| errout.write("\n");
|
959 |
| |
960 |
| } |
961 |
2
| errout.flush();
|
962 |
| } |
963 |
| catch (IOException e) |
964 |
| { |
965 |
0
| throw new RuntimeException(e.getMessage());
|
966 |
| } |
967 |
| |
968 |
| } |
969 |
| |
970 |
| |
971 |
| |
972 |
| |
973 |
| static class Flag implements Comparable |
974 |
| { |
975 |
| |
976 |
| |
977 |
| |
978 |
| |
979 |
| private String name; |
980 |
| |
981 |
| |
982 |
| |
983 |
| |
984 |
| private String fieldName; |
985 |
| |
986 |
| |
987 |
| |
988 |
| |
989 |
| private Field location; |
990 |
| |
991 |
| |
992 |
| |
993 |
| |
994 |
| private ParseProperty parser; |
995 |
| |
996 |
| |
997 |
| |
998 |
| |
999 |
| |
1000 |
| |
1001 |
| |
1002 |
1014
| Flag(String name, String fieldName, ParseProperty parser)
|
1003 |
| { |
1004 |
| |
1005 |
1014
| this.fieldName = fieldName;
|
1006 |
1014
| this.name = name;
|
1007 |
1014
| this.parser = parser;
|
1008 |
| } |
1009 |
| |
1010 |
| |
1011 |
| |
1012 |
| |
1013 |
| |
1014 |
1281
| public Field getLocation()
|
1015 |
| { |
1016 |
| |
1017 |
1281
| if (fieldName != null && this.location == null)
|
1018 |
| { |
1019 |
164
| try
|
1020 |
| { |
1021 |
164
| this.location = Configuration.class.getDeclaredField(fieldName);
|
1022 |
| } |
1023 |
| catch (NoSuchFieldException e) |
1024 |
| { |
1025 |
0
| throw new RuntimeException("NoSuchField exception during config initialization for field "
|
1026 |
| + fieldName); |
1027 |
| } |
1028 |
| catch (SecurityException e) |
1029 |
| { |
1030 |
0
| throw new RuntimeException("Security exception during config initialization for field "
|
1031 |
| + fieldName |
1032 |
| + ": " |
1033 |
| + e.getMessage()); |
1034 |
| } |
1035 |
| } |
1036 |
| |
1037 |
1281
| return this.location;
|
1038 |
| } |
1039 |
| |
1040 |
| |
1041 |
| |
1042 |
| |
1043 |
| |
1044 |
1404
| public String getName()
|
1045 |
| { |
1046 |
1404
| return this.name;
|
1047 |
| } |
1048 |
| |
1049 |
| |
1050 |
| |
1051 |
| |
1052 |
| |
1053 |
1084
| public ParseProperty getParser()
|
1054 |
| { |
1055 |
1084
| return this.parser;
|
1056 |
| } |
1057 |
| |
1058 |
| |
1059 |
| |
1060 |
| |
1061 |
0
| public boolean equals(Object obj)
|
1062 |
| { |
1063 |
0
| return this.name.equals(((Flag) obj).name);
|
1064 |
| } |
1065 |
| |
1066 |
| |
1067 |
| |
1068 |
| |
1069 |
0
| public int hashCode()
|
1070 |
| { |
1071 |
| |
1072 |
0
| return this.name.hashCode();
|
1073 |
| } |
1074 |
| |
1075 |
| |
1076 |
| |
1077 |
| |
1078 |
830
| public int compareTo(Object o)
|
1079 |
| { |
1080 |
830
| return this.name.compareTo(((Flag) o).name);
|
1081 |
| } |
1082 |
| |
1083 |
| } |
1084 |
| |
1085 |
| |
1086 |
| |
1087 |
| |
1088 |
| |
1089 |
| |
1090 |
634
| protected int getInCharEncoding()
|
1091 |
| { |
1092 |
634
| return this.inCharEncoding;
|
1093 |
| } |
1094 |
| |
1095 |
| |
1096 |
| |
1097 |
| |
1098 |
| |
1099 |
| |
1100 |
2
| protected void setInCharEncoding(int encoding)
|
1101 |
| { |
1102 |
2
| if (encoding == RAW)
|
1103 |
| { |
1104 |
0
| rawOut = true;
|
1105 |
| } |
1106 |
| else |
1107 |
| { |
1108 |
2
| rawOut = false;
|
1109 |
2
| this.inCharEncoding = encoding;
|
1110 |
| } |
1111 |
| } |
1112 |
| |
1113 |
| |
1114 |
| |
1115 |
| |
1116 |
| |
1117 |
265
| protected String getInCharEncodingName()
|
1118 |
| { |
1119 |
265
| return this.inCharEncodingName;
|
1120 |
| } |
1121 |
| |
1122 |
| |
1123 |
| |
1124 |
| |
1125 |
| |
1126 |
24
| protected void setInCharEncodingName(String encoding)
|
1127 |
| { |
1128 |
24
| String javaEncoding = EncodingNameMapper.toJava(encoding);
|
1129 |
24
| if (javaEncoding != null)
|
1130 |
| { |
1131 |
24
| this.inCharEncodingName = javaEncoding;
|
1132 |
24
| this.inCharEncoding = convertCharEncoding(javaEncoding);
|
1133 |
| } |
1134 |
| } |
1135 |
| |
1136 |
| |
1137 |
| |
1138 |
| |
1139 |
| |
1140 |
| |
1141 |
578507
| protected int getOutCharEncoding()
|
1142 |
| { |
1143 |
578507
| return this.outCharEncoding;
|
1144 |
| } |
1145 |
| |
1146 |
| |
1147 |
| |
1148 |
| |
1149 |
| |
1150 |
| |
1151 |
0
| protected void setOutCharEncoding(int encoding)
|
1152 |
| { |
1153 |
0
| switch (encoding)
|
1154 |
| { |
1155 |
0
| case RAW :
|
1156 |
0
| this.rawOut = true;
|
1157 |
0
| break;
|
1158 |
| |
1159 |
0
| case MACROMAN :
|
1160 |
0
| case WIN1252 :
|
1161 |
0
| this.rawOut = false;
|
1162 |
0
| this.outCharEncoding = ASCII;
|
1163 |
0
| break;
|
1164 |
| |
1165 |
0
| default :
|
1166 |
0
| this.rawOut = false;
|
1167 |
0
| this.outCharEncoding = encoding;
|
1168 |
0
| break;
|
1169 |
| } |
1170 |
| } |
1171 |
| |
1172 |
| |
1173 |
| |
1174 |
| |
1175 |
| |
1176 |
394
| protected String getOutCharEncodingName()
|
1177 |
| { |
1178 |
394
| return this.outCharEncodingName;
|
1179 |
| } |
1180 |
| |
1181 |
| |
1182 |
| |
1183 |
| |
1184 |
| |
1185 |
16
| protected void setOutCharEncodingName(String encoding)
|
1186 |
| { |
1187 |
16
| String javaEncoding = EncodingNameMapper.toJava(encoding);
|
1188 |
16
| if (javaEncoding != null)
|
1189 |
| { |
1190 |
16
| this.outCharEncodingName = javaEncoding;
|
1191 |
16
| this.outCharEncoding = convertCharEncoding(javaEncoding);
|
1192 |
| } |
1193 |
| } |
1194 |
| |
1195 |
| |
1196 |
| |
1197 |
| |
1198 |
| |
1199 |
0
| protected void setInOutEncodingName(String encoding)
|
1200 |
| { |
1201 |
0
| setInCharEncodingName(encoding);
|
1202 |
0
| setOutCharEncodingName(encoding);
|
1203 |
| } |
1204 |
| |
1205 |
| |
1206 |
| |
1207 |
| |
1208 |
| |
1209 |
| |
1210 |
0
| protected String convertCharEncoding(int code)
|
1211 |
| { |
1212 |
0
| if (code != 0 && code < ENCODING_NAMES.length)
|
1213 |
| { |
1214 |
0
| return ENCODING_NAMES[code];
|
1215 |
| } |
1216 |
0
| return null;
|
1217 |
| } |
1218 |
| |
1219 |
| |
1220 |
| |
1221 |
| |
1222 |
| |
1223 |
| |
1224 |
40
| protected int convertCharEncoding(String name)
|
1225 |
| { |
1226 |
40
| if (name == null)
|
1227 |
| { |
1228 |
0
| return -1;
|
1229 |
| } |
1230 |
| |
1231 |
40
| for (int j = 1; j < ENCODING_NAMES.length; j++)
|
1232 |
| { |
1233 |
166
| if (name.equals(ENCODING_NAMES[j]))
|
1234 |
| { |
1235 |
38
| return j;
|
1236 |
| } |
1237 |
| } |
1238 |
| |
1239 |
2
| return -1;
|
1240 |
| } |
1241 |
| |
1242 |
| } |