Example usage for org.dom4j DocumentHelper createPattern

List of usage examples for org.dom4j DocumentHelper createPattern

Introduction

In this page you can find the example usage for org.dom4j DocumentHelper createPattern.

Prototype

public static Pattern createPattern(String xpathPattern) 

Source Link

Document

createPattern parses the given XPath expression to create an XSLT style Pattern instance which can then be used in an XSLT processing model.

Usage

From source file:org.apache.commons.jelly.tags.jsl.JSLTagLibrary.java

License:Apache License

public Expression createExpression(ExpressionFactory factory, TagScript tagScript, String attributeName,
        String attributeValue) throws JellyException {

    // #### may need to include some namespace URI information in the XPath instance?

    if (attributeName.equals("select")) {
        if (log.isDebugEnabled()) {
            log.debug("Parsing XPath expression: " + attributeValue);
        }//from  w w w. j a  va  2  s  .  c o  m

        Expression xpathExpr = createXPathTextExpression(attributeValue);

        return new XPathExpression(attributeValue, xpathExpr, tagScript);
    }

    if (attributeName.equals("match")) {
        if (log.isDebugEnabled()) {
            log.debug("Parsing XPath pattern: " + attributeValue);
        }

        try {
            Pattern pattern = DocumentHelper.createPattern(attributeValue);
            return new XPathPatternExpression(attributeValue, pattern);
        } catch (Exception e) {
            throw new JellyException(
                    "Could not parse XPath expression: \"" + attributeValue + "\" reason: " + e, e);
        }
    }

    // will use the default expression instead
    return super.createExpression(factory, tagScript, attributeName, attributeValue);
}

From source file:org.apache.taglibs.xtags.xpath.TemplateTag.java

License:Apache License

protected Pattern createPattern(String xpath) {
    return DocumentHelper.createPattern(xpath);
}

From source file:org.dom4j.samples.rule.SongFilter.java

License:Open Source License

public Document filtering(org.dom4j.Document doc) throws Exception {
    Element resultRoot = DocumentHelper.createElement("result");
    this.resultDoc = DocumentHelper.createDocument(resultRoot);

    Rule songElementRule = new Rule();
    songElementRule.setPattern(DocumentHelper.createPattern("/Songs/song/mp3/id3"));
    songElementRule.setAction(new SongElementBuilder());

    Rule titleTextNodeFilter = new Rule();
    titleTextNodeFilter.setPattern(DocumentHelper.createPattern("/Songs/song/mp3/id3/title"));
    titleTextNodeFilter.setAction(new NodeTextFilter());

    this.style = new Stylesheet();
    this.style.addRule(songElementRule);
    this.style.addRule(titleTextNodeFilter);

    style.run(doc);/* w w w .java2s .c o m*/

    return this.resultDoc;
}