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 ; 9 10 11 14 15 public class XSLOutputCharacter extends StyleElement { 16 17 private int codepoint = -1; 18 private String 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 f = getNamePool().getClarkName(nc); 28 if (f==StandardNames.CHARACTER) { 29 String s = atts.getValue(a); 30 switch (s.length()) { 31 case 0: 32 compileError("character attribute must not be zero-length", "XTSE0020"); 33 codepoint = 256; 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; } 46 break; 47 default: 48 compileError("character attribute must be a single XML character", "XTSE0020"); 49 codepoint = 256; } 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 getReplacementString() { 84 return replacementString; 85 } 86 87 } 88 89 | Popular Tags |