You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by ga...@locus.apache.org on 2000/11/28 19:14:24 UTC

cvs commit: xml-xalan/java/src/org/apache/xpath/functions FuncExtFunctionAvailable.java

garyp       00/11/28 10:14:24

  Modified:    java/src/org/apache/xpath/compiler Keywords.java
               java/src/org/apache/xpath/functions
                        FuncExtFunctionAvailable.java
  Log:
  Implement function-available for built-in functions.
  
  Revision  Changes    Path
  1.5       +27 -0     xml-xalan/java/src/org/apache/xpath/compiler/Keywords.java
  
  Index: Keywords.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/compiler/Keywords.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Keywords.java	2000/11/23 04:59:04	1.4
  +++ Keywords.java	2000/11/28 18:14:23	1.5
  @@ -420,4 +420,31 @@
       m_functions.put(new StringKey(FUNC_DOCLOCATION_STRING),
                       new Integer(FunctionTable.FUNC_DOCLOCATION));
     }
  +
  +  public static boolean functionAvailable(String methName)
  +  {
  +
  +    try
  +    {
  +      Object tblEntry = m_functions.get(methName);
  +      if (null == tblEntry)
  +        return false;
  +      int funcType = ((Integer) tblEntry).intValue();
  +      switch (funcType)
  +      {
  +        case OpCodes.NODETYPE_COMMENT:
  +        case OpCodes.NODETYPE_TEXT:
  +        case OpCodes.NODETYPE_PI:
  +        case OpCodes.NODETYPE_NODE:
  +          return false;                 // These look like functions but they're NodeTests.
  +
  +        default:
  +          return true;
  +      }
  +    }
  +    catch (Exception e)
  +    {
  +      return false;
  +    }
  +  }
   }
  
  
  
  1.5       +39 -9     xml-xalan/java/src/org/apache/xpath/functions/FuncExtFunctionAvailable.java
  
  Index: FuncExtFunctionAvailable.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncExtFunctionAvailable.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FuncExtFunctionAvailable.java	2000/11/23 04:59:11	1.4
  +++ FuncExtFunctionAvailable.java	2000/11/28 18:14:24	1.5
  @@ -57,6 +57,7 @@
   package org.apache.xpath.functions;
   
   import org.apache.xml.utils.PrefixResolver;
  +import org.apache.xalan.templates.Constants;
   import org.apache.xalan.extensions.ExtensionsTable;
   
   import org.w3c.dom.Node;
  @@ -65,6 +66,7 @@
   
   import org.apache.xpath.XPathContext;
   import org.apache.xpath.XPath;
  +import org.apache.xpath.compiler.Keywords;
   import org.apache.xpath.objects.XObject;
   import org.apache.xpath.objects.XBoolean;
   
  @@ -86,17 +88,45 @@
     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(':');
  -    String prefix = (indexOfNSSep >= 0)
  -                    ? fullName.substring(0, indexOfNSSep) : "";
  -    String namespace =
  -      xctxt.getNamespaceContext().getNamespaceForPrefix(prefix);
  -    String methName = (indexOfNSSep < 0)
  -                      ? fullName : fullName.substring(indexOfNSSep + 1);
  -    ExtensionsTable etable = xctxt.getExtensionsTable();
   
  -    return etable.functionAvailable(namespace, methName)
  -           ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  +    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
  +    {
  +      ExtensionsTable etable = xctxt.getExtensionsTable();
  +
  +      return etable.functionAvailable(namespace, methName)
  +             ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  +    }
     }
   }