Xalan-C++ API Reference 1.12.0
ElemNumber.hpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18#if !defined(XALAN_ELEMNUMBER_HEADER_GUARD)
19#define XALAN_ELEMNUMBER_HEADER_GUARD
20
21
22
23// Base include file. Must be first.
25
26
27
29
30
31
32// Base class header file.
34
35
36
38
39
40
44
45
46
47namespace XALAN_CPP_NAMESPACE {
48
49
50
51class AVT;
52class MutableNodeRefList;
53class XalanNumberFormat;
54class XPath;
55class XPathExecutionContext;
56
57
58
60{
61public:
62
64
65 enum eLevel
66 {
69 eAny
70 };
71
73
74 /**
75 * Perform static initialization. See class XSLTInit.
76 */
77 static void
78 initialize(MemoryManager& theManager);
79
80 /**
81 * Perform static shut down. See class XSLTInit.
82 */
83 static void
85
86 /**
87 * Construct an object corresponding to an "xsl:number" element
88 *
89 * @param constructionContext context for construction of object
90 * @param stylesheetTree stylesheet containing element
91 * @param atts list of attributes for element
92 * @param lineNumber line number in document
93 * @param columnNumber column number in document
94 * @param id The unique ID within the stylesheet for this xsl:number element
95 */
102 unsigned long id);
103
104 static ElemNumber*
106 MemoryManager& theManager,
109 const AttributeListType& atts,
112 unsigned long id);
113
114 virtual
116
117 // These methods are inherited from ElemTemplateElement ...
118
119 virtual const XalanDOMString&
121
122#if !defined(XALAN_RECURSIVE_STYLESHEET_EXECUTION)
123 virtual const ElemTemplateElement*
125#else
126 virtual void
128#endif
129
130 unsigned long
131 getID() const
132 {
133 return m_id;
134 }
135
136 /**
137 * Get the previous node to be counted.
138 */
141 XalanNode* pos) const;
142
143 /**
144 * Get the target node that will be counted..
145 */
148 XalanNode* sourceNode) const;
149
150 virtual const XPath*
151 getXPath(XalanSize_t index) const;
152
153protected:
154
155 /**
156 * Given a 'from' pattern (ala xsl:number), a match pattern
157 * and a context, find the first ancestor that matches the
158 * pattern (including the context handed in).
159 *
160 * @param executionContext The current execution context
161 * @param matchPatternString The match pattern.
162 * @param matchPatternString The count match pattern.
163 * @param node The context node
164 * @return A pointer to the matched node.
165 */
166 XalanNode*
169 const XPath* fromMatchPattern,
171 XalanNode* context) const;
172
173 /**
174 * Given a 'from' pattern (ala xsl:number), a match pattern
175 * and a context, find the first ancestor that matches the
176 * pattern (including the context handed in).
177 *
178 * @param executionContext The current execution context
179 * @param matchPatternString The match pattern.
180 * @param matchPatternString The count match pattern.
181 * @param node The context node
182 * @return A pointer to the matched node.
183 */
184 XalanNode*
187 const XPath* fromMatchPattern,
189 XalanNode* context) const;
190
191 /**
192 * Get the count match pattern, or a default value.
193 */
194 const XPath*
197 XalanNode* contextNode) const;
198
199 /**
200 * Given an XML source node, get the count according to the
201 * parameters set up by the xsl:number attributes.
202 */
203 void
207
208 void
216
217 /**
218 * Get the ancestors, up to the root, that match the
219 * pattern.
220 * @param patterns if non-0, count only nodes
221 * that match this pattern, if 0 count all ancestors.
222 * @param executionContext The current execution context.
223 * @param node Count this node and it's ancestors.
224 * @param stopAtFirstFound If true, only get the first matching ancestor
225 * @param ancestors The ancestors that match the pattern.
226 */
227 void
230 XalanNode* node,
231 bool stopAtFirstFound,
233
234 /**
235 * Get a formatter.
236 * @param executionContext The current execution context.
237 * @return A new XalanNumberFormat instance. The caller owns the memory.
238 */
241
242 /**
243 * Format an array of integrals into a formatted string.
244 *
245 * @param executionContext The current execution context.
246 * @param theList Array of one or more integer numbers.
247 * @param theListLength The length of the array.
248 * @param formattedNumber The formatted number result.
249 */
250 void
253 const CountType theList[],
256
257 /**
258 * Convert an intergral into alphabetic counting, in other words
259 * count using the sequence A B C ... Z.
260 * @param val Value to convert -- must be greater than zero.
261 * @param table a table containing one character for each digit in the radix
262 * @param theResult A string representing alpha count of number.
263 * @see XSLTEngineImpl#DecimalToRoman
264 *
265 * Note that the radix of the conversion is inferred from the size
266 * of the table.
267 */
268 static void
271 const XalanDOMString& table,
273
274 /**
275 * Convert an integral into alphabetic counting, in other words
276 * count using the sequence A B C ... Z AA AB AC.... etc.
277 * @param val Value to convert -- must be greater than zero.
278 * @param table a table containing one character for each digit in the radix
279 * @param length the table length
280 * @param result returns the stringrepresenting alpha count of number.
281 * @see XSLTEngineImpl#DecimalToRoman
282 *
283 * Note that the radix of the conversion is inferred from the size
284 * of the table.
285 */
286 static void
289 const XalanDOMChar table[],
292
293 /**
294 * Convert an integral into roman numerals.
295 * @param val Value to convert.
296 * @param prefixesAreOK true to enable prefix notation (e.g. 4 = "IV"), false to disable prefix notation (e.g. 4 = "IIII").
297 * @param theResult The formatted Roman numeral string.
298 * @see DecimalToRoman
299 * @see m_romanConvertTable
300 */
301 static void
304 bool prefixesAreOK,
306
307private:
308
309 void
310 evaluateLetterValueAVT(
312 XalanDOMString& value) const;
313
314 void
315 traditionalAlphaCount(
319
320 /*
321 * Get Formatted number
322 */
323 void
324 getFormattedNumber(
330
331 const XPath* m_countMatchPattern;
332 const XPath* m_fromMatchPattern;
333 const XPath* m_valueExpr;
334
335 CountType m_level; // = Constants.NUMBERLEVEL_SINGLE;
336
337 const AVT* m_format_avt;
338 const AVT* m_lang_avt;
339 const AVT* m_lettervalue_avt;
340 const AVT* m_groupingSeparator_avt;
341 const AVT* m_groupingSize_avt;
342
343 const unsigned long m_id;
344
345 /**
346 * The string "@".
347 */
348 static const XalanDOMChar s_atString[];
349
350 /**
351 * The string "text()".
352 */
353 static const XalanDOMString& s_textString;
354
355 /**
356 * The string "comment()".
357 */
358 static const XalanDOMString& s_commentString;
359
360 /**
361 * The string "/".
362 */
363 static const XalanDOMString& s_slashString;
364
365 /**
366 * The string "processing-instruction(".
367 */
368 static const XalanDOMChar s_piString[];
369
370 /**
371 * The string "level".
372 */
373 static const XalanDOMChar s_levelString[];
374
375 /**
376 * The string "multiple".
377 */
378 static const XalanDOMChar s_multipleString[];
379
380 /**
381 * The string "any".
382 */
383 static const XalanDOMChar s_anyString[];
384
385 /**
386 * The string "single".
387 */
388 static const XalanDOMChar s_singleString[];
389
390 /**
391 * The string "alphabetic".
392 */
393 static const XalanDOMChar s_alphabeticString[];
394
395 /**
396 * The string "traditional".
397 */
398 static const XalanDOMChar s_traditionalString[];
399
400 /**
401 * The string "#error".
402 */
403 static const XalanDOMChar s_errorString[];
404
405 /**
406 * Chars for converting integers into alpha counts.
407 */
408 static const XalanDOMChar s_alphaCountTable[];
409
410 static const XalanDOMString::size_type s_alphaCountTableSize;
411
412 static const XalanDOMChar s_elalphaCountTable[];
413
414 static const XalanDOMString::size_type s_elalphaCountTableSize;
415
416 /**
417 * Table to help in converting decimals to roman numerals.
418 * @see XSLTEngineImpl#DecimalToRoman
419 * @see XSLTEngineImpl#long2roman
420 */
421 static const DecimalToRoman s_romanConvertTable[];
422
423 static const size_t s_romanConvertTableSize;
424 /**
425 * numbering resource bundle for Greek numbering.
426 */
427 static const XalanNumberingResourceBundle& s_elalphaResourceBundle;
428
429
430public:
431
432 /**
433 * This class returns tokens using non-alphanumberic characters as
434 * delimiters.
435 */
437 {
438 public:
439
441
442 /**
443 * Construct a NumberFormatStringTokenizer.
444 *
445 * @param theString string to tokenize
446 */
448
449 /**
450 * Sets the string to tokenize.
451 *
452 * @param theString new string to tokenize
453 */
454 void
456
457 /**
458 * Reset tokenizer so that nextToken() starts from the beginning.
459 */
460 void
462 {
463 m_currentPosition = 0;
464 }
465
466
467 /**
468 * Retrieve the next token to be parsed.
469 *
470 * @param theToken The next token string
471 */
472 void
474
475 /**
476 * Determine if there are tokens remaining
477 *
478 * @return true if there are more tokens
479 */
480 bool
482 {
483 return m_currentPosition >= m_maxPosition ? false : true;
484 }
485
486 /**
487 * Count the number of tokens yet to be parsed
488 *
489 * @return number of remaining tokens
490 */
492 countTokens() const;
493
494 private:
495
496 size_type m_currentPosition;
497
498 size_type m_maxPosition;
499
500 const XalanDOMString* m_string;
501 };
502
503private:
504};
505
506
507
508}
509
510
511
512#endif // XALAN_ELEMNUMBER_HEADER_GUARD
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Class to hold an Attribute Value Template.
Definition AVT.hpp:59
<meta name="usage" content="internal"> This is a table of counters, keyed by ElemNumber objects,...
Counter::CountType CountType
This class returns tokens using non-alphanumberic characters as delimiters.
bool hasMoreTokens() const
Determine if there are tokens remaining.
void reset()
Reset tokenizer so that nextToken() starts from the beginning.
size_type countTokens() const
Count the number of tokens yet to be parsed.
void setString(const XalanDOMString &theString)
Sets the string to tokenize.
NumberFormatStringTokenizer(const XalanDOMString &theString)
Construct a NumberFormatStringTokenizer.
void nextToken(XalanDOMString &theToken)
Retrieve the next token to be parsed.
XalanNode * getTargetNode(StylesheetExecutionContext &executionContext, XalanNode *sourceNode) const
Get the target node that will be counted.
virtual ~ElemNumber()
XalanNode * findPrecedingOrAncestorOrSelf(StylesheetExecutionContext &executionContext, const XPath *fromMatchPattern, const XPath *countMatchPattern, XalanNode *context) const
Given a 'from' pattern (ala xsl:number), a match pattern and a context, find the first ancestor that ...
static void terminate()
Perform static shut down.
static void toRoman(CountType val, bool prefixesAreOK, XalanDOMString &theResult)
Convert an integral into roman numerals.
virtual const ElemTemplateElement * startElement(StylesheetExecutionContext &executionContext) const
Completes "pre-processing" before any sub-elements are invoked (i.e.
void getMatchingAncestors(StylesheetExecutionContext &executionContext, XalanNode *node, bool stopAtFirstFound, MutableNodeRefList &ancestors) const
Get the ancestors, up to the root, that match the pattern.
ElemNumber(StylesheetConstructionContext &constructionContext, Stylesheet &stylesheetTree, const AttributeListType &atts, XalanFileLoc lineNumber, XalanFileLoc columnNumber, unsigned long id)
Construct an object corresponding to an "xsl:number" element.
XalanNode * findAncestor(StylesheetExecutionContext &executionContext, const XPath *fromMatchPattern, const XPath *countMatchPattern, XalanNode *context) const
Given a 'from' pattern (ala xsl:number), a match pattern and a context, find the first ancestor that ...
unsigned long getID() const
static void int2singlealphaCount(CountType val, const XalanDOMString &table, XalanDOMString &theResult)
Convert an intergral into alphabetic counting, in other words count using the sequence A B C ....
void formatNumberList(StylesheetExecutionContext &executionContext, const CountType theList[], NodeRefListBase::size_type theListLength, XalanDOMString &formattedNumber) const
Format an array of integrals into a formatted string.
CountersTable::CountType CountType
virtual const XPath * getXPath(XalanSize_t index) const
Get XPath pattern/expression of one of the element atribute.
XalanNumberFormat * getNumberFormatter(StylesheetExecutionContext &executionContext) const
Get a formatter.
const XPath * getCountMatchPattern(StylesheetExecutionContext &executionContext, XalanNode *contextNode) const
Get the count match pattern, or a default value.
static void initialize(MemoryManager &theManager)
Perform static initialization.
static void int2alphaCount(CountType val, const XalanDOMChar table[], XalanDOMString::size_type length, XalanDOMString &theResult)
Convert an integral into alphabetic counting, in other words count using the sequence A B C ....
XalanNode * getPreviousNode(StylesheetExecutionContext &executionContext, XalanNode *pos) const
Get the previous node to be counted.
void getCountString(StylesheetExecutionContext &executionContext, const MutableNodeRefList &ancestors, CountersTable &ctable, CountType numberList[], NodeRefListBase::size_type numberListLength, XalanDOMString &theResult) const
virtual const XalanDOMString & getElementName() const
Get a string for the name of the element.
void getCountString(StylesheetExecutionContext &executionContext, XalanDOMString &theResult) const
Given an XML source node, get the count according to the parameters set up by the xsl:number attribut...
XalanVector< CountType > CountTypeArrayType
static ElemNumber * create(MemoryManager &theManager, StylesheetConstructionContext &constructionContext, Stylesheet &stylesheetTree, const AttributeListType &atts, XalanFileLoc lineNumber, XalanFileLoc columnNumber, unsigned long id)
Local implementation of MutableNodeRefList.
This class represents the base stylesheet or an "import" stylesheet.
xercesc::AttributeList AttributeListType
Structure to help in converting integrals to roman numerals.