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 
47 namespace XALAN_CPP_NAMESPACE {
48 
49 
50 
51 class AVT;
52 class MutableNodeRefList;
53 class XalanNumberFormat;
54 class XPath;
55 class XPathExecutionContext;
56 
57 
58 
60 {
61 public:
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
84  terminate();
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  */
96  ElemNumber(
97  StylesheetConstructionContext& constructionContext,
98  Stylesheet& stylesheetTree,
99  const AttributeListType& atts,
100  XalanFileLoc lineNumber,
101  XalanFileLoc columnNumber,
102  unsigned long id);
103 
104  static ElemNumber*
105  create(
106  MemoryManager& theManager,
107  StylesheetConstructionContext& constructionContext,
108  Stylesheet& stylesheetTree,
109  const AttributeListType& atts,
110  XalanFileLoc lineNumber,
111  XalanFileLoc columnNumber,
112  unsigned long id);
113 
114  virtual
115  ~ElemNumber();
116 
117  // These methods are inherited from ElemTemplateElement ...
118 
119  virtual const XalanDOMString&
120  getElementName() const;
121 
122 #if !defined(XALAN_RECURSIVE_STYLESHEET_EXECUTION)
123  virtual const ElemTemplateElement*
124  startElement(StylesheetExecutionContext& executionContext) const;
125 #else
126  virtual void
127  execute(StylesheetExecutionContext& executionContext) const;
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  */
139  XalanNode* getPreviousNode(
140  StylesheetExecutionContext& executionContext,
141  XalanNode* pos) const;
142 
143  /**
144  * Get the target node that will be counted..
145  */
146  XalanNode* getTargetNode(
147  StylesheetExecutionContext& executionContext,
148  XalanNode* sourceNode) const;
149 
150  virtual const XPath*
151  getXPath(XalanSize_t index) const;
152 
153 protected:
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*
167  findAncestor(
168  StylesheetExecutionContext& executionContext,
169  const XPath* fromMatchPattern,
170  const XPath* countMatchPattern,
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*
185  findPrecedingOrAncestorOrSelf(
186  StylesheetExecutionContext& executionContext,
187  const XPath* fromMatchPattern,
188  const XPath* countMatchPattern,
189  XalanNode* context) const;
190 
191  /**
192  * Get the count match pattern, or a default value.
193  */
194  const XPath*
195  getCountMatchPattern(
196  StylesheetExecutionContext& executionContext,
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
204  getCountString(
205  StylesheetExecutionContext& executionContext,
206  XalanDOMString& theResult) const;
207 
208  void
209  getCountString(
210  StylesheetExecutionContext& executionContext,
211  const MutableNodeRefList& ancestors,
212  CountersTable& ctable,
213  CountType numberList[],
214  NodeRefListBase::size_type numberListLength,
215  XalanDOMString& theResult) const;
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
228  getMatchingAncestors(
229  StylesheetExecutionContext& executionContext,
230  XalanNode* node,
231  bool stopAtFirstFound,
232  MutableNodeRefList& ancestors) const;
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  */
240  getNumberFormatter(StylesheetExecutionContext& executionContext) const;
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
251  formatNumberList(
252  StylesheetExecutionContext& executionContext,
253  const CountType theList[],
254  NodeRefListBase::size_type theListLength,
255  XalanDOMString& formattedNumber) const;
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
269  int2singlealphaCount(
270  CountType val,
271  const XalanDOMString& table,
272  XalanDOMString& theResult);
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
287  int2alphaCount(
288  CountType val,
289  const XalanDOMChar table[],
291  XalanDOMString& theResult);
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
302  toRoman(
303  CountType val,
304  bool prefixesAreOK,
305  XalanDOMString& theResult);
306 
307 private:
308 
309  void
310  evaluateLetterValueAVT(
311  StylesheetExecutionContext& executionContext,
312  XalanDOMString& value) const;
313 
314  void
315  traditionalAlphaCount(
316  CountType theValue,
317  const XalanNumberingResourceBundle& theResourceBundle,
318  XalanDOMString& theResult) const;
319 
320  /*
321  * Get Formatted number
322  */
323  void
324  getFormattedNumber(
325  StylesheetExecutionContext& executionContext,
326  XalanDOMChar numberType,
327  XalanDOMString::size_type numberWidth,
328  CountType listElement,
329  XalanDOMString& theResult) const;
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 
430 public:
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
455  setString(const XalanDOMString& theString);
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
473  nextToken(XalanDOMString& theToken);
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  */
491  size_type
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 
503 private:
504 };
505 
506 
507 
508 }
509 
510 
511 
512 #endif // XALAN_ELEMNUMBER_HEADER_GUARD
xalanc::ElemNumber::NumberFormatStringTokenizer::hasMoreTokens
bool hasMoreTokens() const
Determine if there are tokens remaining.
Definition: ElemNumber.hpp:481
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::AttributeListType
xercesc::AttributeList AttributeListType
Definition: AttributeListImpl.hpp:41
xalanc::XalanNumberFormat
Definition: XalanNumberFormat.hpp:36
xalanc::StylesheetExecutionContext
Definition: StylesheetExecutionContext.hpp:106
xalanc::CountersTable::CountType
Counter::CountType CountType
Definition: CountersTable.hpp:161
xalanc::XalanNode
Definition: XalanNode.hpp:38
xalanc::XalanVector
Definition: XalanVector.hpp:58
xalanc::ElemNumber::NumberFormatStringTokenizer
This class returns tokens using non-alphanumberic characters as delimiters.
Definition: ElemNumber.hpp:436
xalanc::XPath
Definition: XPath.hpp:67
xalanc::ElemNumber::eMultiple
@ eMultiple
Definition: ElemNumber.hpp:68
xalanc::MutableNodeRefList
Local implementation of MutableNodeRefList.
Definition: MutableNodeRefList.hpp:46
XalanNumberingResourceBundle.hpp
xalanc::ElemNumber::CountType
CountersTable::CountType CountType
Definition: ElemNumber.hpp:63
xalanc::size_type
size_t size_type
Definition: XalanMap.hpp:46
xalanc::ElemTemplateElement
Definition: ElemTemplateElement.hpp:79
XalanVector.hpp
DecimalToRoman.hpp
xalanc::ElemNumber::CountTypeArrayType
XalanVector< CountType > CountTypeArrayType
Definition: ElemNumber.hpp:72
xalanc::ElemNumber::NumberFormatStringTokenizer::reset
void reset()
Reset tokenizer so that nextToken() starts from the beginning.
Definition: ElemNumber.hpp:461
xalanc::DecimalToRoman
Structure to help in converting integrals to roman numerals.
Definition: DecimalToRoman.hpp:39
xalanc::ElemNumber::eLevel
eLevel
Definition: ElemNumber.hpp:65
CountersTable.hpp
xalanc::length
XalanDOMString::size_type length(const XalanDOMString &theString)
Get the length of a XalanDOMString.
Definition: DOMStringHelper.hpp:235
xalanc::StylesheetConstructionContext
Definition: StylesheetConstructionContext.hpp:83
ElemTemplateElement.hpp
xalanc::ElemNumber::eSingle
@ eSingle
Definition: ElemNumber.hpp:67
xalanc::XalanNumberingResourceBundle
Definition: XalanNumberingResourceBundle.hpp:41
xalanc::ElemNumber::getID
unsigned long getID() const
Definition: ElemNumber.hpp:131
NodeRefListBase.hpp
XSLTDefinitions.hpp
xalanc::Stylesheet
This class represents the base stylesheet or an "import" stylesheet.
Definition: Stylesheet.hpp:86
xalanc::CountersTable
<meta name="usage" content="internal"> This is a table of counters, keyed by ElemNumber objects,...
Definition: CountersTable.hpp:157
xalanc::ElemNumber::NumberFormatStringTokenizer::size_type
XalanDOMString::size_type size_type
Definition: ElemNumber.hpp:440
xalanc::XalanDOMString::size_type
XalanSize_t size_type
Definition: XalanDOMString.hpp:57
xalanc::NodeRefListBase::size_type
XalanSize_t size_type
Definition: NodeRefListBase.hpp:53
xalanc::XalanDOMString
Definition: XalanDOMString.hpp:45
xalanc::AVT
Class to hold an Attribute Value Template.
Definition: AVT.hpp:58
xalanc::ElemNumber
Definition: ElemNumber.hpp:59