Example usage for org.jdom2.input SAXBuilder build

List of usage examples for org.jdom2.input SAXBuilder build

Introduction

In this page you can find the example usage for org.jdom2.input SAXBuilder build.

Prototype

@Override
public Document build(final String systemId) throws JDOMException, IOException 

Source Link

Document

This builds a document from the supplied URI.

Usage

From source file:modelo.RegistroJuego.java

private RegistroJuego(String ruta) throws JDOMException, IOException {
    SAXBuilder sBuilder = new SAXBuilder();
    sBuilder.setIgnoringElementContentWhitespace(true);
    this.documento = sBuilder.build(ruta);
    this.raiz = documento.getRootElement();
    this.ruta = ruta;
}

From source file:modelo.RegistroPlanesXML.java

private RegistroPlanesXML(String ruta) throws IOException, JDOMException {
    SAXBuilder saxb = new SAXBuilder();
    saxb.setIgnoringElementContentWhitespace(true);
    this.documento = saxb.build(ruta);
    this.ruta = ruta;
    this.raiz = documento.getRootElement();
}

From source file:modelo.RegistroUsuario.java

private RegistroUsuario(String rutaDocumento) throws JDOMException, IOException {
    SAXBuilder saBuilder = new SAXBuilder();
    saBuilder.setIgnoringElementContentWhitespace(true);
    this.documento = saBuilder.build(rutaDocumento);
    this.raiz = documento.getRootElement();
    this.rutaDocumento = rutaDocumento;
}

From source file:modelo.RegistroUsuarioXML.java

private RegistroUsuarioXML(String rutaArchivo) throws JDOMException, IOException {
    SAXBuilder saxB = new SAXBuilder();
    saxB.setIgnoringElementContentWhitespace(true);
    this.documento = saxB.build(rutaArchivo);
    this.raiz = this.documento.getRootElement();
    this.ruta = rutaArchivo;
}

From source file:Modelo.ServidorXMLFIle.java

public static boolean saveUserInServerDataBase(String Hora, String Nombre, String Cantidad, String Protocolo) {
    Document doc;//  w ww . j  a v a2s.  co m
    Element root, newChild;

    SAXBuilder builder = new SAXBuilder();

    try {
        doc = builder.build(Util.USERS_XML_PATH);

        root = doc.getRootElement();

        newChild = new Element(Util.SERVER_TAG);

        newChild.setAttribute(Util.HORA_TAG, Hora);
        newChild.setAttribute(Util.NOMBRE_TAG, Nombre);
        newChild.setAttribute(Util.CANTIDAD_TAG, Cantidad);
        newChild.setAttribute(Util.PRIMITIVA_TAG, Protocolo);

        root.addContent(newChild);

        try {
            Format format = Format.getPrettyFormat();

            XMLOutputter out = new XMLOutputter(format);

            FileOutputStream file = new FileOutputStream(Util.USERS_XML_PATH);

            out.output(doc, file);

            file.flush();
            file.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    } catch (JDOMParseException e) {
        System.out.println(Util.ERROR_XML_EMPTY_FILE);
        e.printStackTrace();
    } catch (JDOMException e) {
        System.out.println(Util.ERROR_XML_PROCESSING_FILE);
        e.printStackTrace();
    } catch (IOException e) {
        System.out.println(Util.ERROR_XML_PROCESSING_FILE);
        e.printStackTrace();
    }

    return true;
}

From source file:mom.trd.opentheso.core.alignment.GpsQuery.java

private ArrayList<NodeAlignment> getlisteAlign(String xmlrecord) {
    ArrayList<NodeAlignment> listeAlign1 = new ArrayList<>();

    //Se crea un SAXBuilder para poder parsear el archivo
    SAXBuilder builder = new SAXBuilder();
    File xmlFile = new File(xmlrecord);
    try {//  w  w  w .  ja  v  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("geoname");

        //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);

            //Se obtiene la lista de hijos del tag 'tabla'
            List lista_campos = tabla.getChildren();

            //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 '&lt;campo&gt;&lt;/campo&gt;'
                //Se obtiene el valor que esta entre los tags '&lt;nombre&gt;&lt;/nombre&gt;'
                String nombre = campo.getChildTextTrim("name");

                //Se obtiene el valor que esta entre los tags '&lt;tipo&gt;&lt;/tipo&gt;'
                String tname = campo.getChildTextTrim("toponymName");

                //Se obtiene el valor que esta entre los tags '&lt;valor&gt;&lt;/valor&gt;'
                String lat = campo.getChildTextTrim("lat");
                String lng = campo.getChildTextTrim("lng");

                System.out.println("\t" + nombre + "\t\t" + tname + "\t\t" + lat + "\t\t" + lng);
            }
        }
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }

    return listeAlign1;
}

From source file:mom.trd.opentheso.core.exports.privatesdatas.importxml.importxml.java

/**
 * cette funtion permet de ouvrir un fichier pour comence a faire une 
 * injection de donnes. /* w w w.j  av a 2  s.c o  m*/
 * C'est seulement pour la creation de un nouvelle BDD.
 * la funtion generique est plus ba
 * @param con
 * @param archive
 * @throws ClassNotFoundException
 * @throws SQLException 
 */
public void ouvreFichier(Connection con, File archive) throws ClassNotFoundException, SQLException {
    LanguageBean langueBean = new LanguageBean();
    SAXBuilder builder = new SAXBuilder();
    ArrayList<Table> toutTables = new ArrayList<>();
    ArrayList<LineOfData> lineOfDatas = new ArrayList<>();
    try {

        //on cre le document a partir du fichier que on a selection
        Document document = (Document) builder.build(archive);
        //Se obtiene la raiz 'tables'
        Element rootNode = document.getRootElement();

        // ici on a toutes les tables (les enfants de la racine)
        List list = rootNode.getChildren("table");

        // ici on fait le tour pour les enfants de 'tables'
        for (int i = 0; i < list.size(); i++) {

            // ici on a la premire table
            Element tabla = (Element) list.get(i);

            //ici on a le nom de la table
            String nombreTabla = tabla.getAttributeValue("nom");
            // ici c'est la liste des lignes de la table
            List lista_campos = tabla.getChildren();

            //ici on dcoupe la liste des lignes
            for (int j = 0; j < lista_campos.size(); j++) {

                //ici on a une ligne de la table
                Element campo = (Element) lista_campos.get(j);
                for (Element colonne : campo.getChildren()) {
                    LineOfData lineOfData = new LineOfData();
                    lineOfData.setColomne(colonne.getName());//  le nom de la colone
                    lineOfData.setValue(colonne.getText());// le value que le correspond
                    lineOfDatas.add(lineOfData);
                }
                insertLine(con, lineOfDatas, nombreTabla);
                lineOfDatas.clear();
            }
            /// mettre  jour la table dans la BDD
        }
    } catch (IOException | JDOMException io) {
        System.out.println("error");
    }
    //FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("impBDD.info1")));
}

From source file:mom.trd.opentheso.core.exports.privatesdatas.importxml.importxml.java

/**
 * cette funtion permet de ouvrir un fichier pour comence a faire une 
 * injection de donnes. //w w w.j  a  v a 2  s  .  c  o m
 * Cette funtion c'est la generique
 * @param ds
 * @param archive
 * @throws ClassNotFoundException
 * @throws SQLException 
 */
public void ouvreFichier2(HikariDataSource ds, File archive) throws ClassNotFoundException, SQLException {
    LanguageBean langueBean = new LanguageBean();
    SAXBuilder builder = new SAXBuilder();
    ArrayList<Table> toutTables = new ArrayList<>();

    ArrayList<LineOfData> lineOfDatas = new ArrayList<>();
    try {

        //on cre le document a partir du fichier que on a selection
        Document document = (Document) builder.build(archive);
        //Se obtiene la raiz 'tables'
        Element rootNode = document.getRootElement();

        // ici on a toutes les tables (les enfants de la racine)
        List list = rootNode.getChildren("table");

        // ici on fait le tour pour les enfants de 'tables'
        for (int i = 0; i < list.size(); i++) {

            // ici on a la premire table
            Element tabla = (Element) list.get(i);

            //ici on a le nom de la table
            String nombreTabla = tabla.getAttributeValue("nom");
            // ici c'est la liste des lignes de la table
            List lista_campos = tabla.getChildren();

            //ici on dcoupe la liste des lignes
            for (int j = 0; j < lista_campos.size(); j++) {

                //ici on a une ligne de la table
                Element campo = (Element) lista_campos.get(j);
                for (Element colonne : campo.getChildren()) {
                    LineOfData lineOfData = new LineOfData();
                    lineOfData.setColomne(colonne.getName());
                    lineOfData.setValue(colonne.getText());
                    lineOfDatas.add(lineOfData);
                }
                insertLine2(ds, lineOfDatas, nombreTabla);
                lineOfDatas.clear();
            }
            /// mettre  jour la table dans la BDD
        }
    } catch (IOException | JDOMException io) {
        System.out.println(io.toString());
    }
    //FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("impBDD.info1")));
}

From source file:msi.gama.doc.util.UnifyDoc.java

License:Open Source License

private static Document mergeFiles(final HashMap<String, File> hmFilesPackages) {
    try {/*from w  w  w .j a  v  a 2 s.  co m*/

        SAXBuilder builder = new SAXBuilder();
        Document doc = null;

        doc = new Document(new Element(XMLElements.DOC));
        for (String elt : tabEltXML) {
            doc.getRootElement().addContent(new Element(elt));
        }

        for (Entry<String, File> fileDoc : hmFilesPackages.entrySet()) {
            Document docTemp = builder.build(fileDoc.getValue());

            for (String catXML : tabEltXML) {
                if (docTemp.getRootElement().getChild(catXML) != null) {

                    List<Element> existingElt = doc.getRootElement().getChild(catXML).getChildren();

                    for (Element e : docTemp.getRootElement().getChild(catXML).getChildren()) {
                        // Do not add the projectName for every kinds of
                        // categories
                        //      if (!Arrays.asList(tabCategoriesEltXML).contains(catXML)) {
                        e.setAttribute("projectName", fileDoc.getKey());
                        //      }

                        // Test whether the element is already in the merged
                        // doc
                        boolean found = false;
                        for (Element exElt : existingElt) {
                            boolean equals = exElt.getName().equals(e.getName());
                            for (Attribute att : exElt.getAttributes()) {
                                String valueExElt = exElt.getAttribute(att.getName()) != null
                                        ? exElt.getAttributeValue(att.getName())
                                        : "";
                                String valueE = e.getAttribute(att.getName()) != null
                                        ? e.getAttributeValue(att.getName())
                                        : "";
                                equals = equals && valueExElt.equals(valueE);
                            }
                            found = found || equals;
                        }
                        // Add if it is not already in the merged doc
                        if (!found) {
                            doc.getRootElement().getChild(catXML).addContent(e.clone());
                        }
                    }
                }
            }
        }

        // Add an element for the generated types
        doc.getRootElement().getChild(XMLElements.OPERATORS_CATEGORIES)
                .addContent(new Element(XMLElements.CATEGORY).setAttribute(XMLElements.ATT_CAT_ID,
                        new TypeConverter().getProperCategory("Types")));

        return doc;
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}

From source file:msk.drugbank4.DrugBankParser.java

License:Apache License

/**
 * return a set of drugs/*ww w.  j  a  v  a2s .  c  o m*/
 * DrugModel contains also the list of targets
 */
public Set<DrugModel> parse(File drugBankXml) throws JDOMException, IOException {
    SAXBuilder builder = new SAXBuilder();

    Document document = (Document) builder.build(drugBankXml);
    Element rootNode = document.getRootElement();

    Set<DrugModel> drugs = new HashSet<DrugModel>();

    List<Element> list = rootNode.getChildren("drug", nsDrugBank);
    for (Element drug : list) {
        DrugModel model = new DrugModel();

        Element id = drug.getChild("drugbank-id", nsDrugBank);
        model.setDrugbankID(id.getValue());

        Element name = drug.getChild("name", nsDrugBank);
        model.setName(name.getValue());

        Element cas = drug.getChild("cas-number", nsDrugBank);
        model.setCasNumber(cas.getValue());

        model.setInChiKey(getInchiKey(drug));
        model.getGroups().addAll(getGroups(drug));
        model.getCategories().addAll(getCategories(drug));
        model.getTargets().addAll(getTargets(drug));

        drugs.add(model);
    }

    return drugs;
}