Example usage for org.jdom2 Element getText

List of usage examples for org.jdom2 Element getText

Introduction

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

Prototype

public String getText() 

Source Link

Document

Returns the textual content directly held under this element as a string.

Usage

From source file:io.smartspaces.master.server.services.internal.support.JdomMasterDomainModelImporter.java

License:Apache License

/**
 * Get an activity configuration.//ww w . ja v a2 s .  c  om
 *
 * @param rootElement
 *          the XML element that might contain an activity configuration
 * @param activityRepository
 *          repository for activity entities
 *
 * @return an activity configuration, if there was one, or {@code null}
 */
private ActivityConfiguration getActivityConfiguration(Element rootElement,
        ActivityRepository activityRepository) {
    Element configurationElement = rootElement.getChild(ELEMENT_NAME_ACTIVITY_CONFIGURATION);
    if (configurationElement != null) {
        ActivityConfiguration configuration = activityRepository.newActivityConfiguration();
        Element parametersElement = configurationElement
                .getChild(ELEMENT_NAME_ACTIVITY_CONFIGURATION_ROOT_PARAMETERS);
        if (parametersElement != null) {
            List<Element> parameterElements = parametersElement
                    .getChildren(ELEMENT_NAME_ACTIVITY_CONFIGURATION_INDIVIDUAL_PARAMETER);
            for (Element parameterElement : parameterElements) {
                ConfigurationParameter parameter = activityRepository.newActivityConfigurationParameter();

                String name = parameterElement
                        .getAttributeValue(ATTRIBUTE_NAME_ACTIVITY_CONFIGURATION_PARAMETER_NAME);
                String value = parameterElement.getText();

                parameter.setName(name);
                parameter.setValue(value);

                configuration.addParameter(parameter);
            }
        }

        return configuration;
    }

    return null;
}

From source file:io.smartspaces.master.server.services.internal.support.JdomMasterDomainModelImporter.java

License:Apache License

/**
 * Get a metadata map from an element, if any.
 *
 * @param metadataElement//from   w w  w .j  a va 2 s . c o m
 *          the metadata XML element (can be {@code null})
 *
 * @return either a map of metadata or {@code null} if no map.
 */
private Map<String, Object> getMetadata(Element metadataElement) {
    if (metadataElement == null) {
        return null;
    }

    Map<String, Object> metadata = new HashMap<>();

    List<Element> itemElements = metadataElement.getChildren(ELEMENT_NAME_METADATA_ITEM);
    for (Element itemElement : itemElements) {
        String name = itemElement.getAttributeValue(ATTRIBUTE_NAME_METADATA_ITEM_NAME);
        String value = itemElement.getText();

        metadata.put(name, value);
    }

    if (metadata.isEmpty()) {
        return null;
    } else {
        return metadata;
    }
}

From source file:io.wcm.maven.plugins.i18n.readers.XmlI18nReader.java

License:Apache License

private void parseXml(Element node, Map<String, String> map, String prefix) {
    List<Element> children = node.getChildren();
    for (Element child : children) {
        String key = child.getName();
        if (child.getChildren().size() > 0) {
            parseXml(child, map, prefix + key + ".");
        } else {/* w  w  w.  j a v a2s  .  c om*/
            map.put(prefix + key, child.getText());
        }
    }
}

From source file:javaapplication1.LeerXml.java

public void cargarXml() {
    //Se crea un SAXBuilder para poder parsear el archivo
    SAXBuilder builder = new SAXBuilder();
    File xmlFile = new File("archivo.xml");
    try {/*  ww  w .  j  av a 2 s.c om*/
        //Se crea el documento a traves del archivo
        Document document = (Document) builder.build(xmlFile);

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

        //Se obtiene la lista de hijos de la raiz 'tables'
        List list = rootNode.getChildren("dimension");
        List list_dobles = rootNode.getChildren("dobles");
        List list_triples = rootNode.getChildren("triples");
        List list_diccionario = rootNode.getChildren("diccionario");
        //Se recorre la lista de hijos de 'tables'
        for (int i = 0; i < list.size(); i++) {
            //Se obtiene el elemento 'tabla'
            Element tabla = (Element) list.get(i);
            System.out.println("Dimension: " + tabla.getText());
            dimension = Integer.parseInt(tabla.getText());
            m = new Matriz(dimension, dimension);
        }
        for (int i = 0; i < list_dobles.size(); i++) {
            //Se obtiene el elemento 'tabla'
            Element tabla = (Element) list_dobles.get(i);
            //Se obtiene el atributo 'nombre' que esta en el tag 'tabla'
            //String nombreTabla = tabla.getAttributeValue("nombre");

            //System.out.println("Tabla: " + nombreTabla);
            //Se obtiene la lista de hijos del tag 'tabla'
            List lista_campos = tabla.getChildren();

            //System.out.println("\tNombre\t\tTipo\t\tValor");
            //Se recorre la lista de campos
            for (int j = 0; j < lista_campos.size(); j++) {
                //Se obtiene el elemento 'campo'
                Element campo = (Element) lista_campos.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 x = campo.getChildTextTrim("x");

                //Se obtiene el valor que esta entre los tags '<tipo></tipo>'
                String y = campo.getChildTextTrim("y");
                m.item(Integer.parseInt(x) - 1, Integer.parseInt(y) - 1).datos = 2;
                System.out.println("Puntos Dobles en la posicion X:" + x + " Y: " + y);
            }
        }
        for (int i = 0; i < list_triples.size(); i++) {
            //Se obtiene el elemento 'tabla'
            Element tabla = (Element) list_triples.get(i);
            //Se obtiene el atributo 'nombre' que esta en el tag 'tabla'
            //String nombreTabla = tabla.getAttributeValue("nombre");

            //System.out.println("Tabla: " + nombreTabla);
            //Se obtiene la lista de hijos del tag 'tabla'
            List lista_campos = tabla.getChildren();

            //System.out.println("\tNombre\t\tTipo\t\tValor");
            //Se recorre la lista de campos
            for (int j = 0; j < lista_campos.size(); j++) {
                //Se obtiene el elemento 'campo'
                Element campo = (Element) lista_campos.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 x = campo.getChildTextTrim("x");

                //Se obtiene el valor que esta entre los tags '<tipo></tipo>'
                String y = campo.getChildTextTrim("y");
                m.item(Integer.parseInt(x) - 1, Integer.parseInt(y) - 1).datos = 3;
                System.out.println("Puntos Triples en la posicion X:" + x + " Y: " + y);
            }
        }

        for (int i = 0; i < list_diccionario.size(); i++) {
            //Se obtiene el elemento 'tabla'
            Element tabla = (Element) list_diccionario.get(i);
            //Se obtiene el atributo 'nombre' que esta en el tag 'tabla'
            //String nombreTabla = tabla.getAttributeValue("nombre");

            //System.out.println("Tabla: " + nombreTabla);
            //Se obtiene la lista de hijos del tag 'tabla'
            List lista_campos = tabla.getChildren();

            //System.out.println("\tNombre\t\tTipo\t\tValor");
            //Se recorre la lista de campos
            for (int j = 0; j < lista_campos.size(); j++) {
                //Se obtiene el elemento 'campo'
                Element campo = (Element) lista_campos.get(j);
                System.out.println("Palabra: " + campo.getText() + " tamano lista " + diccionario.getsize());
                diccionario.insertarAlFinal(campo.getText());
            }
        }
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }
}

From source file:javaapplication5.JavaApplication5.java

public static Boolean checkRemitente(String from) throws JDOMException, IOException {
    boolean resultado = false;
    //Se crea un SAXBuilder para poder parsear el archivo
    SAXBuilder builder = new SAXBuilder();
    //Traigo el XML de remitentes validos
    File xmlFile = new File(
            "C:\\Users\\Matias\\Documents\\NetBeansProjects\\Repo\\JavaApplication5\\src\\javaapplication5\\remitentes.xml");

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

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

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

    //Se recorre la lista de hijos de 'remitentes'
    for (int i = 0; i < list.size(); i++) {
        //por cada remitente
        Element remitente = (Element) list.get(i);
        String rem = remitente.getText();
        //si el remitente q me vino del mail esta en el XML pone en true la variable resultado
        if (from.equals(rem)) {
            resultado = true;/*from  w  w w.java2s  .com*/
            return (resultado);

        }
    }
    return resultado;
}

From source file:jmri.implementation.configurexml.MergSD2SignalHeadXml.java

License:Open Source License

NamedBeanHandle<Turnout> loadTurnout(Object o) {
    Element e = (Element) o;

    if (e.getName().equals("turnout")) {
        String name = e.getAttribute("systemName").getValue();
        Turnout t;/*from  w  w  w. j  a v  a 2s.co m*/
        if (e.getAttribute("userName") != null && !e.getAttribute("userName").getValue().equals("")) {
            name = e.getAttribute("userName").getValue();
            t = InstanceManager.turnoutManagerInstance().getTurnout(name);
        } else {
            t = InstanceManager.turnoutManagerInstance().getBySystemName(name);
        }
        return jmri.InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).getNamedBeanHandle(name, t);
    } else {
        String name = e.getText();
        Turnout t = InstanceManager.turnoutManagerInstance().provideTurnout(name);
        return jmri.InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).getNamedBeanHandle(name, t);
    }
}

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

License:Open Source License

@Override
public void setXml(Element e, VSDFile vf) {
    Element el;//from   w w w  . j  a  va2  s .c  o  m
    String fn;
    D3Notch sb;

    // Handle the common stuff.
    super.setXml(e, vf);

    //log.debug("Diesel EngineSound: " + e.getAttribute("name").getValue());
    _soundName = this.getName() + ":LoopSound";
    log.debug("Diesel3: name: " + this.getName() + " soundName " + _soundName);
    notch_sounds = new HashMap<Integer, D3Notch>();
    String in = e.getChildText("idle-notch");
    Integer idle_notch = null;
    if (in != null) {
        idle_notch = Integer.parseInt(in);
    } else {
        // leave idle_notch null for now. We'll use it at the end to trigger a "grandfathering" action
        log.warn("No Idle Notch Specified!");
    }

    // Get the notch sounds
    Iterator<Element> itr = (e.getChildren("notch-sound")).iterator();
    int i = 0;
    while (itr.hasNext()) {
        el = itr.next();
        sb = new D3Notch();
        int nn = Integer.parseInt(el.getChildText("notch"));
        sb.setNotch(nn);
        if ((idle_notch != null) && (nn == idle_notch)) {
            sb.setIdleNotch(true);
            log.debug("This Notch (" + nn + ") is Idle.");
        }
        List<Element> elist = el.getChildren("file");
        int j = 0;
        for (Element fe : elist) {
            fn = fe.getText();
            //AudioBuffer b = D3Notch.getBuffer(vf, fn, "Engine_n" + i + "_" + j, "Engine_" + i + "_" + j);
            //log.debug("Buffer created: " + b + " name: " + b.getSystemName());
            //sb.addLoopBuffer(b);
            List<AudioBuffer> l = D3Notch.getBufferList(vf, fn, "Engine_n" + i + "_" + j,
                    "Engine_" + i + "_" + j);
            log.debug("Buffers Created: ");
            for (AudioBuffer b : l) {
                log.debug("\tSubBuffer: " + b.getSystemName());
            }
            sb.addLoopBuffers(l);
            j++;
        }
        //log.debug("Notch: " + nn + " File: " + fn);

        // Gain is broken, for the moment.  Buffers don't have gain. Sources do.
        //_sound.setGain(setXMLGain(el));
        //_sound.setGain(default_gain);
        sb.setNextNotch(el.getChildText("next-notch"));
        sb.setPrevNotch(el.getChildText("prev-notch"));
        sb.setAccelLimit(el.getChildText("accel-limit"));
        sb.setDecelLimit(el.getChildText("decel-limit"));
        if (el.getChildText("accel-file") != null) {
            sb.setAccelBuffer(
                    D3Notch.getBuffer(vf, el.getChildText("accel-file"), "Engine_na" + i, "Engine_na" + i));
        } else {
            sb.setAccelBuffer(null);
        }
        if (el.getChildText("decel-file") != null) {
            sb.setDecelBuffer(
                    D3Notch.getBuffer(vf, el.getChildText("decel-file"), "Engine_nd" + i, "Engine_nd" + i));
        } else {
            sb.setDecelBuffer(null);
        }
        // Store in the list.
        notch_sounds.put(nn, sb);
        i++;
    }

    // Get the start and stop sounds
    el = e.getChild("start-sound");
    if (el != null) {
        fn = el.getChild("file").getValue();
        //log.debug("Start sound: " + fn);
        start_buffer = D3Notch.getBuffer(vf, fn, "Engine_start", "Engine_Start");
    }
    el = e.getChild("shutdown-sound");
    if (el != null) {
        fn = el.getChild("file").getValue();
        //log.debug("Shutdown sound: " + fn);
        stop_buffer = D3Notch.getBuffer(vf, fn, "Engine_shutdown", "Engine_Shutdown");
    }

    // Handle "grandfathering the idle notch indication
    // If the VSD designer did not explicitly designate an idle notch...
    // Find the Notch with the lowest notch number, and make it the idle notch.
    // If there's a tie, this will take the first value, but the notches /should/
    // all have unique notch numbers.
    if (idle_notch == null) {
        D3Notch min_notch = null;
        // No, this is not a terribly efficient "min" operation.  But that's OK.
        for (D3Notch n : notch_sounds.values()) {
            if ((min_notch == null) || (n.getNotch() < min_notch.getNotch())) {
                min_notch = n;
            }
        }
        log.debug("No Idle Notch Specified.  Choosing Notch ("
                + (min_notch != null ? min_notch.getNotch() : "min_notch not set") + ") to be the Idle Notch.");
        if (min_notch != null) {
            min_notch.setIdleNotch(true);
        } else {
            log.warn("Could not set idle notch because min_notch was still null");
        }
    }

    // Kick-start the loop thread.
    this.startThread();
}

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

License:Open Source License

@Override
public Element getXml() {
    Element me = new Element("SoundEvent");
    me.setAttribute("name", name);
    me.setAttribute("label", me.getText());
    for (Trigger t : trigger_list.values()) {
        me.addContent(t.getXml());//from   ww  w  .j a va 2s .  co m
    }

    return (me);
}

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

License:Open Source License

public Element getXml() {
    Element me = new Element("SoundEvent");
    me.setAttribute("name", name);
    me.setAttribute("label", me.getText());
    for (Trigger t : trigger_list.values()) {
        me.addContent(t.getXml());//w  w w.  j a  v a  2 s.com
    }

    return (me);
}