Search in sources :

Example 96 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project scylla by bptlab.

the class SimulationConfigurationCreator method createFromFile.

/**
 * Creates a new SCCreator from an existing SC xml file
 * @param scPath to xml file
 * @return new SCCreator
 * @throws JDOMException when errors occur in parsing
 * @throws IOException when an I/O error prevents a document from being fully parsed
 * @throws NotAValidFileException a) when the file has no simulation configuration root element
 */
public static SimulationConfigurationCreator createFromFile(String scPath) throws JDOMException, IOException, NotAValidFileException {
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(scPath);
    Element r = doc.getRootElement();
    if (r.getChild("simulationConfiguration", stdNsp) == null)
        throw new NotAValidFileException("Cannot open simulation configuration with path " + scPath + " : root element not found");
    SimulationConfigurationCreator sc = new SimulationConfigurationCreator(r, doc);
    return sc;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 97 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project opentheso by miledrousset.

the class importxml method ouvreFichier.

/*  
        for (Table user : DataTable) {
            for (LineOfData lineOfData : user.getLineOfDatas()) {
                writeLine(lineOfData.getColomne(), lineOfData.getValue());
            }
     */
/*
    public void choisirfichier (HikariDataSource ds){
        JFileChooser fileChooser = new JFileChooser();
        int seleccion = fileChooser.showOpenDialog(null);
        fichero = fileChooser.getSelectedFile();
               //Acciones que se quieran realizar
        ouvreFichier();
       
    }*/
/**
 * cette funtion permet de ouvrir un fichier pour comencée a faire une
 * injection de données.
 * 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 crée 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 première 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 découpe 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();
                    // le nom de la colone
                    lineOfData.setColomne(colonne.getName());
                    // le value que le correspond
                    lineOfData.setValue(colonne.getText());
                    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")));
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Table(mom.trd.opentheso.core.exports.privatesdatas.tables.Table) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) LineOfData(mom.trd.opentheso.core.exports.privatesdatas.LineOfData) ArrayList(java.util.ArrayList) List(java.util.List) LanguageBean(mom.trd.opentheso.SelectedBeans.LanguageBean)

Example 98 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project opentheso by miledrousset.

the class GpsQuery method getlisteAlign.

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 {
        // 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;
}
Also used : NodeAlignment(mom.trd.opentheso.bdd.helper.nodes.NodeAlignment) SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) File(java.io.File)

Example 99 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project gocd by gocd.

the class SvnLogXmlParserTest method shouldParseLogWithEmptyRevision.

@Test
public void shouldParseLogWithEmptyRevision() throws ParseException {
    SvnLogXmlParser parser = new SvnLogXmlParser();
    List<Modification> materialRevisions = parser.parse("<?xml version=\"1.0\"?>\n" + "<log>\n" + "<logentry\n" + "   revision=\"2\">\n" + "</logentry>\n" + "<logentry\n" + "   revision=\"3\">\n" + "<author>cceuser</author>\n" + "<date>2008-03-11T07:52:41.162075Z</date>\n" + "<paths>\n" + "<path\n" + "   action=\"A\">/trunk/revision3.txt</path>\n" + "</paths>\n" + "</logentry>\n" + "</log>", "", new SAXBuilder());
    assertThat(materialRevisions.size(), is(1));
    Modification mod = materialRevisions.get(0);
    assertThat(mod.getRevision(), is("3"));
    assertThat(mod.getComment(), is(nullValue()));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) SAXBuilder(org.jdom2.input.SAXBuilder) Test(org.junit.jupiter.api.Test)

Example 100 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project gocd by gocd.

the class SvnLogXmlParserTest method shouldParseLogEntryWithoutComment.

@Test
public void shouldParseLogEntryWithoutComment() throws ParseException {
    SvnLogXmlParser parser = new SvnLogXmlParser();
    List<Modification> materialRevisions = parser.parse("<?xml version=\"1.0\"?>\n" + "<log>\n" + "<logentry\n" + "   revision=\"3\">\n" + "<author>cceuser</author>\n" + "<date>2008-03-11T07:52:41.162075Z</date>\n" + "<paths>\n" + "<path\n" + "   action=\"A\">/trunk/revision3.txt</path>\n" + "</paths>\n" + "</logentry>\n" + "</log>", "", new SAXBuilder());
    assertThat(materialRevisions.size(), is(1));
    Modification mod = materialRevisions.get(0);
    assertThat(mod.getRevision(), is("3"));
    assertThat(mod.getComment(), is(nullValue()));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) SAXBuilder(org.jdom2.input.SAXBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

SAXBuilder (org.jdom2.input.SAXBuilder)134 Document (org.jdom2.Document)94 Element (org.jdom2.Element)55 IOException (java.io.IOException)33 JDOMException (org.jdom2.JDOMException)27 File (java.io.File)20 StringReader (java.io.StringReader)20 Test (org.junit.jupiter.api.Test)18 InputStream (java.io.InputStream)14 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)11 URL (java.net.URL)9 XMLOutputter (org.jdom2.output.XMLOutputter)8 Modification (com.thoughtworks.go.domain.materials.Modification)7 List (java.util.List)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputSource (org.xml.sax.InputSource)6 ParseException (java.text.ParseException)5 MCRPath (org.mycore.datamodel.niofs.MCRPath)5 BufferedInputStream (java.io.BufferedInputStream)4