1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xalan.transformer;
  58. import java.util.Locale;
  59. import org.apache.xpath.XPath;
  60. import java.text.Collator;
  61. import org.apache.xalan.res.XSLTErrorResources;
  62. /**
  63. * <meta name="usage" content="internal"/>
  64. * Data structure for use by the NodeSorter class.
  65. */
  66. class NodeSortKey
  67. {
  68. /** Select pattern for this sort key */
  69. XPath m_selectPat;
  70. /** Flag indicating whether to treat thee result as a number */
  71. boolean m_treatAsNumbers;
  72. /** Flag indicating whether to sort in descending order */
  73. boolean m_descending;
  74. /** Flag indicating by case */
  75. boolean m_caseOrderUpper;
  76. /** Collator instance */
  77. Collator m_col;
  78. /** Locale we're in */
  79. Locale m_locale;
  80. /** Prefix resolver to use */
  81. org.apache.xml.utils.PrefixResolver m_namespaceContext;
  82. /** Transformer instance */
  83. TransformerImpl m_processor; // needed for error reporting.
  84. /**
  85. * Constructor NodeSortKey
  86. *
  87. *
  88. * @param transformer non null transformer instance
  89. * @param selectPat Select pattern for this key
  90. * @param treatAsNumbers Flag indicating whether the result will be a number
  91. * @param descending Flag indicating whether to sort in descending order
  92. * @param langValue Lang value to use to get locale
  93. * @param caseOrderUpper Flag indicating whether case is relevant
  94. * @param namespaceContext Prefix resolver
  95. *
  96. * @throws javax.xml.transform.TransformerException
  97. */
  98. NodeSortKey(
  99. TransformerImpl transformer, XPath selectPat, boolean treatAsNumbers,
  100. boolean descending, String langValue, boolean caseOrderUpper,
  101. org.apache.xml.utils.PrefixResolver namespaceContext)
  102. throws javax.xml.transform.TransformerException
  103. {
  104. m_processor = transformer;
  105. m_namespaceContext = namespaceContext;
  106. m_selectPat = selectPat;
  107. m_treatAsNumbers = treatAsNumbers;
  108. m_descending = descending;
  109. m_caseOrderUpper = caseOrderUpper;
  110. if (null != langValue && m_treatAsNumbers == false)
  111. {
  112. // See http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2851
  113. // The constructor of Locale is defined as
  114. // public Locale(String language, String country)
  115. // with
  116. // language - lowercase two-letter ISO-639 code
  117. // country - uppercase two-letter ISO-3166 code
  118. // a) language must be provided as a lower-case ISO-code
  119. // instead of an upper-case code
  120. // b) country must be provided as an ISO-code
  121. // instead of a full localized country name (e.g. "France")
  122. m_locale = new Locale(langValue.toLowerCase(),
  123. Locale.getDefault().getCountry());
  124. // (old, before bug report 2851).
  125. // m_locale = new Locale(langValue.toUpperCase(),
  126. // Locale.getDefault().getDisplayCountry());
  127. if (null == m_locale)
  128. {
  129. // m_processor.warn("Could not find locale for <sort xml:lang="+langValue);
  130. m_locale = Locale.getDefault();
  131. }
  132. }
  133. else
  134. {
  135. m_locale = Locale.getDefault();
  136. }
  137. m_col = Collator.getInstance(m_locale);
  138. if (null == m_col)
  139. {
  140. m_processor.getMsgMgr().warn(null, XSLTErrorResources.WG_CANNOT_FIND_COLLATOR,
  141. new Object[]{ langValue }); //"Could not find Collator for <sort xml:lang="+langValue);
  142. m_col = Collator.getInstance();
  143. }
  144. }
  145. }