001: package net.sf.saxon.style;
002:
003: import net.sf.saxon.expr.Expression;
004: import net.sf.saxon.instruct.Executable;
005: import net.sf.saxon.om.AttributeCollection;
006: import net.sf.saxon.om.XMLChar;
007: import net.sf.saxon.trans.XPathException;
008:
009: import javax.xml.transform.TransformerConfigurationException;
010:
011: /**
012: * An xsl:output-character element in the stylesheet. <br>
013: */
014:
015: public class XSLOutputCharacter extends StyleElement {
016:
017: private int codepoint = -1;
018: // the character to be substituted, as a Unicode codepoint (may be > 65535)
019: private String replacementString = null;
020:
021: public void prepareAttributes() throws XPathException {
022:
023: AttributeCollection atts = getAttributeList();
024:
025: for (int a = 0; a < atts.getLength(); a++) {
026: int nc = atts.getNameCode(a);
027: String f = getNamePool().getClarkName(nc);
028: if (f == StandardNames.CHARACTER) {
029: String s = atts.getValue(a);
030: switch (s.length()) {
031: case 0:
032: compileError(
033: "character attribute must not be zero-length",
034: "XTSE0020");
035: codepoint = 256; // for error recovery
036: break;
037: case 1:
038: codepoint = s.charAt(0);
039: break;
040: case 2:
041: if (XMLChar.isHighSurrogate(s.charAt(0))
042: && XMLChar.isLowSurrogate(s.charAt(1))) {
043: codepoint = XMLChar.supplemental(s.charAt(0), s
044: .charAt(1));
045: } else {
046: compileError(
047: "character attribute must be a single XML character",
048: "XTSE0020");
049: codepoint = 256; // for error recovery
050: }
051: break;
052: default:
053: compileError(
054: "character attribute must be a single XML character",
055: "XTSE0020");
056: codepoint = 256; // for error recovery
057: }
058: } else if (f == StandardNames.STRING) {
059: replacementString = atts.getValue(a);
060: } else {
061: checkUnknownAttribute(nc);
062: }
063: }
064: if (codepoint == -1) {
065: reportAbsence("character");
066: return;
067: }
068:
069: if (replacementString == null) {
070: reportAbsence("string");
071: return;
072: }
073:
074: }
075:
076: public void validate() throws XPathException {
077: if (!(getParent() instanceof XSLCharacterMap)) {
078: compileError(
079: "xsl:output-character may appear only as a child of xsl:character-map",
080: "XTSE0010");
081: }
082: ;
083: }
084:
085: public Expression compile(Executable exec) throws XPathException {
086: return null;
087: }
088:
089: public int getCodePoint() {
090: return codepoint;
091: }
092:
093: public String getReplacementString() {
094: return replacementString;
095: }
096:
097: }
098:
099: //
100: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
101: // you may not use this file except in compliance with the License. You may obtain a copy of the
102: // License at http://www.mozilla.org/MPL/
103: //
104: // Software distributed under the License is distributed on an "AS IS" basis,
105: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
106: // See the License for the specific language governing rights and limitations under the License.
107: //
108: // The Original Code is: all this file.
109: //
110: // The Initial Developer of the Original Code is Michael H. Kay
111: //
112: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
113: //
114: // Contributor(s): none.
115: //
|