| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.style; |
| 9 |
|
| 10 |
import net.sf.saxon.Configuration; |
| 11 |
import net.sf.saxon.expr.Expression; |
| 12 |
import net.sf.saxon.expr.Literal; |
| 13 |
import net.sf.saxon.expr.parser.Location; |
| 14 |
import net.sf.saxon.expr.parser.RetainedStaticContext; |
| 15 |
import net.sf.saxon.functions.FunctionLibrary; |
| 16 |
import net.sf.saxon.functions.FunctionLibraryList; |
| 17 |
import net.sf.saxon.functions.registry.ConstructorFunctionLibrary; |
| 18 |
import net.sf.saxon.lib.NamespaceConstant; |
| 19 |
import net.sf.saxon.om.*; |
| 20 |
import net.sf.saxon.sxpath.AbstractStaticContext; |
| 21 |
import net.sf.saxon.trans.DecimalFormatManager; |
| 22 |
import net.sf.saxon.trans.XPathException; |
| 23 |
import net.sf.saxon.type.ItemType; |
| 24 |
|
| 25 |
import java.util.Collections; |
| 26 |
import java.util.Set; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public class UseWhenStaticContext extends AbstractStaticContext implements XSLTStaticContext { |
| 38 |
|
| 39 |
private NamespaceResolver namespaceContext; |
| 40 |
private FunctionLibrary functionLibrary; |
| 41 |
private Compilation compilation; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public UseWhenStaticContext(Compilation compilation, NamespaceResolver namespaceContext) { |
| 51 |
Configuration config = compilation.getConfiguration(); |
| 52 |
setConfiguration(config); |
| 53 |
this.compilation = compilation; |
| 54 |
setPackageData(compilation.getPackageData()); |
| 55 |
this.namespaceContext = namespaceContext; |
| 56 |
setXPathLanguageLevel(31); |
| 57 |
|
| 58 |
FunctionLibraryList lib = new FunctionLibraryList(); |
| 59 |
lib.addFunctionLibrary(config.getUseWhenFunctionSet()); |
| 60 |
lib.addFunctionLibrary(getConfiguration().getBuiltInExtensionLibraryList()); |
| 61 |
lib.addFunctionLibrary(new ConstructorFunctionLibrary(getConfiguration())); |
| 62 |
lib.addFunctionLibrary(config.getIntegratedFunctionLibrary()); |
| 63 |
config.addExtensionBinders(lib); |
| 64 |
functionLibrary = lib; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
public RetainedStaticContext makeRetainedStaticContext() { |
| 76 |
return new RetainedStaticContext(this); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
public Compilation getCompilation() { |
| 81 |
return compilation; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
public void issueWarning(String s, Location locator) { |
| 89 |
XPathException err = new XPathException(s); |
| 90 |
err.setLocator(locator); |
| 91 |
getConfiguration().getErrorListener().warning(err); |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
public String getSystemId() { |
| 101 |
return getStaticBaseURI(); |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
public Expression bindVariable(StructuredQName qName) throws XPathException { |
| 115 |
GroundedValue<?> val = compilation.getStaticVariable(qName); |
| 116 |
if (val != null) { |
| 117 |
return Literal.makeLiteral(val); |
| 118 |
} else { |
| 119 |
XPathException err = new XPathException |
| 120 |
("Variables (other than XSLT 3.0 static variables) cannot be used in a static expression: " + |
| 121 |
qName.getDisplayName()); |
| 122 |
err.setErrorCode("XPST0008"); |
| 123 |
err.setIsStaticError(true); |
| 124 |
throw err; |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
public FunctionLibrary getFunctionLibrary() { |
| 134 |
return functionLibrary; |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
public String getDefaultCollationName() { |
| 145 |
return NamespaceConstant.CODEPOINT_COLLATION_URI; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
public String getDefaultFunctionNamespace() { |
| 153 |
return NamespaceConstant.FN; |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
public boolean isInBackwardsCompatibleMode() { |
| 161 |
return false; |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
public boolean isImportedSchema(String namespace) { |
| 174 |
return false; |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
public Set<String> getImportedSchemaNamespaces() { |
| 184 |
return Collections.emptySet(); |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
public NamespaceResolver getNamespaceResolver() { |
| 194 |
return namespaceContext; |
| 195 |
} |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
public DecimalFormatManager getDecimalFormatManager() { |
| 206 |
return null; |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
public boolean isElementAvailable(String qname) throws XPathException { |
| 217 |
try { |
| 218 |
String[] parts = NameChecker.getQNameParts(qname); |
| 219 |
String uri; |
| 220 |
if (parts[0].isEmpty()) { |
| 221 |
uri = getDefaultElementNamespace(); |
| 222 |
} else { |
| 223 |
uri = namespaceContext.getURIForPrefix(parts[0], false); |
| 224 |
} |
| 225 |
StyleNodeFactory factory = getConfiguration().makeStyleNodeFactory(compilation); |
| 226 |
return factory.isElementAvailable(uri, parts[1], true); |
| 227 |
} catch (QNameException e) { |
| 228 |
XPathException err = new XPathException("Invalid element name. " + e.getMessage()); |
| 229 |
err.setErrorCode("XTDE1440"); |
| 230 |
throw err; |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
public int getColumnNumber() { |
| 235 |
return 0; |
| 236 |
} |
| 237 |
|
| 238 |
public String getPublicId() { |
| 239 |
return null; |
| 240 |
} |
| 241 |
|
| 242 |
public int getLineNumber() { |
| 243 |
return -1; |
| 244 |
} |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
@Override |
| 257 |
public ItemType resolveTypeAlias(StructuredQName typeName) { |
| 258 |
return null; |
| 259 |
} |
| 260 |
|
| 261 |
} |
| 262 |
|