Example usage for org.jdom2 Element getChildText

List of usage examples for org.jdom2 Element getChildText

Introduction

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

Prototype

public String getChildText(final String cname) 

Source Link

Document

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

Usage

From source file:jmri.jmrit.vsdecoder.VSDFile.java

License:Open Source License

protected boolean validateFiles(Element el, String name, String[] fnames, Boolean required) {
    List<Element> elist = el.getChildren(name);
    String s;/*from   w w w  . ja  v a2 s  .  co  m*/

    // First, check to see if any elements of this <name> exist.
    if ((elist.size() == 0) && (required)) {
        // Only fail if this type of element is required.
        log.debug("No elements of name " + name);
        return (false);
    }

    // Now, if the elements exist, make sure the files they point to exist.
    // Would like to get rid of this suppression, but I think it's fairly safe to assume a list of children
    // returned from an Element is going to be a list of Elements.
    Iterator<Element> ns_i = elist.iterator();
    while (ns_i.hasNext()) {
        Element ns_e = ns_i.next();
        for (String fn : fnames) {
            s = ns_e.getChildText(fn);
            if ((s == null) || (getFile(s) == null)) {
                log.debug("File " + s + " for element " + fn + " in Element " + ns_e.getAttributeValue("name")
                        + " not found.");
                return (false);
            }
        }
    }
    // Made it this far, all is well.
    return (true);
}

From source file:kinomaniak.beans.Product.java

public Product(Element node) {
    if (!node.getName().equals("Product")) {
        //            throw new RuntimeException("Wrong element type");
        System.out.println("Wrong element type: Product, got: " + node.getName());
    }/*from  www  . j  a va  2s .  co  m*/

    this.name = node.getChildText("name");
    this.type = Integer.valueOf(node.getChildText("type"));
    this.count = Integer.valueOf(node.getChildText("count"));
    this.price = Float.valueOf(node.getChildText("price"));
}

From source file:lu.list.itis.dkd.aig.resolution.Dependency.java

License:Apache License

/**
 * Constructor initializing all fields from a provided element.
 *
 * @param dependencyElement//from  w w w  .  j  a  v  a2 s .c  om
 *
 * @throws TemplateParseException
 */
public Dependency(final Element dependencyElement) throws TemplateParseException {
    try {
        head = new URI(dependencyElement.getChildText(Externalization.HEAD_ELEMENT));
    } catch (final URISyntaxException e) {
        throw new TemplateParseException("The \"head\" element did not refer to a valid URI!", e); //$NON-NLS-1$
    }

    try {
        priority = Integer.parseInt(dependencyElement.getChildText(Externalization.PRIORITY_ELEMENT));
    } catch (final NumberFormatException e) {
        throw new TemplateParseException("The provided \"priority\" was not a valid integer!", e); //$NON-NLS-1$
    }

    try {
        cardinality = Integer.parseInt(dependencyElement.getChildText(Externalization.CARDINALITY_ELEMENT));
    } catch (final NumberFormatException e) {
        throw new TemplateParseException("The provided \"cardinality\" was not a valid integer!", e); //$NON-NLS-1$
    }

    for (final String identifier : Splitter.on(",").omitEmptyStrings().trimResults() //$NON-NLS-1$
            .splitToList(dependencyElement.getChildText(Externalization.TAIL_ELEMENT))) {
        try {
            tail.add(new URI(identifier));
        } catch (final URISyntaxException e) {
            throw new TemplateParseException(
                    "The \"tail\" element " + identifier + " did not refer to a valid URI!", e); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }

    unmappedTailElements.addAll(tail);
}

From source file:lu.list.itis.dkd.aig.TemplateResourceBuilder.java

License:Apache License

/**
 * Method used to construct a list of values
 *
 * @param parentElement//from   w  w w .j  av a 2s  .  co  m
 *        The parent element for which to extract all possible values.
 * @return A list of all values listed for the given parent element.
 * @throws TemplateParseException
 */
protected static List<Value> getValues(final Element parentElement) throws TemplateParseException {
    final List<Value> values = new ArrayList<>();

    for (final Element element : parentElement.getChild(Externalization.VALUES_ELEMENT).getChildren()) {
        if (Strings.isNullOrEmpty(element.getChildText(Externalization.TYPE_ELEMENT))) {
            throw new TemplateParseException("The type element must be provided and cannot be empty!"); //$NON-NLS-1$
        }
        values.add(TemplateResourceBuilder.buildValue(element));
    }
    return values;
}

From source file:lu.list.itis.dkd.aig.TemplateResourceBuilder.java

License:Apache License

private static Value buildValue(final Element element) throws TemplateParseException {
    URI identifier;/*ww  w  . jav a 2  s  . c om*/
    try {
        identifier = new URI(element.getChildText(Externalization.KEY_ELEMENT));
    } catch (final URISyntaxException e) {
        throw new TemplateParseException("The key of the value element was not a valid URI!", e); //$NON-NLS-1$
    }

    final ValueType type = ValueType.valueOf(element.getChildText(Externalization.TYPE_ELEMENT).toUpperCase());
    if (type.equals(ValueType.CODE)) {
        return new Value(identifier, type, UUID.randomUUID());
    } else {
        return new Value(identifier, type);
    }
}

From source file:main.Var.java

License:Open Source License

private static void XMLLoad(String ruta) {
    try {//from   w  w  w  .j av a 2 s .  c o m
        con = new Conexion();
        conFtp = new ConexionFtp();
        SAXBuilder builder = new SAXBuilder();
        File xmlFile = new File(ruta);

        Document document = (Document) builder.build(xmlFile);
        Element config = document.getRootElement();

        Element conexion = config.getChild("conexion");
        con.setDireccion(conexion.getChildText("db-host"));
        con.setPuerto(conexion.getChildText("db-port"));
        con.setUsuario(conexion.getChildText("db-username"));
        con.setPass(conexion.getChildText("db-password"));

        Element ftp = config.getChild("ftp");
        conFtp.setHost(ftp.getChildText("ftp-host"));
        conFtp.setPort(Integer.parseInt(ftp.getChildText("ftp-port")));
        conFtp.setUser(ftp.getChildText("ftp-user"));
        conFtp.setPass(ftp.getChildText("ftp-pass"));

        Element admin = config.getChild("modoAdmin");
        String activo = admin.getChildText("activo");
        modoAdmin = activo.equals("true");
        String pass = admin.getChildText("password");
        passwordAdmin = pass;
        String limit = admin.getChildText("query-limit");
        queryLimit = limit;

    } catch (JDOMException | IOException ex) {
        Logger.getLogger(Var.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:MDBInt.DBMongo.java

License:Apache License

public void init(String file) {
    Element params;
    try {/*from  w w  w.j a  v  a 2s  . c o  m*/
        parser = new ParserXML(new File(file));
        params = parser.getRootElement().getChild("pluginParams");
        dbName = params.getChildText("dbName");
        user = params.getChildText("user");
        password = params.getChildText("password");
        serverList = params.getChild("serversList");
        //this.connectReplication();

    } //init();
    catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:MDBInt.DBMongo.java

License:Apache License

public void initStable(String file) {
    Element params;
    try {/*  ww w . ja v  a2 s.  c o m*/
        parser = new ParserXML(new File(file));
        params = parser.getRootElement().getChild("pluginParams");
        dbName = params.getChildText("dbName");
        user = params.getChildText("user");
        password = params.getChildText("password");
        //serverList = params.getChild("serversList");
        this.mdbIp = params.getChildText("serverip");

    } catch (Exception ex) {
        ex.printStackTrace();
    }
    this.connectLocale(this.mdbIp);
}

From source file:MDBInt.DBMongo.java

License:Apache License

public void init() {
    //String file=configFile;
    String file = System.getenv("HOME");
    if (file == null) {
        file = "/home/beacon/beaconConf/configuration_bigDataPlugin.xml";

        /*String restkey="[";
        String rest="["; //  w  w w  .j  a  v a  2s  .co m
        Object[] tk=System.getenv().keySet().toArray();
        Object[] t=System.getenv().values().toArray();
        for(int i=0;i<t.length;i++){
        restkey=restkey+";"+(String)tk[i];
        rest=rest+";"+(String)t[i];
        }
        rest=rest+"]";
        restkey=restkey+"]";
        LOGGER.error(restkey+"\n"+rest);*/
    } else {

        file = file + "/webapps/OSFFM/WEB-INF/configuration_bigDataPlugin.xml";
    }
    Element params;
    try {
        parser = new ParserXML(new File(file));
        params = parser.getRootElement().getChild("pluginParams");
        dbName = params.getChildText("dbName");
        user = params.getChildText("user");
        password = params.getChildText("password");
        //serverList = params.getChild("serversList");
        this.mdbIp = params.getChildText("serverip");

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:mgbean.Listing.java

public Listing() {
    SAXBuilder builder = new SAXBuilder();

    File f = new File("/home/joci/Joci/Java_Tanfolyam/cd_catalog.xml");

    try {//from  w w w  .  j a v  a 2 s.  c o  m
        Document document = builder.build(f);
        Element root = document.getRootElement();

        List<Element> elements = root.getChildren();

        cds = new ArrayList<>();

        for (Element oneCD : elements) {

            CD cd = new CD(oneCD.getChildText("ARTIST"), oneCD.getChildText("TITLE"),
                    oneCD.getChildText("COMPANY"), oneCD.getChildText("COUNTRY"),
                    Double.parseDouble(oneCD.getChildText("PRICE")),
                    Integer.parseInt(oneCD.getChildText("YEAR")));
            cds.add(cd);

        }

    } catch (JDOMException | IOException ex) {
        System.out.println(ex);

    }

}