1 16 19 package org.apache.xml.serializer; 20 21 import java.io.IOException ; 22 import java.io.OutputStream ; 23 import java.io.UnsupportedEncodingException ; 24 import java.io.Writer ; 25 import java.util.Properties ; 26 import java.util.StringTokenizer ; 27 import java.util.Vector ; 28 29 import javax.xml.transform.OutputKeys ; 30 import javax.xml.transform.Transformer ; 31 32 import org.apache.xml.res.XMLErrorResources; 33 import org.apache.xml.res.XMLMessages; 34 import org.apache.xml.utils.BoolStack; 35 import org.apache.xml.utils.FastStringBuffer; 36 import org.apache.xml.utils.QName; 37 import org.apache.xml.utils.TreeWalker; 38 import org.apache.xml.utils.WrappedRuntimeException; 39 import org.w3c.dom.Node ; 40 import org.xml.sax.Attributes ; 41 import org.xml.sax.ContentHandler ; 42 import org.xml.sax.SAXException ; 43 44 46 52 abstract public class ToStream extends SerializerBase 53 { 54 55 private static final String COMMENT_BEGIN = "<!--"; 56 private static final String COMMENT_END = "-->"; 57 58 59 protected BoolStack m_disableOutputEscapingStates = new BoolStack(); 60 61 64 boolean m_triedToGetConverter = false; 65 69 java.lang.reflect.Method m_canConvertMeth; 70 71 75 Object m_charToByteConverter = null; 76 77 86 protected BoolStack m_preserves = new BoolStack(); 87 88 96 protected boolean m_ispreserve = false; 97 98 106 protected boolean m_isprevtext = false; 107 108 112 protected int m_maxCharacter = Encodings.getLastPrintable(); 113 114 117 protected final char[] m_lineSep = 118 System.getProperty("line.separator").toCharArray(); 119 120 123 protected boolean m_lineSepUse = true; 124 125 129 protected final int m_lineSepLen = m_lineSep.length; 130 131 135 protected CharInfo m_charInfo; 136 137 138 boolean m_shouldFlush = true; 139 140 143 protected boolean m_spaceBeforeClose = false; 144 145 151 boolean m_startNewLine; 152 153 156 protected boolean m_inDoctype = false; 157 158 161 boolean m_isUTF8 = false; 162 163 164 protected Properties m_format; 165 166 169 protected boolean m_cdataStartCalled = false; 170 171 174 public ToStream() 175 { 176 } 177 178 183 protected void closeCDATA() throws org.xml.sax.SAXException 184 { 185 try 186 { 187 m_writer.write(CDATA_DELIMITER_CLOSE); 188 m_cdataTagOpen = false; } 191 catch (IOException e) 192 { 193 throw new SAXException (e); 194 } 195 } 196 197 206 public void serialize(Node node) throws IOException 207 { 208 209 try 210 { 211 TreeWalker walker = 212 new TreeWalker(this, new org.apache.xml.utils.DOM2Helper()); 213 214 walker.traverse(node); 215 } 216 catch (org.xml.sax.SAXException se) 217 { 218 throw new WrappedRuntimeException(se); 219 } 220 } 221 222 229 static final boolean isUTF16Surrogate(char c) 230 { 231 return (c & 0xFC00) == 0xD800; 232 } 233 234 237 private boolean m_escaping = true; 238 239 244 protected final void flushWriter() throws org.xml.sax.SAXException 245 { 246 final java.io.Writer writer = m_writer; 247 if (null != writer) 248 { 249 try 250 { 251 if (writer instanceof WriterToUTF8Buffered) 252 { 253 if (m_shouldFlush) 254 ((WriterToUTF8Buffered) writer).flush(); 255 else 256 ((WriterToUTF8Buffered) writer).flushBuffer(); 257 } 258 if (writer instanceof WriterToASCI) 259 { 260 if (m_shouldFlush) 261 writer.flush(); 262 } 263 else 264 { 265 writer.flush(); 269 } 270 } 271 catch (IOException ioe) 272 { 273 throw new org.xml.sax.SAXException (ioe); 274 } 275 } 276 } 277 278 284 public OutputStream getOutputStream() 285 { 286 287 if (m_writer instanceof WriterToUTF8Buffered) 288 return ((WriterToUTF8Buffered) m_writer).getOutputStream(); 289 if (m_writer instanceof WriterToASCI) 290 return ((WriterToASCI) m_writer).getOutputStream(); 291 else 292 return null; 293 } 294 295 297 310 public void elementDecl(String name, String model) throws SAXException 311 { 312 if (m_inExternalDTD) 314 return; 315 try 316 { 317 final java.io.Writer writer = m_writer; 318 if (m_needToOutputDocTypeDecl) 319 { 320 outputDocTypeDecl(m_elemContext.m_elementName, false); 321 m_needToOutputDocTypeDecl = false; 322 } 323 if (m_inDoctype) 324 { 325 writer.write(" ["); 326 writer.write(m_lineSep, 0, m_lineSepLen); 327 328 m_inDoctype = false; 329 } 330 331 writer.write("<!ELEMENT "); 332 writer.write(name); 333 writer.write(' '); 334 writer.write(model); 335 writer.write('>'); 336 writer.write(m_lineSep, 0, m_lineSepLen); 337 } 338 catch (IOException e) 339 { 340 throw new SAXException (e); 341 } 342 343 } 344 345 358 public void internalEntityDecl(String name, String value) 359 throws SAXException 360 { 361 if (m_inExternalDTD) 363 return; 364 try 365 { 366 if (m_needToOutputDocTypeDecl) 367 { 368 outputDocTypeDecl(m_elemContext.m_elementName, false); 369 m_needToOutputDocTypeDecl = false; 370 } 371 if (m_inDoctype) 372 { 373 final java.io.Writer writer = m_writer; 374 writer.write(" ["); 375 writer.write(m_lineSep, 0, m_lineSepLen); 376 377 m_inDoctype = false; 378 } 379 380 outputEntityDecl(name, value); 381 } 382 catch (IOException e) 383 { 384 throw new SAXException (e); 385 } 386 387 } 388 389 397 void outputEntityDecl(String name, String value) throws IOException 398 { 399 final java.io.Writer writer = m_writer; 400 writer.write("<!ENTITY "); 401 writer.write(name); 402 writer.write(" \""); 403 writer.write(value); 404 writer.write("\">"); 405 writer.write(m_lineSep, 0, m_lineSepLen); 406 } 407 408 413 protected final void outputLineSep() throws IOException 414 { 415 416 m_writer.write(m_lineSep, 0, m_lineSepLen); 417 } 418 419 428 public void setOutputFormat(Properties format) 429 { 430 431 boolean shouldFlush = m_shouldFlush; 432 433 init(m_writer, format, false, false); 434 435 m_shouldFlush = shouldFlush; 436 } 437 438 446 private synchronized void init( 447 Writer writer, 448 Properties format, 449 boolean defaultProperties, 450 boolean shouldFlush) 451 { 452 453 m_shouldFlush = shouldFlush; 454 455 456 if (m_tracer != null 459 && !(writer instanceof SerializerTraceWriter) ) 460 m_writer = new SerializerTraceWriter(writer, m_tracer); 461 else 462 m_writer = writer; 463 464 465 m_format = format; 466 setCdataSectionElements(OutputKeys.CDATA_SECTION_ELEMENTS, format); 471 472 setIndentAmount( 473 OutputPropertyUtils.getIntProperty( 474 OutputPropertiesFactory.S_KEY_INDENT_AMOUNT, 475 format)); 476 setIndent( 477 OutputPropertyUtils.getBooleanProperty(OutputKeys.INDENT, format)); 478 479 boolean shouldNotWriteXMLHeader = 480 OutputPropertyUtils.getBooleanProperty( 481 OutputKeys.OMIT_XML_DECLARATION, 482 format); 483 setOmitXMLDeclaration(shouldNotWriteXMLHeader); 484 setDoctypeSystem(format.getProperty(OutputKeys.DOCTYPE_SYSTEM)); 485 String doctypePublic = format.getProperty(OutputKeys.DOCTYPE_PUBLIC); 486 setDoctypePublic(doctypePublic); 487 488 if (format.get(OutputKeys.STANDALONE) != null) 490 { 491 String val = format.getProperty(OutputKeys.STANDALONE); 492 if (defaultProperties) 493 setStandaloneInternal(val); 494 else 495 setStandalone(val); 496 } 497 498 setMediaType(format.getProperty(OutputKeys.MEDIA_TYPE)); 499 500 if (null != doctypePublic) 501 { 502 if (doctypePublic.startsWith("-//W3C//DTD XHTML")) 503 m_spaceBeforeClose = true; 504 } 505 506 String encoding = getEncoding(); 508 if (null == encoding) 509 { 510 encoding = 511 Encodings.getMimeEncoding( 512 format.getProperty(OutputKeys.ENCODING)); 513 setEncoding(encoding); 514 } 515 516 m_isUTF8 = encoding.equals(Encodings.DEFAULT_MIME_ENCODING); 517 m_maxCharacter = Encodings.getLastPrintable(encoding); 518 519 String entitiesFileName = 522 (String ) format.get(OutputPropertiesFactory.S_KEY_ENTITIES); 523 524 if (null != entitiesFileName) 525 { 526 527 String method = 528 (String ) format.get(OutputKeys.METHOD); 529 530 m_charInfo = CharInfo.getCharInfo(entitiesFileName, method); 531 } 532 533 } 534 535 542 private synchronized void init(Writer writer, Properties format) 543 { 544 init(writer, format, false, false); 545 } 546 558 protected synchronized void init( 559 OutputStream output, 560 Properties format, 561 boolean defaultProperties) 562 throws UnsupportedEncodingException 563 { 564 565 String encoding = getEncoding(); 566 if (encoding == null) 567 { 568 encoding = 570 Encodings.getMimeEncoding( 571 format.getProperty(OutputKeys.ENCODING)); 572 setEncoding(encoding); 573 } 574 575 if (encoding.equalsIgnoreCase("UTF-8")) 576 { 577 m_isUTF8 = true; 578 593 594 init( 595 new WriterToUTF8Buffered(output), 596 format, 597 defaultProperties, 598 true); 599 600 601 } 602 else if ( 603 encoding.equals("WINDOWS-1250") 604 || encoding.equals("US-ASCII") 605 || encoding.equals("ASCII")) 606 { 607 init(new WriterToASCI(output), format, defaultProperties, true); 608 } 609 else 610 { 611 Writer osw; 612 613 try 614 { 615 osw = Encodings.getWriter(output, encoding); 616 } 617 catch (UnsupportedEncodingException uee) 618 { 619 System.out.println( 620 "Warning: encoding \"" 621 + encoding 622 + "\" not supported" 623 + ", using " 624 + Encodings.DEFAULT_MIME_ENCODING); 625 626 encoding = Encodings.DEFAULT_MIME_ENCODING; 627 setEncoding(encoding); 628 osw = Encodings.getWriter(output, encoding); 629 } 630 631 m_maxCharacter = Encodings.getLastPrintable(encoding); 632 633 init(osw, format, defaultProperties, true); 634 } 635 636 } 637 638 643 public Properties getOutputFormat() 644 { 645 return m_format; 646 } 647 648 655 public void setWriter(Writer writer) 656 { 657 if (m_tracer != null 660 && !(writer instanceof SerializerTraceWriter) ) 661 m_writer = new SerializerTraceWriter(writer, m_tracer); 662 else 663 m_writer = writer; 664 } 665 666 678 public boolean setLineSepUse(boolean use_sytem_line_break) 679 { 680 boolean oldValue = m_lineSepUse; 681 m_lineSepUse = use_sytem_line_break; 682 return oldValue; 683 } 684 685 696 public void setOutputStream(OutputStream output) 697 { 698 699 try 700 { 701 Properties format; 702 if (null == m_format) 703 format = 704 OutputPropertiesFactory.getDefaultMethodProperties( 705 Method.XML); 706 else 707 format = m_format; 708 init(output, format, true); 709 } 710 catch (UnsupportedEncodingException uee) 711 { 712 713 } 715 } 716 717 720 public boolean setEscaping(boolean escape) 721 { 722 final boolean temp = m_escaping; 723 m_escaping = escape; 724 return temp; 725 726 } 727 728 729 737 protected void indent(int depth) throws IOException 738 { 739 740 if (m_startNewLine) 741 outputLineSep(); 742 746 if (m_indentAmount > 0) 747 printSpace(depth * m_indentAmount); 748 749 } 750 751 755 protected void indent() throws IOException 756 { 757 indent(m_elemContext.m_currentElemDepth); 758 } 759 766 private void printSpace(int n) throws IOException 767 { 768 final java.io.Writer writer = m_writer; 769 for (int i = 0; i < n; i++) 770 { 771 writer.write(' '); 772 } 773 774 } 775 776 795 public void attributeDecl( 796 String eName, 797 String aName, 798 String type, 799 String valueDefault, 800 String value) 801 throws SAXException 802 { 803 if (m_inExternalDTD) 805 return; 806 try 807 { 808 final java.io.Writer writer = m_writer; 809 if (m_needToOutputDocTypeDecl) 810 { 811 outputDocTypeDecl(m_elemContext.m_elementName, false); 812 m_needToOutputDocTypeDecl = false; 813 } 814 if (m_inDoctype) 815 { 816 writer.write(" ["); 817 writer.write(m_lineSep, 0, m_lineSepLen); 818 819 m_inDoctype = false; 820 } 821 822 writer.write("<!ATTLIST "); 823 writer.write(eName); 824 writer.write(' '); 825 826 writer.write(aName); 827 writer.write(' '); 828 writer.write(type); 829 if (valueDefault != null) 830 { 831 writer.write(' '); 832 writer.write(valueDefault); 833 } 834 835 writer.write('>'); 838 writer.write(m_lineSep, 0, m_lineSepLen); 839 } 840 catch (IOException e) 841 { 842 throw new SAXException (e); 843 } 844 } 845 846 851 public Writer getWriter() 852 { 853 return m_writer; 854 } 855 856 871 public void externalEntityDecl( 872 String name, 873 String publicId, 874 String systemId) 875 throws SAXException 876 { 877 } 878 879 882 protected boolean escapingNotNeeded(char ch) 883 { 884 if (ch < 127) 885 { 886 if (ch >= 0x20 || (0x0A == ch || 0x0D == ch || 0x09 == ch)) 887 return true; 888 else 889 return false; 890 } 891 892 if (null == m_charToByteConverter && false == m_triedToGetConverter) 893 { 894 m_triedToGetConverter = true; 895 try 896 { 897 m_charToByteConverter = 898 Encodings.getCharToByteConverter(getEncoding()); 899 if (null != m_charToByteConverter) 900 { 901 Class argsTypes[] = new Class [1]; 902 argsTypes[0] = Character.TYPE; 903 Class convClass = m_charToByteConverter.getClass(); 904 m_canConvertMeth = 905 convClass.getMethod("canConvert", argsTypes); 906 } 907 } 908 catch (Exception e) 909 { 910 System.err.println("Warning: " + e.getMessage()); 912 } 913 } 914 if (null != m_charToByteConverter) 915 { 916 try 917 { 918 Object args[] = new Object [1]; 919 args[0] = new Character (ch); 920 Boolean bool = 921 (Boolean ) m_canConvertMeth.invoke( 922 m_charToByteConverter, 923 args); 924 return bool.booleanValue() 925 ? !Character.isISOControl(ch) 926 : false; 927 } 928 catch (java.lang.reflect.InvocationTargetException ite) 929 { 930 System.err.println( 932 "Warning: InvocationTargetException in canConvert!"); 933 } 934 catch (java.lang.IllegalAccessException iae) 935 { 936 System.err.println( 938 "Warning: IllegalAccessException in canConvert!"); 939 } 940 } 941 return (ch <= m_maxCharacter); 943 } 944 945 956 protected void writeUTF16Surrogate(char c, char ch[], int i, int end) 957 throws IOException 958 { 959 960 int surrogateValue = getURF16SurrogateValue(c, ch, i, end); 962 963 final java.io.Writer writer = m_writer; 964 writer.write('&'); 965 writer.write('#'); 966 967 writer.write(Integer.toString(surrogateValue)); 969 writer.write(';'); 970 } 971 972 983 int getURF16SurrogateValue(char c, char ch[], int i, int end) 984 throws IOException 985 { 986 987 int next; 988 989 if (i + 1 >= end) 990 { 991 throw new IOException ( 992 XMLMessages.createXMLMessage( 993 XMLErrorResources.ER_INVALID_UTF16_SURROGATE, 994 new Object [] { Integer.toHexString((int) c)})); 995 997 } 999 else 1000 { 1001 next = ch[++i]; 1002 1003 if (!(0xdc00 <= next && next < 0xe000)) 1004 throw new IOException ( 1005 XMLMessages.createXMLMessage( 1006 XMLErrorResources.ER_INVALID_UTF16_SURROGATE, 1007 new Object [] { 1008 Integer.toHexString((int) c) 1009 + " " 1010 + Integer.toHexString(next)})); 1011 1013 next = ((c - 0xd800) << 10) + next - 0xdc00 + 0x00010000; 1015 } 1016 1017 return next; 1018 } 1019 1020 1036 protected int accumDefaultEntity( 1037 java.io.Writer writer, 1038 char ch, 1039 int i, 1040 char[] chars, 1041 int len, 1042 boolean fromTextNode, 1043 boolean escLF) 1044 throws IOException 1045 { 1046 1047 if (!escLF && CharInfo.S_LINEFEED == ch) 1048 { 1049 writer.write(m_lineSep, 0, m_lineSepLen); 1050 } 1051 else 1052 { 1053 if ((fromTextNode && m_charInfo.isSpecialTextChar(ch)) || (!fromTextNode && m_charInfo.isSpecialAttrChar(ch))) 1056 { 1057 String entityRef = m_charInfo.getEntityNameForChar(ch); 1058 1059 if (null != entityRef) 1060 { 1061 writer.write('&'); 1062 writer.write(entityRef); 1063 writer.write(';'); 1064 } 1065 else 1066 return i; 1067 } 1068 else 1069 return i; 1070 } 1071 1072 return i + 1; 1073 1074 } 1075 1088 void writeNormalizedChars( 1089 char ch[], 1090 int start, 1091 int length, 1092 boolean isCData, 1093 boolean useSystemLineSeparator) 1094 throws IOException , org.xml.sax.SAXException 1095 { 1096 final java.io.Writer writer = m_writer; 1097 int end = start + length; 1098 1099 for (int i = start; i < end; i++) 1100 { 1101 char c = ch[i]; 1102 1103 if (CharInfo.S_LINEFEED == c && useSystemLineSeparator) 1104 { 1105 writer.write(m_lineSep, 0, m_lineSepLen); 1106 } 1107 else if (isCData && (!escapingNotNeeded(c))) 1108 { 1109 if (m_cdataTagOpen) 1111 closeCDATA(); 1112 1113 if (isUTF16Surrogate(c)) 1115 { 1116 writeUTF16Surrogate(c, ch, i, end); 1117 i++ ; } 1119 else 1120 { 1121 writer.write("&#"); 1122 1123 String intStr = Integer.toString((int) c); 1124 1125 writer.write(intStr); 1126 writer.write(';'); 1127 } 1128 1129 } 1136 else if ( 1137 isCData 1138 && ((i < (end - 2)) 1139 && (']' == c) 1140 && (']' == ch[i + 1]) 1141 && ('>' == ch[i + 2]))) 1142 { 1143 writer.write(CDATA_CONTINUE); 1144 1145 i += 2; 1146 } 1147 else 1148 { 1149 if (escapingNotNeeded(c)) 1150 { 1151 if (isCData && !m_cdataTagOpen) 1152 { 1153 writer.write(CDATA_DELIMITER_OPEN); 1154 m_cdataTagOpen = true; 1155 } 1156 writer.write(c); 1157 } 1158 1159 else if (isUTF16Surrogate(c)) 1161 { 1162 if (m_cdataTagOpen) 1163 closeCDATA(); 1164 writeUTF16Surrogate(c, ch, i, end); 1165 i++; } 1167 else 1168 { 1169 if (m_cdataTagOpen) 1170 closeCDATA(); 1171 writer.write("&#"); 1172 1173 String intStr = Integer.toString((int) c); 1174 1175 writer.write(intStr); 1176 writer.write(';'); 1177 } 1178 } 1179 } 1180 1181 } 1182 1183 1190 public void endNonEscaping() throws org.xml.sax.SAXException 1191 { 1192 m_disableOutputEscapingStates.pop(); 1193 } 1194 1195 1205 public void startNonEscaping() throws org.xml.sax.SAXException 1206 { 1207 m_disableOutputEscapingStates.push(true); 1208 } 1209 1210 1237 protected void cdata(char ch[], int start, final int length) 1238 throws org.xml.sax.SAXException 1239 { 1240 1241 try 1242 { 1243 final int old_start = start; 1244 if (m_elemContext.m_startTagOpen) 1245 { 1246 closeStartTag(); 1247 m_elemContext.m_startTagOpen = false; 1248 } 1249 m_ispreserve = true; 1250 1251 if (shouldIndent()) 1252 indent(); 1253 1254 boolean writeCDataBrackets = 1255 (((length >= 1) && escapingNotNeeded(ch[start]))); 1256 1257 1261 if (writeCDataBrackets && !m_cdataTagOpen) 1262 { 1263 m_writer.write(CDATA_DELIMITER_OPEN); 1264 m_cdataTagOpen = true; 1265 } 1266 1267 if (isEscapingDisabled()) 1269 { 1270 charactersRaw(ch, start, length); 1271 } 1272 else 1273 writeNormalizedChars(ch, start, length, true, m_lineSepUse); 1274 1275 1279 if (writeCDataBrackets) 1280 { 1281 1286 if (ch[start + length - 1] == ']') 1287 closeCDATA(); 1288 } 1289 1290 if (m_tracer != null) 1292 super.fireCDATAEvent(ch, old_start, length); 1293 } 1294 catch (IOException ioe) 1295 { 1296 throw new org.xml.sax.SAXException ( 1297 XMLMessages.createXMLMessage( 1298 XMLErrorResources.ER_OIERROR, 1299 null), 1300 ioe); 1301 } 1303 } 1304 1305 1310 private boolean isEscapingDisabled() 1311 { 1312 return m_disableOutputEscapingStates.peekOrFalse(); 1313 } 1314 1315 1325 protected void charactersRaw(char ch[], int start, int length) 1326 throws org.xml.sax.SAXException 1327 { 1328 1329 if (m_inEntityRef) 1330 return; 1331 try 1332 { 1333 if (m_elemContext.m_startTagOpen) 1334 { 1335 closeStartTag(); 1336 m_elemContext.m_startTagOpen = false; 1337 } 1338 1339 m_ispreserve = true; 1340 1341 m_writer.write(ch, start, length); 1342 } 1343 catch (IOException e) 1344 { 1345 throw new SAXException (e); 1346 } 1347 1348 } 1349 1350 1377 public void characters(final char chars[], final int start, final int length) 1378 throws org.xml.sax.SAXException 1379 { 1380 if (m_elemContext.m_startTagOpen) 1381 { 1382 closeStartTag(); 1383 m_elemContext.m_startTagOpen = false; 1384 } 1385 else if (m_needToCallStartDocument) 1386 { 1387 startDocumentInternal(); 1388 } 1389 1390 if (m_cdataStartCalled || m_elemContext.m_isCdataSection) 1391 { 1392 1395 cdata(chars, start, length); 1396 1397 return; 1398 } 1399 1400 if (m_cdataTagOpen) 1401 closeCDATA(); 1402 1404 if (m_disableOutputEscapingStates.peekOrFalse() || (!m_escaping)) 1405 { 1406 charactersRaw(chars, start, length); 1407 1408 if (m_tracer != null) 1410 super.fireCharEvent(chars, start, length); 1411 1412 return; 1413 } 1414 1415 if (m_elemContext.m_startTagOpen) 1416 { 1417 closeStartTag(); 1418 m_elemContext.m_startTagOpen = false; 1419 } 1420 1421 1422 try 1423 { 1424 int i; 1425 char ch1; 1426 int startClean; 1427 1428 final int end = start + length; 1432 int lastDirty = start - 1; for (i = start; 1434 ((i < end) 1435 && ((ch1 = chars[i]) == 0x20 1436 || (ch1 == 0xA && m_lineSepUse) 1437 || ch1 == 0xD 1438 || ch1 == 0x09)); 1439 i++) 1440 { 1441 1446 if (!m_charInfo.isTextASCIIClean(ch1)) 1447 { 1448 lastDirty = processDirty(chars,end, i,ch1, lastDirty, true); 1449 i = lastDirty; 1450 } 1451 } 1452 1455 if (i < end) 1456 m_ispreserve = true; 1457 1458 1459 1462 for (; i < end; i++) 1464 { 1465 { 1466 char ch2; 1470 while (i<end 1471 && ((ch2 = chars[i])<127) 1472 && m_charInfo.isTextASCIIClean(ch2)) 1473 i++; 1474 if (i == end) 1475 break; 1476 } 1477 1478 final char ch = chars[i]; 1479 if ( 1480 1481 (escapingNotNeeded(ch) && (!m_charInfo.isSpecialTextChar(ch))) 1482 || ('"' == ch)) 1483 { 1484 ; } 1486 else 1487 { 1488 lastDirty = processDirty(chars,end, i, ch, lastDirty, true); 1489 i = lastDirty; 1490 } 1491 } 1492 1493 startClean = lastDirty + 1; 1496 if (i > startClean) 1497 { 1498 int lengthClean = i - startClean; 1499 m_writer.write(chars, startClean, lengthClean); 1500 } 1501 1502 m_isprevtext = true; 1504 } 1505 catch (IOException e) 1506 { 1507 throw new SAXException (e); 1508 } 1509 1510 if (m_tracer != null) 1512 super.fireCharEvent(chars, start, length); 1513 } 1514 1527 private int processDirty( 1528 char[] chars, 1529 int end, 1530 int i, 1531 char ch, 1532 int lastDirty, 1533 boolean fromTextNode) throws IOException 1534 { 1535 int startClean = lastDirty + 1; 1536 if (i > startClean) 1539 { 1540 int lengthClean = i - startClean; 1541 m_writer.write(chars, startClean, lengthClean); 1542 } 1543 1544 if (CharInfo.S_LINEFEED == ch && fromTextNode) 1546 { 1547 m_writer.write(m_lineSep, 0, m_lineSepLen); 1548 } 1549 else 1550 { 1551 startClean = 1552 accumDefaultEscape( 1553 m_writer, 1554 (char)ch, 1555 i, 1556 chars, 1557 end, 1558 fromTextNode, 1559 false); 1560 i = startClean - 1; 1561 } 1562 return i; 1565 } 1566 1567 1574 public void characters(String s) throws org.xml.sax.SAXException 1575 { 1576 final int length = s.length(); 1577 if (length > m_charsBuff.length) 1578 { 1579 m_charsBuff = new char[length * 2 + 1]; 1580 } 1581 s.getChars(0, length, m_charsBuff, 0); 1582 characters(m_charsBuff, 0, length); 1583 } 1584 1585 1602 protected int accumDefaultEscape( 1603 Writer writer, 1604 char ch, 1605 int i, 1606 char[] chars, 1607 int len, 1608 boolean fromTextNode, 1609 boolean escLF) 1610 throws IOException 1611 { 1612 1613 int pos = accumDefaultEntity(writer, ch, i, chars, len, fromTextNode, escLF); 1614 1615 if (i == pos) 1616 { 1617 if (0xd800 <= ch && ch < 0xdc00) 1618 { 1619 1620 int next; 1622 1623 if (i + 1 >= len) 1624 { 1625 throw new IOException ( 1626 XMLMessages.createXMLMessage( 1627 XMLErrorResources.ER_INVALID_UTF16_SURROGATE, 1628 new Object [] { Integer.toHexString(ch)})); 1629 1631 } 1633 else 1634 { 1635 next = chars[++i]; 1636 1637 if (!(0xdc00 <= next && next < 0xe000)) 1638 throw new IOException ( 1639 XMLMessages.createXMLMessage( 1640 XMLErrorResources 1641 .ER_INVALID_UTF16_SURROGATE, 1642 new Object [] { 1643 Integer.toHexString(ch) 1644 + " " 1645 + Integer.toHexString(next)})); 1646 1648 next = ((ch - 0xd800) << 10) + next - 0xdc00 + 0x00010000; 1650 } 1651 1652 writer.write("&#"); 1653 writer.write(Integer.toString(next)); 1654 writer.write(';'); 1655 pos += 2; } 1657 else 1658 { 1659 if (!escapingNotNeeded(ch) || 1660 ( (fromTextNode && m_charInfo.isSpecialTextChar(ch)) 1661 || (!fromTextNode && m_charInfo.isSpecialAttrChar(ch)))) 1662 { 1663 writer.write("&#"); 1664 writer.write(Integer.toString(ch)); 1665 writer.write(';'); 1666 } 1667 else 1668 { 1669 writer.write(ch); 1670 } 1671 pos++; } 1673 1674 } 1675 return pos; 1676 } 1677 1678 1700 public void startElement( 1701 String namespaceURI, 1702 String localName, 1703 String name, 1704 Attributes atts) 1705 throws org.xml.sax.SAXException 1706 { 1707 if (m_inEntityRef) 1708 return; 1709 1710 if (m_needToCallStartDocument) 1711 { 1712 startDocumentInternal(); 1713 m_needToCallStartDocument = false; 1714 } 1715 else if (m_cdataTagOpen) 1716 closeCDATA(); 1717 try 1718 { 1719 if ((true == m_needToOutputDocTypeDecl) 1720 && (null != getDoctypeSystem())) 1721 { 1722 outputDocTypeDecl(name, true); 1723 } 1724 1725 m_needToOutputDocTypeDecl = false; 1726 1727 1730 if (m_elemContext.m_startTagOpen) 1731 { 1732 closeStartTag(); 1733 m_elemContext.m_startTagOpen = false; 1734 } 1735 1736 if (namespaceURI != null) 1737 ensurePrefixIsDeclared(namespaceURI, name); 1738 1739 m_ispreserve = false; 1740 1741 if (shouldIndent() && m_startNewLine) 1742 { 1743 indent(); 1744 } 1745 1746 m_startNewLine = true; 1747 1748 final java.io.Writer writer = m_writer; 1749 writer.write('<'); 1750 writer.write(name); 1751 } 1752 catch (IOException e) 1753 { 1754 throw new SAXException (e); 1755 } 1756 1757 if (atts != null) 1759 addAttributes(atts); 1760 1761 m_elemContext = m_elemContext.push(namespaceURI,localName,name); 1762 m_isprevtext = false; 1763 1764 if (m_tracer != null) 1765 firePseudoAttributes(); 1766 } 1767 1768 1789 public void startElement( 1790 String elementNamespaceURI, 1791 String elementLocalName, 1792 String elementName) 1793 throws SAXException 1794 { 1795 startElement(elementNamespaceURI, elementLocalName, elementName, null); 1796 } 1797 1798 public void startElement(String elementName) throws SAXException 1799 { 1800 startElement(null, null, elementName, null); 1801 } 1802 1803 1811 void outputDocTypeDecl(String name, boolean closeDecl) throws SAXException 1812 { 1813 if (m_cdataTagOpen) 1814 closeCDATA(); 1815 try 1816 { 1817 final java.io.Writer writer = m_writer; 1818 writer.write("<!DOCTYPE "); 1819 writer.write(name); 1820 1821 String doctypePublic = getDoctypePublic(); 1822 if (null != doctypePublic) 1823 { 1824 writer.write(" PUBLIC \""); 1825 writer.write(doctypePublic); 1826 writer.write('\"'); 1827 } 1828 1829 String doctypeSystem = getDoctypeSystem(); 1830 if (null != doctypeSystem) 1831 { 1832 if (null == doctypePublic) 1833 writer.write(" SYSTEM \""); 1834 else 1835 writer.write(" \""); 1836 1837 writer.write(doctypeSystem); 1838 1839 if (closeDecl) 1840 { 1841 writer.write("\">"); 1842 writer.write(m_lineSep, 0, m_lineSepLen); 1843 closeDecl = false; } 1845 else 1846 writer.write('\"'); 1847 } 1848 boolean dothis = false; 1849 if (dothis) 1850 { 1851 if (closeDecl) 1854 { 1855 writer.write('>'); 1856 writer.write(m_lineSep, 0, m_lineSepLen); 1857 } 1858 } 1859 } 1860 catch (IOException e) 1861 { 1862 throw new SAXException (e); 1863 } 1864 } 1865 1866 1878 public void processAttributes(java.io.Writer writer, int nAttrs) throws IOException , SAXException 1879 { 1880 1885 1886 String encoding = getEncoding(); 1887 for (int i = 0; i < nAttrs; i++) 1888 { 1889 final String name = m_attributes.getQName(i); 1891 final String value = m_attributes.getValue(i); 1892 writer.write(' '); 1893 writer.write(name); 1894 writer.write("=\""); 1895 writeAttrString(writer, value, encoding); 1896 writer.write('\"'); 1897 } 1898 } 1899 1900 1909 public void writeAttrString( 1910 Writer writer, 1911 String string, 1912 String encoding) 1913 throws IOException 1914 { 1915 final int len = string.length(); 1916 if (len > m_attrBuff.length) 1917 { 1918 m_attrBuff = new char[len*2 + 1]; 1919 } 1920 string.getChars(0,len, m_attrBuff, 0); 1921 final char[] stringChars = m_attrBuff; 1922 1923 for (int i = 0; i < len; i++) 1924 { 1925 char ch = stringChars[i]; 1926 if (escapingNotNeeded(ch) && (!m_charInfo.isSpecialAttrChar(ch))) 1927 { 1928 writer.write(ch); 1929 } 1930 else 1931 { 1940 accumDefaultEscape(writer, ch, i, stringChars, len, false, true); 1941 } 1942 } 1943 1944 } 1945 1946 1962 public void endElement(String namespaceURI, String localName, String name) 1963 throws org.xml.sax.SAXException 1964 { 1965 if (m_inEntityRef) 1966 return; 1967 1968 m_prefixMap.popNamespaces(m_elemContext.m_currentElemDepth, null); 1971 1972 try 1973 { 1974 final java.io.Writer writer = m_writer; 1975 if (m_elemContext.m_startTagOpen) 1976 { 1977 if (m_tracer != null) 1978 super.fireStartElem(m_elemContext.m_elementName); 1979 int nAttrs = m_attributes.getLength(); 1980 if (nAttrs > 0) 1981 { 1982 processAttributes(m_writer, nAttrs); 1983 m_attributes.clear(); 1985 } 1986 if (m_spaceBeforeClose) 1987 writer.write(" />"); 1988 else 1989 writer.write("/>"); 1990 1994 1995 } 1996 else 1997 { 1998 if (m_cdataTagOpen) 1999 closeCDATA(); 2000 2001 if (shouldIndent()) 2002 indent(m_elemContext.m_currentElemDepth - 1); 2003 writer.write('<'); 2004 writer.write('/'); 2005 writer.write(name); 2006 writer.write('>'); 2007 } 2008 } 2009 catch (IOException e) 2010 { 2011 throw new SAXException (e); 2012 } 2013 2014 if (!m_elemContext.m_startTagOpen && m_doIndent) 2015 { 2016 m_ispreserve = m_preserves.isEmpty() ? false : m_preserves.pop(); 2017 } 2018 2019 m_isprevtext = false; 2020 2021 if (m_tracer != null) 2023 super.fireEndElem(name); 2024 m_elemContext = m_elemContext.m_prev; 2025 } 2026 2027 2033 public void endElement(String name) throws org.xml.sax.SAXException 2034 { 2035 endElement(null, null, name); 2036 } 2037 2038 2053 public void startPrefixMapping(String prefix, String uri) 2054 throws org.xml.sax.SAXException 2055 { 2056 startPrefixMapping(prefix, uri, true); 2058 } 2059 2060 2081 public boolean startPrefixMapping( 2082 String prefix, 2083 String uri, 2084 boolean shouldFlush) 2085 throws org.xml.sax.SAXException 2086 { 2087 2088 2093 2094 boolean pushed; 2095 int pushDepth; 2096 if (shouldFlush) 2097 { 2098 flushPending(); 2099 pushDepth = m_elemContext.m_currentElemDepth + 1; 2101 } 2102 else 2103 { 2104 pushDepth = m_elemContext.m_currentElemDepth; 2106 } 2107 pushed = m_prefixMap.pushNamespace(prefix, uri, pushDepth); 2108 2109 if (pushed) 2110 { 2111 2116 String name; 2117 if (EMPTYSTRING.equals(prefix)) 2118 { 2119 name = "xmlns"; 2120 addAttributeAlways(XMLNS_URI, prefix, name, "CDATA", uri); 2121 } 2122 else 2123 { 2124 if (!EMPTYSTRING.equals(uri)) 2125 { name = "xmlns:" + prefix; 2128 2129 2133 addAttributeAlways(XMLNS_URI, prefix, name, "CDATA", uri); 2134 } 2135 } 2136 } 2137 return pushed; 2138 } 2139 2140 2149 public void comment(char ch[], int start, int length) 2150 throws org.xml.sax.SAXException 2151 { 2152 2153 int start_old = start; 2154 if (m_inEntityRef) 2155 return; 2156 if (m_elemContext.m_startTagOpen) 2157 { 2158 closeStartTag(); 2159 m_elemContext.m_startTagOpen = false; 2160 } 2161 else if (m_needToCallStartDocument) 2162 { 2163 startDocumentInternal(); 2164 m_needToCallStartDocument = false; 2165 } 2166 2167 try 2168 { 2169 if (shouldIndent()) 2170 indent(); 2171 2172 final int limit = start + length; 2173 boolean wasDash = false; 2174 if (m_cdataTagOpen) 2175 closeCDATA(); 2176 final java.io.Writer writer = m_writer; 2177 writer.write(COMMENT_BEGIN); 2178 for (int i = start; i < limit; i++) 2180 { 2181 if (wasDash && ch[i] == '-') 2182 { 2183 writer.write(ch, start, i - start); 2184 writer.write(" -"); 2185 start = i + 1; 2186 } 2187 wasDash = (ch[i] == '-'); 2188 } 2189 2190 if (length > 0) 2192 { 2193 final int remainingChars = (limit - start); 2195 if (remainingChars > 0) 2196 writer.write(ch, start, remainingChars); 2197 if (ch[limit - 1] == '-') 2199 writer.write(' '); 2200 } 2201 writer.write(COMMENT_END); 2202 } 2203 catch (IOException e) 2204 { 2205 throw new SAXException (e); 2206 } 2207 2208 m_startNewLine = true; 2209 if (m_tracer != null) 2211 super.fireCommentEvent(ch, start_old,length); 2212 } 2213 2214 2220 public void endCDATA() throws org.xml.sax.SAXException 2221 { 2222 if (m_cdataTagOpen) 2223 closeCDATA(); 2224 m_cdataStartCalled = false; 2225 } 2226 2227 2232 public void endDTD() throws org.xml.sax.SAXException 2233 { 2234 try 2235 { 2236 if (m_needToOutputDocTypeDecl) 2237 { 2238 outputDocTypeDecl(m_elemContext.m_elementName, false); 2239 m_needToOutputDocTypeDecl = false; 2240 } 2241 final java.io.Writer writer = m_writer; 2242 if (!m_inDoctype) 2243 writer.write("]>"); 2244 else 2245 { 2246 writer.write('>'); 2247 } 2248 2249 writer.write(m_lineSep, 0, m_lineSepLen); 2250 } 2251 catch (IOException e) 2252 { 2253 throw new SAXException (e); 2254 } 2255 2256 } 2257 2258 2266 public void endPrefixMapping(String prefix) throws org.xml.sax.SAXException 2267 { } 2269 2270 2284 public void ignorableWhitespace(char ch[], int start, int length) 2285 throws org.xml.sax.SAXException 2286 { 2287 2288 if (0 == length) 2289 return; 2290 characters(ch, start, length); 2291 } 2292 2293 2304 public void skippedEntity(String name) throws org.xml.sax.SAXException 2305 { } 2307 2308 2314 public void startCDATA() throws org.xml.sax.SAXException 2315 { 2316 m_cdataStartCalled = true; 2317 } 2318 2319 2334 public void startEntity(String name) throws org.xml.sax.SAXException 2335 { 2336 if (name.equals("[dtd]")) 2337 m_inExternalDTD = true; 2338 m_inEntityRef = true; 2339 } 2340 2341 2347 protected void closeStartTag() throws SAXException 2348 { 2349 2350 if (m_elemContext.m_startTagOpen) 2351 { 2352 2353 try 2354 { 2355 if (m_tracer != null) 2356 super.fireStartElem(m_elemContext.m_elementName); 2357 int nAttrs = m_attributes.getLength(); 2358 if (nAttrs > 0) 2359 { 2360 processAttributes(m_writer, nAttrs); 2361 m_attributes.clear(); 2363 } 2364 m_writer.write('>'); 2365 } 2366 catch (IOException e) 2367 { 2368 throw new SAXException (e); 2369 } 2370 2371 2375 if (m_cdataSectionElements != null) 2376 m_elemContext.m_isCdataSection = isCdataSection(); 2377 2378 if (m_doIndent) 2379 { 2380 m_isprevtext = false; 2381 m_preserves.push(m_ispreserve); 2382 } 2383 } 2384 2385 } 2386 2387 2403 public void startDTD(String name, String publicId, String systemId) 2404 throws org.xml.sax.SAXException 2405 { 2406 setDoctypeSystem(systemId); 2407 setDoctypePublic(publicId); 2408 2409 m_elemContext.m_elementName = name; 2410 m_inDoctype = true; 2411 } 2412 2413 2417 public int getIndentAmount() 2418 { 2419 return m_indentAmount; 2420 } 2421 2422 2427 public void setIndentAmount(int m_indentAmount) 2428 { 2429 this.m_indentAmount = m_indentAmount; 2430 } 2431 2432 2438 protected boolean shouldIndent() 2439 { 2440 return m_doIndent && (!m_ispreserve && !m_isprevtext); 2441 } 2442 2443 2459 private void setCdataSectionElements(String key, Properties props) 2460 { 2461 2462 String s = props.getProperty(key); 2463 2464 if (null != s) 2465 { 2466 Vector v = new Vector (); 2468 int l = s.length(); 2469 boolean inCurly = false; 2470 FastStringBuffer buf = new FastStringBuffer(); 2471 2472 for (int i = 0; i < l; i++) 2476 { 2477 char c = s.charAt(i); 2478 2479 if (Character.isWhitespace(c)) 2480 { 2481 if (!inCurly) 2482 { 2483 if (buf.length() > 0) 2484 { 2485 addCdataSectionElement(buf.toString(), v); 2486 buf.reset(); 2487 } 2488 continue; 2489 } 2490 } 2491 else if ('{' == c) 2492 inCurly = true; 2493 else if ('}' == c) 2494 inCurly = false; 2495 2496 buf.append(c); 2497 } 2498 2499 if (buf.length() > 0) 2500 { 2501 addCdataSectionElement(buf.toString(), v); 2502 buf.reset(); 2503 } 2504 setCdataSectionElements(v); 2506 } 2507 2508 } 2509 2510 2517 private void addCdataSectionElement(String URI_and_localName, Vector v) 2518 { 2519 2520 StringTokenizer tokenizer = 2521 new StringTokenizer (URI_and_localName, "{}", false); 2522 QName qname; 2523 String s1 = tokenizer.nextToken(); 2524 String s2 = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null; 2525 2526 if (null == s2) 2527 { 2528 v.addElement(null); 2530 v.addElement(s1); 2531 } 2532 else 2533 { 2534 v.addElement(s1); 2536 v.addElement(s2); 2537 } 2538 } 2539 2540 2547 public void setCdataSectionElements(Vector URI_and_localNames) 2548 { 2549 m_cdataSectionElements = URI_and_localNames; 2550 } 2551 2552 2561 protected String ensureAttributesNamespaceIsDeclared( 2562 String ns, 2563 String localName, 2564 String rawName) 2565 throws org.xml.sax.SAXException 2566 { 2567 2568 if (ns != null && ns.length() > 0) 2569 { 2570 2571 int index = 0; 2573 String prefixFromRawName = 2574 (index = rawName.indexOf(":")) < 0 2575 ? "" 2576 : rawName.substring(0, index); 2577 2578 if (index > 0) 2579 { 2580 String uri = m_prefixMap.lookupNamespace(prefixFromRawName); 2582 if (uri != null && uri.equals(ns)) 2583 { 2584 return null; 2587 } 2588 else 2589 { 2590 this.startPrefixMapping(prefixFromRawName, ns, false); 2593 this.addAttribute( 2594 "http://www.w3.org/2000/xmlns/", 2595 prefixFromRawName, 2596 "xmlns:" + prefixFromRawName, 2597 "CDATA", 2598 ns); 2599 return prefixFromRawName; 2600 } 2601 } 2602 else 2603 { 2604 String prefix = m_prefixMap.lookupPrefix(ns); 2607 if (prefix == null) 2608 { 2609 prefix = m_prefixMap.generateNextPrefix(); 2612 this.startPrefixMapping(prefix, ns, false); 2613 this.addAttribute( 2614 "http://www.w3.org/2000/xmlns/", 2615 prefix, 2616 "xmlns:" + prefix, 2617 "CDATA", 2618 ns); 2619 } 2620 2621 return prefix; 2622 2623 } 2624 } 2625 return null; 2626 } 2627 2628 void ensurePrefixIsDeclared(String ns, String rawName) 2629 throws org.xml.sax.SAXException 2630 { 2631 2632 if (ns != null && ns.length() > 0) 2633 { 2634 int index; 2635 String prefix = 2636 (index = rawName.indexOf(":")) < 0 2637 ? "" 2638 : rawName.substring(0, index); 2639 2640 if (null != prefix) 2641 { 2642 String foundURI = m_prefixMap.lookupNamespace(prefix); 2643 2644 if ((null == foundURI) || !foundURI.equals(ns)) 2645 { 2646 this.startPrefixMapping(prefix, ns); 2647 2648 2651 this.addAttributeAlways( 2652 "http://www.w3.org/2000/xmlns/", 2653 prefix, 2654 "xmlns" + (prefix.length() == 0 ? "" : ":") + prefix, 2655 "CDATA", 2656 ns); 2657 } 2658 2659 } 2660 } 2661 } 2662 2663 2667 public void flushPending() throws SAXException 2668 { 2669 if (m_needToCallStartDocument) 2670 { 2671 startDocumentInternal(); 2672 m_needToCallStartDocument = false; 2673 } 2674 if (m_elemContext.m_startTagOpen) 2675 { 2676 closeStartTag(); 2677 m_elemContext.m_startTagOpen = false; 2678 } 2679 2680 if (m_cdataTagOpen) 2681 { 2682 closeCDATA(); 2683 m_cdataTagOpen = false; 2684 } 2685 } 2686 2687 public void setContentHandler(ContentHandler ch) 2688 { 2689 } 2693 2694 2709 public void addAttributeAlways( 2710 String uri, 2711 String localName, 2712 String rawName, 2713 String type, 2714 String value) 2715 { 2716 2717 int index; 2718 index = m_attributes.getIndex(rawName); 2719 if (index >= 0) 2720 { 2721 String old_value = null; 2722 if (m_tracer != null) 2723 { 2724 old_value = m_attributes.getValue(index); 2725 if (value.equals(old_value)) 2726 old_value = null; 2727 } 2728 2729 2733 m_attributes.setValue(index, value); 2734 if (old_value != null) 2735 firePseudoAttributes(); 2736 2737 } 2738 else 2739 { 2740 m_attributes.addAttribute(uri, localName, rawName, type, value); 2742 if (m_tracer != null) 2743 firePseudoAttributes(); 2744 } 2745 2746 } 2747 2748 2753 2754 protected void firePseudoAttributes() 2755 { 2756 if (m_tracer != null) 2757 { 2758 try 2759 { 2760 m_writer.flush(); 2762 2763 StringBuffer sb = new StringBuffer (); 2765 int nAttrs = m_attributes.getLength(); 2766 if (nAttrs > 0) 2767 { 2768 java.io.Writer writer = 2771 new ToStream.WritertoStringBuffer(sb); 2772 2773 processAttributes(writer, nAttrs); 2774 } 2778 sb.append('>'); char ch[] = sb.toString().toCharArray(); 2783 m_tracer.fireGenerateEvent( 2784 SerializerTrace.EVENTTYPE_OUTPUT_PSEUDO_CHARACTERS, 2785 ch, 2786 0, 2787 ch.length); 2788 } 2789 catch (IOException ioe) 2790 { 2791 } 2793 catch (SAXException se) 2794 { 2795 } 2797 } 2798 } 2799 2800 2806 private class WritertoStringBuffer extends java.io.Writer 2807 { 2808 final private StringBuffer m_stringbuf; 2809 2812 WritertoStringBuffer(StringBuffer sb) 2813 { 2814 m_stringbuf = sb; 2815 } 2816 2817 public void write(char[] arg0, int arg1, int arg2) throws IOException 2818 { 2819 m_stringbuf.append(arg0, arg1, arg2); 2820 } 2821 2824 public void flush() throws IOException 2825 { 2826 } 2827 2830 public void close() throws IOException 2831 { 2832 } 2833 2834 public void write(int i) 2835 { 2836 m_stringbuf.append((char) i); 2837 } 2838 2839 public void write(String s) 2840 { 2841 m_stringbuf.append(s); 2842 } 2843 } 2844 2845 2848 public void setTransformer(Transformer transformer) { 2849 super.setTransformer(transformer); 2850 if (m_tracer != null 2851 && !(m_writer instanceof SerializerTraceWriter) ) 2852 m_writer = new SerializerTraceWriter(m_writer, m_tracer); 2853 2854 2855 } 2856 2863 public boolean reset() 2864 { 2865 boolean wasReset = false; 2866 if (super.reset()) 2867 { 2868 resetToStream(); 2869 wasReset = true; 2870 } 2871 return wasReset; 2872 } 2873 2874 2878 private void resetToStream() 2879 { 2880 this.m_canConvertMeth = null; 2881 this.m_cdataStartCalled = false; 2882 2888 this.m_charToByteConverter = null; 2890 this.m_disableOutputEscapingStates.clear(); 2891 2892 this.m_escaping = true; 2893 this.m_inDoctype = false; 2896 this.m_ispreserve = false; 2897 this.m_ispreserve = false; 2898 this.m_isprevtext = false; 2899 this.m_isUTF8 = false; this.m_maxCharacter = Encodings.getLastPrintable(); 2901 this.m_preserves.clear(); 2902 this.m_shouldFlush = true; 2903 this.m_spaceBeforeClose = false; 2904 this.m_startNewLine = false; 2905 this.m_triedToGetConverter = false; 2906 this.m_lineSepUse = true; 2907 2910 } 2911} 2912 | Popular Tags |