KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > transformer > NodeSortKey


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: NodeSortKey.java,v 1.13 2004/02/16 20:41:30 minchau Exp $
18  */

19 package org.apache.xalan.transformer;
20
21 import java.text.Collator JavaDoc;
22 import java.util.Locale JavaDoc;
23
24 import org.apache.xalan.res.XSLTErrorResources;
25 import org.apache.xpath.XPath;
26
27 /**
28  * Data structure for use by the NodeSorter class.
29  * @xsl.usage internal
30  */

31 class NodeSortKey
32 {
33
34   /** Select pattern for this sort key */
35   XPath m_selectPat;
36
37   /** Flag indicating whether to treat thee result as a number */
38   boolean m_treatAsNumbers;
39
40   /** Flag indicating whether to sort in descending order */
41   boolean m_descending;
42
43   /** Flag indicating by case */
44   boolean m_caseOrderUpper;
45
46   /** Collator instance */
47   Collator JavaDoc m_col;
48
49   /** Locale we're in */
50   Locale JavaDoc m_locale;
51
52   /** Prefix resolver to use */
53   org.apache.xml.utils.PrefixResolver m_namespaceContext;
54
55   /** Transformer instance */
56   TransformerImpl m_processor; // needed for error reporting.
57

58   /**
59    * Constructor NodeSortKey
60    *
61    *
62    * @param transformer non null transformer instance
63    * @param selectPat Select pattern for this key
64    * @param treatAsNumbers Flag indicating whether the result will be a number
65    * @param descending Flag indicating whether to sort in descending order
66    * @param langValue Lang value to use to get locale
67    * @param caseOrderUpper Flag indicating whether case is relevant
68    * @param namespaceContext Prefix resolver
69    *
70    * @throws javax.xml.transform.TransformerException
71    */

72   NodeSortKey(
73           TransformerImpl transformer, XPath selectPat, boolean treatAsNumbers,
74           boolean descending, String JavaDoc langValue, boolean caseOrderUpper,
75           org.apache.xml.utils.PrefixResolver namespaceContext)
76             throws javax.xml.transform.TransformerException JavaDoc
77   {
78
79     m_processor = transformer;
80     m_namespaceContext = namespaceContext;
81     m_selectPat = selectPat;
82     m_treatAsNumbers = treatAsNumbers;
83     m_descending = descending;
84     m_caseOrderUpper = caseOrderUpper;
85
86     if (null != langValue && m_treatAsNumbers == false)
87     {
88       // See http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2851
89
// The constructor of Locale is defined as
90
// public Locale(String language, String country)
91
// with
92
// language - lowercase two-letter ISO-639 code
93
// country - uppercase two-letter ISO-3166 code
94
// a) language must be provided as a lower-case ISO-code
95
// instead of an upper-case code
96
// b) country must be provided as an ISO-code
97
// instead of a full localized country name (e.g. "France")
98
m_locale = new Locale JavaDoc(langValue.toLowerCase(),
99                   Locale.getDefault().getCountry());
100                   
101       // (old, before bug report 2851).
102
// m_locale = new Locale(langValue.toUpperCase(),
103
// Locale.getDefault().getDisplayCountry());
104

105       if (null == m_locale)
106       {
107
108         // m_processor.warn("Could not find locale for <sort xml:lang="+langValue);
109
m_locale = Locale.getDefault();
110       }
111     }
112     else
113     {
114       m_locale = Locale.getDefault();
115     }
116
117     m_col = Collator.getInstance(m_locale);
118
119     if (null == m_col)
120     {
121       m_processor.getMsgMgr().warn(null, XSLTErrorResources.WG_CANNOT_FIND_COLLATOR,
122                                    new Object JavaDoc[]{ langValue }); //"Could not find Collator for <sort xml:lang="+langValue);
123

124       m_col = Collator.getInstance();
125     }
126   }
127 }
128
Popular Tags