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;
}
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")));
}
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 '<campo></campo>'
// Se obtiene el valor que esta entre los tags '<nombre></nombre>'
String nombre = campo.getChildTextTrim("name");
// Se obtiene el valor que esta entre los tags '<tipo></tipo>'
String tname = campo.getChildTextTrim("toponymName");
// Se obtiene el valor que esta entre los tags '<valor></valor>'
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;
}
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()));
}
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()));
}
Aggregations