/** * Convert this expression to an equivalent XSLT pattern * * @param config the Saxon configuration * @return the equivalent pattern * @throws net.sf.saxon.trans.XPathException * if conversion is not possible */ @Override public Pattern toPattern(Configuration config) throws XPathException { return new NodeTestPattern(NodeKindTest.DOCUMENT); }
/** * Convert the pattern to a typed pattern, in which an element name is treated as * schema-element(N) * * @param val either "strict" or "lax" depending on the value of xsl:mode/@typed * @return either the original pattern unchanged, or a new pattern as the result of the * conversion */ @Override public Pattern convertToTypedPattern(String val) throws XPathException { if (nodeTest instanceof NameTest && nodeTest.getUType() == UType.ELEMENT) { SchemaDeclaration decl = getConfiguration().getElementDeclaration(nodeTest.getMatchingNodeName()); if (decl == null) { if ("lax".equals(val)) { return this; } else { // See spec bug 25517 throw new XPathException("The mode specifies typed='strict', " + "but there is no schema element declaration named " + nodeTest, "XTSE3105"); } } else { NodeTest schemaNodeTest = decl.makeSchemaNodeTest(); return new NodeTestPattern(schemaNodeTest); } } else { return this; } }
/** * Copy a pattern. This makes a deep copy. * * @return the copy of the original pattern * @param rebindings variables that need to be re-bound */ /*@NotNull*/ public Pattern copy(RebindingMap rebindings) { NodeTestPattern n = new NodeTestPattern(nodeTest.copy()); n.setPriority(getDefaultPriority()); ExpressionTool.copyLocationInfo(this, n); return n; }
!firstElementPattern && !lastElementPattern) { NodeTestPattern ntp = new NodeTestPattern(nodeTest); ntp.setSystemId(getSystemId()); ntp.setLineNumber(getLineNumber()); return ntp;
while (st.hasMoreTokens()) { String s = st.nextToken(); NodeTestPattern pat = new NodeTestPattern(); pat.setOriginalText(s); pat.setSystemId(getSystemId()); pat.setLineNumber(getLineNumber()); NodeTest nt; if (s.equals("*")) { nt = AnyNodeTest.getInstance(); pat.setNodeTest(nt); stripperRules.addRule( pat, Type.ELEMENT, uri); pat.setNodeTest(nt); stripperRules.addRule( pat, Type.ELEMENT, localname); pat.setNodeTest(nt); stripperRules.addRule( pat, int nameCode = target.allocate("", uri, localName); nt = new NameTest(Type.ELEMENT, nameCode, getNamePool()); pat.setNodeTest(nt);
/** * Make a pattern in the context of this stylesheet element * * @param pattern the source text of the pattern * @return the compiled pattern */ public Pattern makePattern(String pattern, String attributeName) { try { StaticContext env = getStaticContext(new StructuredQName("", "", attributeName)); Pattern p = Pattern.make(pattern, env, getCompilation().getPackageData()); p.setLocation(allocateLocation()); return p; } catch (XPathException err) { if ("XPST0003".equals(err.getErrorCodeLocalPart())) { err.setErrorCode("XTSE0340"); } compileError(err); NodeTestPattern nsp = new NodeTestPattern(AnyNodeTest.getInstance()); nsp.setLocation(allocateLocation()); return nsp; } }
/** * Create an NodeTestPattern that matches all items of a given type * * @param test the type that the items must satisfy for the pattern to match */ public NodeTestPattern(NodeTest test) { nodeTest = test; setPriority(test.getDefaultPriority()); }
public void export(ExpressionPresenter presenter) throws XPathException { presenter.startElement("p.nodeTest"); presenter.emitAttribute("test", nodeTest.toString()); if ("JS".equals(((ExpressionPresenter.ExportOptions) presenter.getOptions()).target)) { int targetVersion = ((ExpressionPresenter.ExportOptions) presenter.getOptions()).targetVersion; try { presenter.emitAttribute("jsTest", nodeTest.generateJavaScriptItemTypeTest(AnyItemType.getInstance(), targetVersion)); } catch (XPathException e) { e.maybeSetLocation(getLocation()); throw e; } } presenter.endElement(); }
public void addRule(NodeTestPattern pattern, Stripper.StripRuleTarget action, int precedence, int minImportPrecedence) throws XPathException { NodeTest test = pattern.getNodeTest(); double priority = test.getDefaultPriority(); Rule newRule = new Rule(pattern, action, precedence, minImportPrecedence, priority, sequence++); int prio = priority == 0 ? 2 : priority == -0.25 ? 1 : 0; newRule.setRank((precedence << 18) + (prio << 16) + sequence); if (test instanceof NodeKindTest) { newRule.setAlwaysMatches(true); anyElementRule = addRuleToList(newRule, anyElementRule, true); } else if (test instanceof NameTest) { newRule.setAlwaysMatches(true); int fp = test.getFingerprint(); CodedName key = new CodedName(fp, "", ((NameTest) test).getNamePool()); Rule chain = namedElementRules.get(key); namedElementRules.put(key, addRuleToList(newRule, chain, true)); } else { unnamedElementRuleChain = addRuleToList(newRule, unnamedElementRuleChain, false); } }
while (st.hasMoreTokens()) { String s = st.nextToken(); NodeTestPattern pat = new NodeTestPattern(); pat.setOriginalText(s); pat.setSystemId(getSystemId()); pat.setLineNumber(getLineNumber()); NodeTest nt; if (s.equals("*")) { nt = AnyNodeTest.getInstance(); pat.setNodeTest(nt); stripperRules.addRule( pat, Type.ELEMENT, uri); pat.setNodeTest(nt); stripperRules.addRule( pat, Type.ELEMENT, localname); pat.setNodeTest(nt); stripperRules.addRule( pat, int nameCode = target.allocate("", uri, localName); nt = new NameTest(Type.ELEMENT, nameCode, getNamePool()); pat.setNodeTest(nt);
!firstElementPattern && !lastElementPattern) { NodeTestPattern ntp = new NodeTestPattern(nodeTest); ntp.setSystemId(getSystemId()); ntp.setLineNumber(getLineNumber()); return ntp;
/** * Make a pattern in the context of this stylesheet element * * @param pattern the source text of the pattern * @return the compiled pattern */ public Pattern makePattern(String pattern, String attributeName) { try { StaticContext env = getStaticContext(new StructuredQName("", "", attributeName)); Pattern p = Pattern.make(pattern, env, getCompilation().getPackageData()); p.setLocation(allocateLocation()); return p; } catch (XPathException err) { if ("XPST0003".equals(err.getErrorCodeLocalPart())) { err.setErrorCode("XTSE0340"); } compileError(err); NodeTestPattern nsp = new NodeTestPattern(AnyNodeTest.getInstance()); nsp.setLocation(allocateLocation()); return nsp; } }
/** * Create an NodeTestPattern that matches all items of a given type * * @param test the type that the items must satisfy for the pattern to match */ public NodeTestPattern(NodeTest test) { nodeTest = test; setPriority(test.getDefaultPriority()); }
public void export(ExpressionPresenter presenter) throws XPathException { presenter.startElement("p.nodeTest"); presenter.emitAttribute("test", nodeTest.toString()); if ("JS".equals(((ExpressionPresenter.ExportOptions) presenter.getOptions()).target)) { int targetVersion = ((ExpressionPresenter.ExportOptions) presenter.getOptions()).targetVersion; try { presenter.emitAttribute("jsTest", nodeTest.generateJavaScriptItemTypeTest(AnyItemType.getInstance(), targetVersion)); } catch (XPathException e) { e.maybeSetLocation(getLocation()); throw e; } } presenter.endElement(); }
public void addRule(NodeTestPattern pattern, Stripper.StripRuleTarget action, int precedence, int minImportPrecedence) throws XPathException { NodeTest test = pattern.getNodeTest(); double priority = test.getDefaultPriority(); Rule newRule = new Rule(pattern, action, precedence, minImportPrecedence, priority, sequence++); int prio = priority == 0 ? 2 : priority == -0.25 ? 1 : 0; newRule.setRank((precedence << 18) + (prio << 16) + sequence); if (test instanceof NodeKindTest) { newRule.setAlwaysMatches(true); anyElementRule = addRuleToList(newRule, anyElementRule, true); } else if (test instanceof NameTest) { newRule.setAlwaysMatches(true); int fp = test.getFingerprint(); NamePool pool = ((NameTest) test).getNamePool(); FingerprintedQName key = new FingerprintedQName(pool.getUnprefixedQName(fp), pool); Rule chain = namedElementRules.get(key); namedElementRules.put(key, addRuleToList(newRule, chain, true)); } else { unnamedElementRuleChain = addRuleToList(newRule, unnamedElementRuleChain, false); } }
/** * Convert this expression to an equivalent XSLT pattern * * @param config the Saxon configuration * @return the equivalent pattern * @throws net.sf.saxon.trans.XPathException * if conversion is not possible */ @Override public Pattern toPattern(Configuration config) throws XPathException { return new NodeTestPattern(NodeKindTest.DOCUMENT); }
/** * Copy a pattern. This makes a deep copy. * * @return the copy of the original pattern * @param rebindings variables that need to be re-bound */ /*@NotNull*/ public Pattern copy(RebindingMap rebindings) { NodeTestPattern n = new NodeTestPattern(nodeTest.copy()); n.setPriority(getDefaultPriority()); ExpressionTool.copyLocationInfo(this, n); return n; }
/** * Convert the pattern to a typed pattern, in which an element name is treated as * schema-element(N) * * @param val either "strict" or "lax" depending on the value of xsl:mode/@typed * @return either the original pattern unchanged, or a new pattern as the result of the * conversion */ @Override public Pattern convertToTypedPattern(String val) throws XPathException { if (nodeTest instanceof NameTest && nodeTest.getUType() == UType.ELEMENT) { SchemaDeclaration decl = getConfiguration().getElementDeclaration(nodeTest.getMatchingNodeName()); if (decl == null) { if ("lax".equals(val)) { return this; } else { // See spec bug 25517 throw new XPathException("The mode specifies typed='strict', " + "but there is no schema element declaration named " + nodeTest, "XTSE3105"); } } else { NodeTest schemaNodeTest = decl.makeSchemaNodeTest(); return new NodeTestPattern(schemaNodeTest); } } else { return this; } }
pat = new NodeTestPattern(test); } else if (axis == AxisInfo.ATTRIBUTE) { if (kind == Type.NODE) { pat = new NodeTestPattern(NodeKindTest.ATTRIBUTE); } else if (!AxisInfo.containsNodeKind(axis, kind)) { pat = new NodeTestPattern(ErrorType.getInstance()); } else { pat = new NodeTestPattern(test); pat = new NodeTestPattern(ErrorType.getInstance()); } else { pat = new NodeTestPattern(test); pat = new NodeTestPattern(NodeKindTest.NAMESPACE); } else if (!AxisInfo.containsNodeKind(axis, kind)) { pat = new NodeTestPattern(ErrorType.getInstance()); } else { pat = new NodeTestPattern(test);
pat = new NodeTestPattern(test); } else if (axis == AxisInfo.ATTRIBUTE) { if (kind == Type.NODE) { pat = new NodeTestPattern(NodeKindTest.ATTRIBUTE); } else if (!AxisInfo.containsNodeKind(axis, kind)) { pat = new NodeTestPattern(ErrorType.getInstance()); } else { pat = new NodeTestPattern(test); pat = new NodeTestPattern(ErrorType.getInstance()); } else { pat = new NodeTestPattern(test); pat = new NodeTestPattern(NodeKindTest.NAMESPACE); } else if (!AxisInfo.containsNodeKind(axis, kind)) { pat = new NodeTestPattern(ErrorType.getInstance()); } else { pat = new NodeTestPattern(test);