1 16 19 package org.apache.xalan.templates; 20 21 import javax.xml.transform.TransformerException ; 22 23 import org.apache.xalan.extensions.ExtensionNamespaceSupport; 24 import org.apache.xalan.transformer.TransformerImpl; 25 import org.apache.xpath.VariableStack; 26 import org.apache.xpath.XPathContext; 27 import org.apache.xpath.objects.XObject; 28 29 import org.w3c.dom.Node ; 30 import org.w3c.dom.NodeList ; 31 32 33 37 public class ElemExsltFunction extends ElemTemplate 38 { 39 46 public int getXSLToken() 47 { 48 return Constants.EXSLT_ELEMNAME_FUNCTION; 49 } 50 51 58 public String getNodeName() 59 { 60 return Constants.EXSLT_ELEMNAME_FUNCTION_STRING; 61 } 62 63 public void execute(TransformerImpl transformer, XObject[] args) 64 throws TransformerException 65 { 66 XPathContext xctxt = transformer.getXPathContext(); 67 VariableStack vars = xctxt.getVarStack(); 68 69 int thisFrame = vars.getStackFrame(); 72 int nextFrame = vars.link(m_frameSize); 73 74 if (m_inArgsSize < args.length) { 75 throw new TransformerException ("function called with too many args"); 76 } 77 78 if (m_inArgsSize > 0) { 81 vars.clearLocalSlots(0, m_inArgsSize); 82 83 if (args.length > 0) { 84 vars.setStackFrame(thisFrame); 85 NodeList children = this.getChildNodes(); 86 87 for (int i = 0; i < args.length; i ++) { 88 Node child = children.item(i); 89 if (children.item(i) instanceof ElemParam) { 90 ElemParam param = (ElemParam)children.item(i); 91 vars.setLocalVariable(param.getIndex(), args[i], nextFrame); 92 } 93 } 94 95 vars.setStackFrame(nextFrame); 96 } 97 } 98 99 104 if (TransformerImpl.S_DEBUG) 105 transformer.getTraceManager().fireTraceEvent(this); 106 107 vars.setStackFrame(nextFrame); 108 transformer.executeChildTemplates(this, true); 109 110 vars.unlink(thisFrame); 112 113 if (TransformerImpl.S_DEBUG) 114 transformer.getTraceManager().fireTraceEndEvent(this); 115 116 119 } 120 121 127 public void compose(StylesheetRoot sroot) throws TransformerException 128 { 129 super.compose(sroot); 130 131 String namespace = getName().getNamespace(); 133 String handlerClass = "org.apache.xalan.extensions.ExtensionHandlerExsltFunction"; 134 Object [] args ={namespace, sroot}; 135 ExtensionNamespaceSupport extNsSpt = 136 new ExtensionNamespaceSupport(namespace, handlerClass, args); 137 sroot.getExtensionNamespacesManager().registerExtension(extNsSpt); 138 if (!(namespace.equals(Constants.S_EXSLT_FUNCTIONS_URL))) 141 { 142 namespace = Constants.S_EXSLT_FUNCTIONS_URL; 143 args = new Object []{namespace, sroot}; 144 extNsSpt = new ExtensionNamespaceSupport(namespace, handlerClass, args); 145 sroot.getExtensionNamespacesManager().registerExtension(extNsSpt); 146 } 147 } 148 } 149 | Popular Tags |