1 package net.sf.saxon.style; 2 3 import net.sf.saxon.Configuration; 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.*; 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 javax.xml.transform.TransformerException ; 15 import java.util.Comparator ; 16 17 20 21 public class UseWhenStaticContext implements XSLTStaticContext { 22 23 public Configuration config; 24 public NamespaceResolver namespaceContext; 25 public FunctionLibrary functionLibrary; 26 public LocationMap locationMap; 27 public StyleNodeFactory nodeFactory; 28 public String baseURI; 29 public short defaultXPathNamespace; 30 31 public UseWhenStaticContext(Configuration config, NamespaceResolver namespaceContext) { 32 this.config = config; 33 this.namespaceContext = namespaceContext; 34 this.locationMap = new LocationMap(); 35 36 FunctionLibraryList lib = new FunctionLibraryList(); 37 lib.addFunctionLibrary(new SystemFunctionLibrary(SystemFunctionLibrary.USE_WHEN)); 38 lib.addFunctionLibrary(getConfiguration().getVendorFunctionLibrary()); 39 lib.addFunctionLibrary(new ConstructorFunctionLibrary(getConfiguration())); 40 if (config.isAllowExternalFunctions()) { 41 lib.addFunctionLibrary(config.getExtensionBinder()); 42 } 43 functionLibrary = lib; 44 } 45 46 49 50 public Configuration getConfiguration() { 51 return config; 52 } 53 54 57 58 public LocationMap getLocationMap() { 59 return locationMap; 60 } 61 62 65 66 public void issueWarning(String s, SourceLocator locator) { 67 StaticError err = new StaticError(s); 68 err.setLocator(locator); 69 try { 70 config.getErrorListener().warning(err); 71 } catch (TransformerException e) { 72 } 74 } 75 76 81 82 public String getSystemId() { 83 return baseURI; 84 } 85 86 90 91 public int getLineNumber() { 92 return -1; 93 } 94 95 101 102 public String getBaseURI() { 103 return baseURI; 104 } 105 106 114 115 public String getURIForPrefix(String prefix) throws XPathException { 116 return namespaceContext.getURIForPrefix(prefix, false); 117 } 118 119 122 123 public NamePool getNamePool() { 124 return getConfiguration().getNamePool(); 125 } 126 127 130 131 public VariableDeclaration bindVariable(int fingerprint) throws StaticError { 132 StaticError err = new StaticError("Variables cannot be used in a use-when expression"); 133 err.setErrorCode("XO0008"); 134 throw err; 135 } 136 137 141 142 public FunctionLibrary getFunctionLibrary() { 143 return functionLibrary; 144 } 145 146 152 153 public Comparator getCollation(String name) throws XPathException { 154 return null; 155 } 156 157 163 164 public String getDefaultCollationName() { 165 return NamespaceConstant.CODEPOINT_COLLATION_URI; 166 } 167 168 171 172 public short getDefaultElementNamespace() { 173 return defaultXPathNamespace; 174 } 175 176 179 180 public String getDefaultFunctionNamespace() { 181 return NamespaceConstant.FN; 182 } 183 184 187 188 public boolean isInBackwardsCompatibleMode() { 189 return false; 190 } 191 192 200 201 public boolean isImportedSchema(String namespace) { 202 return false; 203 } 204 205 213 214 public boolean isAllowedBuiltInType(AtomicType type) { 215 if (getConfiguration().isSchemaAware(Configuration.XSLT)) { 216 return true; 217 } else if (type instanceof BuiltInAtomicType) { 218 return ((BuiltInAtomicType)type).isAllowedInBasicXSLT(); 219 } else { 220 return false; 221 } 222 } 223 224 229 230 public NamespaceResolver getNamespaceResolver() { 231 return namespaceContext; 232 } 233 234 238 239 public boolean isElementAvailable(String qname) throws XPathException { 240 try { 241 String [] parts = Name.getQNameParts(qname); 242 String uri = getURIForPrefix(parts[0]); 243 if (nodeFactory == null) { 244 nodeFactory = new StyleNodeFactory(config); 245 } 246 return nodeFactory.isElementAvailable(uri, parts[1]); 247 } catch (QNameException e) { 248 StaticError err = new StaticError("Invalid element name. " + e.getMessage()); 249 err.setErrorCode("XTDE1440"); 250 throw err; 251 } 252 } 253 254 257 258 public void setBaseURI(String uri) { 259 baseURI = uri; 260 } 261 262 265 266 public void setDefaultElementNamespace(short code) { 267 defaultXPathNamespace = code; 268 } 269 270 } 271 | Popular Tags |