/** * Get the original pattern text */ @Override public String toString() { return wrappedPattern.toString(); }
/** * The default priority of an "except" pattern is the priority of the LH operand * * @return the priority of the LH operand */ @Override public double getDefaultPriority() { return p1.getDefaultPriority(); }
/** * Determine the name fingerprint of nodes to which this pattern applies. Used for * optimisation. * * @return A fingerprint that the nodes must match, or -1 if it can match multiple fingerprints, * or it if matches atomic values */ @Override public int getFingerprint() { return wrappedPattern.getFingerprint(); }
/** * Static method to make a Pattern by parsing a String. <br> * @param pattern The pattern text as a String * @param env An object defining the compile-time context for the expression * @param exec The executable containing this pattern * @return The pattern object */ public static Pattern make(String pattern, StaticContext env, Executable exec) throws XPathException { Pattern pat = (new ExpressionParser()).parsePattern(pattern, env); pat.setSystemId(env.getSystemId()); pat.setLineNumber(env.getLineNumber()); // System.err.println("Simplified [" + pattern + "] to " + pat.getClass() + " default prio = " + pat.getDefaultPriority()); // set the pattern text for use in diagnostics pat.setOriginalText(pattern); pat.setExecutable(exec); ExpressionVisitor visitor = ExpressionVisitor.make(env); visitor.setExecutable(exec); pat = pat.simplify(visitor); return pat; }
Pattern match1 = match.copy(new RebindingMap()); String typed = mode.getActivePart().getPropertyValue("typed"); if ("strict".equals(typed) || "lax".equals(typed)) { Pattern match2; try { match2 = match1.convertToTypedPattern(typed); } catch (XPathException e) { e.maybeSetLocation(this); ContextItemStaticInfo info = getConfiguration().makeContextItemStaticInfo(AnyItemType.getInstance(), false); ExpressionTool.copyLocationInfo(match, match2); match2.setOriginalText(match.toString()); match2 = match2.typeCheck(visitor, info); match1 = match2; if (!match1.isMotionless()) { boolean fallback = getConfiguration().getBooleanProperty(Feature.STREAMING_FALLBACK); String message = "Template rule is declared streamable but the match pattern is not motionless"; mgr.setTemplateRule(match1.copy(new RebindingMap()), ruleCopy, m, module, prio);
if (p.getNodeTest() instanceof EmptySequenceTest) { return; int fingerprint = p.getFingerprint(); int type = p.getNodeKind();
/** * Determine if the supplied node matches the pattern * * @param item the node to be compared * @return true if the node matches either of the operand patterns */ public boolean matches(Item<?> item, XPathContext context) throws XPathException { return p1.matches(item, context) && !p2.matches(item, context); }
/** * Prepare (compile) an XSLT pattern for subsequent evaluation. The result is an XPathExpression * object representing a (pseudo-) expression that when evaluated returns a boolean result: true * if the context node matches the pattern, false if it does not. * * @param pattern the XSLT pattern to be compiled, supplied as a string * @return an XPathExpression object representing the pattern, wrapped as an expression * @throws XPathException if the syntax of the expression is wrong, or if it references namespaces, * variables, or functions that have not been declared. * @since 9.1 */ /*@NotNull*/ public XPathExpression createPattern(String pattern) throws XPathException { Configuration config = getConfiguration(); Executable exec = new Executable(config); Pattern pat = Pattern.make(pattern, staticContext, new PackageData(config)); ExpressionVisitor visitor = ExpressionVisitor.make(staticContext); pat.typeCheck(visitor, config.makeContextItemStaticInfo(Type.NODE_TYPE, true)); SlotManager map = staticContext.getStackFrameMap(); int slots = map.getNumberOfVariables(); slots = pat.allocateSlots(map, slots); //PatternSponsor sponsor = new PatternSponsor(pat); XPathExpression xpe = new XPathExpression(staticContext, pat, exec); xpe.setStackFrameMap(map, slots); return xpe; }
/** * Prepare (compile) an XSLT pattern for subsequent evaluation. The result is an XPathExpression * object representing a (pseudo-) expression that when evaluated returns a boolean result: true * if the context node matches the pattern, false if it does not. * @param pattern the XSLT pattern to be compiled, supplied as a string * @return an XPathExpression object representing the pattern, wrapped as an expression * @throws XPathException if the syntax of the expression is wrong, or if it references namespaces, * variables, or functions that have not been declared. * @since 9.1 */ public XPathExpression createPattern(String pattern) throws XPathException { Pattern pat = Pattern.make(pattern, staticContext, staticContext.getExecutable()); ExpressionVisitor visitor = ExpressionVisitor.make(staticContext); pat.analyze(visitor, Type.NODE_TYPE); SlotManager map = staticContext.getStackFrameMap(); int slots = map.getNumberOfVariables(); slots = pat.allocateSlots(staticContext, map, slots); PatternSponsor sponsor = new PatternSponsor(pat); XPathExpression xpe = new XPathExpression(this, sponsor); xpe.setStackFrameMap(map, slots); return xpe; }
public PatternThatSetsCurrent(Pattern wrappedPattern, LocalVariableBinding binding) { this.wrappedPattern = wrappedPattern; this.binding = binding; binding.setRequiredType(SequenceType.makeSequenceType(wrappedPattern.getItemType(), StaticProperty.EXACTLY_ONE)); adoptChildExpression(wrappedPattern); setPriority(wrappedPattern.getDefaultPriority()); }
/** * Allocate slots to any variables used within the pattern * * @param slotManager represents the stack frame on which slots are allocated * @param nextFree the next slot that is free to be allocated @return the next slot that is free to be allocated */ public int allocateSlots(SlotManager slotManager, int nextFree) { nextFree = p1.allocateSlots(slotManager, nextFree); nextFree = p2.allocateSlots(slotManager, nextFree); return nextFree; }
/** * Ask whether a pattern has dependencies on local variables * @param pattern the pattern (typically a pattern in an xsl:number or xsl:for-each-group); or null * @return true if the pattern is non-null and has dependencies on local variables */ public static boolean patternContainsVariable (Pattern pattern) { return pattern != null && (pattern.getDependencies() & StaticProperty.DEPENDS_ON_LOCAL_VARIABLES) != 0; }
"Matches both \"" + showPattern(pat1) + "\" on line " + pat1.getLineNumber() + " of " + pat1.getSystemId() + "\nand \"" + showPattern(pat2) + "\" on line " + pat2.getLineNumber() + " of " + pat2.getSystemId()); err.setErrorCode(errorCode);
public void addRule(Pattern pattern, Rule newRule) { UType uType = pattern.getUType(); if (uType.equals(UType.ELEMENT)) { int fp = pattern.getFingerprint(); addRuleToNamedOrUnnamedChain( newRule, fp, unnamedElementRuleChain, namedElementRuleChains); } else if (uType.equals(UType.ATTRIBUTE)) { int fp = pattern.getFingerprint(); addRuleToNamedOrUnnamedChain( newRule, fp, unnamedAttributeRuleChain, namedAttributeRuleChains); } else if (uType.equals(UType.DOCUMENT)) { addRuleToList(newRule, documentRuleChain); } else if (uType.equals(UType.TEXT)) { addRuleToList(newRule, textRuleChain); } else if (uType.equals(UType.COMMENT)) { addRuleToList(newRule, commentRuleChain); } else if (uType.equals(UType.PI)) { addRuleToList(newRule, processingInstructionRuleChain); } else if (uType.equals(UType.NAMESPACE)) { addRuleToList(newRule, namespaceRuleChain); } else if (UType.ANY_ATOMIC.subsumes(uType)) { addRuleToList(newRule, atomicValueRuleChain); } else if (UType.FUNCTION.subsumes(uType)) { addRuleToList(newRule, functionItemRuleChain); } else { addRuleToList(newRule, genericRuleChain); } }
/** * 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; } }
/** * Set the original text */ public void setOriginalText(String pattern) { super.setOriginalText(pattern); p1.setOriginalText(pattern); p2.setOriginalText(pattern); }
/** * 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) throws XPathException { try { return Pattern.make(pattern, staticContext, getPrincipalStylesheet().getExecutable()); } catch (XPathException err) { compileError(err); return new NodeTestPattern(AnyNodeTest.getInstance()); } }
/** * Static method to make a Pattern by parsing a String. <br> * @param pattern The pattern text as a String * @param env An object defining the compile-time context for the expression * @param exec The executable containing this pattern * @return The pattern object */ public static Pattern make(String pattern, StaticContext env, Executable exec) throws XPathException { Pattern pat = (new ExpressionParser()).parsePattern(pattern, env); pat.setSystemId(env.getSystemId()); pat.setLineNumber(env.getLineNumber()); // System.err.println("Simplified [" + pattern + "] to " + pat.getClass() + " default prio = " + pat.getDefaultPriority()); // set the pattern text for use in diagnostics pat.setOriginalText(pattern); pat.setExecutable(exec); ExpressionVisitor visitor = ExpressionVisitor.make(env); visitor.setExecutable(exec); pat = pat.simplify(visitor); return pat; }
Pattern match1 = match.copy(new RebindingMap()); String typed = mode.getActivePart().getPropertyValue("typed"); if ("strict".equals(typed) || "lax".equals(typed)) { Pattern match2; try { match2 = match1.convertToTypedPattern(typed); } catch (XPathException e) { e.maybeSetLocation(this); ContextItemStaticInfo info = getConfiguration().makeContextItemStaticInfo(AnyItemType.getInstance(), false); ExpressionTool.copyLocationInfo(match, match2); match2.setOriginalText(match.toString()); match2 = match2.typeCheck(visitor, info); match1 = match2; if (!match1.isMotionless()) { boolean fallback = getConfiguration().getBooleanProperty(Feature.STREAMING_FALLBACK); String message = "Template rule is declared streamable but the match pattern is not motionless"; mgr.setTemplateRule(match1.copy(new RebindingMap()), ruleCopy, m, module, prio);