/** * Execute the function. The function must return a valid object. * * @param xctxt The current execution context. * @return A valid XObject. * @throws javax.xml.transform.TransformerException */ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException { String prefix; String namespace; String methName; String fullName = m_arg0.execute(xctxt).str(); int indexOfNSSep = fullName.indexOf(':'); if (indexOfNSSep < 0) { prefix = ""; namespace = Constants.S_XSLNAMESPACEURL; methName = fullName; } else { prefix = fullName.substring(0, indexOfNSSep); namespace = xctxt.getNamespaceContext().getNamespaceForPrefix(prefix); if (null == namespace) return XBoolean.S_FALSE; methName = fullName.substring(indexOfNSSep + 1); } if (namespace.equals(Constants.S_XSLNAMESPACEURL)) { try { return Keywords.functionAvailable(methName) ? XBoolean.S_TRUE : XBoolean.S_FALSE; } catch (Exception e) { return XBoolean.S_FALSE; } } else { // dml ExtensionsProvider extProvider = (ExtensionsProvider) xctxt.getOwnerObject(); return extProvider.functionAvailable(namespace, methName) ? XBoolean.S_TRUE : XBoolean.S_FALSE; } }
/** * Get a variable based on it's qualified name. This is for external use only. * * @param xctxt The XPath context, which must be passed in order to lazy evaluate variables. * @param qname The qualified name of the variable. * @return The evaluated value of the variable. * @throws javax.xml.transform.TransformerException */ public XObject getVariableOrParam(XPathContext xctxt, org.apache.xml.utils.QName qname) throws javax.xml.transform.TransformerException { org.apache.xml.utils.PrefixResolver prefixResolver = xctxt.getNamespaceContext(); // Get the current ElemTemplateElement, which must be pushed in as the // prefix resolver, and then walk backwards in document order, searching // for an xsl:param element or xsl:variable element that matches our // qname. If we reach the top level, use the StylesheetRoot's composed // list of top level variables and parameters. if (prefixResolver instanceof org.apache.xalan.templates.ElemTemplateElement) { org.apache.xalan.templates.ElemVariable vvar; org.apache.xalan.templates.ElemTemplateElement prev = (org.apache.xalan.templates.ElemTemplateElement) prefixResolver; if (!(prev instanceof org.apache.xalan.templates.Stylesheet)) { while (!(prev.getParentNode() instanceof org.apache.xalan.templates.Stylesheet)) { org.apache.xalan.templates.ElemTemplateElement savedprev = prev; while (null != (prev = prev.getPreviousSiblingElem())) { if (prev instanceof org.apache.xalan.templates.ElemVariable) { vvar = (org.apache.xalan.templates.ElemVariable) prev; if (vvar.getName().equals(qname)) return getLocalVariable(xctxt, vvar.getIndex()); } } prev = savedprev.getParentElem(); } } vvar = prev.getStylesheetRoot().getVariableOrParamComposed(qname); if (null != vvar) return getGlobalVariable(xctxt, vvar.getIndex()); } throw new javax.xml.transform.TransformerException( XSLMessages.createXPATHMessage( XPATHErrorResources.ER_VAR_NOT_RESOLVABLE, new Object[] {qname.toString()})); // "Variable not resolvable: " + qname); }
/** * Execute the function. The function must return a valid object. * * @param xctxt The current execution context. * @return A valid XObject. * @throws javax.xml.transform.TransformerException */ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException { // TransformerImpl transformer = (TransformerImpl)xctxt; TransformerImpl transformer = (TransformerImpl) xctxt.getOwnerObject(); XNodeSet nodes = null; int context = xctxt.getCurrentNode(); DTM dtm = xctxt.getDTM(context); int docContext = dtm.getDocumentRoot(context); if (DTM.NULL == docContext) { // path.error(context, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC); //"context does not // have an owner document!"); } String xkeyname = getArg0().execute(xctxt).str(); QName keyname = new QName(xkeyname, xctxt.getNamespaceContext()); XObject arg = getArg1().execute(xctxt); boolean argIsNodeSetDTM = (XObject.CLASS_NODESET == arg.getType()); KeyManager kmgr = transformer.getKeyManager(); // Don't bother with nodeset logic if the thing is only one node. if (argIsNodeSetDTM) { XNodeSet ns = (XNodeSet) arg; ns.setShouldCacheNodes(true); int len = ns.getLength(); if (len <= 1) argIsNodeSetDTM = false; } if (argIsNodeSetDTM) { Hashtable usedrefs = null; DTMIterator ni = arg.iter(); int pos; UnionPathIterator upi = new UnionPathIterator(); upi.exprSetParent(this); while (DTM.NULL != (pos = ni.nextNode())) { dtm = xctxt.getDTM(pos); XMLString ref = dtm.getStringValue(pos); if (null == ref) continue; if (null == usedrefs) usedrefs = new Hashtable(); if (usedrefs.get(ref) != null) { continue; // We already have 'em. } else { // ISTRUE being used as a dummy value. usedrefs.put(ref, ISTRUE); } XNodeSet nl = kmgr.getNodeSetDTMByKey(xctxt, docContext, keyname, ref, xctxt.getNamespaceContext()); nl.setRoot(xctxt.getCurrentNode(), xctxt); // try // { upi.addIterator(nl); // } // catch(CloneNotSupportedException cnse) // { // // will never happen. // } // mnodeset.addNodesInDocOrder(nl, xctxt); needed?? } int current = xctxt.getCurrentNode(); upi.setRoot(current, xctxt); nodes = new XNodeSet(upi); } else { XMLString ref = arg.xstr(); nodes = kmgr.getNodeSetDTMByKey(xctxt, docContext, keyname, ref, xctxt.getNamespaceContext()); nodes.setRoot(xctxt.getCurrentNode(), xctxt); } return nodes; }
/** * Execute the function. The function must return a valid object. * * @param xctxt The current execution context. * @return A valid XObject. * @throws javax.xml.transform.TransformerException */ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException { String fullName = m_arg0.execute(xctxt).str(); int indexOfNSSep = fullName.indexOf(':'); String result = null; String propName = ""; // List of properties where the name of the // property argument is to be looked for. Properties xsltInfo = new Properties(); loadPropertyFile(XSLT_PROPERTIES, xsltInfo); if (indexOfNSSep > 0) { String prefix = (indexOfNSSep >= 0) ? fullName.substring(0, indexOfNSSep) : ""; String namespace; namespace = xctxt.getNamespaceContext().getNamespaceForPrefix(prefix); propName = (indexOfNSSep < 0) ? fullName : fullName.substring(indexOfNSSep + 1); if (namespace.startsWith("http://www.w3.org/XSL/Transform") || namespace.equals("http://www.w3.org/1999/XSL/Transform")) { result = xsltInfo.getProperty(propName); if (null == result) { warn( xctxt, XPATHErrorResources.WG_PROPERTY_NOT_SUPPORTED, new Object[] {fullName}); // "XSL Property not supported: "+fullName); return XString.EMPTYSTRING; } } else { warn( xctxt, XPATHErrorResources.WG_DONT_DO_ANYTHING_WITH_NS, new Object[] { namespace, fullName }); // "Don't currently do anything with namespace "+namespace+" in property: // "+fullName); try { // if secure procession is enabled only handle required properties do not not map any // valid system property if (!xctxt.isSecureProcessing()) { result = System.getProperty(propName); } else { warn( xctxt, XPATHErrorResources.WG_SECURITY_EXCEPTION, new Object[] { fullName }); // "SecurityException when trying to access XSL system property: "+fullName); } if (null == result) { return XString.EMPTYSTRING; } } catch (SecurityException se) { warn( xctxt, XPATHErrorResources.WG_SECURITY_EXCEPTION, new Object[] { fullName }); // "SecurityException when trying to access XSL system property: "+fullName); return XString.EMPTYSTRING; } } } else { try { // if secure procession is enabled only handle required properties do not not map any valid // system property if (!xctxt.isSecureProcessing()) { result = System.getProperty(fullName); } else { warn( xctxt, XPATHErrorResources.WG_SECURITY_EXCEPTION, new Object[] { fullName }); // "SecurityException when trying to access XSL system property: "+fullName); } if (null == result) { return XString.EMPTYSTRING; } } catch (SecurityException se) { warn( xctxt, XPATHErrorResources.WG_SECURITY_EXCEPTION, new Object[] { fullName }); // "SecurityException when trying to access XSL system property: "+fullName); return XString.EMPTYSTRING; } } if (propName.equals("version") && result.length() > 0) { try { // Needs to return the version number of the spec we conform to. return new XString("1.0"); } catch (Exception ex) { return new XString(result); } } else return new XString(result); }