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(XALAN_ELEMNUMBER_HEADER_GUARD) 00019 #define XALAN_ELEMNUMBER_HEADER_GUARD 00020 00021 00022 00023 // Base include file. Must be first. 00024 #include <xalanc/XSLT/XSLTDefinitions.hpp> 00025 00026 00027 00028 #include <xalanc/Include/XalanVector.hpp> 00029 00030 00031 00032 // Base class header file. 00033 #include <xalanc/XSLT/ElemTemplateElement.hpp> 00034 00035 00036 00037 #include <xalanc/XPath/NodeRefListBase.hpp> 00038 00039 00040 00041 #include <xalanc/XSLT/CountersTable.hpp> 00042 #include <xalanc/XSLT/DecimalToRoman.hpp> 00043 #include <xalanc/XSLT/XalanNumberingResourceBundle.hpp> 00044 00045 00046 00047 XALAN_CPP_NAMESPACE_BEGIN 00048 00049 00050 00051 class AVT; 00052 class MutableNodeRefList; 00053 class XalanNumberFormat; 00054 class XPath; 00055 class XPathExecutionContext; 00056 00057 00058 00059 class ElemNumber: public ElemTemplateElement 00060 { 00061 public: 00062 00063 typedef CountersTable::CountType CountType; 00064 00065 enum eLevel 00066 { 00067 eSingle, 00068 eMultiple, 00069 eAny 00070 }; 00071 00072 typedef XalanVector<CountType> CountTypeArrayType; 00073 00074 /** 00075 * Perform static initialization. See class XSLTInit. 00076 */ 00077 static void 00078 initialize(MemoryManager& theManager); 00079 00080 /** 00081 * Perform static shut down. See class XSLTInit. 00082 */ 00083 static void 00084 terminate(); 00085 00086 /** 00087 * Construct an object corresponding to an "xsl:number" element 00088 * 00089 * @param constructionContext context for construction of object 00090 * @param stylesheetTree stylesheet containing element 00091 * @param atts list of attributes for element 00092 * @param lineNumber line number in document 00093 * @param columnNumber column number in document 00094 * @param id The unique ID within the stylesheet for this xsl:number element 00095 */ 00096 ElemNumber( 00097 StylesheetConstructionContext& constructionContext, 00098 Stylesheet& stylesheetTree, 00099 const AttributeListType& atts, 00100 XalanFileLoc lineNumber, 00101 XalanFileLoc columnNumber, 00102 unsigned long id); 00103 00104 static ElemNumber* 00105 create( 00106 MemoryManager& theManager, 00107 StylesheetConstructionContext& constructionContext, 00108 Stylesheet& stylesheetTree, 00109 const AttributeListType& atts, 00110 XalanFileLoc lineNumber, 00111 XalanFileLoc columnNumber, 00112 unsigned long id); 00113 00114 virtual 00115 ~ElemNumber(); 00116 00117 // These methods are inherited from ElemTemplateElement ... 00118 00119 virtual const XalanDOMString& 00120 getElementName() const; 00121 00122 #if !defined(XALAN_RECURSIVE_STYLESHEET_EXECUTION) 00123 virtual const ElemTemplateElement* 00124 startElement(StylesheetExecutionContext& executionContext) const; 00125 #else 00126 virtual void 00127 execute(StylesheetExecutionContext& executionContext) const; 00128 #endif 00129 00130 unsigned long 00131 getID() const 00132 { 00133 return m_id; 00134 } 00135 00136 /** 00137 * Get the previous node to be counted. 00138 */ 00139 XalanNode* getPreviousNode( 00140 StylesheetExecutionContext& executionContext, 00141 XalanNode* pos) const; 00142 00143 /** 00144 * Get the target node that will be counted.. 00145 */ 00146 XalanNode* getTargetNode( 00147 StylesheetExecutionContext& executionContext, 00148 XalanNode* sourceNode) const; 00149 00150 virtual const XPath* 00151 getXPath(XalanSize_t index) const; 00152 00153 protected: 00154 00155 /** 00156 * Given a 'from' pattern (ala xsl:number), a match pattern 00157 * and a context, find the first ancestor that matches the 00158 * pattern (including the context handed in). 00159 * 00160 * @param executionContext The current execution context 00161 * @param matchPatternString The match pattern. 00162 * @param matchPatternString The count match pattern. 00163 * @param node The context node 00164 * @return A pointer to the matched node. 00165 */ 00166 XalanNode* 00167 findAncestor( 00168 StylesheetExecutionContext& executionContext, 00169 const XPath* fromMatchPattern, 00170 const XPath* countMatchPattern, 00171 XalanNode* context) const; 00172 00173 /** 00174 * Given a 'from' pattern (ala xsl:number), a match pattern 00175 * and a context, find the first ancestor that matches the 00176 * pattern (including the context handed in). 00177 * 00178 * @param executionContext The current execution context 00179 * @param matchPatternString The match pattern. 00180 * @param matchPatternString The count match pattern. 00181 * @param node The context node 00182 * @return A pointer to the matched node. 00183 */ 00184 XalanNode* 00185 findPrecedingOrAncestorOrSelf( 00186 StylesheetExecutionContext& executionContext, 00187 const XPath* fromMatchPattern, 00188 const XPath* countMatchPattern, 00189 XalanNode* context) const; 00190 00191 /** 00192 * Get the count match pattern, or a default value. 00193 */ 00194 const XPath* 00195 getCountMatchPattern( 00196 StylesheetExecutionContext& executionContext, 00197 XalanNode* contextNode) const; 00198 00199 /** 00200 * Given an XML source node, get the count according to the 00201 * parameters set up by the xsl:number attributes. 00202 */ 00203 void 00204 getCountString( 00205 StylesheetExecutionContext& executionContext, 00206 XalanDOMString& theResult) const; 00207 00208 void 00209 getCountString( 00210 StylesheetExecutionContext& executionContext, 00211 const MutableNodeRefList& ancestors, 00212 CountersTable& ctable, 00213 CountType numberList[], 00214 NodeRefListBase::size_type numberListLength, 00215 XalanDOMString& theResult) const; 00216 00217 /** 00218 * Get the ancestors, up to the root, that match the 00219 * pattern. 00220 * @param patterns if non-0, count only nodes 00221 * that match this pattern, if 0 count all ancestors. 00222 * @param executionContext The current execution context. 00223 * @param node Count this node and it's ancestors. 00224 * @param stopAtFirstFound If true, only get the first matching ancestor 00225 * @param ancestors The ancestors that match the pattern. 00226 */ 00227 void 00228 getMatchingAncestors( 00229 StylesheetExecutionContext& executionContext, 00230 XalanNode* node, 00231 bool stopAtFirstFound, 00232 MutableNodeRefList& ancestors) const; 00233 00234 /** 00235 * Get a formatter. 00236 * @param executionContext The current execution context. 00237 * @return A new XalanNumberFormat instance. The caller owns the memory. 00238 */ 00239 XalanNumberFormat* 00240 getNumberFormatter(StylesheetExecutionContext& executionContext) const; 00241 00242 /** 00243 * Format an array of integrals into a formatted string. 00244 * 00245 * @param executionContext The current execution context. 00246 * @param theList Array of one or more integer numbers. 00247 * @param theListLength The length of the array. 00248 * @param formattedNumber The formatted number result. 00249 */ 00250 void 00251 formatNumberList( 00252 StylesheetExecutionContext& executionContext, 00253 const CountType theList[], 00254 NodeRefListBase::size_type theListLength, 00255 XalanDOMString& formattedNumber) const; 00256 00257 /** 00258 * Convert an intergral into alphabetic counting, in other words 00259 * count using the sequence A B C ... Z. 00260 * @param val Value to convert -- must be greater than zero. 00261 * @param table a table containing one character for each digit in the radix 00262 * @param theResult A string representing alpha count of number. 00263 * @see XSLTEngineImpl#DecimalToRoman 00264 * 00265 * Note that the radix of the conversion is inferred from the size 00266 * of the table. 00267 */ 00268 static void 00269 int2singlealphaCount( 00270 CountType val, 00271 const XalanDOMString& table, 00272 XalanDOMString& theResult); 00273 00274 /** 00275 * Convert an integral into alphabetic counting, in other words 00276 * count using the sequence A B C ... Z AA AB AC.... etc. 00277 * @param val Value to convert -- must be greater than zero. 00278 * @param table a table containing one character for each digit in the radix 00279 * @param length the table length 00280 * @param result returns the stringrepresenting alpha count of number. 00281 * @see XSLTEngineImpl#DecimalToRoman 00282 * 00283 * Note that the radix of the conversion is inferred from the size 00284 * of the table. 00285 */ 00286 static void 00287 int2alphaCount( 00288 CountType val, 00289 const XalanDOMChar table[], 00290 XalanDOMString::size_type length, 00291 XalanDOMString& theResult); 00292 00293 /** 00294 * Convert an integral into roman numerals. 00295 * @param val Value to convert. 00296 * @param prefixesAreOK true to enable prefix notation (e.g. 4 = "IV"), false to disable prefix notation (e.g. 4 = "IIII"). 00297 * @param theResult The formatted Roman numeral string. 00298 * @see DecimalToRoman 00299 * @see m_romanConvertTable 00300 */ 00301 static void 00302 toRoman( 00303 CountType val, 00304 bool prefixesAreOK, 00305 XalanDOMString& theResult); 00306 00307 private: 00308 00309 void 00310 evaluateLetterValueAVT( 00311 StylesheetExecutionContext& executionContext, 00312 XalanDOMString& value) const; 00313 00314 void 00315 traditionalAlphaCount( 00316 CountType theValue, 00317 const XalanNumberingResourceBundle& theResourceBundle, 00318 XalanDOMString& theResult) const; 00319 00320 /* 00321 * Get Formatted number 00322 */ 00323 void 00324 getFormattedNumber( 00325 StylesheetExecutionContext& executionContext, 00326 XalanDOMChar numberType, 00327 XalanDOMString::size_type numberWidth, 00328 CountType listElement, 00329 XalanDOMString& theResult) const; 00330 00331 const XPath* m_countMatchPattern; 00332 const XPath* m_fromMatchPattern; 00333 const XPath* m_valueExpr; 00334 00335 CountType m_level; // = Constants.NUMBERLEVEL_SINGLE; 00336 00337 const AVT* m_format_avt; 00338 const AVT* m_lang_avt; 00339 const AVT* m_lettervalue_avt; 00340 const AVT* m_groupingSeparator_avt; 00341 const AVT* m_groupingSize_avt; 00342 00343 const unsigned long m_id; 00344 00345 /** 00346 * The string "@". 00347 */ 00348 static const XalanDOMChar s_atString[]; 00349 00350 /** 00351 * The string "text()". 00352 */ 00353 static const XalanDOMString& s_textString; 00354 00355 /** 00356 * The string "comment()". 00357 */ 00358 static const XalanDOMString& s_commentString; 00359 00360 /** 00361 * The string "/". 00362 */ 00363 static const XalanDOMString& s_slashString; 00364 00365 /** 00366 * The string "processing-instruction(". 00367 */ 00368 static const XalanDOMChar s_piString[]; 00369 00370 /** 00371 * The string "level". 00372 */ 00373 static const XalanDOMChar s_levelString[]; 00374 00375 /** 00376 * The string "multiple". 00377 */ 00378 static const XalanDOMChar s_multipleString[]; 00379 00380 /** 00381 * The string "any". 00382 */ 00383 static const XalanDOMChar s_anyString[]; 00384 00385 /** 00386 * The string "single". 00387 */ 00388 static const XalanDOMChar s_singleString[]; 00389 00390 /** 00391 * The string "alphabetic". 00392 */ 00393 static const XalanDOMChar s_alphabeticString[]; 00394 00395 /** 00396 * The string "traditional". 00397 */ 00398 static const XalanDOMChar s_traditionalString[]; 00399 00400 /** 00401 * The string "#error". 00402 */ 00403 static const XalanDOMChar s_errorString[]; 00404 00405 /** 00406 * Chars for converting integers into alpha counts. 00407 */ 00408 static const XalanDOMChar s_alphaCountTable[]; 00409 00410 static const XalanDOMString::size_type s_alphaCountTableSize; 00411 00412 static const XalanDOMChar s_elalphaCountTable[]; 00413 00414 static const XalanDOMString::size_type s_elalphaCountTableSize; 00415 00416 /** 00417 * Table to help in converting decimals to roman numerals. 00418 * @see XSLTEngineImpl#DecimalToRoman 00419 * @see XSLTEngineImpl#long2roman 00420 */ 00421 static const DecimalToRoman s_romanConvertTable[]; 00422 00423 static const size_t s_romanConvertTableSize; 00424 /** 00425 * numbering resource bundle for Greek numbering. 00426 */ 00427 static const XalanNumberingResourceBundle& s_elalphaResourceBundle; 00428 00429 00430 public: 00431 00432 /** 00433 * This class returns tokens using non-alphanumberic characters as 00434 * delimiters. 00435 */ 00436 class NumberFormatStringTokenizer 00437 { 00438 public: 00439 00440 typedef XalanDOMString::size_type size_type; 00441 00442 /** 00443 * Construct a NumberFormatStringTokenizer. 00444 * 00445 * @param theString string to tokenize 00446 */ 00447 NumberFormatStringTokenizer(const XalanDOMString& theString); 00448 00449 /** 00450 * Sets the string to tokenize. 00451 * 00452 * @param theString new string to tokenize 00453 */ 00454 void 00455 setString(const XalanDOMString& theString); 00456 00457 /** 00458 * Reset tokenizer so that nextToken() starts from the beginning. 00459 */ 00460 void 00461 reset() 00462 { 00463 m_currentPosition = 0; 00464 } 00465 00466 00467 /** 00468 * Retrieve the next token to be parsed. 00469 * 00470 * @param theToken The next token string 00471 */ 00472 void 00473 nextToken(XalanDOMString& theToken); 00474 00475 /** 00476 * Determine if there are tokens remaining 00477 * 00478 * @return true if there are more tokens 00479 */ 00480 bool 00481 hasMoreTokens() const 00482 { 00483 return m_currentPosition >= m_maxPosition ? false : true; 00484 } 00485 00486 /** 00487 * Count the number of tokens yet to be parsed 00488 * 00489 * @return number of remaining tokens 00490 */ 00491 size_type 00492 countTokens() const; 00493 00494 private: 00495 00496 size_type m_currentPosition; 00497 00498 size_type m_maxPosition; 00499 00500 const XalanDOMString* m_string; 00501 }; 00502 00503 private: 00504 }; 00505 00506 00507 00508 XALAN_CPP_NAMESPACE_END 00509 00510 00511 00512 #endif // XALAN_ELEMNUMBER_HEADER_GUARD
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
Xalan-C++ XSLT Processor Version 1.11 |
|