You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by jy...@apache.org on 2005/05/17 23:25:47 UTC
cvs commit: xml-xalan/java/src/org/apache/xpath/functions FuncExtFunctionAvailable.java
jycli 2005/05/17 14:25:47
Modified: java/src/org/apache/xpath/compiler Compiler.java
FunctionTable.java Keywords.java XPathParser.java
java/src/org/apache/xpath/functions
FuncExtFunctionAvailable.java
Removed: java/src/org/apache/xpath/compiler FuncLoader.java
ObjectFactory.java SecuritySupport.java
SecuritySupport12.java
Log:
Modified FunctionTable. Although it is not recommanded, but it is doable for users to add a customized function or overwrite the default implementation of a build-in function. Fixed bug report XALANJ-2116
patch is reviewed by Henry Zongaro
Revision Changes Path
1.41 +18 -1 xml-xalan/java/src/org/apache/xpath/compiler/Compiler.java
Index: Compiler.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/compiler/Compiler.java,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- Compiler.java 24 Jan 2005 04:04:40 -0000 1.40
+++ Compiler.java 17 May 2005 21:25:46 -0000 1.41
@@ -33,6 +33,7 @@
import org.apache.xpath.axes.UnionPathIterator;
import org.apache.xpath.axes.WalkerFactory;
import org.apache.xpath.functions.FuncExtFunction;
+import org.apache.xpath.functions.FuncExtFunctionAvailable;
import org.apache.xpath.functions.Function;
import org.apache.xpath.functions.WrongNumberArgsException;
import org.apache.xpath.objects.XNumber;
@@ -618,6 +619,14 @@
}
/**
+ * Get the function table
+ */
+ FunctionTable getFunctionTable()
+ {
+ return m_functionTable;
+ }
+
+ /**
* Compile a location path. The LocPathIterator itself may create
* {@link org.apache.xpath.axes.AxesWalker} children.
*
@@ -1018,6 +1027,14 @@
if (-1 != funcID)
{
Function func = m_functionTable.getFunction(funcID);
+
+ /**
+ * It is a trick for function-available. Since the function table is an
+ * instance field, insert this table at compilation time for later usage
+ */
+
+ if (func instanceof FuncExtFunctionAvailable)
+ ((FuncExtFunctionAvailable) func).setFunctionTable(m_functionTable);
func.postCompileStep(this);
1.9 +194 -76 xml-xalan/java/src/org/apache/xpath/compiler/FunctionTable.java
Index: FunctionTable.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/compiler/FunctionTable.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- FunctionTable.java 15 Dec 2004 17:35:55 -0000 1.8
+++ FunctionTable.java 17 May 2005 21:25:46 -0000 1.9
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@
import org.apache.xpath.Expression;
import org.apache.xpath.functions.Function;
+import java.util.HashMap;
+import javax.xml.transform.TransformerException;
/**
* The function table for XPath.
@@ -137,14 +139,22 @@
/**
* The function table.
*/
- private static FuncLoader m_functions[];
-
+ private static Class m_functions[];
+
+ /** Table of function name to function ID associations. */
+ private static HashMap m_functionID = new HashMap();
+
/**
- * The function table contains functions defined in XSLT
+ * The function table contains customized functions
*/
- private FuncLoader m_functions_xslt[] = new FuncLoader[NUM_ALLOWABLE_ADDINS];
+ private Class m_functions_customer[] = new Class[NUM_ALLOWABLE_ADDINS];
/**
+ * Table of function name to function ID associations for customized functions
+ */
+ private HashMap m_functionID_customer = new HashMap();
+
+ /**
* Number of built in functions. Be sure to update this as
* built-in functions are added.
*/
@@ -162,66 +172,133 @@
static
{
- m_functions = new FuncLoader[NUM_BUILT_IN_FUNCS];
- m_functions[FUNC_CURRENT] = new FuncLoader("FuncCurrent", FUNC_CURRENT);
- m_functions[FUNC_LAST] = new FuncLoader("FuncLast", FUNC_LAST);
- m_functions[FUNC_POSITION] = new FuncLoader("FuncPosition",
- FUNC_POSITION);
- m_functions[FUNC_COUNT] = new FuncLoader("FuncCount", FUNC_COUNT);
- m_functions[FUNC_ID] = new FuncLoader("FuncId", FUNC_ID);
+ m_functions = new Class[NUM_BUILT_IN_FUNCS];
+ m_functions[FUNC_CURRENT] = org.apache.xpath.functions.FuncCurrent.class;
+ m_functions[FUNC_LAST] = org.apache.xpath.functions.FuncLast.class;
+ m_functions[FUNC_POSITION] = org.apache.xpath.functions.FuncPosition.class;
+ m_functions[FUNC_COUNT] = org.apache.xpath.functions.FuncCount.class;
+ m_functions[FUNC_ID] = org.apache.xpath.functions.FuncId.class;
m_functions[FUNC_KEY] =
- new FuncLoader("org.apache.xalan.templates.FuncKey", FUNC_KEY);
-
- // m_functions[FUNC_DOC] = new FuncDoc();
- m_functions[FUNC_LOCAL_PART] = new FuncLoader("FuncLocalPart",
- FUNC_LOCAL_PART);
- m_functions[FUNC_NAMESPACE] = new FuncLoader("FuncNamespace",
- FUNC_NAMESPACE);
- m_functions[FUNC_QNAME] = new FuncLoader("FuncQname", FUNC_QNAME);
- m_functions[FUNC_GENERATE_ID] = new FuncLoader("FuncGenerateId",
- FUNC_GENERATE_ID);
- m_functions[FUNC_NOT] = new FuncLoader("FuncNot", FUNC_NOT);
- m_functions[FUNC_TRUE] = new FuncLoader("FuncTrue", FUNC_TRUE);
- m_functions[FUNC_FALSE] = new FuncLoader("FuncFalse", FUNC_FALSE);
- m_functions[FUNC_BOOLEAN] = new FuncLoader("FuncBoolean", FUNC_BOOLEAN);
- m_functions[FUNC_LANG] = new FuncLoader("FuncLang", FUNC_LANG);
- m_functions[FUNC_NUMBER] = new FuncLoader("FuncNumber", FUNC_NUMBER);
- m_functions[FUNC_FLOOR] = new FuncLoader("FuncFloor", FUNC_FLOOR);
- m_functions[FUNC_CEILING] = new FuncLoader("FuncCeiling", FUNC_CEILING);
- m_functions[FUNC_ROUND] = new FuncLoader("FuncRound", FUNC_ROUND);
- m_functions[FUNC_SUM] = new FuncLoader("FuncSum", FUNC_SUM);
- m_functions[FUNC_STRING] = new FuncLoader("FuncString", FUNC_STRING);
- m_functions[FUNC_STARTS_WITH] = new FuncLoader("FuncStartsWith",
- FUNC_STARTS_WITH);
- m_functions[FUNC_CONTAINS] = new FuncLoader("FuncContains",
- FUNC_CONTAINS);
- m_functions[FUNC_SUBSTRING_BEFORE] = new FuncLoader("FuncSubstringBefore",
- FUNC_SUBSTRING_BEFORE);
- m_functions[FUNC_SUBSTRING_AFTER] = new FuncLoader("FuncSubstringAfter",
- FUNC_SUBSTRING_AFTER);
- m_functions[FUNC_NORMALIZE_SPACE] = new FuncLoader("FuncNormalizeSpace",
- FUNC_NORMALIZE_SPACE);
- m_functions[FUNC_TRANSLATE] = new FuncLoader("FuncTranslate",
- FUNC_TRANSLATE);
- m_functions[FUNC_CONCAT] = new FuncLoader("FuncConcat", FUNC_CONCAT);
-
- //m_functions[FUNC_FORMAT_NUMBER] = new FuncFormatNumber();
- m_functions[FUNC_SYSTEM_PROPERTY] = new FuncLoader("FuncSystemProperty",
- FUNC_SYSTEM_PROPERTY);
+ org.apache.xalan.templates.FuncKey.class;
+ m_functions[FUNC_LOCAL_PART] =
+ org.apache.xpath.functions.FuncLocalPart.class;
+ m_functions[FUNC_NAMESPACE] =
+ org.apache.xpath.functions.FuncNamespace.class;
+ m_functions[FUNC_QNAME] = org.apache.xpath.functions.FuncQname.class;
+ m_functions[FUNC_GENERATE_ID] =
+ org.apache.xpath.functions.FuncGenerateId.class;
+ m_functions[FUNC_NOT] = org.apache.xpath.functions.FuncNot.class;
+ m_functions[FUNC_TRUE] = org.apache.xpath.functions.FuncTrue.class;
+ m_functions[FUNC_FALSE] = org.apache.xpath.functions.FuncFalse.class;
+ m_functions[FUNC_BOOLEAN] = org.apache.xpath.functions.FuncBoolean.class;
+ m_functions[FUNC_LANG] = org.apache.xpath.functions.FuncLang.class;
+ m_functions[FUNC_NUMBER] = org.apache.xpath.functions.FuncNumber.class;
+ m_functions[FUNC_FLOOR] = org.apache.xpath.functions.FuncFloor.class;
+ m_functions[FUNC_CEILING] = org.apache.xpath.functions.FuncCeiling.class;
+ m_functions[FUNC_ROUND] = org.apache.xpath.functions.FuncRound.class;
+ m_functions[FUNC_SUM] = org.apache.xpath.functions.FuncSum.class;
+ m_functions[FUNC_STRING] = org.apache.xpath.functions.FuncString.class;
+ m_functions[FUNC_STARTS_WITH] =
+ org.apache.xpath.functions.FuncStartsWith.class;
+ m_functions[FUNC_CONTAINS] = org.apache.xpath.functions.FuncContains.class;
+ m_functions[FUNC_SUBSTRING_BEFORE] =
+ org.apache.xpath.functions.FuncSubstringBefore.class;
+ m_functions[FUNC_SUBSTRING_AFTER] =
+ org.apache.xpath.functions.FuncSubstringAfter.class;
+ m_functions[FUNC_NORMALIZE_SPACE] =
+ org.apache.xpath.functions.FuncNormalizeSpace.class;
+ m_functions[FUNC_TRANSLATE] =
+ org.apache.xpath.functions.FuncTranslate.class;
+ m_functions[FUNC_CONCAT] = org.apache.xpath.functions.FuncConcat.class;
+ m_functions[FUNC_SYSTEM_PROPERTY] =
+ org.apache.xpath.functions.FuncSystemProperty.class;
m_functions[FUNC_EXT_FUNCTION_AVAILABLE] =
- new FuncLoader("FuncExtFunctionAvailable", FUNC_EXT_FUNCTION_AVAILABLE);
+ org.apache.xpath.functions.FuncExtFunctionAvailable.class;
m_functions[FUNC_EXT_ELEM_AVAILABLE] =
- new FuncLoader("FuncExtElementAvailable", FUNC_EXT_ELEM_AVAILABLE);
- m_functions[FUNC_SUBSTRING] = new FuncLoader("FuncSubstring",
- FUNC_SUBSTRING);
- m_functions[FUNC_STRING_LENGTH] = new FuncLoader("FuncStringLength",
- FUNC_STRING_LENGTH);
- m_functions[FUNC_DOCLOCATION] = new FuncLoader("FuncDoclocation",
- FUNC_DOCLOCATION);
+ org.apache.xpath.functions.FuncExtElementAvailable.class;
+ m_functions[FUNC_SUBSTRING] =
+ org.apache.xpath.functions.FuncSubstring.class;
+ m_functions[FUNC_STRING_LENGTH] =
+ org.apache.xpath.functions.FuncStringLength.class;
+ m_functions[FUNC_DOCLOCATION] =
+ org.apache.xpath.functions.FuncDoclocation.class;
m_functions[FUNC_UNPARSED_ENTITY_URI] =
- new FuncLoader("FuncUnparsedEntityURI", FUNC_UNPARSED_ENTITY_URI);
+ org.apache.xpath.functions.FuncUnparsedEntityURI.class;
}
+ static{
+ m_functionID.put(Keywords.FUNC_CURRENT_STRING,
+ new Integer(FunctionTable.FUNC_CURRENT));
+ m_functionID.put(Keywords.FUNC_LAST_STRING,
+ new Integer(FunctionTable.FUNC_LAST));
+ m_functionID.put(Keywords.FUNC_POSITION_STRING,
+ new Integer(FunctionTable.FUNC_POSITION));
+ m_functionID.put(Keywords.FUNC_COUNT_STRING,
+ new Integer(FunctionTable.FUNC_COUNT));
+ m_functionID.put(Keywords.FUNC_ID_STRING,
+ new Integer(FunctionTable.FUNC_ID));
+ m_functionID.put(Keywords.FUNC_KEY_STRING,
+ new Integer(FunctionTable.FUNC_KEY));
+ m_functionID.put(Keywords.FUNC_LOCAL_PART_STRING,
+ new Integer(FunctionTable.FUNC_LOCAL_PART));
+ m_functionID.put(Keywords.FUNC_NAMESPACE_STRING,
+ new Integer(FunctionTable.FUNC_NAMESPACE));
+ m_functionID.put(Keywords.FUNC_NAME_STRING,
+ new Integer(FunctionTable.FUNC_QNAME));
+ m_functionID.put(Keywords.FUNC_GENERATE_ID_STRING,
+ new Integer(FunctionTable.FUNC_GENERATE_ID));
+ m_functionID.put(Keywords.FUNC_NOT_STRING,
+ new Integer(FunctionTable.FUNC_NOT));
+ m_functionID.put(Keywords.FUNC_TRUE_STRING,
+ new Integer(FunctionTable.FUNC_TRUE));
+ m_functionID.put(Keywords.FUNC_FALSE_STRING,
+ new Integer(FunctionTable.FUNC_FALSE));
+ m_functionID.put(Keywords.FUNC_BOOLEAN_STRING,
+ new Integer(FunctionTable.FUNC_BOOLEAN));
+ m_functionID.put(Keywords.FUNC_LANG_STRING,
+ new Integer(FunctionTable.FUNC_LANG));
+ m_functionID.put(Keywords.FUNC_NUMBER_STRING,
+ new Integer(FunctionTable.FUNC_NUMBER));
+ m_functionID.put(Keywords.FUNC_FLOOR_STRING,
+ new Integer(FunctionTable.FUNC_FLOOR));
+ m_functionID.put(Keywords.FUNC_CEILING_STRING,
+ new Integer(FunctionTable.FUNC_CEILING));
+ m_functionID.put(Keywords.FUNC_ROUND_STRING,
+ new Integer(FunctionTable.FUNC_ROUND));
+ m_functionID.put(Keywords.FUNC_SUM_STRING,
+ new Integer(FunctionTable.FUNC_SUM));
+ m_functionID.put(Keywords.FUNC_STRING_STRING,
+ new Integer(FunctionTable.FUNC_STRING));
+ m_functionID.put(Keywords.FUNC_STARTS_WITH_STRING,
+ new Integer(FunctionTable.FUNC_STARTS_WITH));
+ m_functionID.put(Keywords.FUNC_CONTAINS_STRING,
+ new Integer(FunctionTable.FUNC_CONTAINS));
+ m_functionID.put(Keywords.FUNC_SUBSTRING_BEFORE_STRING,
+ new Integer(FunctionTable.FUNC_SUBSTRING_BEFORE));
+ m_functionID.put(Keywords.FUNC_SUBSTRING_AFTER_STRING,
+ new Integer(FunctionTable.FUNC_SUBSTRING_AFTER));
+ m_functionID.put(Keywords.FUNC_NORMALIZE_SPACE_STRING,
+ new Integer(FunctionTable.FUNC_NORMALIZE_SPACE));
+ m_functionID.put(Keywords.FUNC_TRANSLATE_STRING,
+ new Integer(FunctionTable.FUNC_TRANSLATE));
+ m_functionID.put(Keywords.FUNC_CONCAT_STRING,
+ new Integer(FunctionTable.FUNC_CONCAT));
+ m_functionID.put(Keywords.FUNC_SYSTEM_PROPERTY_STRING,
+ new Integer(FunctionTable.FUNC_SYSTEM_PROPERTY));
+ m_functionID.put(Keywords.FUNC_EXT_FUNCTION_AVAILABLE_STRING,
+ new Integer(FunctionTable.FUNC_EXT_FUNCTION_AVAILABLE));
+ m_functionID.put(Keywords.FUNC_EXT_ELEM_AVAILABLE_STRING,
+ new Integer(FunctionTable.FUNC_EXT_ELEM_AVAILABLE));
+ m_functionID.put(Keywords.FUNC_SUBSTRING_STRING,
+ new Integer(FunctionTable.FUNC_SUBSTRING));
+ m_functionID.put(Keywords.FUNC_STRING_LENGTH_STRING,
+ new Integer(FunctionTable.FUNC_STRING_LENGTH));
+ m_functionID.put(Keywords.FUNC_UNPARSED_ENTITY_URI_STRING,
+ new Integer(FunctionTable.FUNC_UNPARSED_ENTITY_URI));
+ m_functionID.put(Keywords.FUNC_DOCLOCATION_STRING,
+ new Integer(FunctionTable.FUNC_DOCLOCATION));
+ }
+
public FunctionTable(){
}
@@ -231,7 +308,7 @@
*/
String getFunctionName(int funcID) {
if (funcID < NUM_BUILT_IN_FUNCS) return m_functions[funcID].getName();
- else return m_functions_xslt[funcID - NUM_BUILT_IN_FUNCS].getName();
+ else return m_functions_customer[funcID - NUM_BUILT_IN_FUNCS].getName();
}
/**
@@ -249,39 +326,80 @@
Function getFunction(int which)
throws javax.xml.transform.TransformerException
{
- if (which < NUM_BUILT_IN_FUNCS) return m_functions[which].getFunction();
- else return m_functions_xslt[which - NUM_BUILT_IN_FUNCS].getFunction();
+ try{
+ if (which < NUM_BUILT_IN_FUNCS)
+ return (Function) m_functions[which].newInstance();
+ else
+ return (Function) m_functions_customer[
+ which-NUM_BUILT_IN_FUNCS].newInstance();
+ }catch (IllegalAccessException ex){
+ throw new TransformerException(ex.getMessage());
+ }catch (InstantiationException ex){
+ throw new TransformerException(ex.getMessage());
+ }
+ }
+
+ /**
+ * Obtain a function ID from a given function name
+ * @param key the function name in a java.lang.String format.
+ * @return a function ID, which may correspond to one of the FUNC_XXX values
+ * found in {@link org.apache.xpath.compiler.FunctionTable}, but may be a
+ * value installed by an external module.
+ */
+ Object getFunctionID(String key){
+ Object id = m_functionID_customer.get(key);
+ if (null == id) id = m_functionID.get(key);
+ return id;
}
+
/**
* Install a built-in function.
- * @param name The unqualified name of the function.
+ * @param name The unqualified name of the function, must not be null
* @param func A Implementation of an XPath Function object.
* @return the position of the function in the internal index.
*/
- public int installFunction(String name, Expression func)
+ public int installFunction(String name, Class func)
{
int funcIndex;
- Object funcIndexObj = Keywords.getFunction(name);
+ Object funcIndexObj = getFunctionID(name);
if (null != funcIndexObj)
{
funcIndex = ((Integer) funcIndexObj).intValue();
+
+ if (funcIndex < NUM_BUILT_IN_FUNCS){
+ funcIndex = m_funcNextFreeIndex++;
+ m_functionID_customer.put(name, new Integer(funcIndex));
+ }
+ m_functions_customer[funcIndex - NUM_BUILT_IN_FUNCS] = func;
}
else
{
- funcIndex = m_funcNextFreeIndex;
-
- m_funcNextFreeIndex++;
-
- Keywords.putFunction(name, new Integer(funcIndex));
+ funcIndex = m_funcNextFreeIndex++;
+
+ m_functions_customer[funcIndex-NUM_BUILT_IN_FUNCS] = func;
+
+ m_functionID_customer.put(name,
+ new Integer(funcIndex));
}
-
- FuncLoader loader = new FuncLoader(func.getClass().getName(), funcIndex);
-
- m_functions_xslt[funcIndex - NUM_BUILT_IN_FUNCS] = loader;
-
return funcIndex;
}
+ /**
+ * Tell if a built-in, non-namespaced function is available.
+ *
+ * @param methName The local name of the function.
+ *
+ * @return True if the function can be executed.
+ */
+ public boolean functionAvailable(String methName)
+ {
+ Object tblEntry = m_functionID.get(methName);
+ if (null != tblEntry) return true;
+ else{
+ tblEntry = m_functionID_customer.get(methName);
+ return (null != tblEntry)? true : false;
+ }
+ }
}
1.12 +42 -155 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.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Keywords.java 15 Dec 2004 17:35:55 -0000 1.11
+++ Keywords.java 17 May 2005 21:25:46 -0000 1.12
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@
private static Hashtable m_axisnames = new Hashtable();
/** Table of function name to function ID associations. */
- private static Hashtable m_functions = new Hashtable();
+ private static Hashtable m_nodetests = new Hashtable();
/** Table of node type strings to opcode associations. */
private static Hashtable m_nodetypes = new Hashtable();
@@ -101,16 +101,16 @@
private static final String NODETYPE_ANYELEMENT_STRING = "*";
/** current function string. */
- private static final String FUNC_CURRENT_STRING = "current";
+ public static final String FUNC_CURRENT_STRING = "current";
/** last function string. */
- private static final String FUNC_LAST_STRING = "last";
+ public static final String FUNC_LAST_STRING = "last";
/** position function string. */
- private static final String FUNC_POSITION_STRING = "position";
+ public static final String FUNC_POSITION_STRING = "position";
/** count function string. */
- private static final String FUNC_COUNT_STRING = "count";
+ public static final String FUNC_COUNT_STRING = "count";
/** id function string. */
static final String FUNC_ID_STRING = "id";
@@ -119,97 +119,97 @@
public static final String FUNC_KEY_STRING = "key";
/** local-name function string. */
- private static final String FUNC_LOCAL_PART_STRING = "local-name";
+ public static final String FUNC_LOCAL_PART_STRING = "local-name";
/** namespace-uri function string. */
- private static final String FUNC_NAMESPACE_STRING = "namespace-uri";
+ public static final String FUNC_NAMESPACE_STRING = "namespace-uri";
/** name function string. */
- private static final String FUNC_NAME_STRING = "name";
+ public static final String FUNC_NAME_STRING = "name";
/** generate-id function string (XSLT). */
- private static final String FUNC_GENERATE_ID_STRING = "generate-id";
+ public static final String FUNC_GENERATE_ID_STRING = "generate-id";
/** not function string. */
- private static final String FUNC_NOT_STRING = "not";
+ public static final String FUNC_NOT_STRING = "not";
/** true function string. */
- private static final String FUNC_TRUE_STRING = "true";
+ public static final String FUNC_TRUE_STRING = "true";
/** false function string. */
- private static final String FUNC_FALSE_STRING = "false";
+ public static final String FUNC_FALSE_STRING = "false";
/** boolean function string. */
- private static final String FUNC_BOOLEAN_STRING = "boolean";
+ public static final String FUNC_BOOLEAN_STRING = "boolean";
/** lang function string. */
- private static final String FUNC_LANG_STRING = "lang";
+ public static final String FUNC_LANG_STRING = "lang";
/** number function string. */
- private static final String FUNC_NUMBER_STRING = "number";
+ public static final String FUNC_NUMBER_STRING = "number";
/** floor function string. */
- private static final String FUNC_FLOOR_STRING = "floor";
+ public static final String FUNC_FLOOR_STRING = "floor";
/** ceiling function string. */
- private static final String FUNC_CEILING_STRING = "ceiling";
+ public static final String FUNC_CEILING_STRING = "ceiling";
/** round function string. */
- private static final String FUNC_ROUND_STRING = "round";
+ public static final String FUNC_ROUND_STRING = "round";
/** sum function string. */
- private static final String FUNC_SUM_STRING = "sum";
+ public static final String FUNC_SUM_STRING = "sum";
/** string function string. */
- private static final String FUNC_STRING_STRING = "string";
+ public static final String FUNC_STRING_STRING = "string";
/** starts-with function string. */
- private static final String FUNC_STARTS_WITH_STRING = "starts-with";
+ public static final String FUNC_STARTS_WITH_STRING = "starts-with";
/** contains function string. */
- private static final String FUNC_CONTAINS_STRING = "contains";
+ public static final String FUNC_CONTAINS_STRING = "contains";
/** substring-before function string. */
- private static final String FUNC_SUBSTRING_BEFORE_STRING =
+ public static final String FUNC_SUBSTRING_BEFORE_STRING =
"substring-before";
/** substring-after function string. */
- private static final String FUNC_SUBSTRING_AFTER_STRING = "substring-after";
+ public static final String FUNC_SUBSTRING_AFTER_STRING = "substring-after";
/** normalize-space function string. */
- private static final String FUNC_NORMALIZE_SPACE_STRING = "normalize-space";
+ public static final String FUNC_NORMALIZE_SPACE_STRING = "normalize-space";
/** translate function string. */
- private static final String FUNC_TRANSLATE_STRING = "translate";
+ public static final String FUNC_TRANSLATE_STRING = "translate";
/** concat function string. */
- private static final String FUNC_CONCAT_STRING = "concat";
+ public static final String FUNC_CONCAT_STRING = "concat";
/** system-property function string. */
- private static final String FUNC_SYSTEM_PROPERTY_STRING = "system-property";
+ public static final String FUNC_SYSTEM_PROPERTY_STRING = "system-property";
/** function-available function string (XSLT). */
- private static final String FUNC_EXT_FUNCTION_AVAILABLE_STRING =
+ public static final String FUNC_EXT_FUNCTION_AVAILABLE_STRING =
"function-available";
/** element-available function string (XSLT). */
- private static final String FUNC_EXT_ELEM_AVAILABLE_STRING =
+ public static final String FUNC_EXT_ELEM_AVAILABLE_STRING =
"element-available";
/** substring function string. */
- private static final String FUNC_SUBSTRING_STRING = "substring";
+ public static final String FUNC_SUBSTRING_STRING = "substring";
/** string-length function string. */
- private static final String FUNC_STRING_LENGTH_STRING = "string-length";
+ public static final String FUNC_STRING_LENGTH_STRING = "string-length";
/** unparsed-entity-uri function string (XSLT). */
- private static final String FUNC_UNPARSED_ENTITY_URI_STRING =
+ public static final String FUNC_UNPARSED_ENTITY_URI_STRING =
"unparsed-entity-uri";
// Proprietary, built in functions
/** current function string (Proprietary). */
- private static final String FUNC_DOCLOCATION_STRING = "document-location";
+ public static final String FUNC_DOCLOCATION_STRING = "document-location";
static
{
@@ -255,136 +255,23 @@
new Integer(FunctionTable.FUNC_ID));
m_keywords.put(FUNC_KEY_STRING,
new Integer(FunctionTable.FUNC_KEY));
- m_functions.put(FUNC_CURRENT_STRING,
- new Integer(FunctionTable.FUNC_CURRENT));
- m_functions.put(FUNC_LAST_STRING,
- new Integer(FunctionTable.FUNC_LAST));
- m_functions.put(FUNC_POSITION_STRING,
- new Integer(FunctionTable.FUNC_POSITION));
- m_functions.put(FUNC_COUNT_STRING,
- new Integer(FunctionTable.FUNC_COUNT));
- m_functions.put(FUNC_ID_STRING,
- new Integer(FunctionTable.FUNC_ID));
- m_functions.put(FUNC_KEY_STRING,
- new Integer(FunctionTable.FUNC_KEY));
- m_functions.put(FUNC_LOCAL_PART_STRING,
- new Integer(FunctionTable.FUNC_LOCAL_PART));
- m_functions.put(FUNC_NAMESPACE_STRING,
- new Integer(FunctionTable.FUNC_NAMESPACE));
- m_functions.put(FUNC_NAME_STRING,
- new Integer(FunctionTable.FUNC_QNAME));
- m_functions.put(FUNC_GENERATE_ID_STRING,
- new Integer(FunctionTable.FUNC_GENERATE_ID));
- m_functions.put(FUNC_NOT_STRING,
- new Integer(FunctionTable.FUNC_NOT));
- m_functions.put(FUNC_TRUE_STRING,
- new Integer(FunctionTable.FUNC_TRUE));
- m_functions.put(FUNC_FALSE_STRING,
- new Integer(FunctionTable.FUNC_FALSE));
- m_functions.put(FUNC_BOOLEAN_STRING,
- new Integer(FunctionTable.FUNC_BOOLEAN));
- m_functions.put(FUNC_LANG_STRING,
- new Integer(FunctionTable.FUNC_LANG));
- m_functions.put(FUNC_NUMBER_STRING,
- new Integer(FunctionTable.FUNC_NUMBER));
- m_functions.put(FUNC_FLOOR_STRING,
- new Integer(FunctionTable.FUNC_FLOOR));
- m_functions.put(FUNC_CEILING_STRING,
- new Integer(FunctionTable.FUNC_CEILING));
- m_functions.put(FUNC_ROUND_STRING,
- new Integer(FunctionTable.FUNC_ROUND));
- m_functions.put(FUNC_SUM_STRING,
- new Integer(FunctionTable.FUNC_SUM));
- m_functions.put(FUNC_STRING_STRING,
- new Integer(FunctionTable.FUNC_STRING));
- m_functions.put(FUNC_STARTS_WITH_STRING,
- new Integer(FunctionTable.FUNC_STARTS_WITH));
- m_functions.put(FUNC_CONTAINS_STRING,
- new Integer(FunctionTable.FUNC_CONTAINS));
- m_functions.put(FUNC_SUBSTRING_BEFORE_STRING,
- new Integer(FunctionTable.FUNC_SUBSTRING_BEFORE));
- m_functions.put(FUNC_SUBSTRING_AFTER_STRING,
- new Integer(FunctionTable.FUNC_SUBSTRING_AFTER));
- m_functions.put(FUNC_NORMALIZE_SPACE_STRING,
- new Integer(FunctionTable.FUNC_NORMALIZE_SPACE));
- m_functions.put(FUNC_TRANSLATE_STRING,
- new Integer(FunctionTable.FUNC_TRANSLATE));
- m_functions.put(FUNC_CONCAT_STRING,
- new Integer(FunctionTable.FUNC_CONCAT));
-
- //m_functions.put(FUNC_FORMAT_NUMBER_STRING, new Integer(FunctionTable.FUNC_FORMAT_NUMBER));
- m_functions.put(FUNC_SYSTEM_PROPERTY_STRING,
- new Integer(FunctionTable.FUNC_SYSTEM_PROPERTY));
- m_functions.put(FUNC_EXT_FUNCTION_AVAILABLE_STRING,
- new Integer(FunctionTable.FUNC_EXT_FUNCTION_AVAILABLE));
- m_functions.put(FUNC_EXT_ELEM_AVAILABLE_STRING,
- new Integer(FunctionTable.FUNC_EXT_ELEM_AVAILABLE));
- m_functions.put(FUNC_SUBSTRING_STRING,
- new Integer(FunctionTable.FUNC_SUBSTRING));
- m_functions.put(FUNC_STRING_LENGTH_STRING,
- new Integer(FunctionTable.FUNC_STRING_LENGTH));
- m_functions.put(FUNC_UNPARSED_ENTITY_URI_STRING,
- new Integer(FunctionTable.FUNC_UNPARSED_ENTITY_URI));
- // These aren't really functions.
- m_functions.put(NODETYPE_COMMENT_STRING,
+ m_nodetests.put(NODETYPE_COMMENT_STRING,
new Integer(OpCodes.NODETYPE_COMMENT));
- m_functions.put(NODETYPE_TEXT_STRING,
+ m_nodetests.put(NODETYPE_TEXT_STRING,
new Integer(OpCodes.NODETYPE_TEXT));
- m_functions.put(NODETYPE_PI_STRING,
+ m_nodetests.put(NODETYPE_PI_STRING,
new Integer(OpCodes.NODETYPE_PI));
- m_functions.put(NODETYPE_NODE_STRING,
+ m_nodetests.put(NODETYPE_NODE_STRING,
new Integer(OpCodes.NODETYPE_NODE));
- m_functions.put(FUNC_DOCLOCATION_STRING,
- new Integer(FunctionTable.FUNC_DOCLOCATION));
- }
-
- /**
- * Tell if a built-in, non-namespaced function is available.
- *
- * @param methName The local name of the function.
- *
- * @return True if the function can be executed.
- */
- 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;
- }
}
static Object getAxisName(String key){
return m_axisnames.get(key);
}
- static Object getFunction(String key){
- return m_functions.get(key);
- }
-
- static void putFunction(String key, Integer index){
- m_functions.put(key, index);
+ static Object lookupNodeTest(String key){
+ return m_nodetests.get(key);
}
static Object getKeyWord(String key){
1.33 +13 -2 xml-xalan/java/src/org/apache/xpath/compiler/XPathParser.java
Index: XPathParser.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/compiler/XPathParser.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- XPathParser.java 9 Feb 2005 21:44:08 -0000 1.32
+++ XPathParser.java 17 May 2005 21:25:46 -0000 1.33
@@ -103,6 +103,7 @@
m_ops = compiler;
m_namespaceContext = namespaceContext;
+ m_functionTable = compiler.getFunctionTable();
Lexer lexer = new Lexer(compiler, namespaceContext, this);
@@ -178,6 +179,7 @@
m_ops = compiler;
m_namespaceContext = namespaceContext;
+ m_functionTable = compiler.getFunctionTable();
Lexer lexer = new Lexer(compiler, namespaceContext, this);
@@ -220,6 +222,9 @@
/** The source location of the XPath. */
javax.xml.transform.SourceLocator m_sourceLocator;
+
+ /** The table contains build-in functions and customized functions */
+ private FunctionTable m_functionTable;
/**
* Allow an application to register an error event handler, where syntax
@@ -704,10 +709,16 @@
{
int tok;
+
+ Object id;
try
{
- tok = ((Integer) (Keywords.getFunction(key))).intValue();
+ // These are nodetests, xpathparser treats them as functions when parsing
+ // a FilterExpr.
+ id = Keywords.lookupNodeTest(key);
+ if (null == id) id = m_functionTable.getFunctionID(key);
+ tok = ((Integer) id).intValue();
}
catch (NullPointerException npe)
{
1.13 +18 -4 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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- FuncExtFunctionAvailable.java 17 Aug 2004 19:25:36 -0000 1.12
+++ FuncExtFunctionAvailable.java 17 May 2005 21:25:47 -0000 1.13
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@
import org.apache.xalan.templates.Constants;
import org.apache.xpath.ExtensionsProvider;
import org.apache.xpath.XPathContext;
-import org.apache.xpath.compiler.Keywords;
+import org.apache.xpath.compiler.FunctionTable;
import org.apache.xpath.objects.XBoolean;
import org.apache.xpath.objects.XObject;
@@ -32,6 +32,8 @@
public class FuncExtFunctionAvailable extends FunctionOneArg
{
static final long serialVersionUID = 5118814314918592241L;
+
+ transient private FunctionTable m_functionTable = null;
/**
* Execute the function. The function must return
@@ -70,7 +72,8 @@
{
try
{
- return Keywords.functionAvailable(methName) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
+ if (null == m_functionTable) m_functionTable = new FunctionTable();
+ return m_functionTable.functionAvailable(methName) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
catch (Exception e)
{
@@ -85,4 +88,15 @@
? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
}
+
+ /**
+ * The function table is an instance field. In order to access this instance
+ * field during evaluation, this method is called at compilation time to
+ * insert function table information for later usage. It should only be used
+ * during compiling of XPath expressions.
+ * @param aTable an instance of the function table
+ */
+ public void setFunctionTable(FunctionTable aTable){
+ m_functionTable = aTable;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org