00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one 00003 * or more contributor license agreements. See the NOTICE file 00004 * distributed with this work for additional information 00005 * regarding copyright ownership. The ASF licenses this file 00006 * to you under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 #if !defined(XPATHFUNCTIONTABLE_HEADER_GUARD_1357924680) 00019 #define XPATHFUNCTIONTABLE_HEADER_GUARD_1357924680 00020 00021 00022 00023 // Base include file. Must be first. 00024 #include <xalanc/XPath/XPathDefinitions.hpp> 00025 00026 00027 00028 #include <algorithm> 00029 00030 00031 00032 #include <xalanc/XalanDOM/XalanDOMString.hpp> 00033 00034 00035 00036 #include <xalanc/Include/STLHelper.hpp> 00037 00038 00039 00040 #include <xalanc/XPath/Function.hpp> 00041 #include <xalanc/XPath/XalanXPathException.hpp> 00042 00043 00044 00045 XALAN_CPP_NAMESPACE_BEGIN 00046 00047 00048 00049 /** 00050 * Exception class thrown when an unknown function is encountered 00051 */ 00052 class XALAN_XPATH_EXPORT XPathExceptionFunctionNotAvailable : public XalanXPathException 00053 { 00054 public: 00055 00056 typedef Function::LocatorType LocatorType; 00057 00058 XPathExceptionFunctionNotAvailable( 00059 const XalanDOMString& theFunctionName, 00060 XalanDOMString& theResult, 00061 const Locator* theLocator); 00062 00063 XPathExceptionFunctionNotAvailable(const XPathExceptionFunctionNotAvailable& other); 00064 00065 ~XPathExceptionFunctionNotAvailable(); 00066 }; 00067 00068 00069 00070 /** 00071 * Exception class thrown when an installFunction() is called with a 00072 * function name that is not supported. 00073 */ 00074 class XALAN_XPATH_EXPORT XPathExceptionFunctionNotSupported : public XalanXPathException 00075 { 00076 public: 00077 00078 XPathExceptionFunctionNotSupported( 00079 const XalanDOMChar* theFunctionName, 00080 XalanDOMString& theResult, 00081 const Locator* theLocator); 00082 00083 XPathExceptionFunctionNotSupported(const XPathExceptionFunctionNotSupported& other); 00084 00085 ~XPathExceptionFunctionNotSupported(); 00086 }; 00087 00088 00089 00090 /** 00091 * Class defines a table of functions that can be called in XPath expresions. 00092 */ 00093 class XALAN_XPATH_EXPORT XPathFunctionTable 00094 { 00095 public: 00096 00097 enum { InvalidFunctionNumberID = -1, TableSize = 36 }; 00098 00099 typedef size_t SizeType; 00100 typedef XalanDOMString::size_type StringSizeType; 00101 typedef DeleteFunctor<Function> DeleteFunctorType; 00102 00103 /** 00104 * Constructor. 00105 * 00106 * @param fCreateTable If true, the internal table will be created. Otherwise, CreateTable() must be called. 00107 */ 00108 XPathFunctionTable(bool fCreateTable = true); 00109 00110 ~XPathFunctionTable(); 00111 00112 void 00113 setMemoryManager(MemoryManager& theManager) 00114 { 00115 m_memoryManager = &theManager; 00116 } 00117 /** 00118 * Set up the internal table. 00119 */ 00120 void 00121 CreateTable(); 00122 00123 /** 00124 * Destroy the internal table. 00125 */ 00126 void 00127 DestroyTable(); 00128 00129 /** 00130 * Retrieve the function object for a specified function name. If 00131 * the named Function is not found, an exception is thrown. 00132 * 00133 * @param theFunctionName The name of function 00134 * @param theLocator The Locator instance to use when reporting an error. 00135 * @return function named 00136 */ 00137 const Function& 00138 get( 00139 const XalanDOMString& theFunctionName, 00140 const Locator* theLocator) const 00141 { 00142 const int theFunctionID = 00143 getFunctionIndex(theFunctionName); 00144 00145 if (theFunctionID != InvalidFunctionNumberID) 00146 { 00147 return *m_functionTable[theFunctionID]; 00148 } 00149 else 00150 { 00151 MemoryManager* const theManager = m_memoryManager; 00152 00153 XalanDOMString theResult(*theManager); 00154 00155 throw XPathExceptionFunctionNotAvailable( 00156 theFunctionName, 00157 theResult, 00158 theLocator); 00159 } 00160 } 00161 00162 private: 00163 00164 /** 00165 * Retrieve the function object for a specified function name. 00166 * 00167 * @deprecated This operator is deprecated. 00168 * @param theFunctionName name of function 00169 * @return function named 00170 */ 00171 const Function& 00172 operator[](const XalanDOMString& theFunctionName) const 00173 { 00174 const int theFunctionID = 00175 getFunctionIndex(theFunctionName); 00176 00177 if (theFunctionID != InvalidFunctionNumberID) 00178 { 00179 return *m_functionTable[theFunctionID]; 00180 } 00181 else 00182 { 00183 MemoryManager* const theManager = m_memoryManager; 00184 00185 XalanDOMString theResult(*theManager); 00186 00187 throw XPathExceptionFunctionNotAvailable( 00188 theFunctionName, 00189 theResult, 00190 0); 00191 } 00192 } 00193 00194 public: 00195 00196 /** 00197 * Retrieve the function object for a specified function ID number. 00198 * 00199 * @param theFunctionID ID number of the function 00200 * @return function named 00201 */ 00202 const Function& 00203 operator[](int theFunctionID) const 00204 { 00205 assert(theFunctionID >= 0 && theFunctionID < TableSize); 00206 assert(m_functionTable[theFunctionID] != 0); 00207 00208 return *m_functionTable[theFunctionID]; 00209 } 00210 00211 /** 00212 * Map a function ID to the corresponding name. 00213 * 00214 * @param theFunctionID The ID number of the function 00215 * @return The name of the function, or an empty string if the function doesn't exist. 00216 */ 00217 const XalanDOMString& 00218 idToName(int theFunctionID, 00219 XalanDOMString& theResult) const 00220 { 00221 00222 if (theFunctionID >= 0 && theFunctionID < TableSize) 00223 { 00224 theResult.assign( 00225 s_functionNames[theFunctionID].m_name, 00226 s_functionNames[theFunctionID].m_size); 00227 } 00228 00229 return theResult; 00230 } 00231 00232 /** 00233 * Map a function name to the corresponding ID number. 00234 * 00235 * @param theName name of function 00236 * @return The ID number of function, or InvalidFunctionNumberID if the function doesn't exist. 00237 */ 00238 int 00239 nameToID(const XalanDOMString& theName) const 00240 { 00241 return getFunctionIndex(theName); 00242 } 00243 00244 /** 00245 * Insert a named function into the function table. 00246 * 00247 * @param theFunctionName name of function 00248 * @param theFunction function object corresponding to name 00249 */ 00250 void 00251 InstallFunction( 00252 const XalanDOMString& theFunctionName, 00253 const Function& theFunction) 00254 { 00255 InstallFunction(theFunctionName.c_str(), theFunction); 00256 } 00257 00258 /** 00259 * Remove a named function from the function table. 00260 * 00261 * @param theFunctionName name of function 00262 * @return true if the function was found and removed. 00263 */ 00264 bool 00265 UninstallFunction(const XalanDOMString& theFunctionName) 00266 { 00267 return UninstallFunction(theFunctionName.c_str()); 00268 } 00269 00270 /** 00271 * Insert a named function into the function table. 00272 * 00273 * @param theFunctionName name of function 00274 * @param theFunction function object corresponding to name 00275 */ 00276 void 00277 InstallFunction( 00278 const XalanDOMChar* theFunctionName, 00279 const Function& theFunction); 00280 00281 /** 00282 * Remove a named function from the function table. 00283 * 00284 * @param theFunctionName name of function 00285 * @return true if the function was found and removed. 00286 */ 00287 bool 00288 UninstallFunction(const XalanDOMChar* theFunctionName); 00289 00290 /** 00291 * Whether a named function is in the function table. 00292 * 00293 * @param theFunctionName name of function 00294 * @return true if function is in table 00295 */ 00296 bool 00297 isInstalledFunction(const XalanDOMString& theFunctionName) const 00298 { 00299 return getFunctionIndex(theFunctionName) != InvalidFunctionNumberID ? true : false; 00300 } 00301 00302 /** 00303 * Add a list of the names of installed functions to a vector of names. 00304 * 00305 * @param theIterator function table iterator to append names to 00306 */ 00307 template<class OutputIteratorType> 00308 void 00309 getInstalledFunctionNames(OutputIteratorType theIterator) const 00310 { 00311 XalanDOMString theString(XalanMemMgrs::getDefaultXercesMemMgr()); 00312 00313 for (int i = 0; i < TableSize; ++i) 00314 { 00315 if (m_functionTable[i] != 0) 00316 { 00317 theString.assign( 00318 s_functionNames[i].m_name, 00319 s_functionNames[i].m_size); 00320 00321 *theIterator = theString; 00322 00323 ++theIterator; 00324 } 00325 } 00326 } 00327 00328 struct FunctionNameTableEntry 00329 { 00330 const XalanDOMChar* m_name; 00331 00332 StringSizeType m_size; 00333 }; 00334 00335 // These are static strings for the functions supported. 00336 // Note that the XSLT functions are also here, since it's 00337 // just easier to do it this way. 00338 00339 // The string "id" 00340 static const XalanDOMChar s_id[]; 00341 00342 // The string "key" 00343 static const XalanDOMChar s_key[]; 00344 00345 // The string "not" 00346 static const XalanDOMChar s_not[]; 00347 00348 // The string "sum" 00349 static const XalanDOMChar s_sum[]; 00350 00351 // The string "lang" 00352 static const XalanDOMChar s_lang[]; 00353 00354 // The string "last" 00355 static const XalanDOMChar s_last[]; 00356 00357 // The string "name" 00358 static const XalanDOMChar s_name[]; 00359 00360 // The string "true" 00361 static const XalanDOMChar s_true[]; 00362 00363 // The string "count" 00364 static const XalanDOMChar s_count[]; 00365 00366 // The string "false" 00367 static const XalanDOMChar s_false[]; 00368 00369 // The string "floor" 00370 static const XalanDOMChar s_floor[]; 00371 00372 // The string "round" 00373 static const XalanDOMChar s_round[]; 00374 00375 // The string "concat" 00376 static const XalanDOMChar s_concat[]; 00377 00378 // The string "number" 00379 static const XalanDOMChar s_number[]; 00380 00381 // The string "string" 00382 static const XalanDOMChar s_string[]; 00383 00384 // The string "boolean" 00385 static const XalanDOMChar s_boolean[]; 00386 00387 // The string "ceiling" 00388 static const XalanDOMChar s_ceiling[]; 00389 00390 // The string "current" 00391 static const XalanDOMChar s_current[]; 00392 00393 // The string "contains" 00394 static const XalanDOMChar s_contains[]; 00395 00396 // The string "document" 00397 static const XalanDOMChar s_document[]; 00398 00399 // The string "position" 00400 static const XalanDOMChar s_position[]; 00401 00402 // The string "substring" 00403 static const XalanDOMChar s_substring[]; 00404 00405 // The string "translate" 00406 static const XalanDOMChar s_translate[]; 00407 00408 // The string "local-name" 00409 static const XalanDOMChar s_localName[]; 00410 00411 // The string "generate-id" 00412 static const XalanDOMChar s_generateId[]; 00413 00414 // The string "starts-with" 00415 static const XalanDOMChar s_startsWith[]; 00416 00417 // The string "format-number" 00418 static const XalanDOMChar s_formatNumber[]; 00419 00420 // The string "namespace-uri" 00421 static const XalanDOMChar s_namespaceUri[]; 00422 00423 // The string "string-length" 00424 static const XalanDOMChar s_stringLength[]; 00425 00426 // The string "normalize-space" 00427 static const XalanDOMChar s_normalizeSpace[]; 00428 00429 // The string "substring-after" 00430 static const XalanDOMChar s_substringAfter[]; 00431 00432 // The string "system-property" 00433 static const XalanDOMChar s_systemProperty[]; 00434 00435 // The string "substring-before" 00436 static const XalanDOMChar s_substringBefore[]; 00437 00438 // The string "element-available" 00439 static const XalanDOMChar s_elementAvailable[]; 00440 00441 // The string "function-available" 00442 static const XalanDOMChar s_functionAvailable[]; 00443 00444 // The string "unparsed-entity-uri" 00445 static const XalanDOMChar s_unparsedEntityUri[]; 00446 00447 // A table of function names. 00448 static const FunctionNameTableEntry s_functionNames[]; 00449 00450 // The size of the table. 00451 static const SizeType s_functionNamesSize; 00452 00453 private: 00454 00455 static int 00456 getFunctionIndex(const XalanDOMString& theName) 00457 { 00458 return getFunctionIndex( 00459 theName.c_str(), 00460 theName.length()); 00461 } 00462 00463 static int 00464 getFunctionIndex(const XalanDOMChar* theName) 00465 { 00466 return getFunctionIndex( 00467 theName, 00468 XalanDOMString::length(theName)); 00469 } 00470 00471 static int 00472 getFunctionIndex( 00473 const XalanDOMChar* theName, 00474 StringSizeType theNameLength); 00475 00476 MemoryManager* m_memoryManager; 00477 00478 const Function* m_functionTable[TableSize]; 00479 00480 const Function** const m_functionTableEnd; 00481 00482 // The last one in the table of function names. 00483 static const FunctionNameTableEntry* const s_lastFunctionName; 00484 }; 00485 00486 00487 00488 XALAN_CPP_NAMESPACE_END 00489 00490 00491 00492 #endif // XPATHFUNCTIONTABLE_HEADER_GUARD_1357924680
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
Xalan-C++ XSLT Processor Version 1.11 |
|