Example usage for org.jdom2 Element getChildTextTrim

List of usage examples for org.jdom2 Element getChildTextTrim

Introduction

In this page you can find the example usage for org.jdom2 Element getChildTextTrim.

Prototype

public String getChildTextTrim(final String cname) 

Source Link

Document

Returns the trimmed textual content of the named child element, or null if there's no such child.

Usage

From source file:com.gmapp.comun.LeerPathFromXML.java

public String cargarXml(String tipoPathBuscado) {
    //System.out.println("Buscando path para \"" + tipoPathBuscado + "\" ...");
    String pathBuscado = "";
    //Se crea un SAXBuilder para poder parsear el archivo
    SAXBuilder builder = new SAXBuilder();

    InputStream xmlFile = getClass().getResourceAsStream("/xml/pathFiles.xml");

    try {//from   ww w  . j  a  va2  s. c o  m

        //Se crea el documento a traves del archivo
        Document document = (Document) builder.build(xmlFile);

        //Se obtiene la raiz 'Sistemas'
        Element rootNode = document.getRootElement();

        //Se obtiene la lista de hijos de la raiz 'Sistemas'
        List list = rootNode.getChildren("Sistema");

        //Se recorre la lista de hijos de 'Sistemas'
        for (int i = 0; i < list.size(); i++) {
            //Se obtiene el elemento 'Sistema'
            Element sistema = (Element) list.get(i);

            //Se obtiene el atributo 'nombre' que esta en el tag 'Sistema'
            String nombreSistema = sistema.getAttributeValue("nombre");
            if (SysOper.contains(nombreSistema)) {
                //System.out.println("Sistema: " + nombreSistema );
                //Se obtiene la lista de hijos del tag 'Sistema~nombre '
                List lista_registros = sistema.getChildren();
                //Se recorre la lista de campos
                for (int j = 0; j < lista_registros.size(); j++) {
                    //Se obtiene el elemento 'campo'
                    Element campo = (Element) lista_registros.get(j);
                    //Se obtienen los valores que estan entre los tags '<campo></campo>'
                    //Se obtiene el valor que esta entre los tags '<nombre></nombre>'
                    String nombre = campo.getChildTextTrim("nombrePath");
                    if (nombre.equals(tipoPathBuscado)) {
                        //Se obtiene el valor que esta entre los tags '<valor></valor>'
                        pathBuscado = campo.getChildTextTrim("path");

                        //System.out.println( "\t"+nombre+"\t"+pathBuscado);
                    }
                }
            }
        }
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }

    return pathBuscado;
}

From source file:com.mercurypay.ws.sdk.MercuryResponse.java

License:Open Source License

public String getTransactionId() {
    Element tranResponseElement = responseRoot.getChild("TranResponse"); //$NON-NLS-1$
    if (tranResponseElement == null) {
        return null;
    }/*  w  w  w .j  a  va  2  s. c o m*/

    return tranResponseElement.getChildTextTrim("RecordNo"); //$NON-NLS-1$
}

From source file:com.mercurypay.ws.sdk.MercuryResponse.java

License:Open Source License

public String getAuthCode() {
    Element tranResponseElement = responseRoot.getChild("TranResponse"); //$NON-NLS-1$
    if (tranResponseElement == null) {
        return null;
    }//from www .  j av a2s  . c o m

    return tranResponseElement.getChildTextTrim("AuthCode"); //$NON-NLS-1$
}

From source file:com.mercurypay.ws.sdk.MercuryResponse.java

License:Open Source License

public String getAcqRefData() {
    Element tranResponseElement = responseRoot.getChild("TranResponse"); //$NON-NLS-1$
    if (tranResponseElement == null) {
        return null;
    }//from  www  .ja  v a2  s.c  o m

    return tranResponseElement.getChildTextTrim("AcqRefData"); //$NON-NLS-1$
}

From source file:com.oagsoft.grafo.util.XMLLoader.java

public static Grafo leerArchivoXml(String nomArch) {
    SAXBuilder builder = new SAXBuilder();
    Grafo g = null;//from w  ww.  j  av a  2  s  .c om
    try {
        Document document = (Document) builder.build(new File(nomArch));
        Element rootNode = document.getRootElement();
        Element nV = rootNode.getChild("numero-vertices");
        int numVertices = Integer.parseInt(nV.getValue().trim());
        g = new Grafo(numVertices);
        Element ad = rootNode.getChild("adyacencias");
        List<Element> hijos = ad.getChildren("adyacencia");
        for (Element hijo : hijos) {
            int nIni = Integer.parseInt(hijo.getChildTextTrim("nodo-inicial"));
            int nFin = Integer.parseInt(hijo.getChildTextTrim("nodo-final"));
            g.adyacencia(nIni, nFin);
        }
        //            System.out.println("Hay " + hijos.size()+ " adyacencias");
    } catch (JDOMException | IOException ex) {
        System.out.println(ex.getMessage());
    }
    return g;
}

From source file:com.oagsoft.wazgle.tools.XMLLoader.java

public static Grafo<GraphicNode> leerArchivoXml(String nomArch) {
    SAXBuilder builder = new SAXBuilder();
    Grafo<GraphicNode> g = null;/*from   w  w  w  .j av  a  2 s.  c  o  m*/
    try {
        Document document = (Document) builder.build(new File(nomArch));
        Element rootNode = document.getRootElement();
        Element nV = rootNode.getChild("numero-vertices");
        int numVertices = Integer.parseInt(nV.getValue().trim());
        g = new Grafo(numVertices);
        Element nodos = rootNode.getChild("nodos");
        List<Element> hijos = nodos.getChildren("nodo");
        for (Element hijo : hijos) {
            int id = Integer.parseInt(hijo.getChildTextTrim("id"));
            int coorX = Integer.parseInt(hijo.getChildTextTrim("coor-x"));
            int coorY = Integer.parseInt(hijo.getChildTextTrim("coor-y"));
            GraphicNode nodo = new GraphicNode(id, new Point(coorX, coorY), 10, false);
            g.adVertice(nodo);
        }
        Element adyacencias = rootNode.getChild("adyacencias");
        List<Element> ad = adyacencias.getChildren("adyacencia");
        for (Element hijo : ad) {
            int vIni = Integer.parseInt(hijo.getChildTextTrim("nodo-inicial"));
            int vFinal = Integer.parseInt(hijo.getChildTextTrim("nodo-final"));
            GraphicNode nIni = g.getVertice(vIni);
            GraphicNode nFin = g.getVertice(vFinal);

            g.adyacencia(nIni, nFin);

        }
        //            System.out.println("Hay " + hijos.size()+ " adyacencias");
    } catch (JDOMException | IOException ex) {
        System.out.println(ex.getMessage());
    }
    return g;
}

From source file:com.rometools.opml.io.impl.OPML10Parser.java

License:Apache License

/**
 * Parses an XML document (JDOM Document) into a feed bean.
 * <p>/*  w w  w  .j  a v a 2 s.  c om*/
 *
 * @param document XML document (JDOM) to parse.
 * @param validate indicates if the feed should be strictly validated (NOT YET IMPLEMENTED).
 * @return the resulting feed bean.
 * @throws IllegalArgumentException thrown if the parser cannot handle the given feed type.
 * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM).
 */
@Override
public WireFeed parse(final Document document, final boolean validate, final Locale locale)
        throws IllegalArgumentException, FeedException {
    final Opml opml = new Opml();
    opml.setFeedType("opml_1.0");

    final Element root = document.getRootElement();
    final Element head = root.getChild("head");

    if (head != null) {
        opml.setTitle(head.getChildText("title"));

        if (head.getChildText("dateCreated") != null) {
            opml.setCreated(DateParser.parseRFC822(head.getChildText("dateCreated"), Locale.US));
        }

        if (head.getChildText("dateModified") != null) {
            opml.setModified(DateParser.parseRFC822(head.getChildText("dateModified"), Locale.US));
        }

        opml.setOwnerName(head.getChildTextTrim("ownerName"));
        opml.setOwnerEmail(head.getChildTextTrim("ownerEmail"));
        opml.setVerticalScrollState(readInteger(head.getChildText("vertScrollState")));

        try {
            opml.setWindowBottom(readInteger(head.getChildText("windowBottom")));
        } catch (final NumberFormatException nfe) {
            LOG.warn("Unable to parse windowBottom", nfe);
            if (validate) {
                throw new FeedException("Unable to parse windowBottom", nfe);
            }
        }

        try {
            opml.setWindowLeft(readInteger(head.getChildText("windowLeft")));
        } catch (final NumberFormatException nfe) {
            LOG.warn("Unable to parse windowLeft", nfe);
            if (validate) {
                throw new FeedException("Unable to parse windowLeft", nfe);
            }
        }

        try {
            opml.setWindowRight(readInteger(head.getChildText("windowRight")));
        } catch (final NumberFormatException nfe) {
            LOG.warn("Unable to parse windowRight", nfe);
            if (validate) {
                throw new FeedException("Unable to parse windowRight", nfe);
            }
        }

        try {
            opml.setWindowLeft(readInteger(head.getChildText("windowLeft")));
        } catch (final NumberFormatException nfe) {
            LOG.warn("Unable to parse windowLeft", nfe);
            if (validate) {
                throw new FeedException("Unable to parse windowLeft", nfe);
            }
        }

        try {
            opml.setWindowTop(readInteger(head.getChildText("windowTop")));
        } catch (final NumberFormatException nfe) {
            LOG.warn("Unable to parse windowTop", nfe);
            if (validate) {
                throw new FeedException("Unable to parse windowTop", nfe);
            }
        }

        try {
            opml.setExpansionState(readIntArray(head.getChildText("expansionState")));
        } catch (final NumberFormatException nfe) {
            LOG.warn("Unable to parse expansionState", nfe);
            if (validate) {
                throw new FeedException("Unable to parse expansionState", nfe);
            }
        }
    }

    opml.setOutlines(parseOutlines(root.getChild("body").getChildren("outline"), validate, locale));
    opml.setModules(parseFeedModules(root, locale));

    return opml;
}

From source file:com.rometools.opml.io.impl.OPML20Parser.java

License:Apache License

/**
 * Parses an XML document (JDOM Document) into a feed bean.
 * <p>/*from   w  ww  .j a va 2  s  .  co  m*/
 *
 * @param document XML document (JDOM) to parse.
 * @param validate indicates if the feed should be strictly validated (NOT YET IMPLEMENTED).
 * @return the resulting feed bean.
 * @throws IllegalArgumentException thrown if the parser cannot handle the given feed type.
 * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM).
 */
@Override
public WireFeed parse(final Document document, final boolean validate, final Locale locale)
        throws IllegalArgumentException, FeedException {
    Opml opml;
    opml = (Opml) super.parse(document, validate, locale);

    final Element head = document.getRootElement().getChild("head");

    if (head != null) {
        opml.setOwnerId(head.getChildTextTrim("ownerId"));
        opml.setDocs(head.getChildTextTrim("docs"));

        if (opml.getDocs() == null) {
            opml.setDocs("http://www.opml.org/spec2");
        }
    }

    opml.setFeedType("opml_2.0");

    return opml;
}

From source file:com.rometools.rome.io.impl.OPML10Parser.java

License:Apache License

/**
       * Parses an XML document (JDOM Document) into a feed bean.
       * <p>// ww w  . j a v  a 2 s.  co m
       *
       * @param document XML document (JDOM) to parse.
       * @param validate indicates if the feed should be strictly validated (NOT YET IMPLEMENTED).
       * @return the resulting feed bean.
       * @throws IllegalArgumentException thrown if the parser cannot handle the given feed type.
       * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM).
       */
@Override
public WireFeed parse(final Document document, final boolean validate, final Locale locale)
        throws IllegalArgumentException, FeedException {
    final Opml opml = new Opml();
    opml.setFeedType("opml_1.0");

    final Element root = document.getRootElement();
    final Element head = root.getChild("head");

    if (head != null) {
        opml.setTitle(head.getChildText("title"));

        if (head.getChildText("dateCreated") != null) {
            opml.setCreated(DateParser.parseRFC822(head.getChildText("dateCreated"), Locale.US));
        }

        if (head.getChildText("dateModified") != null) {
            opml.setModified(DateParser.parseRFC822(head.getChildText("dateModified"), Locale.US));
        }

        opml.setOwnerName(head.getChildTextTrim("ownerName"));
        opml.setOwnerEmail(head.getChildTextTrim("ownerEmail"));
        opml.setVerticalScrollState(readInteger(head.getChildText("vertScrollState")));
    }

    try {
        opml.setWindowBottom(readInteger(head.getChildText("windowBottom")));
    } catch (final NumberFormatException nfe) {

        if (validate) {
            throw new FeedException("Unable to parse windowBottom", nfe);
        }
    }

    try {
        opml.setWindowLeft(readInteger(head.getChildText("windowLeft")));
    } catch (final NumberFormatException nfe) {
    }

    try {
        opml.setWindowRight(readInteger(head.getChildText("windowRight")));
    } catch (final NumberFormatException nfe) {

        if (validate) {
            throw new FeedException("Unable to parse windowRight", nfe);
        }
    }

    try {
        opml.setWindowLeft(readInteger(head.getChildText("windowLeft")));
    } catch (final NumberFormatException nfe) {

        if (validate) {
            throw new FeedException("Unable to parse windowLeft", nfe);
        }
    }

    try {
        opml.setWindowTop(readInteger(head.getChildText("windowTop")));
    } catch (final NumberFormatException nfe) {

        if (validate) {
            throw new FeedException("Unable to parse windowTop", nfe);
        }
    }

    try {
        opml.setExpansionState(readIntArray(head.getChildText("expansionState")));
    } catch (final NumberFormatException nfe) {

        if (validate) {
            throw new FeedException("Unable to parse expansionState", nfe);
        }
    }

    opml.setOutlines(parseOutlines(root.getChild("body").getChildren("outline"), validate, locale));
    opml.setModules(parseFeedModules(root, locale));

    return opml;
}

From source file:de.nava.informa.parsers.RSS_0_91_Parser.java

License:Open Source License

/**
 * @see de.nava.informa.core.ChannelParserIF#parse(de.nava.informa.core.ChannelBuilderIF, org.jdom2.Element)
 */// ww w . ja  v  a 2  s. co  m
public ChannelIF parse(ChannelBuilderIF cBuilder, Element root) throws ParseException {
    if (cBuilder == null) {
        throw new RuntimeException("Without builder no channel can " + "be created.");
    }
    Date dateParsed = new Date();
    logger.debug("start parsing.");

    // Get the channel element (only one occurs)
    ParserUtils.matchCaseOfChildren(root, "channel");
    Element channel = root.getChild("channel");
    if (channel == null) {
        logger.warn("Channel element could not be retrieved from feed.");
        throw new ParseException("No channel element found in feed.");
    }

    // --- read in channel information

    ParserUtils.matchCaseOfChildren(channel,
            new String[] { "title", "description", "link", "language", "item", "image", "textinput",
                    "copyright", "rating", "pubDate", "lastBuildDate", "docs", "managingEditor", "webMaster",
                    "cloud" });

    // 1 title element
    ChannelIF chnl = cBuilder.createChannel(channel, channel.getChildTextTrim("title"));

    chnl.setFormat(ChannelFormat.RSS_0_91);

    // 1 description element
    chnl.setDescription(channel.getChildTextTrim("description"));

    // 1 link element
    chnl.setSite(ParserUtils.getURL(channel.getChildTextTrim("link")));

    // 1 language element
    chnl.setLanguage(channel.getChildTextTrim("language"));

    // 1..n item elements
    List items = channel.getChildren("item");
    Iterator i = items.iterator();
    while (i.hasNext()) {
        Element item = (Element) i.next();

        ParserUtils.matchCaseOfChildren(item,
                new String[] { "title", "link", "description", "source", "enclosure" });

        // get title element
        Element elTitle = item.getChild("title");
        String strTitle = "<No Title>";
        if (elTitle != null) {
            strTitle = elTitle.getTextTrim();
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Item element found (" + strTitle + ").");
        }

        // get link element
        Element elLink = item.getChild("link");
        String strLink = "";
        if (elLink != null) {
            strLink = elLink.getTextTrim();
        }

        // get description element
        Element elDesc = item.getChild("description");
        String strDesc = "";
        if (elDesc != null) {
            strDesc = elDesc.getTextTrim();
        }

        // generate new RSS item (link to article)
        ItemIF rssItem = cBuilder.createItem(item, chnl, strTitle, strDesc, ParserUtils.getURL(strLink));
        rssItem.setFound(dateParsed);

        // get source element (an RSS 0.92 element)
        Element source = item.getChild("source");
        if (source != null) {
            String sourceName = source.getTextTrim();
            Attribute sourceAttribute = source.getAttribute("url");
            if (sourceAttribute != null) {
                String location = sourceAttribute.getValue().trim();
                ItemSourceIF itemSource = cBuilder.createItemSource(rssItem, sourceName, location, null);
                rssItem.setSource(itemSource);
            }
        }

        // get enclosure element (an RSS 0.92 element)
        Element enclosure = item.getChild("enclosure");
        if (enclosure != null) {
            URL location = null;
            String type = null;
            int length = -1;
            Attribute urlAttribute = enclosure.getAttribute("url");
            if (urlAttribute != null) {
                location = ParserUtils.getURL(urlAttribute.getValue().trim());
            }
            Attribute typeAttribute = enclosure.getAttribute("type");
            if (typeAttribute != null) {
                type = typeAttribute.getValue().trim();
            }
            Attribute lengthAttribute = enclosure.getAttribute("length");
            if (lengthAttribute != null) {
                try {
                    length = Integer.parseInt(lengthAttribute.getValue().trim());
                } catch (NumberFormatException e) {
                    logger.warn(e);
                }
            }
            ItemEnclosureIF itemEnclosure = cBuilder.createItemEnclosure(rssItem, location, type, length);
            rssItem.setEnclosure(itemEnclosure);
        }
    }

    // 0..1 image element
    Element image = channel.getChild("image");
    if (image != null) {

        ParserUtils.matchCaseOfChildren(image,
                new String[] { "title", "url", "link", "width", "height", "description" });

        ImageIF rssImage = cBuilder.createImage(image.getChildTextTrim("title"),
                ParserUtils.getURL(image.getChildTextTrim("url")),
                ParserUtils.getURL(image.getChildTextTrim("link")));
        Element imgWidth = image.getChild("width");
        if (imgWidth != null) {
            try {
                rssImage.setWidth(Integer.parseInt(imgWidth.getTextTrim()));
            } catch (NumberFormatException e) {
                logger.warn(e);
            }
        }
        Element imgHeight = image.getChild("height");
        if (imgHeight != null) {
            try {
                rssImage.setHeight(Integer.parseInt(imgHeight.getTextTrim()));
            } catch (NumberFormatException e) {
                logger.warn(e);
            }
        }
        Element imgDescr = image.getChild("description");
        if (imgDescr != null) {
            rssImage.setDescription(imgDescr.getTextTrim());
        }
        chnl.setImage(rssImage);
    }

    // 0..1 textinput element
    Element txtinp = channel.getChild("textinput");
    if (txtinp != null) {

        ParserUtils.matchCaseOfChildren(txtinp, new String[] { "title", "description", "name", "link" });

        TextInputIF rssTextInput = cBuilder.createTextInput(txtinp.getChild("title").getTextTrim(),
                txtinp.getChild("description").getTextTrim(), txtinp.getChild("name").getTextTrim(),
                ParserUtils.getURL(txtinp.getChild("link").getTextTrim()));
        chnl.setTextInput(rssTextInput);
    }

    // 0..1 copyright element
    Element copyright = channel.getChild("copyright");
    if (copyright != null) {
        chnl.setCopyright(copyright.getTextTrim());
    }

    // 0..1 rating element
    Element rating = channel.getChild("rating");
    if (rating != null) {
        chnl.setRating(rating.getTextTrim());
    }

    // 0..1 pubDate element
    Element pubDate = channel.getChild("pubDate");
    if (pubDate != null) {
        chnl.setPubDate(ParserUtils.getDate(pubDate.getTextTrim()));
    }

    // 0..1 lastBuildDate element
    Element lastBuildDate = channel.getChild("lastBuildDate");
    if (lastBuildDate != null) {
        chnl.setLastBuildDate(ParserUtils.getDate(lastBuildDate.getTextTrim()));
    }

    // 0..1 docs element
    Element docs = channel.getChild("docs");
    if (docs != null) {
        chnl.setDocs(docs.getTextTrim());
    }

    // 0..1 managingEditor element
    Element managingEditor = channel.getChild("managingEditor");
    if (managingEditor != null) {
        chnl.setCreator(managingEditor.getTextTrim());
    }

    // 0..1 webMaster element
    Element webMaster = channel.getChild("webMaster");
    if (webMaster != null) {
        chnl.setPublisher(webMaster.getTextTrim());
    }

    // 0..1 cloud element
    Element cloud = channel.getChild("cloud");
    if (cloud != null) {
        String _port = cloud.getAttributeValue("port");
        int port = -1;
        if (_port != null) {
            try {
                port = Integer.parseInt(_port);
            } catch (NumberFormatException e) {
                logger.warn(e);
            }
        }
        chnl.setCloud(
                cBuilder.createCloud(cloud.getAttributeValue("domain"), port, cloud.getAttributeValue("path"),
                        cloud.getAttributeValue("registerProcedure"), cloud.getAttributeValue("protocol")));
    }

    chnl.setLastUpdated(dateParsed);
    // 0..1 skipHours element
    // 0..1 skipDays element

    return chnl;
}