Example usage for org.apache.commons.jxpath JXPathContext compile

List of usage examples for org.apache.commons.jxpath JXPathContext compile

Introduction

In this page you can find the example usage for org.apache.commons.jxpath JXPathContext compile.

Prototype

public static CompiledExpression compile(String xpath) 

Source Link

Document

Compiles the supplied XPath and returns an internal representation of the path that can then be evaluated.

Usage

From source file:com.opera.core.systems.scope.services.ums.WindowManager.java

public WindowManager(ScopeServices services, String version) {
    super(services, version);

    String serviceName = "window-manager";

    if (!isVersionInRange(version, "3.0", serviceName))
        throw new UnsupportedOperationException(serviceName + " version " + version + " is not supported");

    services.setWindowManager(this);
    windowFinder = JXPathContext.compile("/.[windowType='normal']/windowID");
}

From source file:org.apache.camel.language.jxpath.JXPathExpression.java

private synchronized CompiledExpression getJXPathExpression() {
    if (compiledExpression == null) {
        compiledExpression = JXPathContext.compile(expression);
    }// w w  w.ja v a 2  s  .c o m
    return compiledExpression;
}

From source file:org.apache.cocoon.components.expression.jxpath.JXPathExpression.java

public JXPathExpression(String language, String expression) throws ExpressionException {
    this.language = language;
    this.expression = expression;
    this.compiledExpression = JXPathContext.compile(expression);
}

From source file:org.apache.cocoon.generation.JXTemplateGenerator.java

private static JXTExpression compile(final String variable, boolean xpath) throws Exception {
    Object compiled;/*from  www. j  av a 2 s.  c  o  m*/
    if (xpath) {
        compiled = JXPathContext.compile(variable);
    } else {
        compiled = ExpressionFactory.createExpression(variable);
    }
    return new JXTExpression(variable, compiled);
}

From source file:org.apache.cocoon.selection.XPathExceptionSelector.java

public void configure(Configuration conf) throws ConfigurationException {

    super.configure(conf);

    Configuration[] children = conf.getChildren("exception");
    Configuration[] xPathChildren;

    for (int i = 0; i < children.length; i++) {
        // Check if there are XPath-Expressions configured
        xPathChildren = children[i].getChildren("xpath");
        Map xPathMap = new LinkedMap(11);

        for (int j = 0; j < xPathChildren.length; j++) {
            Configuration xPathChild = xPathChildren[j];

            String xPathName = xPathChild.getAttribute("name");
            CompiledExpression xPath = JXPathContext.compile(xPathChild.getAttribute("test"));

            xPathMap.put(xPathName, xPath);
        }// w  ww .  j  a va  2  s  .c  om
        if (xPathMap.size() > 0) {
            // store xpath - config if there is some
            exception2XPath.put(children[i].getAttribute("name", null), xPathMap);
        }
    }
}

From source file:org.apache.cocoon.transformation.JPathTransformer.java

/**
 * Helper method for obtaining the value of a particular variable.
 *
 * @param variable variable name/*from   www.j  a  va2s. c  o m*/
 * @return variable value as an <code>Object</code>
 */
private Object getValue(final String variable) {

    Object value;

    if (m_cache.containsKey(variable)) {
        value = m_cache.get(variable);
    } else {
        value = JXPathContext.compile(variable).getValue(m_jxpathContext);

        if (value == null) {
            if (getLogger().isWarnEnabled()) {
                final String msg = "Value for jpath variable '" + variable + "' does not exist";
                getLogger().warn(msg);
            }
        }

        m_cache.put(variable, value);
    }

    return value;
}

From source file:org.lockss.daemon.TitleSetXpath.java

/** Create a TitleSet that consists of all known titles whose {@link
 * TitleConfig} matches the supplied xpath predicate.  In addition to the
 * standard XPath functions, the extension
 * <code>RE:isMatchRe(<i>string</i>, <i>regexp</i>)</code> performs a
 * regexp match against the string.//from  w w w .j  ava  2 s.  com
 * @param daemon used to get list of all known titles
 * @param xpathPred an XPath predicate (<i>eg</i>,
 * <code>[journalTitle='Dog Journal']</code> )
 */
TitleSetXpath(LockssDaemon daemon, String name, String xpathPred) {
    super(daemon, name);
    if (!(xpathPred.startsWith("[") && xpathPred.endsWith("]"))) {
        throw new IllegalArgumentException("XPath predicate must be enclosed in \"[\" ... \"]\"");
    }
    xpath = "." + xpathPred;
    expr = JXPathContext.compile(xpath);
}

From source file:org.openl.rules.variation.JXPathVariation.java

/**
 * Constructs JXPath variation./*from ww w .  j a v  a2 s.co m*/
 * 
 * @param variationID Unique ID of variations.
 * @param updatedArgumentIndex index of argument to modify.
 * @param path Path supported by JXPath that point to field to modify.
 * @param valueToSet
 */
public JXPathVariation(String variationID, int updatedArgumentIndex, String path, Object valueToSet) {
    super(variationID);
    if (updatedArgumentIndex < 0) {
        throw new IllegalArgumentException("Number of argument to be modified should be non negative.");
    } else {
        this.updatedArgumentIndex = updatedArgumentIndex;
    }
    this.path = path;
    this.valueToSet = valueToSet;
    this.compiledExpression = JXPathContext.compile(path);
}

From source file:org.xchain.namespaces.core.TestUnknownFunction.java

@Ignore
@Test/*  w w w . j a v a  2s .  c om*/
public void testUnknownFunctionFromExpression() {
    try {
        CompiledExpression expression = JXPathContext.compile("unknown()");
        expression.getValue(context);
        fail("Unknown function should have thrown an exception.");
    } catch (Exception e) {
        // success.
    }
}