001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements. See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership. The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the  "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    /*
019     * $Id: Keywords.java 468655 2006-10-28 07:12:06Z minchau $
020     */
021    package org.apache.xpath.compiler;
022    
023    import java.util.Hashtable;
024    
025    /**
026     * Table of strings to operation code lookups.
027     * @xsl.usage internal
028     */
029    public class Keywords
030    {
031    
032      /** Table of keywords to opcode associations. */
033      private static Hashtable m_keywords = new Hashtable();
034    
035      /** Table of axes names to opcode associations. */
036      private static Hashtable m_axisnames = new Hashtable();
037    
038      /** Table of function name to function ID associations. */
039      private static Hashtable m_nodetests = new Hashtable();
040    
041      /** Table of node type strings to opcode associations. */
042      private static Hashtable m_nodetypes = new Hashtable();
043    
044      /** ancestor axes string. */
045      private static final String FROM_ANCESTORS_STRING = "ancestor";
046    
047      /** ancestor-or-self axes string. */
048      private static final String FROM_ANCESTORS_OR_SELF_STRING =
049        "ancestor-or-self";
050    
051      /** attribute axes string. */
052      private static final String FROM_ATTRIBUTES_STRING = "attribute";
053    
054      /** child axes string. */
055      private static final String FROM_CHILDREN_STRING = "child";
056    
057      /** descendant-or-self axes string. */
058      private static final String FROM_DESCENDANTS_STRING = "descendant";
059    
060      /** ancestor axes string. */
061      private static final String FROM_DESCENDANTS_OR_SELF_STRING =
062        "descendant-or-self";
063    
064      /** following axes string. */
065      private static final String FROM_FOLLOWING_STRING = "following";
066    
067      /** following-sibling axes string. */
068      private static final String FROM_FOLLOWING_SIBLINGS_STRING =
069        "following-sibling";
070    
071      /** parent axes string. */
072      private static final String FROM_PARENT_STRING = "parent";
073    
074      /** preceding axes string. */
075      private static final String FROM_PRECEDING_STRING = "preceding";
076    
077      /** preceding-sibling axes string. */
078      private static final String FROM_PRECEDING_SIBLINGS_STRING =
079        "preceding-sibling";
080    
081      /** self axes string. */
082      private static final String FROM_SELF_STRING = "self";
083    
084      /** namespace axes string. */
085      private static final String FROM_NAMESPACE_STRING = "namespace";
086    
087      /** self axes abreviated string. */
088      private static final String FROM_SELF_ABBREVIATED_STRING = ".";
089    
090      /** comment node test string. */
091      private static final String NODETYPE_COMMENT_STRING = "comment";
092    
093      /** text node test string. */
094      private static final String NODETYPE_TEXT_STRING = "text";
095    
096      /** processing-instruction node test string. */
097      private static final String NODETYPE_PI_STRING = "processing-instruction";
098    
099      /** Any node test string. */
100      private static final String NODETYPE_NODE_STRING = "node";
101    
102      /** Wildcard element string. */
103      private static final String NODETYPE_ANYELEMENT_STRING = "*";
104    
105      /** current function string. */
106      public static final String FUNC_CURRENT_STRING = "current";
107    
108      /** last function string. */
109      public static final String FUNC_LAST_STRING = "last";
110    
111      /** position function string. */
112      public static final String FUNC_POSITION_STRING = "position";
113    
114      /** count function string. */
115      public static final String FUNC_COUNT_STRING = "count";
116    
117      /** id function string. */
118      static final String FUNC_ID_STRING = "id";
119    
120      /** key function string (XSLT). */
121      public static final String FUNC_KEY_STRING = "key";
122    
123      /** local-name function string. */
124      public static final String FUNC_LOCAL_PART_STRING = "local-name";
125    
126      /** namespace-uri function string. */
127      public static final String FUNC_NAMESPACE_STRING = "namespace-uri";
128    
129      /** name function string. */
130      public static final String FUNC_NAME_STRING = "name";
131    
132      /** generate-id function string (XSLT). */
133      public static final String FUNC_GENERATE_ID_STRING = "generate-id";
134    
135      /** not function string. */
136      public static final String FUNC_NOT_STRING = "not";
137    
138      /** true function string. */
139      public static final String FUNC_TRUE_STRING = "true";
140    
141      /** false function string. */
142      public static final String FUNC_FALSE_STRING = "false";
143    
144      /** boolean function string. */
145      public static final String FUNC_BOOLEAN_STRING = "boolean";
146    
147      /** lang function string. */
148      public static final String FUNC_LANG_STRING = "lang";
149    
150      /** number function string. */
151      public static final String FUNC_NUMBER_STRING = "number";
152    
153      /** floor function string. */
154      public static final String FUNC_FLOOR_STRING = "floor";
155    
156      /** ceiling function string. */
157      public static final String FUNC_CEILING_STRING = "ceiling";
158    
159      /** round function string. */
160      public static final String FUNC_ROUND_STRING = "round";
161    
162      /** sum function string. */
163      public static final String FUNC_SUM_STRING = "sum";
164    
165      /** string function string. */
166      public static final String FUNC_STRING_STRING = "string";
167    
168      /** starts-with function string. */
169      public static final String FUNC_STARTS_WITH_STRING = "starts-with";
170    
171      /** contains function string. */
172      public static final String FUNC_CONTAINS_STRING = "contains";
173    
174      /** substring-before function string. */
175      public static final String FUNC_SUBSTRING_BEFORE_STRING =
176        "substring-before";
177    
178      /** substring-after function string. */
179      public static final String FUNC_SUBSTRING_AFTER_STRING = "substring-after";
180    
181      /** normalize-space function string. */
182      public static final String FUNC_NORMALIZE_SPACE_STRING = "normalize-space";
183    
184      /** translate function string. */
185      public static final String FUNC_TRANSLATE_STRING = "translate";
186    
187      /** concat function string. */
188      public static final String FUNC_CONCAT_STRING = "concat";
189    
190      /** system-property function string. */
191      public static final String FUNC_SYSTEM_PROPERTY_STRING = "system-property";
192    
193      /** function-available function string (XSLT). */
194      public static final String FUNC_EXT_FUNCTION_AVAILABLE_STRING =
195        "function-available";
196    
197      /** element-available function string (XSLT). */
198      public static final String FUNC_EXT_ELEM_AVAILABLE_STRING =
199        "element-available";
200    
201      /** substring function string. */
202      public static final String FUNC_SUBSTRING_STRING = "substring";
203    
204      /** string-length function string. */
205      public static final String FUNC_STRING_LENGTH_STRING = "string-length";
206    
207      /** unparsed-entity-uri function string (XSLT). */
208      public static final String FUNC_UNPARSED_ENTITY_URI_STRING =
209        "unparsed-entity-uri";
210    
211      // Proprietary, built in functions
212    
213      /** current function string (Proprietary). */
214      public static final String FUNC_DOCLOCATION_STRING = "document-location";
215    
216      static
217      {
218        m_axisnames.put(FROM_ANCESTORS_STRING,
219                        new Integer(OpCodes.FROM_ANCESTORS));
220        m_axisnames.put(FROM_ANCESTORS_OR_SELF_STRING,
221                        new Integer(OpCodes.FROM_ANCESTORS_OR_SELF));
222        m_axisnames.put(FROM_ATTRIBUTES_STRING,
223                        new Integer(OpCodes.FROM_ATTRIBUTES));
224        m_axisnames.put(FROM_CHILDREN_STRING,
225                        new Integer(OpCodes.FROM_CHILDREN));
226        m_axisnames.put(FROM_DESCENDANTS_STRING,
227                        new Integer(OpCodes.FROM_DESCENDANTS));
228        m_axisnames.put(FROM_DESCENDANTS_OR_SELF_STRING,
229                        new Integer(OpCodes.FROM_DESCENDANTS_OR_SELF));
230        m_axisnames.put(FROM_FOLLOWING_STRING,
231                        new Integer(OpCodes.FROM_FOLLOWING));
232        m_axisnames.put(FROM_FOLLOWING_SIBLINGS_STRING,
233                        new Integer(OpCodes.FROM_FOLLOWING_SIBLINGS));
234        m_axisnames.put(FROM_PARENT_STRING,
235                        new Integer(OpCodes.FROM_PARENT));
236        m_axisnames.put(FROM_PRECEDING_STRING,
237                        new Integer(OpCodes.FROM_PRECEDING));
238        m_axisnames.put(FROM_PRECEDING_SIBLINGS_STRING,
239                        new Integer(OpCodes.FROM_PRECEDING_SIBLINGS));
240        m_axisnames.put(FROM_SELF_STRING,
241                        new Integer(OpCodes.FROM_SELF));
242        m_axisnames.put(FROM_NAMESPACE_STRING,
243                        new Integer(OpCodes.FROM_NAMESPACE));
244        m_nodetypes.put(NODETYPE_COMMENT_STRING,
245                        new Integer(OpCodes.NODETYPE_COMMENT));
246        m_nodetypes.put(NODETYPE_TEXT_STRING,
247                        new Integer(OpCodes.NODETYPE_TEXT));
248        m_nodetypes.put(NODETYPE_PI_STRING,
249                        new Integer(OpCodes.NODETYPE_PI));
250        m_nodetypes.put(NODETYPE_NODE_STRING,
251                        new Integer(OpCodes.NODETYPE_NODE));
252        m_nodetypes.put(NODETYPE_ANYELEMENT_STRING,
253                        new Integer(OpCodes.NODETYPE_ANYELEMENT));
254        m_keywords.put(FROM_SELF_ABBREVIATED_STRING,
255                       new Integer(OpCodes.FROM_SELF));
256        m_keywords.put(FUNC_ID_STRING,
257                       new Integer(FunctionTable.FUNC_ID));
258        m_keywords.put(FUNC_KEY_STRING,
259                       new Integer(FunctionTable.FUNC_KEY));
260    
261        m_nodetests.put(NODETYPE_COMMENT_STRING,
262                        new Integer(OpCodes.NODETYPE_COMMENT));
263        m_nodetests.put(NODETYPE_TEXT_STRING,
264                        new Integer(OpCodes.NODETYPE_TEXT));
265        m_nodetests.put(NODETYPE_PI_STRING,
266                        new Integer(OpCodes.NODETYPE_PI));
267        m_nodetests.put(NODETYPE_NODE_STRING,
268                        new Integer(OpCodes.NODETYPE_NODE));
269      }
270      
271      static Object getAxisName(String key){
272              return m_axisnames.get(key);
273      }
274      
275      static Object lookupNodeTest(String key){
276              return m_nodetests.get(key);
277      }
278      
279      static Object getKeyWord(String key){
280              return m_keywords.get(key);
281      }
282      
283      static Object getNodeType(String key){
284              return m_nodetypes.get(key);
285      }      
286    }