Example usage for org.jdom2 Element getTextTrim

List of usage examples for org.jdom2 Element getTextTrim

Introduction

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

Prototype

public String getTextTrim() 

Source Link

Document

Returns the textual content of this element with all surrounding whitespace removed.

Usage

From source file:org.sonar.cxx.sensors.rats.CxxRatsSensor.java

License:Open Source License

private static String getVulnerabilityType(@Nullable Element child) {
    if (child != null) {
        return child.getTextTrim();
    }//from   w  w w.  j a  v  a  2  s. c  om
    return MISSING_RATS_TYPE;
}

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 . jav  a2s  . c  o  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: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 {// w  ww .  j ava  2s. 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);
    }
}

From source file:XMLWriter.WriteCoursesXML.java

License:Open Source License

public static boolean removeCode(String idCourse, String idCode, String xmlSource) {
    try {//from   w  w  w.j  a va2s .co m
        Document doc = builder.build(xmlSource);
        Element rootNode = doc.getRootElement();
        List<Element> lista = rootNode.getChildren("curso", ns);
        boolean find = false;

        for (Element e : lista)
            if (e.getAttributeValue("id").equals(idCourse)) {
                for (Element c : e.getChildren("idCodigo", ns))
                    if (c.getTextTrim().equals(idCode)) {
                        find = e.removeContent(c);
                        break;
                    }
                break;
            }
        if (!find)
            return false;

        Format form = Format.getPrettyFormat().clone();
        form.setTextMode(Format.TextMode.TRIM_FULL_WHITE);
        XMLOutputter xmlOut = new XMLOutputter(form);
        FileOutputStream file = new FileOutputStream(xmlSource);
        xmlOut.output(doc, file);
        file.close();
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }

    return true;
}

From source file:XMLWriter.WriteCoursesXML.java

License:Open Source License

public static boolean removeUser(String idCourse, String idUser, String xmlSource) {
    try {// ww  w  . j  a v  a  2s . c  o  m
        Document doc = builder.build(xmlSource);
        Element rootNode = doc.getRootElement();
        List<Element> lista = rootNode.getChildren("curso", ns);
        boolean find = false;

        for (Element e : lista)
            if (e.getAttributeValue("id").equals(idCourse)) {
                for (Element c : e.getChildren("idAlumno", ns))
                    if (c.getTextTrim().equals(idUser)) {
                        find = e.removeContent(c);
                        break;
                    }
                break;
            }
        if (!find)
            return false;

        Format form = Format.getPrettyFormat().clone();
        form.setTextMode(Format.TextMode.TRIM_FULL_WHITE);
        XMLOutputter xmlOut = new XMLOutputter(form);
        FileOutputStream file = new FileOutputStream(xmlSource);
        xmlOut.output(doc, file);
        file.close();
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }

    return true;
}

From source file:XMLWriter.WriteUsersXML.java

License:Open Source License

public static boolean removeCourse(String idUser, String idCourse, String xmlSource) {
    try {// w  w w .  j ava 2s .co  m
        Document doc = builder.build(xmlSource);
        Element rootNode = doc.getRootElement();
        boolean find = false;

        for (Element e : rootNode.getChildren("user", ns))
            if (e.getAttributeValue("id").equals(idUser))
                for (Element c : e.getChildren("idCurso", ns))
                    if (c.getTextTrim().equals(idCourse)) {
                        find = e.removeContent(c);
                        break;
                    }

        if (!find)
            return false;

        Format form = Format.getPrettyFormat().clone();
        form.setTextMode(Format.TextMode.TRIM_FULL_WHITE);
        XMLOutputter xmlOut = new XMLOutputter(form);
        FileOutputStream file = new FileOutputStream(xmlSource);
        xmlOut.output(doc, file);
        file.close();
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }

    return true;
}