KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > style > XSLOutputCharacter


1 package net.sf.saxon.style;
2 import net.sf.saxon.expr.Expression;
3 import net.sf.saxon.instruct.Executable;
4 import net.sf.saxon.om.AttributeCollection;
5 import net.sf.saxon.om.XMLChar;
6 import net.sf.saxon.trans.XPathException;
7
8 import javax.xml.transform.TransformerConfigurationException JavaDoc;
9
10
11 /**
12 * An xsl:output-character element in the stylesheet. <br>
13 */

14
15 public class XSLOutputCharacter extends StyleElement {
16
17     private int codepoint = -1;
18         // the character to be substituted, as a Unicode codepoint (may be > 65535)
19
private String JavaDoc replacementString = null;
20
21     public void prepareAttributes() throws XPathException {
22
23         AttributeCollection atts = getAttributeList();
24
25         for (int a=0; a<atts.getLength(); a++) {
26             int nc = atts.getNameCode(a);
27             String JavaDoc f = getNamePool().getClarkName(nc);
28             if (f==StandardNames.CHARACTER) {
29                 String JavaDoc s = atts.getValue(a);
30                 switch (s.length()) {
31                     case 0:
32                         compileError("character attribute must not be zero-length", "XTSE0020");
33                         codepoint = 256; // for error recovery
34
break;
35                     case 1:
36                         codepoint = s.charAt(0);
37                         break;
38                     case 2:
39                         if (XMLChar.isHighSurrogate(s.charAt(0)) &&
40                                 XMLChar.isLowSurrogate(s.charAt(1))) {
41                             codepoint = XMLChar.supplemental(s.charAt(0), s.charAt(1));
42                         } else {
43                             compileError("character attribute must be a single XML character", "XTSE0020");
44                             codepoint = 256; // for error recovery
45
}
46                         break;
47                     default:
48                         compileError("character attribute must be a single XML character", "XTSE0020");
49                         codepoint = 256; // for error recovery
50
}
51             } else if (f==StandardNames.STRING) {
52                 replacementString = atts.getValue(a);
53             } else {
54                 checkUnknownAttribute(nc);
55             }
56         }
57         if (codepoint==-1) {
58             reportAbsence("character");
59             return;
60         }
61
62         if (replacementString==null) {
63             reportAbsence("string");
64             return;
65         }
66
67     }
68
69     public void validate() throws XPathException {
70         if (!(getParent() instanceof XSLCharacterMap)) {
71             compileError("xsl:output-character may appear only as a child of xsl:character-map", "XTSE0010");
72         };
73     }
74
75     public Expression compile(Executable exec) throws XPathException {
76         return null;
77     }
78
79     public int getCodePoint() {
80         return codepoint;
81     }
82
83     public String JavaDoc getReplacementString() {
84         return replacementString;
85     }
86
87 }
88
89 //
90
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
91
// you may not use this file except in compliance with the License. You may obtain a copy of the
92
// License at http://www.mozilla.org/MPL/
93
//
94
// Software distributed under the License is distributed on an "AS IS" basis,
95
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
96
// See the License for the specific language governing rights and limitations under the License.
97
//
98
// The Original Code is: all this file.
99
//
100
// The Initial Developer of the Original Code is Michael H. Kay
101
//
102
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
103
//
104
// Contributor(s): none.
105
//
106
Popular Tags