Example usage for org.jdom2.xpath XPathFactory compile

List of usage examples for org.jdom2.xpath XPathFactory compile

Introduction

In this page you can find the example usage for org.jdom2.xpath XPathFactory compile.

Prototype

public XPathExpression<Object> compile(String expression) 

Source Link

Document

Create a XPathExpression<Object> instance from this factory.

Usage

From source file:de.andreasschoknecht.LS3.PNMLReader.java

License:Open Source License

/**
 * Extract the terms of all transition and place labels in a PNML file.
 *
 * @param pnmlPath The path to a PNML file for parsing
 * @return labels A list of labels from transition and places contained in a PNML file
 * @throws JDOMException if no valid XML document is parsed
 * @throws IOException if input/output errors occur when parsing a PNML file
 *//* www  .  ja v a  2s.  c  om*/
private List<Object> getPNMLLabelTerms(String pnmlPath) throws JDOMException, IOException {
    // Create internal document with SAXBuilder from PNML file
    Document doc = new SAXBuilder().build(new File(pnmlPath));

    // Create xpathFactory for querying doc
    XPathFactory xpathFactory = XPathFactory.instance();

    // Define XPath expression for filtering the labels of transition and place labels
    XPathExpression<Object> expr = xpathFactory.compile("//name/text");
    List<Object> labels = expr.evaluate(doc);

    return labels;
}

From source file:password.pwm.config.PwmSetting.java

License:Open Source License

public StoredValue getDefaultValue(final Template template)
        throws PwmOperationalException, PwmUnrecoverableException {
    if (!CACHE_DEFAULT_VALUES.containsKey(template)) {
        if (this.getSyntax() == PwmSettingSyntax.PASSWORD) {
            CACHE_DEFAULT_VALUES.put(template, new PasswordValue(null));
        } else {/*from   www . j  a  v  a 2 s. co  m*/
            final Element settingElement = PwmSettingXml.readSettingXml(this);
            final XPathFactory xpfac = XPathFactory.instance();
            Element defaultElement = null;
            if (template != null) {
                XPathExpression xp = xpfac.compile("default[@template=\"" + template.toString() + "\"]");
                defaultElement = (Element) xp.evaluateFirst(settingElement);
            }
            if (defaultElement == null) {
                XPathExpression xp = xpfac.compile("default[not(@template)]");
                defaultElement = (Element) xp.evaluateFirst(settingElement);
            }
            if (defaultElement == null) {
                throw new IllegalStateException("no default value for setting " + this.getKey());
            }
            CACHE_DEFAULT_VALUES.put(template, ValueFactory.fromXmlValues(this, defaultElement, this.getKey()));
        }
    }
    return CACHE_DEFAULT_VALUES.get(template);
}

From source file:password.pwm.config.PwmSettingXml.java

License:Open Source License

static Element readSettingXml(final PwmSetting setting) {
    final XPathFactory xpfac = XPathFactory.instance();
    final XPathExpression xp = xpfac.compile("/settings/setting[@key=\"" + setting.getKey() + "\"]");
    return (Element) xp.evaluateFirst(readXml());
}

From source file:password.pwm.config.PwmSettingXml.java

License:Open Source License

static Element readCategoryXml(final PwmSettingCategory category) {
    final XPathFactory xpfac = XPathFactory.instance();
    final XPathExpression xp = xpfac.compile("/settings/category[@key=\"" + category.toString() + "\"]");
    return (Element) xp.evaluateFirst(readXml());
}

From source file:password.pwm.config.PwmSettingXml.java

License:Open Source License

static Element readTemplateXml(final PwmSetting.Template template) {
    final XPathFactory xpfac = XPathFactory.instance();
    final XPathExpression xp = xpfac.compile("/settings/template[@key=\"" + template.toString() + "\"]");
    return (Element) xp.evaluateFirst(readXml());
}