1 package net.sf.saxon.style; 2 import net.sf.saxon.Configuration; 3 import net.sf.saxon.Err; 4 import net.sf.saxon.type.AtomicType; 5 import net.sf.saxon.type.BuiltInAtomicType; 6 import net.sf.saxon.expr.VariableDeclaration; 7 import net.sf.saxon.functions.FunctionLibrary; 8 import net.sf.saxon.instruct.LocationMap; 9 import net.sf.saxon.om.*; 10 import net.sf.saxon.trans.StaticError; 11 import net.sf.saxon.trans.XPathException; 12 13 import javax.xml.transform.SourceLocator ; 14 import java.util.Comparator ; 15 16 20 21 public class ExpressionContext implements XSLTStaticContext { 22 23 private StyleElement element; 24 private NamePool namePool; 25 26 public ExpressionContext(StyleElement styleElement) { 27 element = styleElement; 28 namePool = styleElement.getTargetNamePool(); 29 } 30 31 34 35 public Configuration getConfiguration() { 36 return element.getPreparedStylesheet().getConfiguration(); 37 } 38 39 42 43 public LocationMap getLocationMap() { 44 return element.getPrincipalStylesheet().getLocationMap(); 45 } 46 47 50 51 public void issueWarning(String s, SourceLocator locator) { 52 element.issueWarning(s, locator); 53 } 54 55 58 59 public NamePool getNamePool() { 60 return namePool; 61 } 62 63 66 67 public String getSystemId() { 68 return element.getSystemId(); 69 } 70 71 75 76 public int getLineNumber() { 77 return element.getLineNumber(); 78 } 79 80 85 86 public String getBaseURI() { 87 return element.getBaseURI(); 88 } 89 90 96 97 public String getURIForPrefix(String prefix) throws XPathException { 98 String uri = element.getURIForPrefix(prefix, false); 99 if (uri == null) { 100 StaticError err = new StaticError("Undeclared namespace prefix " + Err.wrap(prefix)); 101 err.setErrorCode("XY0280"); 102 throw err; 103 } 104 return uri; 105 } 106 107 110 111 public NamespaceResolver getNamespaceResolver() { 112 return element.makeNamespaceContext(); 113 } 114 115 123 124 public int getFingerprint(String qname, boolean useDefault) throws XPathException { 125 126 String [] parts; 127 try { 128 parts = Name.getQNameParts(qname); 129 } catch (QNameException err) { 130 throw new StaticError(err.getMessage()); 131 } 132 String prefix = parts[0]; 133 if (prefix.equals("")) { 134 String uri = ""; 135 136 if (useDefault) { 137 uri = getURIForPrefix(prefix); 138 } 139 140 return namePool.getFingerprint(uri, qname); 141 142 } else { 143 144 String uri = getURIForPrefix(prefix); 145 return namePool.getFingerprint(uri, parts[1]); 146 } 147 } 148 149 155 156 public VariableDeclaration bindVariable(int fingerprint) throws StaticError { 157 return element.bindVariable(fingerprint); 158 } 159 160 164 165 public FunctionLibrary getFunctionLibrary() { 166 return element.getPrincipalStylesheet().getFunctionLibrary(); 167 } 168 169 173 174 public boolean isElementAvailable(String qname) throws XPathException { 175 try { 176 String [] parts = Name.getQNameParts(qname); 177 String uri = getURIForPrefix(parts[0]); 178 179 return element.getPreparedStylesheet(). 180 getStyleNodeFactory().isElementAvailable(uri, parts[1]); 181 } catch (QNameException e) { 182 StaticError err = new StaticError("Invalid element name. " + e.getMessage()); 183 err.setErrorCode("XTDE1440"); 184 throw err; 185 } 186 } 187 188 193 194 public Comparator getCollation(String name) throws XPathException { 195 return element.getPrincipalStylesheet().findCollation(name); 196 } 197 198 201 202 public String getDefaultCollationName() { 203 return element.getDefaultCollationName(); 204 } 206 207 210 211 public short getDefaultElementNamespace() { 212 return element.getDefaultXPathNamespace(); 213 } 214 215 218 219 public String getDefaultFunctionNamespace() { 220 return NamespaceConstant.FN; 221 } 222 223 226 227 public boolean isInBackwardsCompatibleMode() { 228 return element.backwardsCompatibleModeIsEnabled(); 229 } 230 231 236 237 public boolean isImportedSchema(String namespace) { 238 return getXSLStylesheet().isImportedSchema(namespace); 239 } 240 241 249 250 public boolean isAllowedBuiltInType(AtomicType type) { 251 if (getConfiguration().isSchemaAware(Configuration.XSLT)) { 252 return true; 253 } else if (type instanceof BuiltInAtomicType) { 254 return ((BuiltInAtomicType)type).isAllowedInBasicXSLT(); 255 } else { 256 return false; 257 } 258 } 259 260 263 264 public XSLStylesheet getXSLStylesheet() { 265 return element.getPrincipalStylesheet(); 266 } 267 268 272 273 public StyleElement getStyleElement() { 274 return element; 275 } 276 } 277 278 | Popular Tags |