1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.xalan.internal.xsltc.dom; 23 24 import com.sun.org.apache.xalan.internal.xsltc.DOM; 25 import com.sun.org.apache.xalan.internal.xsltc.Translet; 26 import com.sun.org.apache.xalan.internal.xsltc.TransletException; 27 import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet; 28 import com.sun.org.apache.xml.internal.utils.LocaleUtility; 29 import com.sun.org.apache.xalan.internal.utils.ObjectFactory; 30 import java.util.Locale; 31 import java.text.Collator; 32 33 public class NodeSortRecordFactory { 34 35 private static int DESCENDING = "descending".length(); 36 private static int NUMBER = "number".length(); 37 38 private final DOM _dom; 39 private final String _className; 40 private Class _class; 41 private SortSettings _sortSettings; 42 43 /** 44 * 45 */ 46 protected Collator _collator; 47 48 /** 49 * Creates a NodeSortRecord producing object. The DOM specifies which tree 50 * to get the nodes to sort from, the class name specifies what auxillary 51 * class to use to sort the nodes (this class is generated by the Sort 52 * class), and the translet parameter is needed for methods called by 53 * this object. 54 * 55 * @deprecated This constructor is no longer used in generated code. It 56 * exists only for backwards compatibility. 57 */ 58 public NodeSortRecordFactory(DOM dom, String className, Translet translet, 59 String order[], String type[]) 60 throws TransletException 61 { 62 this(dom, className, translet, order, type, null, null); 63 } 64 65 /** 66 * Creates a NodeSortRecord producing object. The DOM specifies which tree 67 * to get the nodes to sort from, the class name specifies what auxillary 68 * class to use to sort the nodes (this class is generated by the Sort 69 * class), and the translet parameter is needed for methods called by 70 * this object. 71 */ 72 public NodeSortRecordFactory(DOM dom, String className, Translet translet, 73 String order[], String type[], String lang[], 74 String caseOrder[]) 75 throws TransletException 76 { 77 try { 78 _dom = dom; 79 _className = className; 80 // This should return a Class definition if using TrAX 81 _class = translet.getAuxiliaryClass(className); 82 // This code is only run when the native API is used 83 if (_class == null) { 84 _class = ObjectFactory.findProviderClass(className, true); 85 } 86 87 int levels = order.length; 88 int[] iOrder = new int[levels]; 89 int[] iType = new int[levels]; 90 for (int i = 0; i < levels; i++) { 91 if (order[i].length() == DESCENDING) { 92 iOrder[i] = NodeSortRecord.COMPARE_DESCENDING; 93 } 94 if (type[i].length() == NUMBER) { 95 iType[i] = NodeSortRecord.COMPARE_NUMERIC; 96 } 97 } 98 99 // Old NodeSortRecordFactory constructor had no lang or case_order 100 // arguments. Provide default values in that case for binary 101 // compatibility. 102 String[] emptyStringArray = null; 103 if (lang == null || caseOrder == null) { 104 int numSortKeys = order.length; 105 emptyStringArray = new String[numSortKeys]; 106 107 // Set up array of zero-length strings as default values 108 // of lang and case_order 109 for (int i = 0; i < numSortKeys; i++) { 110 emptyStringArray[i] = ""; 111 } 112 } 113 114 if (lang == null) { 115 lang = emptyStringArray; 116 } 117 if (caseOrder == null) { 118 caseOrder = emptyStringArray; 119 } 120 121 final int length = lang.length; 122 Locale[] locales = new Locale[length]; 123 Collator[] collators = new Collator[length]; 124 for (int i = 0; i< length; i++){ 125 locales[i] = LocaleUtility.langToLocale(lang[i]); 126 collators[i] = Collator.getInstance(locales[i]); 127 } 128 129 _sortSettings = new SortSettings((AbstractTranslet) translet, 130 iOrder, iType, locales, collators, 131 caseOrder); 132 } catch (ClassNotFoundException e) { 133 throw new TransletException(e); 134 } 135 } 136 137 138 139 /** 140 * Create an instance of a sub-class of NodeSortRecord. The name of this 141 * sub-class is passed to us in the constructor. 142 */ 143 public NodeSortRecord makeNodeSortRecord(int node, int last) 144 throws ExceptionInInitializerError, 145 LinkageError, 146 IllegalAccessException, 147 InstantiationException, 148 SecurityException, 149 TransletException { 150 151 final NodeSortRecord sortRecord = 152 (NodeSortRecord)_class.newInstance(); 153 sortRecord.initialize(node, last, _dom, _sortSettings); 154 return sortRecord; 155 } 156 157 public String getClassName() { 158 return _className; 159 } 160 161 private final void setLang(final String lang[]){ 162 163 } 164 }