List of usage examples for org.jdom2.input SAXBuilder build
@Override public Document build(final String systemId) throws JDOMException, IOException
This builds a document from the supplied URI.
From source file:fr.crnan.videso3d.databases.terrainsoaci.TerrainsOaci.java
License:Open Source License
/** * Construit la bdd partir du fichier dans path * @param path Chemin vers le rpertoire contenant la BDS *//*from ww w. j av a 2 s . c o m*/ public TerrainsOaci(String path) { super(path); SAXBuilder sxb = new SAXBuilder(); try { document = sxb.build(new File(path)); } catch (JDOMException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:fr.crnan.videso3d.databases.terrainsoaci.TerrainsOaci.java
License:Open Source License
/** * Construit la bdd partir du fichier dans path et lui donne le nom name * @param path Chemin vers le rpertoire contenant la BDS * @param name Le nom donner cette base de donnes *//*from w w w . j a v a2s. com*/ public TerrainsOaci(String path, String name) { super(path); this.name = name; SAXBuilder sxb = new SAXBuilder(); try { document = sxb.build(new File(path)); } catch (JDOMException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:fr.inria.diverse.trace.commons.PluginXMLHelper.java
License:Open Source License
public void loadDocument(IFile pluginXmlFile) { SAXBuilder sxb = new SAXBuilder(); try {//from www . j a v a2 s. c o m document = sxb.build(pluginXmlFile.getContents()); root = document.getRootElement(); } catch (Exception e) { //Activator.error(e.getMessage(), e); } }
From source file:fr.ms.tomcat.manager.ContextFileUtils.java
License:Apache License
public static File creationFichierContextDocBase(final File fichierContext, final File webappDirectory) throws JDOMException, IOException { Element context = null;// ww w. ja v a2s. co m Document document = null; if (fichierContext.exists()) { LOG.debug("Le fichier context existe dj dans la webapps : {}.", fichierContext.getAbsolutePath()); final SAXBuilder sxb = new SAXBuilder(); document = sxb.build(fichierContext); context = document.getRootElement(); } else { LOG.debug("Le fichier context n'existe pas dans la webapps : {}.", fichierContext.getAbsolutePath()); context = new Element("Context"); document = new Document(context); } final Attribute docBase = new Attribute("docBase", webappDirectory.getAbsolutePath()); final Attribute workDir = new Attribute("workDir", webappDirectory.getAbsolutePath() + "-workDir"); context.setAttribute(docBase); context.setAttribute(workDir); final XMLOutputter xmlContextFile = new XMLOutputter(Format.getPrettyFormat()); if (LOG.isDebugEnabled()) { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); xmlContextFile.output(document, baos); LOG.debug(baos.toString()); } final File fichierContextTemporaire = File.createTempFile("contextTomcat", ".xml"); final FileOutputStream fichierContextTemporaireOutputStream = new FileOutputStream( fichierContextTemporaire); xmlContextFile.output(document, fichierContextTemporaireOutputStream); fichierContextTemporaireOutputStream.close(); return fichierContextTemporaire; }
From source file:fr.rt.acy.locapic.gps.TrackService.java
License:Open Source License
/** * Methode qui ajoute la localisation a partir de l'element JDOM passe en parametre * Utilise les attributs de classe FILE_DIRECTORY et FILE_NAME comme chemin pour le fichier a reecrire * @param loc - Element JDOM representant la nouvelle position * @return true//ww w . j ava 2 s . com */ public boolean addLocation(Element loc) { // Parsing SAXBuilder saxBuilder = new SAXBuilder(); Document document = new Document(new Element("temp")); try { // On creer un nouveau document JDOM a partir du fichier GPX if (!FILE_EXT) document = saxBuilder.build(openFileInput(FILE_NAME)); else document = saxBuilder.build(new FileInputStream(new File(EXT_FILES_DIR + FILE_NAME))); // On recupere la racine du document Element racine = document.getRootElement(); // A partir de la racine, on recupere les tracks (<trk>) List<Element> trkList = racine.getChildren("trk", ns); // A partir de la derniere track, on recupere les segments de track (<trkseg>) List<Element> trksegList = trkList.get(trkList.size() - 1).getChildren("trkseg", ns); // On recupere le dernier segment de track (de la derniere track donc) Element trkseg = trksegList.get(trksegList.size() - 1); // On y ajoute la nouvelle position (Element loc) trkseg.addContent(loc); } catch (Exception e) { Log.e(TAG, e.getMessage()); } // Partie enregistrement dans le Fichier XMLOutputter xmlOutput = new XMLOutputter(Format.getPrettyFormat()); //Log.d(TAG, "addLocation : FILE_EXT = "+FILE_EXT); try { if (!FILE_EXT) xmlOutput.output(document, openFileOutput(FILE_NAME, MODE_WORLD_READABLE)); else xmlOutput.output(document, new FileOutputStream(EXT_FILES_DIR + FILE_NAME)); } catch (FileNotFoundException e) { Log.e(TAG, e.toString()); } catch (IOException ioe) { Log.e(TAG, ioe.toString()); } return true; }
From source file:Frames.CrExperience2.java
private int creerConfig() throws DataConversionException { int x = 0;//from ww w . j a v a 2 s . c o m File f = new File("Exp2/Experiences.xml"); if (f.exists()) { System.out.println("Experiences Existe"); SAXBuilder sxb = new SAXBuilder(); try { document = sxb.build(new File("Exp2/Experiences.xml")); } catch (Exception e) { } racine = document.getRootElement(); if (!racine.getChildren("experience").isEmpty()) { List<Element> childs = racine.getChildren("experience"); x = childs.get(childs.size() - 1).getAttribute("id").getIntValue(); } } else { try { //On utilise ici un affichage classique avec getPrettyFormat() XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat()); //Remarquez qu'il suffit simplement de crer une instance de FileOutputStream //avec en argument le nom du fichier pour effectuer la srialisation. sortie.output(document, new FileOutputStream("Exp2/Experiences.xml")); } catch (IOException ex) { } } return x; }
From source file:Frames.CrExperience3.java
private int creerConfig() throws DataConversionException { int x = 0;//from w w w . ja v a2 s. c o m File f = new File("Exp3/Experiences.xml"); if (f.exists()) { System.out.println("Experiences Existe"); SAXBuilder sxb = new SAXBuilder(); try { document = sxb.build(new File("Exp3/Experiences.xml")); } catch (Exception e) { } racine = document.getRootElement(); if (!racine.getChildren("experience").isEmpty()) { List<Element> childs = racine.getChildren("experience"); x = childs.get(childs.size() - 1).getAttribute("id").getIntValue(); } } else { try { //On utilise ici un affichage classique avec getPrettyFormat() XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat()); //Remarquez qu'il suffit simplement de crer une instance de FileOutputStream //avec en argument le nom du fichier pour effectuer la srialisation. sortie.output(document, new FileOutputStream("Exp3/Experiences.xml")); } catch (IOException ex) { } } return x; }
From source file:geosolutions.zoom.system.XMLConfiguration.java
public boolean readXmlParametrosSystem(String path) { File file = new File(path + "/config.xml"); SAXBuilder sAXBuilder = new SAXBuilder(); if (file.exists()) { Cripto cripto = new Cripto(); try {//from w w w . j av a 2s . c o m Document documento = sAXBuilder.build(file); Element root = documento.getRootElement(); /**------------------servidor---------------------------*/ Element nodoServidor = root.getChild("servidor"); //hijos ParametrosSystem.setDriverPostgres(nodoServidor.getChild("driver").getText()); ParametrosSystem.setUrlPostgres(nodoServidor.getChild("url").getText()); ParametrosSystem.setIpServidor(nodoServidor.getChild("ip_servidor").getText()); ParametrosSystem.setBaseDatos(nodoServidor.getChild("db").getText()); ParametrosSystem.setNombrePcServidor(nodoServidor.getChild("nombre_servidor").getText()); ParametrosSystem.setPuertoPostgres(nodoServidor.getChild("puerto").getText()); ParametrosSystem.setUsuarioPostgres(nodoServidor.getChild("usuario").getText()); ParametrosSystem.setPasswordPostgres(nodoServidor.getChild("password").getText()); ParametrosSystem.setNickSistema(nodoServidor.getChild("nick").getText()); /**------------------ciente---------------------------*/ Element nodoCliente = root.getChild("cliente"); //hijos ParametrosSystem.setIpCliente(nodoCliente.getChild("ip_cliente").getText()); ParametrosSystem.setNombrePcCliente(nodoCliente.getChild("nombre_cliente").getText()); /**------------------otro servidor---------------------------*/ Element nodoOtrosServidor = root.getChild("otro_servidor"); //hijos ParametrosSystem.setOtroIpServidor(nodoOtrosServidor.getChild("otro_ip_servidor").getText()); ParametrosSystem.setOtroPuertoPostgres(nodoOtrosServidor.getChild("otro_puerto").getText()); ParametrosSystem.setOtroDB(nodoOtrosServidor.getChild("otro_db").getText()); /**------------------otros---------------------------*/ Element nodoOtros = root.getChild("otros"); //hijos ParametrosSystem.setEsServidor(nodoOtros.getChild("es_servidor").getText()); ParametrosSystem.setInterrupcion(nodoOtros.getChild("interrupcion").getText()); ParametrosSystem.setHoraCierrePlanilla(nodoOtros.getChild("hora_cierre_planilla").getText()); ParametrosSystem.setEsAutorizado(nodoOtros.getChild("es_autorizado_backup").getText()); /**------------------otros---------------------------*/ Element nodoPath = root.getChild("path"); //hijos ParametrosSystem.setPathReport(nodoPath.getChild("path_reporte").getText()); ParametrosSystem.setPathPgDumpPostgres(nodoPath.getChild("path_pg_dump").getText()); ParametrosSystem.setPathBackup(nodoPath.getChild("path_backup").getText()); return true; } catch (JDOMException ex) { Logger.getLogger(XMLConfiguration.class.getName()).log(Level.SEVERE, null, ex); return false; } catch (IOException ex) { Logger.getLogger(XMLConfiguration.class.getName()).log(Level.SEVERE, null, ex); return false; } } else { return false; } }
From source file:gestetu05.Client.java
static void LireXML(String NomFichier) { Element racine = new Element("repertoire"); Document document = new Document(racine); //On cre une instance de SAXBuilder SAXBuilder sxb = new SAXBuilder(); try {/*from w w w .ja va 2 s .c o m*/ //On cre un nouveau document JDOM avec en argument le fichier XML //Le parsing est termin ;) document = sxb.build(new File(NomFichier)); } catch (JDOMException | IOException e) { } //On initialise un nouvel lment racine avec l'lment racine du document. racine = document.getRootElement(); //On cre une List contenant tous les noeuds "utilisateur" de l'Element racine List listUtilisateurs = racine.getChildren("utilisateur"); //On cre un Iterator sur notre liste Iterator i = listUtilisateurs.iterator(); System.out.println("--------------------Fil d'actualit--------------------"); while (i.hasNext()) { //On recre l'Element courant chaque tour de boucle afin de //pouvoir utiliser les mthodes propres aux Element comme : //slectionner un nud fils, modifier du texte, etc... Element courant = (Element) i.next(); //On affiche le nom de llment courant System.out.println("L'utilisateur " + courant.getChild("nom").getText()); System.out.println(" est " + courant.getChild("Profession").getText()); } }
From source file:gestetu05.Client.java
static void ChercherInformation(String NomFichier, String recherche) { Element racine = new Element("repertoire"); Document document = new Document(racine); //On cre une instance de SAXBuilder SAXBuilder sxb = new SAXBuilder(); try {//from ww w .j av a2 s .c om //On cre un nouveau document JDOM avec en argument le fichier XML //Le parsing est termin ;) document = sxb.build(new File(NomFichier)); } catch (JDOMException | IOException e) { } //On initialise un nouvel lment racine avec l'lment racine du document. racine = document.getRootElement(); //On cre une List contenant tous les noeuds "utilisateur" de l'Element racine List listUtilisateurs = racine.getChildren("utilisateur"); //On cre un Iterator sur notre liste Iterator i = listUtilisateurs.iterator(); System.out.println("Rsultat de la recherche:\n"); while (i.hasNext()) { //On recre l'Element courant chaque tour de boucle afin de //pouvoir utiliser les mthodes propres aux Element comme : //slectionner un nud fils, modifier du texte, etc... Element courant = (Element) i.next(); //On affiche le nom de llment courant if (courant.getChild("nom").getText().equals(recherche) || courant.getChild("Profession").getText().equals(recherche)) { System.out.println("Nom:" + courant.getChild("nom").getText()); System.out.println("Profession:" + courant.getChild("Profession").getText() + "\n"); } } }