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:org.polago.deployconf.task.properties.PropertiesTask.java

License:Open Source License

/**
 * {@inheritDoc}/*from ww  w.j a  v  a2 s .co  m*/
 */
@Override
public void deserialize(Element node, ConfigGroupManager groupManager) throws IOException {
    String attribute = node.getAttributeValue(DOM_ATTRIBUTE_PATH);
    if (attribute == null) {
        attribute = PATH_IGNORE;
    }
    setPath(attribute);

    for (Element e : node.getChildren()) {
        String name = e.getChildTextTrim(DOM_ELEMENT_NAME);
        if (name.length() == 0) {
            throw new IllegalStateException("Property name element does not exists");
        }
        String description = e.getChildTextTrim(DOM_ELEMENT_DESCRIPTION);
        if (description.length() == 0) {
            throw new IllegalStateException("Property description element does not exists");
        }
        String defaultValue = e.getChildTextTrim(DOM_ELEMENT_DEFAULT);

        String group = e.getAttributeValue(DOM_ATTRIBUTE_GROUP);
        String value = null;

        if (group != null) {
            value = groupManager.lookupGroup(group).getProperty(name);
        }

        if (value == null) {
            value = e.getChildTextTrim(DOM_ELEMENT_VALUE);
        }

        Property p = new Property(name, description, defaultValue, value);

        if (group != null) {
            p.setGroup(group);
        }

        properties.add(p);
    }
}

From source file:org.xwiki.contrib.jira.macro.internal.displayer.field.AbstractJIRAFieldDisplayer.java

License:Open Source License

/**
 * Get the field value from the passed XML represented as an {@link Element} and look in custom fields when not
 * found in the default jira fields.//from  w  w w.  j a va  2 s  .co  m
 *
 * @param field the field for which to get the value
 * @param issue the XML representation of the JIRA issue from which to extract the field's value
 * @return
 */
protected String getValue(JIRAField field, Element issue) {
    // First, look for the field name in the default fields
    String text = issue.getChildTextTrim(field.getId());
    if (text == null) {
        // Not found as a default field. Verify if it's a custom field.
        Element customFieldsElement = issue.getChild("customfields");
        if (customFieldsElement != null) {
            for (Element customFieldElement : customFieldsElement.getChildren("customfield")) {
                String customFieldName = customFieldElement.getChildTextTrim("customfieldname");
                if (customFieldName != null && customFieldName.equals(field.getId())) {
                    // Found a matching field, render its value and stop looking
                    // Note: we only take into account the first "customfieldvalue" element for now. If a custom
                    // field needs to hadle multiple values, it'll need a custom field displayer defined.
                    String value = customFieldElement.getChildren("customfieldvalues").get(0).getValue().trim();
                    text = value;
                    break;
                }
            }
        }
    }
    return text;
}

From source file:org.xwiki.contrib.nestedpagesmigrator.testframework.Example.java

License:Open Source License

private Page getPageFromElement(Element element) {
    DocumentReference reference = resolveDocument(element.getChild("fullName").getText());
    DocumentReference parent = element.getChild("parent") != null
            ? resolveDocument(element.getChild("parent").getText())
            : null;/*from  ww w .ja v  a  2  s  . c o  m*/
    DocumentReference from = element.getChild("from") != null
            ? resolveDocument(element.getChild("from").getText())
            : null;
    boolean isFailedToLoad = "true".equals(element.getAttributeValue("errorOnLoad"));
    DocumentReference duplicateOf = element.getChild("duplicateOf") != null
            ? resolveDocument(element.getChildTextTrim("duplicateOf"))
            : null;
    boolean deletePrevious = "true".equals(element.getAttributeValue("deletePrevious"));

    Page page = new Page(reference, parent, from, isFailedToLoad, duplicateOf, deletePrevious);

    Element preferences = element.getChild("preferences");
    if (preferences != null) {
        for (Element preference : preferences.getChildren()) {
            String name = preference.getChildText("name");
            String value = preference.getChildText("value");
            DocumentReference origin = resolveDocument(preference.getChildText("origin"));
            if (origin == null) {
                origin = new DocumentReference("WebPreferences", reference.getLastSpaceReference());
            }
            page.addPreference(new Preference(name, value, origin));
        }
    }

    Element rights = element.getChild("rights");
    if (rights != null) {
        for (Element right : rights.getChildren()) {
            elementToRights(right, page);
        }
    }

    return page;
}

From source file:org.xwiki.contrib.rest.users.internal.DefaultXMLRestUserConfiguration.java

License:Open Source License

private void loadUsers() {
    if (xmlConfiguration.getXML() != null) {
        users.clear();/*from ww w. ja v a 2 s .  co  m*/
        Element usersElement = xmlConfiguration.getXML().getRootElement().getChild("users");
        if (usersElement != null) {
            for (Element userElement : usersElement.getChildren("user")) {
                XMLRestUser user = (XMLRestUser) userProvider.get();
                user.setName(userElement.getChildTextTrim("name"));
                user.setHashedPassword(userElement.getChildTextTrim("password"));
                for (Element groupElement : userElement.getChildren("group")) {
                    String group = groupElement.getTextTrim();
                    if (StringUtils.isNotBlank(group)) {
                        user.addGroup(group);
                    }
                }
                users.put(user.getName(), user);
            }
        }
    }
}

From source file:org.xwiki.rendering.internal.macro.jira.displayer.field.DefaultJIRAFieldDisplayer.java

License:Open Source License

@Override
public List<Block> displayField(String fieldName, Element issue) {
    List<Block> result;// ww  w  .  j av  a2  s .c  o m
    String text = issue.getChildTextTrim(fieldName);
    if (text != null) {
        result = Arrays.<Block>asList(new VerbatimBlock(text, true));
    } else {
        result = Collections.emptyList();
    }
    return result;
}

From source file:practica1_200718932.MainWindow.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

    SAXBuilder builder = new SAXBuilder();
    File xmlfile = new File("XML PRUEBA.xml");

    String pal = null;//from w  w  w . ja  v  a  2s  .  c o  m

    try {
        Document docs = (Document) builder.build(xmlfile);
        Element rootNode = docs.getRootElement();

        List listaDobles = rootNode.getChildren("dobles");
        List listaTriples = rootNode.getChildren("triples");
        List listaDiccionario = rootNode.getChildren("diccionario");

        String dimen = rootNode.getChildTextTrim("dimension");
        System.out.println("\t" + dimen);

        for (int i = 0; i < listaDobles.size(); i++) {

            Element tabladoble = (Element) listaDobles.get(i);
            List lista_dobles = tabladoble.getChildren();

            for (int j = 0; j < lista_dobles.size(); j++) {

                Element casilla = (Element) lista_dobles.get(j);

                String x = casilla.getChildTextTrim("x");
                String y = casilla.getChildTextTrim("y");
                System.out.println("\t" + x + "\t\t" + y);

            }
        }

        for (int m = 0; m < listaTriples.size(); m++) {

            Element tablatriple = (Element) listaTriples.get(m);
            List lista_triples = tablatriple.getChildren(dimen);

            for (int n = 0; n < lista_triples.size(); n++) {

                Element casilla = (Element) lista_triples.get(n);

                String x = casilla.getChildTextTrim("x");
                String y = casilla.getChildTextTrim("y");
                System.out.println("\t" + x + "\t\t" + y);

            }
        }

        for (int k = 0; k < listaDiccionario.size(); k++) {

            Element tabladiccionario = (Element) listaDiccionario.get(k);
            List lista_diccionario = tabladiccionario.getChildren();

            for (int l = 0; l < lista_diccionario.size(); l++) {

                Element palabra = (Element) lista_diccionario.get(l);

                pal = palabra.getChildTextTrim("palabra");
                System.out.println("\t" + pal);

            }
        }

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

}

From source file:starmap.FileLoader.java

public static String getAttribute(Element elem, String name, String defaultValue) {
    String str = elem.getChildTextTrim(name);
    if (str == null)
        return defaultValue;
    return str;//  w w  w .  j  a  v a  2s.c o m
}

From source file:VENTANAS.cargaArchivo.java

/**
 * @param args the command line arguments
 *//*w w w .j a  v  a  2  s .  c om*/
private void leerXML(String path) throws JDOMException, IOException {
    SAXBuilder parser = new SAXBuilder();
    File archivo = new File(path);
    Document documento = (Document) parser.build(archivo);
    Element raiz = documento.getRootElement();
    int tamanio = Integer.parseInt(raiz.getChildTextTrim("dimension"));
    tb.crearMatriz(tamanio);

    Element dobles = raiz.getChild("dobles");

    java.util.List<Element> listaDobles = dobles.getChildren("casilla");

    for (int i = 0; i < listaDobles.size(); i++) {
        System.out.println("Punto de verificacion en primer for");
        Element doble = (Element) listaDobles.get(i);
        int x = Integer.parseInt(doble.getChildTextTrim("x"));
        int y = Integer.parseInt(doble.getChildTextTrim("y"));
        tb.modificarNodo(x, y, "Puntos X 2");

    }
    Element triples = (Element) raiz.getChild("triples");
    java.util.List<Element> listaTriples = triples.getChildren("casilla");
    for (int i = 0; i < listaTriples.size(); i++) {
        Element doble = (Element) listaTriples.get(i);
        int x = Integer.parseInt(doble.getChildTextTrim("x"));
        int y = Integer.parseInt(doble.getChildTextTrim("y"));
        tb.modificarNodo(x, y, "Puntos X 3");

    }
    Element diccio = (Element) raiz.getChild("diccionario");
    java.util.List<Element> listaPalabras = diccio.getChildren("palabra");
    for (int i = 0; i < listaPalabras.size(); i++) {

        String pa = listaPalabras.get(i).getTextTrim();
        listadoP.agregarPalabra(pa);
    }

}

From source file:xmlcam.XMLCam.java

private static void cargarXML() {
    //Se crea un SAXBuilder para poder parsear el archivo
    SAXBuilder builder = new SAXBuilder();
    File xmlFile = new File("posicionesCamaras.xml");
    try {//from   www .  ja  v a 2s.c o  m
        //Se crea el documento a traves del archivo
        Document document = (Document) builder.build(xmlFile);

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

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

        for (Object camara : camaras) {
            //Se obtiene el elemento 'campo'
            Element campo = (Element) camara;

            String ID = campo.getChildTextTrim("ID");
            String posicionX = campo.getChildTextTrim("posicionX");
            String posicionY = campo.getChildTextTrim("posicionY");
            String habitacion = campo.getChildTextTrim("nombrehabitacion");

            System.out.println("ID: " + ID);
            System.out.println("\tPosicin X: " + posicionX);
            System.out.println("\tPosicin Y: " + posicionY);
            System.out.println("\tNombre habitacin: " + habitacion);
        }

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

}

From source file:xmlrod.LectorXML.java

public void cargarXml(String direccion) throws JDOMException {
    //Se crea un SAXBuilder para poder parsear el archivo
    SAXBuilder builder = new SAXBuilder();
    File xmlFile = new File(direccion); //aqui vas a poner direccion
    try {//from  w ww  . ja va2 s . c  o  m
        Document document = (Document) builder.build(xmlFile);
        Element raiz = document.getRootElement();

        //OBTENGO LAS DIMENSIONES
        Element dimension = raiz.getChild("dimension");
        dimensiones = dimension.getTextTrim();
        System.out.println(dimensiones);

        //OBTENGO TODO DEL TAG <DOBLES>
        List dobles = raiz.getChildren("dobles");
        Element casillaDoble = (Element) dobles.get(0);
        List coordenadasDoble = casillaDoble.getChildren();

        for (int j = 0; j < coordenadasDoble.size(); j++) {
            Element coordenada = (Element) coordenadasDoble.get(j);
            String x = coordenada.getChildTextTrim("x");
            String y = coordenada.getChildTextTrim("y");
            doble.insertar(x, y);
        }
        doble.imprimir2();

        //OBTENGO TODO DEL TAG TRIPLES
        List triples = raiz.getChildren("triples");
        Element casillaTriples = (Element) triples.get(0);
        List coordenadasTriple = casillaTriples.getChildren();

        for (int j = 0; j < coordenadasTriple.size(); j++) {
            Element coordenada = (Element) coordenadasTriple.get(j);
            String x = coordenada.getChildTextTrim("x");
            String y = coordenada.getChildTextTrim("y");
            triple.insertar(x, y);
        }
        triple.imprimir2();

        //OBTENGO TODO DEL TAG <DICCIONARIO>
        Element diccionario = raiz.getChild("diccionario");
        List Palabras = diccionario.getChildren();

        for (int i = 0; i < Palabras.size(); i++) {
            Element Palabra = (Element) Palabras.get(i);
            String palabra = Palabra.getTextTrim();
            System.out.println(palabra);
            Diccionario.insertar(palabra);
            //AGREGO LAS PALABRAS A LA LISTA SIMPLE
        }
        //Diccionario.imprimir();
    } catch (IOException ex) {
        Logger.getLogger(LectorXML.class.getName()).log(Level.SEVERE, null, ex);
    }
}