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