KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > style > XSLSort


1 package com.icl.saxon.style;
2 import com.icl.saxon.tree.AttributeCollection;
3 import com.icl.saxon.*;
4 import com.icl.saxon.om.*;
5 import com.icl.saxon.expr.*;
6 import com.icl.saxon.sort.*;
7 import javax.xml.transform.*;
8 import java.io.*;
9 import java.util.*;
10
11 /**
12 * An xsl:sort element in the stylesheet.<BR>
13 */

14
15 public class XSLSort extends StyleElement {
16
17     private SortKeyDefinition sortKeyDefinition;
18     
19     public void prepareAttributes() throws TransformerConfigurationException {
20
21         Expression select;
22         Expression order;
23         Expression dataType;
24         Expression caseOrder;
25         Expression lang;
26
27         StandardNames sn = getStandardNames();
28         AttributeCollection atts = getAttributeList();
29         
30         String JavaDoc selectAtt = null;
31         String JavaDoc orderAtt = null;
32         String JavaDoc dataTypeAtt = null;
33         String JavaDoc caseOrderAtt = null;
34         String JavaDoc langAtt = null;
35                 
36         for (int a=0; a<atts.getLength(); a++) {
37             int nc = atts.getNameCode(a);
38             int f = nc & 0xfffff;
39             if (f==sn.SELECT) {
40                 selectAtt = atts.getValue(a);
41             } else if (f==sn.ORDER) {
42                 orderAtt = atts.getValue(a);
43             } else if (f==sn.DATA_TYPE) {
44                 dataTypeAtt = atts.getValue(a);
45             } else if (f==sn.CASE_ORDER) {
46                 caseOrderAtt = atts.getValue(a);
47             } else if (f==sn.LANG) {
48                 langAtt = atts.getValue(a);
49             } else {
50                 checkUnknownAttribute(nc);
51             }
52         }
53
54         if (selectAtt==null) {
55             select = new ContextNodeExpression();
56         } else {
57             select = makeExpression(selectAtt);
58         }
59
60         if (orderAtt == null) {
61             order = new StringValue("ascending");
62         } else {
63             order = makeAttributeValueTemplate(orderAtt);
64         }
65
66         if (dataTypeAtt == null) {
67             dataType = new StringValue("text");
68         } else {
69             dataType = makeAttributeValueTemplate(dataTypeAtt);
70         }
71
72         if (caseOrderAtt == null) {
73             caseOrder = new StringValue("#default");
74         } else {
75             caseOrder = makeAttributeValueTemplate(caseOrderAtt);
76         }
77
78         if (langAtt == null) {
79             lang = new StringValue(Locale.getDefault().getLanguage());
80         } else {
81             lang = makeAttributeValueTemplate(langAtt);
82         }
83
84         try {
85             sortKeyDefinition = new SortKeyDefinition();
86             sortKeyDefinition.setSortKey(select);
87             sortKeyDefinition.setOrder(order);
88             sortKeyDefinition.setDataType(dataType);
89             sortKeyDefinition.setCaseOrder(caseOrder);
90             sortKeyDefinition.setLanguage(lang);
91             sortKeyDefinition.setStaticContext(new ExpressionContext(this));
92             sortKeyDefinition.bindComparer();
93         } catch (XPathException err) {
94             compileError(err);
95         }
96     }
97
98     public void validate() throws TransformerConfigurationException {
99         NodeInfo parent = (NodeInfo)getParentNode();
100         if (!((parent instanceof XSLApplyTemplates) ||
101                  (parent instanceof XSLForEach) ||
102                  (parent instanceof SAXONGroup) // inelegant, since saxon:group is an extension!
103
)) {
104             compileError("xsl:sort must be child of xsl:apply-templates or xsl:for-each");
105         }
106     }
107
108     public void process(Context context) throws TransformerException
109     {}
110
111     public SortKeyDefinition getSortKeyDefinition() {
112         return sortKeyDefinition;
113     }
114
115 }
116
117 //
118
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
119
// you may not use this file except in compliance with the License. You may obtain a copy of the
120
// License at http://www.mozilla.org/MPL/
121
//
122
// Software distributed under the License is distributed on an "AS IS" basis,
123
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
124
// See the License for the specific language governing rights and limitations under the License.
125
//
126
// The Original Code is: all this file.
127
//
128
// The Initial Developer of the Original Code is
129
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
130
//
131
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
132
//
133
// Contributor(s): none.
134
//
135
Popular Tags