1 /*
2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3  */
4 /**
5  * Licensed to the Apache Software Foundation (ASF) under one
6  * or more contributor license agreements. See the NOTICE file
7  * distributed with this work for additional information
8  * regarding copyright ownership. The ASF licenses this file
9  * to you under the Apache License, Version 2.0 (the
10  * "License"); you may not use this file except in compliance
11  * with the License. You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing,
16  * software distributed under the License is distributed on an
17  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18  * KIND, either express or implied. See the License for the
19  * specific language governing permissions and limitations
20  * under the License.
21  */
22 /*
23  * $Id: Keywords.java,v 1.2.4.1 2005/09/14 19:46:01 jeffsuttor Exp $
24  */
25 package com.sun.org.apache.xpath.internal.compiler;
26 
27 import java.util.Collections;
28 import java.util.HashMap;
29 import java.util.Map;
30 
31 /**
32  * Table of strings to operation code lookups.
33  *
34  * @xsl.usage internal
35  */
36 public class Keywords {
37 
38     /**
39      * Table of keywords to opcode associations.
40      */
41     private static final Map<String, Integer> m_keywords;
42 
43     /**
44      * Table of axes names to opcode associations.
45      */
46     private static final Map<String, Integer> m_axisnames;
47 
48     /**
49      * Table of function name to function ID associations.
50      */
51     private static final Map<String, Integer> m_nodetests;
52 
53     /**
54      * Table of node type strings to opcode associations.
55      */
56     private static final Map<String, Integer> m_nodetypes;
57 
58     /**
59      * ancestor axes string.
60      */
61     private static final String FROM_ANCESTORS_STRING = "ancestor";
62 
63     /**
64      * ancestor-or-self axes string.
65      */
66     private static final String FROM_ANCESTORS_OR_SELF_STRING
67             = "ancestor-or-self";
68 
69     /**
70      * attribute axes string.
71      */
72     private static final String FROM_ATTRIBUTES_STRING = "attribute";
73 
74     /**
75      * child axes string.
76      */
77     private static final String FROM_CHILDREN_STRING = "child";
78 
79     /**
80      * descendant-or-self axes string.
81      */
82     private static final String FROM_DESCENDANTS_STRING = "descendant";
83 
84     /**
85      * ancestor axes string.
86      */
87     private static final String FROM_DESCENDANTS_OR_SELF_STRING
88             = "descendant-or-self";
89 
90     /**
91      * following axes string.
92      */
93     private static final String FROM_FOLLOWING_STRING = "following";
94 
95     /**
96      * following-sibling axes string.
97      */
98     private static final String FROM_FOLLOWING_SIBLINGS_STRING
99             = "following-sibling";
100 
101     /**
102      * parent axes string.
103      */
104     private static final String FROM_PARENT_STRING = "parent";
105 
106     /**
107      * preceding axes string.
108      */
109     private static final String FROM_PRECEDING_STRING = "preceding";
110 
111     /**
112      * preceding-sibling axes string.
113      */
114     private static final String FROM_PRECEDING_SIBLINGS_STRING
115             = "preceding-sibling";
116 
117     /**
118      * self axes string.
119      */
120     private static final String FROM_SELF_STRING = "self";
121 
122     /**
123      * namespace axes string.
124      */
125     private static final String FROM_NAMESPACE_STRING = "namespace";
126 
127     /**
128      * self axes abreviated string.
129      */
130     private static final String FROM_SELF_ABBREVIATED_STRING = ".";
131 
132     /**
133      * comment node test string.
134      */
135     private static final String NODETYPE_COMMENT_STRING = "comment";
136 
137     /**
138      * text node test string.
139      */
140     private static final String NODETYPE_TEXT_STRING = "text";
141 
142     /**
143      * processing-instruction node test string.
144      */
145     private static final String NODETYPE_PI_STRING = "processing-instruction";
146 
147     /**
148      * Any node test string.
149      */
150     private static final String NODETYPE_NODE_STRING = "node";
151 
152     /**
153      * Wildcard element string.
154      */
155     private static final String NODETYPE_ANYELEMENT_STRING = "*";
156 
157     /**
158      * current function string.
159      */
160     public static final String FUNC_CURRENT_STRING = "current";
161 
162     /**
163      * last function string.
164      */
165     public static final String FUNC_LAST_STRING = "last";
166 
167     /**
168      * position function string.
169      */
170     public static final String FUNC_POSITION_STRING = "position";
171 
172     /**
173      * count function string.
174      */
175     public static final String FUNC_COUNT_STRING = "count";
176 
177     /**
178      * id function string.
179      */
180     static final String FUNC_ID_STRING = "id";
181 
182     /**
183      * key function string (XSLT).
184      */
185     public static final String FUNC_KEY_STRING = "key";
186 
187     /**
188      * local-name function string.
189      */
190     public static final String FUNC_LOCAL_PART_STRING = "local-name";
191 
192     /**
193      * namespace-uri function string.
194      */
195     public static final String FUNC_NAMESPACE_STRING = "namespace-uri";
196 
197     /**
198      * name function string.
199      */
200     public static final String FUNC_NAME_STRING = "name";
201 
202     /**
203      * generate-id function string (XSLT).
204      */
205     public static final String FUNC_GENERATE_ID_STRING = "generate-id";
206 
207     /**
208      * not function string.
209      */
210     public static final String FUNC_NOT_STRING = "not";
211 
212     /**
213      * true function string.
214      */
215     public static final String FUNC_TRUE_STRING = "true";
216 
217     /**
218      * false function string.
219      */
220     public static final String FUNC_FALSE_STRING = "false";
221 
222     /**
223      * boolean function string.
224      */
225     public static final String FUNC_BOOLEAN_STRING = "boolean";
226 
227     /**
228      * lang function string.
229      */
230     public static final String FUNC_LANG_STRING = "lang";
231 
232     /**
233      * number function string.
234      */
235     public static final String FUNC_NUMBER_STRING = "number";
236 
237     /**
238      * floor function string.
239      */
240     public static final String FUNC_FLOOR_STRING = "floor";
241 
242     /**
243      * ceiling function string.
244      */
245     public static final String FUNC_CEILING_STRING = "ceiling";
246 
247     /**
248      * round function string.
249      */
250     public static final String FUNC_ROUND_STRING = "round";
251 
252     /**
253      * sum function string.
254      */
255     public static final String FUNC_SUM_STRING = "sum";
256 
257     /**
258      * string function string.
259      */
260     public static final String FUNC_STRING_STRING = "string";
261 
262     /**
263      * starts-with function string.
264      */
265     public static final String FUNC_STARTS_WITH_STRING = "starts-with";
266 
267     /**
268      * contains function string.
269      */
270     public static final String FUNC_CONTAINS_STRING = "contains";
271 
272     /**
273      * substring-before function string.
274      */
275     public static final String FUNC_SUBSTRING_BEFORE_STRING
276             = "substring-before";
277 
278     /**
279      * substring-after function string.
280      */
281     public static final String FUNC_SUBSTRING_AFTER_STRING = "substring-after";
282 
283     /**
284      * normalize-space function string.
285      */
286     public static final String FUNC_NORMALIZE_SPACE_STRING = "normalize-space";
287 
288     /**
289      * translate function string.
290      */
291     public static final String FUNC_TRANSLATE_STRING = "translate";
292 
293     /**
294      * concat function string.
295      */
296     public static final String FUNC_CONCAT_STRING = "concat";
297 
298     /**
299      * system-property function string.
300      */
301     public static final String FUNC_SYSTEM_PROPERTY_STRING = "system-property";
302 
303     /**
304      * function-available function string (XSLT).
305      */
306     public static final String FUNC_EXT_FUNCTION_AVAILABLE_STRING
307             = "function-available";
308 
309     /**
310      * element-available function string (XSLT).
311      */
312     public static final String FUNC_EXT_ELEM_AVAILABLE_STRING
313             = "element-available";
314 
315     /**
316      * substring function string.
317      */
318     public static final String FUNC_SUBSTRING_STRING = "substring";
319 
320     /**
321      * string-length function string.
322      */
323     public static final String FUNC_STRING_LENGTH_STRING = "string-length";
324 
325     /**
326      * unparsed-entity-uri function string (XSLT).
327      */
328     public static final String FUNC_UNPARSED_ENTITY_URI_STRING
329             = "unparsed-entity-uri";
330 
331     /**
332      * here function string (XML Signature).
333      */
334     public static final String FUNC_HERE_STRING = "here";
335 
336   // Proprietary, built in functions
337     /**
338      * current function string (Proprietary).
339      */
340     public static final String FUNC_DOCLOCATION_STRING = "document-location";
341 
342     static {
343         Map<String, Integer> keywords = new HashMap<>();
344         Map<String, Integer> axisnames = new HashMap<>();
345         Map<String, Integer> nodetests = new HashMap<>();
346         Map<String, Integer> nodetypes = new HashMap<>();
347 
axisnames.put(FROM_ANCESTORS_STRING, OpCodes.FROM_ANCESTORS)348         axisnames.put(FROM_ANCESTORS_STRING, OpCodes.FROM_ANCESTORS);
axisnames.put(FROM_ANCESTORS_OR_SELF_STRING, OpCodes.FROM_ANCESTORS_OR_SELF)349         axisnames.put(FROM_ANCESTORS_OR_SELF_STRING, OpCodes.FROM_ANCESTORS_OR_SELF);
axisnames.put(FROM_ATTRIBUTES_STRING, OpCodes.FROM_ATTRIBUTES)350         axisnames.put(FROM_ATTRIBUTES_STRING, OpCodes.FROM_ATTRIBUTES);
axisnames.put(FROM_CHILDREN_STRING, OpCodes.FROM_CHILDREN)351         axisnames.put(FROM_CHILDREN_STRING, OpCodes.FROM_CHILDREN);
axisnames.put(FROM_DESCENDANTS_STRING, OpCodes.FROM_DESCENDANTS)352         axisnames.put(FROM_DESCENDANTS_STRING, OpCodes.FROM_DESCENDANTS);
axisnames.put(FROM_DESCENDANTS_OR_SELF_STRING, OpCodes.FROM_DESCENDANTS_OR_SELF)353         axisnames.put(FROM_DESCENDANTS_OR_SELF_STRING, OpCodes.FROM_DESCENDANTS_OR_SELF);
axisnames.put(FROM_FOLLOWING_STRING, OpCodes.FROM_FOLLOWING)354         axisnames.put(FROM_FOLLOWING_STRING, OpCodes.FROM_FOLLOWING);
axisnames.put(FROM_FOLLOWING_SIBLINGS_STRING, OpCodes.FROM_FOLLOWING_SIBLINGS)355         axisnames.put(FROM_FOLLOWING_SIBLINGS_STRING, OpCodes.FROM_FOLLOWING_SIBLINGS);
axisnames.put(FROM_PARENT_STRING, OpCodes.FROM_PARENT)356         axisnames.put(FROM_PARENT_STRING, OpCodes.FROM_PARENT);
axisnames.put(FROM_PRECEDING_STRING, OpCodes.FROM_PRECEDING)357         axisnames.put(FROM_PRECEDING_STRING, OpCodes.FROM_PRECEDING);
axisnames.put(FROM_PRECEDING_SIBLINGS_STRING, OpCodes.FROM_PRECEDING_SIBLINGS)358         axisnames.put(FROM_PRECEDING_SIBLINGS_STRING, OpCodes.FROM_PRECEDING_SIBLINGS);
axisnames.put(FROM_SELF_STRING, OpCodes.FROM_SELF)359         axisnames.put(FROM_SELF_STRING, OpCodes.FROM_SELF);
axisnames.put(FROM_NAMESPACE_STRING, OpCodes.FROM_NAMESPACE)360         axisnames.put(FROM_NAMESPACE_STRING, OpCodes.FROM_NAMESPACE);
361         m_axisnames = Collections.unmodifiableMap(axisnames);
362 
nodetypes.put(NODETYPE_COMMENT_STRING, OpCodes.NODETYPE_COMMENT)363         nodetypes.put(NODETYPE_COMMENT_STRING, OpCodes.NODETYPE_COMMENT);
nodetypes.put(NODETYPE_TEXT_STRING, OpCodes.NODETYPE_TEXT)364         nodetypes.put(NODETYPE_TEXT_STRING, OpCodes.NODETYPE_TEXT);
nodetypes.put(NODETYPE_PI_STRING, OpCodes.NODETYPE_PI)365         nodetypes.put(NODETYPE_PI_STRING, OpCodes.NODETYPE_PI);
nodetypes.put(NODETYPE_NODE_STRING, OpCodes.NODETYPE_NODE)366         nodetypes.put(NODETYPE_NODE_STRING, OpCodes.NODETYPE_NODE);
nodetypes.put(NODETYPE_ANYELEMENT_STRING, OpCodes.NODETYPE_ANYELEMENT)367         nodetypes.put(NODETYPE_ANYELEMENT_STRING, OpCodes.NODETYPE_ANYELEMENT);
368         m_nodetypes = Collections.unmodifiableMap(nodetypes);
369 
keywords.put(FROM_SELF_ABBREVIATED_STRING, OpCodes.FROM_SELF)370         keywords.put(FROM_SELF_ABBREVIATED_STRING, OpCodes.FROM_SELF);
keywords.put(FUNC_ID_STRING, FunctionTable.FUNC_ID)371         keywords.put(FUNC_ID_STRING, FunctionTable.FUNC_ID);
keywords.put(FUNC_KEY_STRING, FunctionTable.FUNC_KEY)372         keywords.put(FUNC_KEY_STRING, FunctionTable.FUNC_KEY);
373         m_keywords = Collections.unmodifiableMap(keywords);
374 
nodetests.put(NODETYPE_COMMENT_STRING, OpCodes.NODETYPE_COMMENT)375         nodetests.put(NODETYPE_COMMENT_STRING, OpCodes.NODETYPE_COMMENT);
nodetests.put(NODETYPE_TEXT_STRING, OpCodes.NODETYPE_TEXT)376         nodetests.put(NODETYPE_TEXT_STRING, OpCodes.NODETYPE_TEXT);
nodetests.put(NODETYPE_PI_STRING, OpCodes.NODETYPE_PI)377         nodetests.put(NODETYPE_PI_STRING, OpCodes.NODETYPE_PI);
nodetests.put(NODETYPE_NODE_STRING, OpCodes.NODETYPE_NODE)378         nodetests.put(NODETYPE_NODE_STRING, OpCodes.NODETYPE_NODE);
379         m_nodetests = Collections.unmodifiableMap(nodetests);
380     }
381 
getAxisName(String key)382     static Integer getAxisName(String key) {
383         return m_axisnames.get(key);
384     }
385 
lookupNodeTest(String key)386     static Integer lookupNodeTest(String key) {
387         return m_nodetests.get(key);
388     }
389 
getKeyWord(String key)390     static Integer getKeyWord(String key) {
391         return m_keywords.get(key);
392     }
393 
getNodeType(String key)394     static Integer getNodeType(String key) {
395         return m_nodetypes.get(key);
396     }
397 }
398