1 16 19 20 package org.apache.xalan.xsltc.dom; 21 22 import org.apache.xalan.xsltc.DOM; 23 import org.apache.xalan.xsltc.Translet; 24 import org.apache.xalan.xsltc.TransletException; 25 import org.apache.xalan.xsltc.runtime.AbstractTranslet; 26 import org.apache.xml.utils.LocaleUtility; 27 import java.util.Locale ; 28 import java.text.Collator ; 29 30 public class NodeSortRecordFactory { 31 32 private static int DESCENDING = "descending".length(); 33 private static int NUMBER = "number".length(); 34 35 private final DOM _dom; 36 private final String _className; 37 private Class _class; 38 private SortSettings _sortSettings; 39 40 43 protected Collator _collator; 44 45 55 public NodeSortRecordFactory(DOM dom, String className, Translet translet, 56 String order[], String type[]) 57 throws TransletException 58 { 59 this(dom, className, translet, order, type, null, null); 60 } 61 62 69 public NodeSortRecordFactory(DOM dom, String className, Translet translet, 70 String order[], String type[], String lang[], 71 String caseOrder[]) 72 throws TransletException 73 { 74 try { 75 _dom = dom; 76 _className = className; 77 _class = translet.getAuxiliaryClass(className); 79 if (_class == null) { 81 _class = ObjectFactory.findProviderClass( 82 className, ObjectFactory.findClassLoader(), true); 83 } 84 85 int levels = order.length; 86 int[] iOrder = new int[levels]; 87 int[] iType = new int[levels]; 88 for (int i = 0; i < levels; i++) { 89 if (order[i].length() == DESCENDING) { 90 iOrder[i] = NodeSortRecord.COMPARE_DESCENDING; 91 } 92 if (type[i].length() == NUMBER) { 93 iType[i] = NodeSortRecord.COMPARE_NUMERIC; 94 } 95 } 96 97 String [] emptyStringArray = null; 101 if (lang == null || caseOrder == null) { 102 int numSortKeys = order.length; 103 emptyStringArray = new String [numSortKeys]; 104 105 for (int i = 0; i < numSortKeys; i++) { 108 emptyStringArray[i] = ""; 109 } 110 } 111 112 if (lang == null) { 113 lang = emptyStringArray; 114 } 115 if (caseOrder == null) { 116 caseOrder = emptyStringArray; 117 } 118 119 final int length = lang.length; 120 Locale [] locales = new Locale [length]; 121 Collator [] collators = new Collator [length]; 122 for (int i = 0; i< length; i++){ 123 locales[i] = LocaleUtility.langToLocale(lang[i]); 124 collators[i] = Collator.getInstance(locales[i]); 125 } 126 127 _sortSettings = new SortSettings((AbstractTranslet) translet, 128 iOrder, iType, locales, collators, 129 caseOrder); 130 } catch (ClassNotFoundException e) { 131 throw new TransletException(e); 132 } 133 } 134 135 136 137 141 public NodeSortRecord makeNodeSortRecord(int node, int last) 142 throws ExceptionInInitializerError , 143 LinkageError , 144 IllegalAccessException , 145 InstantiationException , 146 SecurityException , 147 TransletException { 148 149 final NodeSortRecord sortRecord = 150 (NodeSortRecord)_class.newInstance(); 151 sortRecord.initialize(node, last, _dom, _sortSettings); 152 return sortRecord; 153 } 154 155 public String getClassName() { 156 return _className; 157 } 158 159 private final void setLang(final String lang[]){ 160 161 } 162 } 163 | Popular Tags |