1 16 19 20 package org.apache.xalan.xsltc.runtime; 21 22 import org.xml.sax.SAXException ; 23 24 import org.apache.xml.serializer.EmptySerializer; 25 26 31 public final class StringValueHandler extends EmptySerializer { 32 33 private StringBuffer _buffer = new StringBuffer (); 34 private String _str = null; 35 private static final String EMPTY_STR = ""; 36 private boolean m_escaping = false; 37 private int _nestedLevel = 0; 38 39 public void characters(char[] ch, int off, int len) 40 throws SAXException 41 { 42 if (_nestedLevel > 0) 43 return; 44 45 if (_str != null) { 46 _buffer.append(_str); 47 _str = null; 48 } 49 _buffer.append(ch, off, len); 50 } 51 52 public String getValue() { 53 if (_buffer.length() != 0) { 54 String result = _buffer.toString(); 55 _buffer.setLength(0); 56 return result; 57 } 58 else { 59 String result = _str; 60 _str = null; 61 return (result != null) ? result : EMPTY_STR; 62 } 63 } 64 65 public void characters(String characters) throws SAXException { 66 if (_nestedLevel > 0) 67 return; 68 69 if (_str == null && _buffer.length() == 0) { 70 _str = characters; 71 } 72 else { 73 if (_str != null) { 74 _buffer.append(_str); 75 _str = null; 76 } 77 78 _buffer.append(characters); 79 } 80 } 81 82 public void startElement(String qname) throws SAXException { 83 _nestedLevel++; 84 } 85 86 public void endElement(String qname) throws SAXException { 87 _nestedLevel--; 88 } 89 90 public boolean setEscaping(boolean bool) { 93 boolean oldEscaping = m_escaping; 94 m_escaping = bool; 95 96 return bool; 97 } 98 99 103 public String getValueOfPI() { 104 final String value = getValue(); 105 106 if (value.indexOf("?>") > 0) { 107 final int n = value.length(); 108 final StringBuffer valueOfPI = new StringBuffer (); 109 110 for (int i = 0; i < n;) { 111 final char ch = value.charAt(i++); 112 if (ch == '?' && value.charAt(i) == '>') { 113 valueOfPI.append("? >"); i++; 114 } 115 else { 116 valueOfPI.append(ch); 117 } 118 } 119 return valueOfPI.toString(); 120 } 121 return value; 122 } 123 } 124 | Popular Tags |