Example usage for org.jdom2.xpath XPathFactory instance

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

Introduction

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

Prototype

public static final XPathFactory instance() 

Source Link

Document

Obtain an instance of an XPathFactory using the default mechanisms to determine what XPathFactory implementation to use.

Usage

From source file:org.yawlfoundation.yawl.util.JDOMUtil.java

License:Open Source License

/****************************************************************************/

public static Element selectElement(Document doc, String path) {
    XPathExpression<Element> expression = XPathFactory.instance().compile(path, new ElementFilter());
    return expression.evaluateFirst(doc);
}

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   w  w  w  .ja va  2s  .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());
}

From source file:ru.iteco.xmldoc.AbstractGenerator.java

License:Open Source License

/**
 *  ,  ?, ?    ?  ? ?//from   ww  w . j  a  va 2s  . co m
 *
 *
 * @param xmlfile 
 * @throws Exception
 */
protected void processFile(File xmlfile) throws Exception {

    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(xmlfile);
    Element root = doc.getRootElement();

    XPathExpression itemExpr = XPathFactory.instance().compile("scope/" + getElementName());
    List<Element> items = itemExpr.evaluate(root);
    for (Element i : items) {
        System.out.println(i.getAttributeValue("id"));
        process(i, xmlfile.getPath());
        counter++;
    }
}

From source file:ru.iteco.xmldoc.ConfigEx.java

License:Open Source License

protected void setUniqueId() {
    StringBuilder result = new StringBuilder();
    result.append(generateBaseUniqueId(id, path));

    //  ?, ?  ?  ?/  
    XPathExpression elExpr = XPathFactory.instance()
            .compile("scope/" + element.getName() + "[@id='" + id + "']");
    List<Element> els = elExpr.evaluate(element.getDocument().getRootElement());

    //?  ?,    ID ? ?
    if (els.size() > 1) {
        result.append("[");
        result.append(getScope().toString());
        result.append("]");
    }//ww w.  j  ava2  s  . c om

    UniqueId = result.toString();
}

From source file:sample.webservices.endpoint.HolidayEndpoint.java

License:Apache License

public HolidayEndpoint(HumanResourceService humanResourceService)
        throws JDOMException, XPathFactoryConfigurationException, XPathExpressionException {
    this.humanResourceService = humanResourceService;
    Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI);
    XPathFactory xPathFactory = XPathFactory.instance();
    this.startDateExpression = xPathFactory.compile("//hr:StartDate", Filters.element(), null, namespace);
    this.endDateExpression = xPathFactory.compile("//hr:EndDate", Filters.element(), null, namespace);
    this.nameExpression = xPathFactory.compile("concat(//hr:FirstName,' ',//hr:LastName)", Filters.fstring(),
            null, namespace);//from w  ww. j a  v a 2  s . c  o m
}

From source file:sample.ws.endpoint.HolidayEndpoint.java

License:Apache License

@Autowired
public HolidayEndpoint(HumanResourceService humanResourceService)
        throws JDOMException, XPathFactoryConfigurationException, XPathExpressionException {
    this.humanResourceService = humanResourceService;

    Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI);

    XPathFactory xPathFactory = XPathFactory.instance();

    this.startDateExpression = xPathFactory.compile("//hr:StartDate", Filters.element(), null, namespace);
    this.endDateExpression = xPathFactory.compile("//hr:EndDate", Filters.element(), null, namespace);
    this.nameExpression = xPathFactory.compile("concat(//hr:FirstName,' ',//hr:LastName)", Filters.fstring(),
            null, namespace);//  w ww. j  av  a 2 s.c  om
}

From source file:se.miun.itm.input.util.xml.XPathProcessor.java

License:Open Source License

public static List<Element> query(String expression, Namespace nameSpace, Object context)
        throws InPUTException {
    XPathFactory inst;/*from w w w  .  j  a  va2 s . c om*/
    inst = XPathFactory.instance();
    expression = correctNamespaceInPUT(expression, nameSpace);

    XPathExpression<Element> expr = inst.compile(expression, ELEMENT_FILTER, null, nameSpace);
    return expr.evaluate(context);
}