1 16 19 package org.apache.xalan.templates; 20 21 import javax.xml.transform.TransformerException ; 22 23 import org.apache.xalan.res.XSLTErrorResources; 24 import org.apache.xalan.transformer.TransformerImpl; 25 import org.apache.xml.utils.XMLChar; 26 import org.apache.xpath.XPathContext; 27 28 40 public class ElemPI extends ElemTemplateElement 41 { 42 43 50 private AVT m_name_atv = null; 51 52 58 public void setName(AVT v) 59 { 60 m_name_atv = v; 61 } 62 63 69 public AVT getName() 70 { 71 return m_name_atv; 72 } 73 74 80 public void compose(StylesheetRoot sroot) throws TransformerException 81 { 82 super.compose(sroot); 83 java.util.Vector vnames = sroot.getComposeState().getVariableNames(); 84 if(null != m_name_atv) 85 m_name_atv.fixupVariables(vnames, sroot.getComposeState().getGlobalsSize()); 86 } 87 88 89 90 96 public int getXSLToken() 97 { 98 return Constants.ELEMNAME_PI; 99 } 100 101 106 public String getNodeName() 107 { 108 return Constants.ELEMNAME_PI_STRING; 109 } 110 111 123 public void execute( 124 TransformerImpl transformer) 125 throws TransformerException 126 { 127 128 if (TransformerImpl.S_DEBUG) 129 transformer.getTraceManager().fireTraceEvent(this); 130 131 XPathContext xctxt = transformer.getXPathContext(); 132 int sourceNode = xctxt.getCurrentNode(); 133 134 String piName = m_name_atv == null ? null : m_name_atv.evaluate(xctxt, sourceNode, this); 135 136 if (piName == null) return; 138 139 if (piName.equalsIgnoreCase("xml")) 140 { 141 transformer.getMsgMgr().warn( 142 this, XSLTErrorResources.WG_PROCESSINGINSTRUCTION_NAME_CANT_BE_XML, 143 new Object []{ Constants.ATTRNAME_NAME, piName }); 144 return; 145 } 146 147 else if ((!m_name_atv.isSimple()) && (!XMLChar.isValidNCName(piName))) 150 { 151 transformer.getMsgMgr().warn( 152 this, XSLTErrorResources.WG_PROCESSINGINSTRUCTION_NOTVALID_NCNAME, 153 new Object []{ Constants.ATTRNAME_NAME, piName }); 154 return; 155 } 156 157 String data = transformer.transformToString(this); 166 167 try 168 { 169 transformer.getResultTreeHandler().processingInstruction(piName, data); 170 } 171 catch(org.xml.sax.SAXException se) 172 { 173 throw new TransformerException (se); 174 } 175 176 if (TransformerImpl.S_DEBUG) 177 transformer.getTraceManager().fireTraceEndEvent(this); 178 } 179 180 189 public ElemTemplateElement appendChild(ElemTemplateElement newChild) 190 { 191 192 int type = ((ElemTemplateElement) newChild).getXSLToken(); 193 194 switch (type) 195 { 196 197 case Constants.ELEMNAME_TEXTLITERALRESULT : 199 case Constants.ELEMNAME_APPLY_TEMPLATES : 200 case Constants.ELEMNAME_APPLY_IMPORTS : 201 case Constants.ELEMNAME_CALLTEMPLATE : 202 case Constants.ELEMNAME_FOREACH : 203 case Constants.ELEMNAME_VALUEOF : 204 case Constants.ELEMNAME_COPY_OF : 205 case Constants.ELEMNAME_NUMBER : 206 case Constants.ELEMNAME_CHOOSE : 207 case Constants.ELEMNAME_IF : 208 case Constants.ELEMNAME_TEXT : 209 case Constants.ELEMNAME_COPY : 210 case Constants.ELEMNAME_VARIABLE : 211 case Constants.ELEMNAME_MESSAGE : 212 213 break; 219 default : 220 error(XSLTErrorResources.ER_CANNOT_ADD, 221 new Object []{ newChild.getNodeName(), 222 this.getNodeName() }); 224 } 226 227 return super.appendChild(newChild); 228 } 229 } 230 | Popular Tags |