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:com.xebialabs.overcast.support.libvirt.jdom.FilesystemXml.java

License:Apache License

public static void removeFilesystemsWithTarget(Document domainXml, String targetDir) {
    XPathFactory xpf = XPathFactory.instance();
    XPathExpression<Element> fsExpr = xpf.compile(
            String.format("/domain/devices/filesystem[@type='mount']/target[@dir='%s']", targetDir),
            Filters.element());//from  w ww .  j  a  va2 s. c om
    List<Element> tfs = fsExpr.evaluate(domainXml);
    for (Element e : tfs) {
        e.getParentElement().getParentElement().removeContent(e.getParentElement());
    }
}

From source file:com.xebialabs.overcast.support.libvirt.jdom.FilesystemXml.java

License:Apache License

/**
 * Get map of {@link Filesystem}s. The key in the map is the target inside the domain. This will only return
 * filesystems of type 'mount'.//  w w w .  j av  a  2 s.c o  m
 */
public static Map<String, Filesystem> getFilesystems(Document domainXml) {
    Map<String, Filesystem> ret = Maps.newHashMap();
    XPathFactory xpf = XPathFactory.instance();
    XPathExpression<Element> fsExpr = xpf.compile(XPATH_FILESYSTEM, Filters.element());
    List<Element> filesystems = fsExpr.evaluate(domainXml);
    for (Element fs : filesystems) {
        Attribute accessMode = fs.getAttribute("accessmode");
        String source = fs.getChild("source").getAttribute("dir").getValue();
        String target = fs.getChild("target").getAttribute("dir").getValue();
        boolean readOnly = fs.getChild("readonly") != null;

        ret.put(target, new Filesystem(source, target,
                AccessMode.valueOf(accessMode.getValue().toUpperCase(Locale.US)), readOnly));
    }
    return ret;
}

From source file:com.xebialabs.overcast.support.libvirt.jdom.InterfaceXml.java

License:Apache License

/**
 * Get a map of mac addresses of interfaces defined on the domain. This is somewhat limited at the moment. It is
 * assumed that only one network interface with mac is connected to a bridge or network. For instance if you have a
 * bridged network device connected to 'br0' then you will find it's MAC address with the key 'br0'.
 */// www. j av  a  2 s  .  com
public static Map<String, String> getMacs(Document domainXml) {
    Map<String, String> macs = Maps.newHashMap();
    XPathFactory xpf = XPathFactory.instance();
    XPathExpression<Element> interfaces = xpf.compile("/domain/devices/interface", Filters.element());
    for (Element iface : interfaces.evaluate(domainXml)) {
        String interfaceType = iface.getAttribute("type").getValue();
        logger.debug("Detecting IP on network of type '{}'", interfaceType);
        if ("bridge".equals(interfaceType)) {
            Element macElement = iface.getChild("mac");
            String mac = macElement.getAttribute("address").getValue();
            Element sourceElement = iface.getChild("source");
            String bridge = sourceElement.getAttribute("bridge").getValue();
            logger.info("Detected MAC '{}' on bridge '{}'", mac, bridge);
            macs.put(bridge, mac);
        } else if ("network".equals(interfaceType)) {
            Element macElement = iface.getChild("mac");
            String mac = macElement.getAttribute("address").getValue();
            Element sourceElement = iface.getChild("source");
            String network = sourceElement.getAttribute("network").getValue();
            logger.info("Detected MAC '{}' on network '{}'", mac, network);
            macs.put(network, mac);
        } else {
            logger.warn("Ignoring network of type {}", interfaceType);
        }
    }
    return macs;
}

From source file:Contabilidad.QUALITAS.java

private void b_xmlActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_xmlActionPerformed
    // TODO add your handling code here:
    if (t_folio_factura.getText().compareTo("") != 0 && t_uuid_factura.getText().compareTo("") != 0) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {//ww w  .j a v a2  s  .c  o m
            session.beginTransaction().begin();
            String ruta = "";
            try {
                ruta = "";
                FileReader f = new FileReader("config.txt");
                BufferedReader b = new BufferedReader(f);
                if ((ruta = b.readLine()) == null)
                    ruta = "";
                b.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            Configuracion config = (Configuracion) session.get(Configuracion.class, 1);
            if (t_xml.getText().compareTo("") == 0)
                t_xml.setText(config.getRfc() + "_" + t_serie_factura.getText() + "_"
                        + t_folio_factura.getText() + "_" + t_rfc.getText() + ".xml");
            File xml = new File(ruta + "xml-timbrados/" + t_xml.getText());
            if (xml.exists())//existe en nuestro directorio
            {
                org.jdom2.Document documentJDOM = new SAXBuilder()
                        .build(ruta + "xml-timbrados/" + t_xml.getText());
                XPathExpression<org.jdom2.Element> xPathExpression = XPathFactory.instance()
                        .compile("/hibernate-configuration/session-factory/property", Filters.element());
                documentJDOM.getContent().remove("documentJDOM");

                Desktop.getDesktop().open(xml);
            } else//descargar el archivo del SAP
            {
                factura = (Factura) session.get(Factura.class, factura.getIdFactura());
                RequestTransaction rq = new RequestTransaction();
                rq.setRequestor(config.getRequestor());//Lo proporcionar MySuite
                rq.setTransaction("GET_DOCUMENT");//Tipo de Transaccion
                rq.setCountry("MX");//Codigo de pais
                rq.setUser(config.getRequestor());//igual que Requestor
                rq.setUserName(config.getUsuario_1());//Country.Entity.nombre_usuario
                rq.setEntity(config.getRfc());
                rq.setData1(t_serie_factura.getText());//serie del documento.
                rq.setData2(t_folio_factura.getText());//folio
                rq.setData3("PDF XML");//documentos
                abrir = "xml";
                llamarSoapDocumento(rq);
            }
        } catch (Exception e) {
            if (session != null)
                if (session.isConnected())
                    session.close();
            JOptionPane.showMessageDialog(null, "Error al consultar la base de datos");
        } finally {
            if (session != null)
                if (session.isOpen())
                    session.close();
        }
    } else {
        JOptionPane.showMessageDialog(null,
                "Debes generar comprobante primero para tratar de recuperar los datos del SAP");
    }
}

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
 *//*  w  w  w . ja v  a 2s  . co  m*/
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:de.sub.goobi.helper.HelperSchritte.java

License:Open Source License

public static void extractAuthorityMetadata(Path metadataFile, Map<String, List<String>> metadataPairs) {
    XPathFactory xFactory = XPathFactory.instance();
    XPathExpression<Element> authorityMetaXpath = xFactory.compile(
            "//mets:xmlData/mods:mods/mods:extension/goobi:goobi/goobi:metadata[goobi:authorityValue]",
            Filters.element(), null, mods, mets, goobiNamespace);
    SAXBuilder builder = new SAXBuilder();
    Document doc;//ww w  .j  a v a 2 s  .  com
    try {
        doc = builder.build(metadataFile.toString());
    } catch (JDOMException | IOException e1) {
        return;
    }
    for (Element meta : authorityMetaXpath.evaluate(doc)) {
        String name = meta.getAttributeValue("name");
        if (name == null) {
            continue;
        } else {
            String key = name + "_authority";
            List<String> values = metadataPairs.get(key);
            if (values == null) {
                values = new ArrayList<>();
                metadataPairs.put(key, values);
            }
            values.add(meta.getChildText("authorityValue", goobiNamespace));
        }
    }
}

From source file:de.uniba.dsg.ppn.ba.validation.XmlLocator.java

License:Open Source License

public XmlLocator() {
    saxBuilder = new SAXBuilder();
    saxBuilder.setJDOMFactory(new LocatedJDOMFactory());
    xPathFactory = XPathFactory.instance();
}

From source file:dibl.diagrams.Template.java

License:Open Source License

private void collectTileElements() {
    final XPathFactory f = XPathFactory.instance();
    // TODO extend xpath with condition inside for-loop
    final XPathExpression<Element> xpath = f.compile("//*[@inkscape:label='base tile']/*", Filters.element(),
            null, NS_INKSCAPE);/*from   w w  w .  ja  v a2s .  co  m*/
    for (final Element el : xpath.evaluate(doc)) {
        if (el.getName().equals("use")) {
            final String cellID = el.getAttributeValue("label", NS_INKSCAPE);
            if (cellID != null && cellID.trim().length() > 0) {
                if (!tileElements.containsKey(cellID.trim()))
                    tileElements.put(cellID.trim(), new HashSet<Element>());
                tileElements.get(cellID.trim()).add((el));
            }
            final int r = cellID.toCharArray()[1] - '1';
            final int c = cellID.toCharArray()[0] - 'A';
            if (r >= getNrOfRows())
                nrOfRows = r + 1;
            if (c >= getNrOfCols())
                nrOfCols = c + 1;
        }
    }
}

From source file:dibl.diagrams.Template.java

License:Open Source License

private void collectStitches() {
    final XPathFactory f = XPathFactory.instance();
    final XPathExpression<Element> xpath = f.compile("//*[@inkscape:label='pile']/*", Filters.element(), null,
            NS_INKSCAPE);/*from www .  j av  a2 s.co  m*/
    for (final Element el : xpath.evaluate(doc)) {
        final String label = el.getAttributeValue("label", NS_INKSCAPE);
        final String id = el.getAttributeValue("id");
        idsByLabels.put(label, id);
        labelsByIDs.put("#" + id, label);
    }
}

From source file:dibl.diagrams.Template.java

License:Open Source License

private void addAppliedMatrixToTextObject(final String[][] newValues) {
    final XPathFactory f = XPathFactory.instance();
    final XPathExpression<Element> xpath = f.compile("//*[@inkscape:label='trace']/*", Filters.element(), null,
            NS_INKSCAPE);//from w ww  .ja v a 2s .c om
    List<Element> traceElements = xpath.evaluate(doc);
    if (!traceElements.isEmpty())
        traceElements.iterator().next().addContent(Arrays.deepToString(newValues));
}