1 16 19 package org.apache.xalan.processor; 20 21 import javax.xml.transform.TransformerException ; 22 23 import org.apache.xalan.templates.ElemTemplateElement; 24 import org.apache.xalan.templates.ElemText; 25 import org.apache.xalan.templates.ElemTextLiteral; 26 import org.apache.xml.utils.XMLCharacterRecognizer; 27 28 import org.w3c.dom.Node ; 29 30 35 public class ProcessorCharacters extends XSLTElementProcessor 36 { 37 38 44 public void startNonText(StylesheetHandler handler) throws org.xml.sax.SAXException 45 { 46 if (this == handler.getCurrentProcessor()) 47 { 48 handler.popProcessor(); 49 } 50 51 int nChars = m_accumulator.length(); 52 53 if ((nChars > 0) 54 && ((null != m_xslTextElement) 55 ||!XMLCharacterRecognizer.isWhiteSpace(m_accumulator)) 56 || handler.isSpacePreserve()) 57 { 58 ElemTextLiteral elem = new ElemTextLiteral(); 59 60 elem.setDOMBackPointer(m_firstBackPointer); 61 elem.setLocaterInfo(handler.getLocator()); 62 try 63 { 64 elem.setPrefixes(handler.getNamespaceSupport()); 65 } 66 catch(TransformerException te) 67 { 68 throw new org.xml.sax.SAXException (te); 69 } 70 71 boolean doe = (null != m_xslTextElement) 72 ? m_xslTextElement.getDisableOutputEscaping() : false; 73 74 elem.setDisableOutputEscaping(doe); 75 elem.setPreserveSpace(true); 76 77 char[] chars = new char[nChars]; 78 79 m_accumulator.getChars(0, nChars, chars, 0); 80 elem.setChars(chars); 81 82 ElemTemplateElement parent = handler.getElemTemplateElement(); 83 84 parent.appendChild(elem); 85 } 86 87 m_accumulator.setLength(0); 88 m_firstBackPointer = null; 89 } 90 91 protected Node m_firstBackPointer = null; 92 93 106 public void characters( 107 StylesheetHandler handler, char ch[], int start, int length) 108 throws org.xml.sax.SAXException 109 { 110 111 m_accumulator.append(ch, start, length); 112 113 if(null == m_firstBackPointer) 114 m_firstBackPointer = handler.getOriginatingNode(); 115 116 if (this != handler.getCurrentProcessor()) 118 handler.pushProcessor(this); 119 } 120 121 142 public void endElement( 143 StylesheetHandler handler, String uri, String localName, String rawName) 144 throws org.xml.sax.SAXException 145 { 146 147 startNonText(handler); 151 handler.getCurrentProcessor().endElement(handler, uri, localName, 152 rawName); 153 handler.popProcessor(); 154 } 155 156 160 private StringBuffer m_accumulator = new StringBuffer (); 161 162 166 private ElemText m_xslTextElement; 167 168 175 void setXslTextElement(ElemText xslTextElement) 176 { 177 m_xslTextElement = xslTextElement; 178 } 179 } 180 | Popular Tags |