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.dtm.DTM; 26 import org.apache.xml.serializer.SerializationHandler; 27 import org.apache.xpath.Expression; 28 import org.apache.xpath.XPath; 29 import org.apache.xpath.XPathContext; 30 import org.apache.xpath.objects.XObject; 31 import org.xml.sax.SAXException ; 32 33 45 public class ElemValueOf extends ElemTemplateElement 46 { 47 48 52 private XPath m_selectExpression = null; 53 54 58 private boolean m_isDot = false; 59 60 68 public void setSelect(XPath v) 69 { 70 71 if (null != v) 72 { 73 String s = v.getPatternString(); 74 75 m_isDot = (null != s) && s.equals("."); 76 } 77 78 m_selectExpression = v; 79 } 80 81 89 public XPath getSelect() 90 { 91 return m_selectExpression; 92 } 93 94 98 private boolean m_disableOutputEscaping = false; 99 100 120 public void setDisableOutputEscaping(boolean v) 121 { 122 m_disableOutputEscaping = v; 123 } 124 125 145 public boolean getDisableOutputEscaping() 146 { 147 return m_disableOutputEscaping; 148 } 149 150 157 public int getXSLToken() 158 { 159 return Constants.ELEMNAME_VALUEOF; 160 } 161 162 172 public void compose(StylesheetRoot sroot) throws TransformerException 173 { 174 175 super.compose(sroot); 176 177 java.util.Vector vnames = sroot.getComposeState().getVariableNames(); 178 179 if (null != m_selectExpression) 180 m_selectExpression.fixupVariables( 181 vnames, sroot.getComposeState().getGlobalsSize()); 182 } 183 184 189 public String getNodeName() 190 { 191 return Constants.ELEMNAME_VALUEOF_STRING; 192 } 193 194 211 public void execute(TransformerImpl transformer) throws TransformerException 212 { 213 214 XPathContext xctxt = transformer.getXPathContext(); 215 SerializationHandler rth = transformer.getResultTreeHandler(); 216 217 if (TransformerImpl.S_DEBUG) 218 transformer.getTraceManager().fireTraceEvent(this); 219 220 try 221 { 222 if (false && m_isDot && !TransformerImpl.S_DEBUG) 224 { 225 int child = xctxt.getCurrentNode(); 226 DTM dtm = xctxt.getDTM(child); 227 228 xctxt.pushCurrentNode(child); 229 230 if (m_disableOutputEscaping) 231 rth.processingInstruction( 232 javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, ""); 233 234 try 235 { 236 dtm.dispatchCharactersEvents(child, rth, false); 237 } 238 finally 239 { 240 if (m_disableOutputEscaping) 241 rth.processingInstruction( 242 javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, ""); 243 244 xctxt.popCurrentNode(); 245 } 246 } 247 else 248 { 249 xctxt.pushNamespaceContext(this); 250 251 int current = xctxt.getCurrentNode(); 252 253 xctxt.pushCurrentNodeAndExpression(current, current); 254 255 if (m_disableOutputEscaping) 256 rth.processingInstruction( 257 javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, ""); 258 259 try 260 { 261 Expression expr = m_selectExpression.getExpression(); 262 263 if (TransformerImpl.S_DEBUG) 264 { 265 XObject obj = expr.execute(xctxt); 266 267 transformer.getTraceManager().fireSelectedEvent(current, this, 268 "select", m_selectExpression, obj); 269 obj.dispatchCharactersEvents(rth); 270 } 271 else 272 { 273 expr.executeCharsToContentHandler(xctxt, rth); 274 } 275 } 276 finally 277 { 278 if (m_disableOutputEscaping) 279 rth.processingInstruction( 280 javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, ""); 281 282 xctxt.popNamespaceContext(); 283 xctxt.popCurrentNodeAndExpression(); 284 } 285 } 286 } 287 catch (SAXException se) 288 { 289 throw new TransformerException (se); 290 } 291 catch (RuntimeException re) { 292 TransformerException te = new TransformerException (re); 293 te.setLocator(this); 294 throw te; 295 } 296 finally 297 { 298 if (TransformerImpl.S_DEBUG) 299 transformer.getTraceManager().fireTraceEndEvent(this); 300 } 301 } 302 303 312 public ElemTemplateElement appendChild(ElemTemplateElement newChild) 313 { 314 315 error(XSLTErrorResources.ER_CANNOT_ADD, 316 new Object []{ newChild.getNodeName(), 317 this.getNodeName() }); 319 return null; 321 } 322 323 327 protected void callChildVisitors(XSLTVisitor visitor, boolean callAttrs) 328 { 329 if(callAttrs) 330 m_selectExpression.getExpression().callVisitors(m_selectExpression, visitor); 331 super.callChildVisitors(visitor, callAttrs); 332 } 333 334 } 335 | Popular Tags |