19f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/*
29f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one
39f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or more contributor license agreements. See the NOTICE file
49f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed with this work for additional information
59f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * regarding copyright ownership. The ASF licenses this file
69f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to you under the Apache License, Version 2.0 (the  "License");
79f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * you may not use this file except in compliance with the License.
89f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * You may obtain a copy of the License at
99f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *     http://www.apache.org/licenses/LICENSE-2.0
119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Unless required by applicable law or agreed to in writing, software
139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS,
149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * See the License for the specific language governing permissions and
169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * limitations under the License.
179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/*
199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * $Id: ExtensionsTable.java 469672 2006-10-31 21:56:19Z minchau $
209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpackage org.apache.xalan.extensions;
229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.util.Hashtable;
249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.util.Vector;
259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.res.XSLMessages;
279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.res.XSLTErrorResources;
289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.templates.StylesheetRoot;
299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.XPathProcessorException;
309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.functions.FuncExtFunction;
319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/**
339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Class holding a table registered extension namespace handlers
349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage internal
359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpublic class ExtensionsTable
379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson{
389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Table of extensions that may be called from the expression language
409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * via the call(name, ...) function.  Objects are keyed on the call
419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * name.
429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @xsl.usage internal
439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public Hashtable m_extensionFunctionNamespaces = new Hashtable();
459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * The StylesheetRoot associated with this extensions table.
489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  private StylesheetRoot m_sroot;
509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * The constructor (called from TransformerImpl) registers the
539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * StylesheetRoot for the transformation and instantiates an
549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * ExtensionHandler for each extension namespace.
559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @xsl.usage advanced
569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public ExtensionsTable(StylesheetRoot sroot)
589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    throws javax.xml.transform.TransformerException
599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_sroot = sroot;
619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    Vector extensions = m_sroot.getExtensions();
629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    for (int i = 0; i < extensions.size(); i++)
639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      ExtensionNamespaceSupport extNamespaceSpt =
659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                 (ExtensionNamespaceSupport)extensions.get(i);
669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      ExtensionHandler extHandler = extNamespaceSpt.launch();
679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        if (extHandler != null)
689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          addExtensionNamespace(extNamespaceSpt.getNamespace(), extHandler);
699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      }
709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get an ExtensionHandler object that represents the
749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * given namespace.
759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param extns A valid extension namespace.
769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return ExtensionHandler object that represents the
789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * given namespace.
799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public ExtensionHandler get(String extns)
819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return (ExtensionHandler) m_extensionFunctionNamespaces.get(extns);
839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Register an extension namespace handler. This handler provides
879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * functions for testing whether a function is known within the
889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * namespace and also for invoking the functions.
899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param uri the URI for the extension.
919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param extNS the extension handler.
929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @xsl.usage advanced
939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void addExtensionNamespace(String uri, ExtensionHandler extNS)
959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_extensionFunctionNamespaces.put(uri, extNS);
979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Execute the function-available() function.
1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param ns       the URI of namespace in which the function is needed
1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param funcName the function name being tested
1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return whether the given function is available or not.
1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @throws javax.xml.transform.TransformerException
1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public boolean functionAvailable(String ns, String funcName)
1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          throws javax.xml.transform.TransformerException
1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    boolean isAvailable = false;
1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if (null != ns)
1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      ExtensionHandler extNS =
1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson           (ExtensionHandler) m_extensionFunctionNamespaces.get(ns);
1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      if (extNS != null)
1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        isAvailable = extNS.isFunctionAvailable(funcName);
1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return isAvailable;
1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Execute the element-available() function.
1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param ns       the URI of namespace in which the function is needed
1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param elemName name of element being tested
1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return whether the given element is available or not.
1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @throws javax.xml.transform.TransformerException
1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public boolean elementAvailable(String ns, String elemName)
1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          throws javax.xml.transform.TransformerException
1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    boolean isAvailable = false;
1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if (null != ns)
1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      ExtensionHandler extNS =
1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson               (ExtensionHandler) m_extensionFunctionNamespaces.get(ns);
1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      if (extNS != null) // defensive
1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        isAvailable = extNS.isElementAvailable(elemName);
1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return isAvailable;
1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Handle an extension function.
1489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param ns        the URI of namespace in which the function is needed
1499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param funcName  the function name being called
1509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param argVec    arguments to the function in a vector
1519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param methodKey a unique key identifying this function instance in the
1529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *                  stylesheet
1539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param exprContext a context which may be passed to an extension function
1549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *                  and provides callback functions to access various
1559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *                  areas in the environment
1569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return result of executing the function
1589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @throws javax.xml.transform.TransformerException
1609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public Object extFunction(String ns, String funcName,
1629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                            Vector argVec, Object methodKey,
1639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                            ExpressionContext exprContext)
1649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            throws javax.xml.transform.TransformerException
1659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    Object result = null;
1679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if (null != ns)
1689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
1699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      ExtensionHandler extNS =
1709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        (ExtensionHandler) m_extensionFunctionNamespaces.get(ns);
1719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      if (null != extNS)
1729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      {
1739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        try
1749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
1759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          result = extNS.callFunction(funcName, argVec, methodKey,
1769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                                      exprContext);
1779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
1789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        catch (javax.xml.transform.TransformerException e)
1799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
1809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          throw e;
1819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
1829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        catch (Exception e)
1839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
1849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          throw new javax.xml.transform.TransformerException(e);
1859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
1869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      }
1879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      else
1889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      {
1899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        throw new XPathProcessorException(XSLMessages.createMessage(XSLTErrorResources.ER_EXTENSION_FUNC_UNKNOWN, new Object[]{ns, funcName }));
1909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        //"Extension function '" + ns + ":" + funcName + "' is unknown");
1919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      }
1929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
1939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return result;
1949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Handle an extension function.
1989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param extFunction  the extension function
1999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param argVec    arguments to the function in a vector
2009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param exprContext a context which may be passed to an extension function
2019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *                  and provides callback functions to access various
2029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *                  areas in the environment
2039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return result of executing the function
2059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @throws javax.xml.transform.TransformerException
2079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
2089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public Object extFunction(FuncExtFunction extFunction, Vector argVec,
2099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                            ExpressionContext exprContext)
2109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson         throws javax.xml.transform.TransformerException
2119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
2129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    Object result = null;
2139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    String ns = extFunction.getNamespace();
2149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if (null != ns)
2159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
2169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      ExtensionHandler extNS =
2179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        (ExtensionHandler) m_extensionFunctionNamespaces.get(ns);
2189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      if (null != extNS)
2199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      {
2209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        try
2219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
2229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          result = extNS.callFunction(extFunction, argVec, exprContext);
2239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
2249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        catch (javax.xml.transform.TransformerException e)
2259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
2269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          throw e;
2279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
2289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        catch (Exception e)
2299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
2309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          throw new javax.xml.transform.TransformerException(e);
2319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
2329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      }
2339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      else
2349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      {
2359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        throw new XPathProcessorException(XSLMessages.createMessage(XSLTErrorResources.ER_EXTENSION_FUNC_UNKNOWN,
2369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                                          new Object[]{ns, extFunction.getFunctionName()}));
2379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      }
2389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
2399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return result;
2409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
2419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson}
242