1 16 19 package org.apache.xpath.functions; 20 21 import org.apache.xalan.templates.Constants; 22 import org.apache.xalan.transformer.TransformerImpl; 23 import org.apache.xml.utils.QName; 24 import org.apache.xpath.ExtensionsProvider; 25 import org.apache.xpath.XPathContext; 26 import org.apache.xpath.objects.XBoolean; 27 import org.apache.xpath.objects.XObject; 28 29 33 public class FuncExtElementAvailable extends FunctionOneArg 34 { 35 36 44 public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException 45 { 46 47 String prefix; 48 String namespace; 49 String methName; 50 51 String fullName = m_arg0.execute(xctxt).str(); 52 int indexOfNSSep = fullName.indexOf(':'); 53 54 if (indexOfNSSep < 0) 55 { 56 prefix = ""; 57 namespace = Constants.S_XSLNAMESPACEURL; 58 methName = fullName; 59 } 60 else 61 { 62 prefix = fullName.substring(0, indexOfNSSep); 63 namespace = xctxt.getNamespaceContext().getNamespaceForPrefix(prefix); 64 if (null == namespace) 65 return XBoolean.S_FALSE; 66 methName= fullName.substring(indexOfNSSep + 1); 67 } 68 69 if (namespace.equals(Constants.S_XSLNAMESPACEURL) 70 || namespace.equals(Constants.S_BUILTIN_EXTENSIONS_URL)) 71 { 72 try 73 { 74 TransformerImpl transformer = (TransformerImpl) xctxt.getOwnerObject(); 75 return transformer.getStylesheet().getAvailableElements().containsKey( 76 new QName(namespace, methName)) 77 ? XBoolean.S_TRUE : XBoolean.S_FALSE; 78 } 79 catch (Exception e) 80 { 81 return XBoolean.S_FALSE; 82 } 83 } 84 else 85 { 86 ExtensionsProvider extProvider = (ExtensionsProvider)xctxt.getOwnerObject(); 88 return extProvider.elementAvailable(namespace, methName) 89 ? XBoolean.S_TRUE : XBoolean.S_FALSE; 90 } 91 } 92 } 93 | Popular Tags |