• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /*
19  * $Id: NodeSortKey.java 468645 2006-10-28 06:57:24Z minchau $
20  */
21 package org.apache.xalan.transformer;
22 
23 import java.text.Collator;
24 import java.util.Locale;
25 
26 import org.apache.xalan.res.XSLTErrorResources;
27 import org.apache.xpath.XPath;
28 
29 /**
30  * Data structure for use by the NodeSorter class.
31  * @xsl.usage internal
32  */
33 class NodeSortKey
34 {
35 
36   /** Select pattern for this sort key          */
37   XPath m_selectPat;
38 
39   /** Flag indicating whether to treat thee result as a number     */
40   boolean m_treatAsNumbers;
41 
42   /** Flag indicating whether to sort in descending order      */
43   boolean m_descending;
44 
45   /** Flag indicating by case          */
46   boolean m_caseOrderUpper;
47 
48   /** Collator instance          */
49   Collator m_col;
50 
51   /** Locale we're in          */
52   Locale m_locale;
53 
54   /** Prefix resolver to use          */
55   org.apache.xml.utils.PrefixResolver m_namespaceContext;
56 
57   /** Transformer instance          */
58   TransformerImpl m_processor;  // needed for error reporting.
59 
60   /**
61    * Constructor NodeSortKey
62    *
63    *
64    * @param transformer non null transformer instance
65    * @param selectPat Select pattern for this key
66    * @param treatAsNumbers Flag indicating whether the result will be a number
67    * @param descending Flag indicating whether to sort in descending order
68    * @param langValue Lang value to use to get locale
69    * @param caseOrderUpper Flag indicating whether case is relevant
70    * @param namespaceContext Prefix resolver
71    *
72    * @throws javax.xml.transform.TransformerException
73    */
NodeSortKey( TransformerImpl transformer, XPath selectPat, boolean treatAsNumbers, boolean descending, String langValue, boolean caseOrderUpper, org.apache.xml.utils.PrefixResolver namespaceContext)74   NodeSortKey(
75           TransformerImpl transformer, XPath selectPat, boolean treatAsNumbers,
76           boolean descending, String langValue, boolean caseOrderUpper,
77           org.apache.xml.utils.PrefixResolver namespaceContext)
78             throws javax.xml.transform.TransformerException
79   {
80 
81     m_processor = transformer;
82     m_namespaceContext = namespaceContext;
83     m_selectPat = selectPat;
84     m_treatAsNumbers = treatAsNumbers;
85     m_descending = descending;
86     m_caseOrderUpper = caseOrderUpper;
87 
88     if (null != langValue && m_treatAsNumbers == false)
89     {
90       // See http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2851
91       // The constructor of Locale is defined as
92       //   public Locale(String language, String country)
93       // with
94       //   language - lowercase two-letter ISO-639 code
95       //   country - uppercase two-letter ISO-3166 code
96       // a) language must be provided as a lower-case ISO-code
97       //    instead of an upper-case code
98       // b) country must be provided as an ISO-code
99       //    instead of a full localized country name (e.g. "France")
100       m_locale = new Locale(langValue.toLowerCase(),
101                   Locale.getDefault().getCountry());
102 
103       // (old, before bug report 2851).
104       //  m_locale = new Locale(langValue.toUpperCase(),
105       //                        Locale.getDefault().getDisplayCountry());
106 
107       if (null == m_locale)
108       {
109 
110         // m_processor.warn("Could not find locale for <sort xml:lang="+langValue);
111         m_locale = Locale.getDefault();
112       }
113     }
114     else
115     {
116       m_locale = Locale.getDefault();
117     }
118 
119     m_col = Collator.getInstance(m_locale);
120 
121     if (null == m_col)
122     {
123       m_processor.getMsgMgr().warn(null, XSLTErrorResources.WG_CANNOT_FIND_COLLATOR,
124                                    new Object[]{ langValue });  //"Could not find Collator for <sort xml:lang="+langValue);
125 
126       m_col = Collator.getInstance();
127     }
128   }
129 }
130