KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.icl.saxon.style;
2 import com.icl.saxon.tree.AttributeCollection;
3 import com.icl.saxon.*;
4 import com.icl.saxon.om.Name;
5 import com.icl.saxon.om.NamespaceException;
6 import com.icl.saxon.pattern.Pattern;
7 import com.icl.saxon.expr.Expression;
8 import com.icl.saxon.expr.XPathException;
9 import javax.xml.transform.*;
10
11 import java.util.*;
12
13 /**
14 * Handler for xsl:key elements in stylesheet.<BR>
15 */

16
17 public class XSLKey extends StyleElement {
18
19     private int fingerprint; // the fingerprint of the key name
20
private Pattern match;
21     private Expression use;
22
23     public void prepareAttributes() throws TransformerConfigurationException {
24
25         String JavaDoc nameAtt = null;
26         String JavaDoc matchAtt = null;
27         String JavaDoc useAtt = null;
28
29         StandardNames sn = getStandardNames();
30         AttributeCollection atts = getAttributeList();
31         
32         for (int a=0; a<atts.getLength(); a++) {
33             int nc = atts.getNameCode(a);
34             int f = nc & 0xfffff;
35             if (f==sn.NAME) {
36                 nameAtt = atts.getValue(a);
37             } else if (f==sn.USE) {
38                 useAtt = atts.getValue(a);
39             } else if (f==sn.MATCH) {
40                 matchAtt = atts.getValue(a);
41             } else {
42                 checkUnknownAttribute(nc);
43             }
44         }
45
46         if (nameAtt==null) {
47             reportAbsence("name");
48             return;
49         }
50         if (!Name.isQName(nameAtt)) {
51             compileError("Name of key must be a valid QName");
52             return;
53         }
54         try {
55             fingerprint = makeNameCode(nameAtt, false) & 0xfffff;
56         } catch (NamespaceException err) {
57             compileError(err.getMessage());
58         }
59         
60         if (matchAtt==null) {
61             reportAbsence("match");
62         } else {
63             match = makePattern(matchAtt);
64         }
65         
66         if (useAtt==null) {
67             reportAbsence("use");
68         } else {
69             use = makeExpression(useAtt);
70         }
71     }
72
73     public void validate() throws TransformerConfigurationException {
74         checkTopLevel();
75         checkEmpty();
76     }
77
78     public void preprocess() throws TransformerConfigurationException
79     {
80         KeyManager km = getPrincipalStyleSheet().getKeyManager();
81         km.setKeyDefinition(new KeyDefinition(fingerprint, match, use));
82     }
83
84     public void process(Context context) throws TransformerException
85     {}
86
87     /**
88     * Disallow variable references in the match and use patterns
89     */

90
91     public Binding bindVariable(int fingerprint) throws XPathException {
92         throw new XPathException("The expressions in xsl:key may not contain references to variables");
93     }
94
95 }
96 //
97
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
98
// you may not use this file except in compliance with the License. You may obtain a copy of the
99
// License at http://www.mozilla.org/MPL/
100
//
101
// Software distributed under the License is distributed on an "AS IS" basis,
102
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
103
// See the License for the specific language governing rights and limitations under the License.
104
//
105
// The Original Code is: all this file.
106
//
107
// The Initial Developer of the Original Code is
108
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
109
//
110
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
111
//
112
// Contributor(s): none.
113
//
114
Popular Tags