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:io.smartspaces.master.server.services.internal.support.JdomMasterDomainModelImporter.java

License:Apache License

/**
 * Get an individual live activity group.
 *
 * @param groupElement//from w w w  . j  a  v a2  s. com
 *          the live activity group XML element
 * @param activityRepository
 *          repository for activity entities
 */
private void getLiveActivityGroup(Element groupElement, ActivityRepository activityRepository) {
    String id = groupElement.getAttributeValue(ATTRIBUTE_NAME_ID);

    LiveActivityGroup group = activityRepository.newLiveActivityGroup();

    String name = groupElement.getChildTextTrim(ELEMENT_NAME_NAME);
    String description = groupElement.getChildTextTrim(ELEMENT_NAME_DESCRIPTION);

    group.setName(name);
    group.setDescription(description);

    Map<String, Object> metadata = getMetadata(groupElement.getChild(ELEMENT_NAME_METADATA));
    if (metadata != null) {
        group.setMetadata(metadata);
    }

    getLiveActivityGroupLiveActivities(groupElement, group);

    liveActivityGroups.put(id, group);

    activityRepository.saveLiveActivityGroup(group);
}

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

License:Apache License

/**
 * Get an individual space./* ww w.  j  a va 2 s.  c  o m*/
 *
 * @param spaceElement
 *          the space XML element
 * @param activityRepository
 *          repository for space entities
 */
private void getSpace(Element spaceElement, ActivityRepository activityRepository) {
    String id = spaceElement.getAttributeValue(ATTRIBUTE_NAME_ID);

    Space space = activityRepository.newSpace();

    String name = spaceElement.getChildTextTrim(ELEMENT_NAME_NAME);
    String description = spaceElement.getChildTextTrim(ELEMENT_NAME_DESCRIPTION);

    space.setName(name);
    space.setDescription(description);

    Map<String, Object> metadata = getMetadata(spaceElement.getChild(ELEMENT_NAME_METADATA));
    if (metadata != null) {
        space.setMetadata(metadata);
    }

    getSpaceSubspaces(spaceElement, space);
    getSpaceLiveActivityGroups(spaceElement, space);

    spaces.put(id, space);

    activityRepository.saveSpace(space);
}

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

License:Apache License

/**
 * Get an individual resource./*www .j  av a  2  s  . c om*/
 *
 * @param resourceElement
 *          the resource XML element
 * @param resourceRepository
 *          repository for resource entities
 */
private void getResource(Element resourceElement, ResourceRepository resourceRepository) {
    String id = resourceElement.getAttributeValue(ATTRIBUTE_NAME_ID);

    Resource resource = resourceRepository.newResource();

    String identifyingName = resourceElement.getChildTextTrim(ELEMENT_NAME_RESOURCE_IDENTIFYING_NAME);
    String version = resourceElement.getChildTextTrim(ELEMENT_NAME_RESOURCE_VERSION);

    resource.setIdentifyingName(identifyingName);
    resource.setVersion(version);

    String lastUploadDateString = resourceElement.getAttributeValue(ATTRIBUTE_NAME_LAST_UPLOAD_DATE);
    if (lastUploadDateString != null) {
        resource.setLastUploadDate(new Date(Long.parseLong(lastUploadDateString)));
    }

    String bundleContentHash = resourceElement.getChildTextTrim(ELEMENT_NAME_RESOURCE_BUNDLE_CONTENT_HASH);
    if (bundleContentHash != null) {
        resource.setBundleContentHash(bundleContentHash);
    }

    resources.put(id, resource);

    resourceRepository.saveResource(resource);
}

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

License:Apache License

/**
 * Get an individual named script.//from w  w w  .j  ava 2  s .c om
 *
 * @param scriptElement
 *          the script XML element
 * @param automationRepository
 *          repository for automation entities
 */
private void getNamedScript(Element scriptElement, AutomationRepository automationRepository) {
    String id = scriptElement.getAttributeValue(ATTRIBUTE_NAME_ID);

    NamedScript script = automationRepository.newNamedScript();

    String name = scriptElement.getChildTextTrim(ELEMENT_NAME_NAME);
    String description = scriptElement.getChildTextTrim(ELEMENT_NAME_DESCRIPTION);
    String language = scriptElement.getChildTextTrim(ELEMENT_NAME_NAMED_SCRIPT_LANGUAGE);
    String content = scriptElement.getChildTextTrim(ELEMENT_NAME_NAMED_SCRIPT_CONTENT);

    script.setName(name);
    script.setDescription(description);
    script.setLanguage(language);
    script.setContent(content);

    Element scheduleElement = scriptElement.getChild(ELEMENT_NAME_NAMED_SCRIPT_SCHEDULE);
    if (scheduleElement != null) {
        script.setSchedule(scheduleElement.getTextTrim());

        script.setScheduled(VALUE_TRUE.equalsIgnoreCase(
                scheduleElement.getAttributeValue(ATTRIBUTE_NAME_NAMED_SCRIPT_SCHEDULE_SCHEDULED)));
    }

    Map<String, Object> metadata = getMetadata(scriptElement.getChild(ELEMENT_NAME_METADATA));
    if (metadata != null) {
        script.setMetadata(metadata);
    }

    automationRepository.saveNamedScript(script);
}

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 {//from  w  w w  .jav  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:jcodecollector.io.PackageManager.java

License:Apache License

public static ArrayList<Snippet> readPackage(File file) {
    ArrayList<Snippet> array = new ArrayList<Snippet>();
    Element root = null;/*from   w  w w.  j av  a 2s  .c o  m*/

    try {
        SAXBuilder builder = new SAXBuilder();
        root = builder.build(file).getRootElement();
    } catch (Exception ex) {
        return null;
    }

    @SuppressWarnings("unchecked")
    Iterator<Element> iterator = root.getChildren("snippet").iterator();
    while (iterator.hasNext()) {
        Element e = iterator.next();

        String category = e.getChildTextTrim("category");
        String name = e.getChildTextTrim("name");
        String syntax = e.getChildTextTrim("syntax");
        String code = e.getChildTextTrim("code");
        String comment = e.getChildTextTrim("comment");

        @SuppressWarnings("unchecked")
        List<Element> tagElements = e.getChildren("tag");
        String[] tags = new String[tagElements.size()];
        for (int i = 0; i < tags.length; i++) {
            tags[i] = tagElements.get(i).getTextTrim();
        }

        Snippet snippet = new Snippet(-1, category, name, tags, code, comment, syntax, false);
        array.add(snippet);
    }

    return array;
}

From source file:jcodecollector.io.XMLManagerOldVersion.java

License:Apache License

@SuppressWarnings("unchecked")
public static ArrayList<Snippet> readPackage(File file) {
    Element root_xml = null;/*from ww  w  .  ja v a 2  s. com*/

    try {
        SAXBuilder builder = new SAXBuilder();
        root_xml = builder.build(file).getRootElement();
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }

    ArrayList<Snippet> array = new ArrayList<Snippet>();

    Iterator<Element> iterator = root_xml.getChildren("snippet").iterator();
    while (iterator.hasNext()) {
        Element element = iterator.next();

        String category = element.getChildTextTrim("category");
        String name = element.getChildTextTrim("name");
        String syntax = element.getChildTextTrim("syntax");
        String code = element.getChildTextTrim("code");
        String comment = element.getChildTextTrim("comment");

        List<Element> tags_xml = element.getChildren("tag");
        String[] tags = new String[tags_xml.size()];
        for (int i = 0; i < tags.length; i++) {
            tags[i] = tags_xml.get(i).getTextTrim();
        }

        boolean locked = Boolean.parseBoolean(element.getChildTextTrim("locked"));

        Snippet snippet = new Snippet(-1, category, name, tags, code, comment, syntax, locked);
        array.add(snippet);
    }

    return array;
}

From source file:jcodecollector.io.XMLManagerOldVersion.java

License:Apache License

@SuppressWarnings("unchecked")
private static ArrayList<Snippet> getSnippetsFromFile(Element root) {
    ArrayList<Snippet> snippets = new ArrayList<Snippet>();

    List<Element> categoriesList = root.getChildren("snippets");
    Iterator<Element> iterator = categoriesList.iterator();
    while (iterator.hasNext()) {
        Element categoryElement = iterator.next();

        String category = categoryElement.getAttributeValue("category");

        List<Element> snippetsList = categoryElement.getChildren("snippet");
        Iterator<Element> innerIterator = snippetsList.iterator();
        while (innerIterator.hasNext()) {
            Element snippet = innerIterator.next();

            int id = Integer.parseInt(snippet.getAttributeValue("id"));
            String name = snippet.getChildTextTrim("name");
            String syntax = snippet.getChildTextTrim("style");
            boolean locked = Boolean.parseBoolean(snippet.getChildTextTrim("is_locked"));
            String code = snippet.getChildTextTrim("code");
            String comment = snippet.getChildTextTrim("comment");

            List<Element> tagsList = snippet.getChild("tags").getChildren("tag");
            ArrayList<String> tags = new ArrayList<String>(tagsList.size());
            Iterator<Element> tagsIterator = tagsList.iterator();
            while (tagsIterator.hasNext()) {
                tags.add(tagsIterator.next().getTextTrim());
            }/*from   w  w w.  j  ava 2 s  . c  o m*/

            snippets.add(new Snippet(id, category, name, tags.toArray(new String[] {}), code, comment, syntax,
                    locked));
        }
    }

    return snippets;
}

From source file:LectorXml.CargarXML.java

public void cargarDimension(String ruta) {

    //se cra un SAXBuilder para poder parsear el archivo
    SAXBuilder builder = new SAXBuilder();
    File ArchivoXml = new File(ruta);

    try {//  ww w.  j  a  v a  2s. c om
        //se crea el docuemento a traves del archio
        Document documento = (Document) builder.build(ArchivoXml);
        //se obtiene la raiz 
        Element raiz = documento.getRootElement();

        //se obtiene la lista de hijos de la raiz 
        List list = raiz.getChildren("dimension");
        //si lista tiene un elemento lo obtiene
        if (list.size() == 1) {
            System.out.println("" + raiz.getChildTextTrim("dimension"));
        } else if (list.size() == 0) {
            JOptionPane.showMessageDialog(null, "No existe ninguna dimension del tablero");
        } else {
            JOptionPane.showMessageDialog(null, "Revise su archivo de entrada");
        }

    } catch (IOException io) {
        JOptionPane.showMessageDialog(null, io.getMessage());
    } catch (JDOMException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage());
    }
}

From source file:LectorXml.CargarXML.java

public void cargarCasilla(String ruta) {

    //se cra un SAXBuilder para poder parsear el archivo
    SAXBuilder builder = new SAXBuilder();
    File ArchivoXml = new File(ruta);

    try {//from   www  .  j ava  2s.  c o  m
        //se crea el docuemento a traves del archio
        Document documento = (Document) builder.build(ArchivoXml);
        //se obtiene la raiz scrabble
        Element raiz = documento.getRootElement();

        //se obtiene la lista de hijos de la raiz 
        List list = raiz.getChildren("dobles");
        //si lista tiene un elemento lo obtiene
        if (list.size() == 1) {

            Element dobles = (Element) list.get(0);

            // se obtiene los elementos de diccionarioque son casillas
            List list_casilla = dobles.getChildren();

            for (int x = 0; x < list_casilla.size(); x++) {
                Element casilla = (Element) list_casilla.get(x);
                System.out.println("x:  " + casilla.getChildTextTrim("x"));
                System.out.println("y:  " + casilla.getChildTextTrim("y"));

            }
        } else if (list.size() == 0) {
            JOptionPane.showMessageDialog(null, "No existe ninguna dimension del tablero");
        } else {
            JOptionPane.showMessageDialog(null, "Revise su archivo de entrada");
        }

    } catch (IOException io) {
        JOptionPane.showMessageDialog(null, io.getMessage());
    } catch (JDOMException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage());
    }
}