001: /*
002: * Copyright 1999-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: /*
017: * $Id: NodeSortKey.java,v 1.13 2004/02/16 20:41:30 minchau Exp $
018: */
019: package org.apache.xalan.transformer;
020:
021: import java.text.Collator;
022: import java.util.Locale;
023:
024: import org.apache.xalan.res.XSLTErrorResources;
025: import org.apache.xpath.XPath;
026:
027: /**
028: * Data structure for use by the NodeSorter class.
029: * @xsl.usage internal
030: */
031: class NodeSortKey {
032:
033: /** Select pattern for this sort key */
034: XPath m_selectPat;
035:
036: /** Flag indicating whether to treat thee result as a number */
037: boolean m_treatAsNumbers;
038:
039: /** Flag indicating whether to sort in descending order */
040: boolean m_descending;
041:
042: /** Flag indicating by case */
043: boolean m_caseOrderUpper;
044:
045: /** Collator instance */
046: Collator m_col;
047:
048: /** Locale we're in */
049: Locale m_locale;
050:
051: /** Prefix resolver to use */
052: org.apache.xml.utils.PrefixResolver m_namespaceContext;
053:
054: /** Transformer instance */
055: TransformerImpl m_processor; // needed for error reporting.
056:
057: /**
058: * Constructor NodeSortKey
059: *
060: *
061: * @param transformer non null transformer instance
062: * @param selectPat Select pattern for this key
063: * @param treatAsNumbers Flag indicating whether the result will be a number
064: * @param descending Flag indicating whether to sort in descending order
065: * @param langValue Lang value to use to get locale
066: * @param caseOrderUpper Flag indicating whether case is relevant
067: * @param namespaceContext Prefix resolver
068: *
069: * @throws javax.xml.transform.TransformerException
070: */
071: NodeSortKey(TransformerImpl transformer, XPath selectPat,
072: boolean treatAsNumbers, boolean descending,
073: String langValue, boolean caseOrderUpper,
074: org.apache.xml.utils.PrefixResolver namespaceContext)
075: throws javax.xml.transform.TransformerException {
076:
077: m_processor = transformer;
078: m_namespaceContext = namespaceContext;
079: m_selectPat = selectPat;
080: m_treatAsNumbers = treatAsNumbers;
081: m_descending = descending;
082: m_caseOrderUpper = caseOrderUpper;
083:
084: if (null != langValue && m_treatAsNumbers == false) {
085: // See http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2851
086: // The constructor of Locale is defined as
087: // public Locale(String language, String country)
088: // with
089: // language - lowercase two-letter ISO-639 code
090: // country - uppercase two-letter ISO-3166 code
091: // a) language must be provided as a lower-case ISO-code
092: // instead of an upper-case code
093: // b) country must be provided as an ISO-code
094: // instead of a full localized country name (e.g. "France")
095: m_locale = new Locale(langValue.toLowerCase(), Locale
096: .getDefault().getCountry());
097:
098: // (old, before bug report 2851).
099: // m_locale = new Locale(langValue.toUpperCase(),
100: // Locale.getDefault().getDisplayCountry());
101:
102: if (null == m_locale) {
103:
104: // m_processor.warn("Could not find locale for <sort xml:lang="+langValue);
105: m_locale = Locale.getDefault();
106: }
107: } else {
108: m_locale = Locale.getDefault();
109: }
110:
111: m_col = Collator.getInstance(m_locale);
112:
113: if (null == m_col) {
114: m_processor.getMsgMgr().warn(null,
115: XSLTErrorResources.WG_CANNOT_FIND_COLLATOR,
116: new Object[] { langValue }); //"Could not find Collator for <sort xml:lang="+langValue);
117:
118: m_col = Collator.getInstance();
119: }
120: }
121: }
|