286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 1999-2005 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A/*
286N/A * $Id: FuncExtFunctionAvailable.java,v 1.2.4.1 2005/09/14 20:05:08 jeffsuttor Exp $
286N/A */
286N/Apackage com.sun.org.apache.xpath.internal.functions;
286N/A
286N/Aimport com.sun.org.apache.xalan.internal.templates.Constants;
286N/Aimport com.sun.org.apache.xpath.internal.ExtensionsProvider;
286N/Aimport com.sun.org.apache.xpath.internal.XPathContext;
286N/Aimport com.sun.org.apache.xpath.internal.compiler.FunctionTable;
286N/Aimport com.sun.org.apache.xpath.internal.objects.XBoolean;
286N/Aimport com.sun.org.apache.xpath.internal.objects.XObject;
286N/A
286N/A/**
286N/A * Execute the ExtFunctionAvailable() function.
286N/A * @xsl.usage advanced
286N/A */
286N/Apublic class FuncExtFunctionAvailable extends FunctionOneArg
286N/A{
286N/A static final long serialVersionUID = 5118814314918592241L;
286N/A
286N/A transient private FunctionTable m_functionTable = null;
286N/A
286N/A /**
286N/A * Execute the function. The function must return
286N/A * a valid object.
286N/A * @param xctxt The current execution context.
286N/A * @return A valid XObject.
286N/A *
286N/A * @throws javax.xml.transform.TransformerException
286N/A */
286N/A public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
286N/A {
286N/A
286N/A String prefix;
286N/A String namespace;
286N/A String methName;
286N/A
286N/A String fullName = m_arg0.execute(xctxt).str();
286N/A int indexOfNSSep = fullName.indexOf(':');
286N/A
286N/A if (indexOfNSSep < 0)
286N/A {
286N/A prefix = "";
286N/A namespace = Constants.S_XSLNAMESPACEURL;
286N/A methName = fullName;
286N/A }
286N/A else
286N/A {
286N/A prefix = fullName.substring(0, indexOfNSSep);
286N/A namespace = xctxt.getNamespaceContext().getNamespaceForPrefix(prefix);
286N/A if (null == namespace)
286N/A return XBoolean.S_FALSE;
286N/A methName = fullName.substring(indexOfNSSep + 1);
286N/A }
286N/A
286N/A if (namespace.equals(Constants.S_XSLNAMESPACEURL))
286N/A {
286N/A try
286N/A {
286N/A if (null == m_functionTable) m_functionTable = new FunctionTable();
286N/A return m_functionTable.functionAvailable(methName) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
286N/A }
286N/A catch (Exception e)
286N/A {
286N/A return XBoolean.S_FALSE;
286N/A }
286N/A }
286N/A else
286N/A {
286N/A //dml
286N/A ExtensionsProvider extProvider = (ExtensionsProvider)xctxt.getOwnerObject();
286N/A return extProvider.functionAvailable(namespace, methName)
286N/A ? XBoolean.S_TRUE : XBoolean.S_FALSE;
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * The function table is an instance field. In order to access this instance
286N/A * field during evaluation, this method is called at compilation time to
286N/A * insert function table information for later usage. It should only be used
286N/A * during compiling of XPath expressions.
286N/A * @param aTable an instance of the function table
286N/A */
286N/A public void setFunctionTable(FunctionTable aTable){
286N/A m_functionTable = aTable;
286N/A }
286N/A}