List of usage examples for org.jdom2.output Format getPrettyFormat
public static Format getPrettyFormat()
From source file:facturacion.controller.FacturaController.java
public void crearArchivo() { try {//from w w w . j a va 2s. com DOMBuilder builder = new DOMBuilder(); org.jdom2.Document jdom = builder.build((new DOMOutputter()).output(facturaXml.getDoc())); XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); FileWriter a = new FileWriter("C:\\tributasoft\\prueba\\filePrueba" + this.factura.getPunto_emision() + this.factura.getNumero_factura() + ".xml"); xmlOutput.output(jdom, a); a.close(); facturaXml.getClaveAcceso(); System.out.println("----> firmar factura +++ 16==" + facturaXml.getClaveAcceso()); } catch (JDOMException e) { // TODO Auto-generated catch block System.out.println("----> firmar factura +++ 1"); e.printStackTrace(); } catch (NullPointerException e) { // TODO Auto-generated catch block System.out.println("----> firmar factura +++ 2"); e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:facturacion.utils.Util.java
public static org.w3c.dom.Document firmarComprobante(String proveedor, Document doc, InputStream token, String clave, String data) { org.w3c.dom.Document fileFirmado = null; File fileF = null;//from www . j a v a 2 s.com File aa = null; try { // validar que el token es null ante de firmarlo XAdESBESSignature firmar = new XAdESBESSignature((new DOMOutputter()).output(doc)); //XAdESBESSignature firmar = new XAdESBESSignature(); fileFirmado = firmar.execute(token, clave); //fileFirmado = firmar.execute(); //token.setFile(FtpServer.getTokenInputStream3(token.getFila_ruta())); //this.fileFirmado = firmar.execute(token.documentToInputStream(), token.getClave()); //this.fileFirmado = firmar.execute(); //creo el archivo firmado DOMBuilder builder = new DOMBuilder(); Document jdom = builder.build(fileFirmado); XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); fileF = File.createTempFile("fileFirmado", ".xml"); //aa = new File("C:\\tributasoft\\prueba\\filePruebaFirmado"+data+".xml"); //FileWriter a = new FileWriter("C:\\tributasoft\\prueba\\filePruebaFirmado"+data+".xml"); //FileWriter a = new FileWriter(fileF); //FileWriter aaa = new FileWriter(aa); //xmlOutput.output(jdom, a); //xmlOutput.output(jdom, aaa); //aaa.close(); //a.close(); //this.clave_acceso = this.factura.getClaveAcceso(); System.out.println("----> firmar factura +++ 16"); } catch (JDOMException e) { // TODO Auto-generated catch block //System.out.println("----> firmar factura +++ 1"); e.printStackTrace(); //return ErrorSri.TOKEN; } catch (NullPointerException e) { // TODO Auto-generated catch block //System.out.println("----> firmar factura +++ 2"); e.printStackTrace(); //return ErrorSri.TOKEN; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return fileFirmado; //return ErrorSri.FIRMADO; }
From source file:fr.amap.lidar.amapvox.gui.viewer3d.Viewer3DFrameController.java
/** * Initializes the controller class./*from ww w. java 2s .c om*/ */ @Override public void initialize(URL url, ResourceBundle rb) { treeviewSceneObjects .setCellFactory(new Callback<TreeView<SceneObjectWrapper>, TreeCell<SceneObjectWrapper>>() { @Override public TreeCell<SceneObjectWrapper> call(TreeView<SceneObjectWrapper> param) { return new SceneObjectTreeCell(); } }); root = new TreeItem<>(); root.setExpanded(true); treeviewSceneObjects.setRoot(root); checkMenuItemPerspective.selectedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { checkMenuItemOrthographic.setSelected(!newValue); } }); checkMenuItemOrthographic.selectedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { checkMenuItemPerspective.setSelected(!newValue); } }); checkMenuItemOrthographic.selectedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (newValue) { try { float near = Float.valueOf(textfieldCameraNear.getText()); float far = Float.valueOf(textfieldCameraFar.getText()); viewer3D.getJoglContext().getScene().getCamera().setViewToOrthographic(near, far, far, far, near, far); viewer3D.getJoglContext().updateCamera(); viewer3D.getJoglContext().refresh(); } catch (Exception e) { } } } }); checkMenuItemPerspective.selectedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (newValue) { try { float fov = Float.valueOf(textFieldPerspective.getText()); float near = Float.valueOf(textfieldCameraNear.getText()); float far = Float.valueOf(textfieldCameraFar.getText()); viewer3D.getJoglContext().getScene().getCamera().setViewToPerspective(fov, near, far); viewer3D.getJoglContext().updateCamera(); viewer3D.getJoglContext().refresh(); } catch (Exception e) { } } } }); textFieldPerspective.textProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { try { float fov = Float.valueOf(newValue); TrackballCamera camera = viewer3D.getJoglContext().getScene().getCamera(); viewer3D.getJoglContext().getScene().getCamera().setPerspective(fov, camera.getAspect(), camera.getNearPersp(), camera.getFarPersp()); viewer3D.getJoglContext().refresh(); } catch (Exception e) { } } }); tableColumnName.setCellValueFactory( new Callback<TableColumn.CellDataFeatures<Viewer3DFrameController.Attribut, String>, ObservableValue<String>>() { @Override public ObservableValue<String> call(TableColumn.CellDataFeatures<Attribut, String> param) { return new SimpleStringProperty(param.getValue().getName()); } }); tableColumnValue.setCellValueFactory( new Callback<TableColumn.CellDataFeatures<Viewer3DFrameController.Attribut, String>, ObservableValue<String>>() { @Override public ObservableValue<String> call(TableColumn.CellDataFeatures<Attribut, String> param) { return new SimpleStringProperty(String.valueOf(param.getValue().getValue())); } }); comboboxGradient.getItems().addAll(Util.AVAILABLE_GRADIENT_COLOR_NAMES); comboboxGradient.getSelectionModel().select("HEAT"); isHidden = false; colorPickerBackgroundColor.valueProperty().addListener(new ChangeListener<javafx.scene.paint.Color>() { @Override public void changed(ObservableValue<? extends javafx.scene.paint.Color> observable, javafx.scene.paint.Color oldValue, javafx.scene.paint.Color newValue) { try { //read sgv file URL resource = Viewer3DFrameController.class.getResource("/fxml/icons/pinceau.svg"); SAXBuilder sxb = new SAXBuilder(); Document document = sxb.build(resource); final Element root = document.getRootElement(); //edit svg file final List<Element> graphicElements = root.getChildren("g", root.getNamespace()); String hexColor = null; for (Element element : graphicElements) { String attributeValue = element.getAttributeValue("label", Namespace.getNamespace("http://www.inkscape.org/namespaces/inkscape")); if (attributeValue != null && attributeValue.equals("ciel")) { final Element ellipse = element.getChild("ellipse", root.getNamespace()); String style = ellipse.getAttributeValue("style"); int indexOf = style.indexOf("fill:#"); hexColor = Integer.toHexString((int) (newValue.getRed() * 255)) + Integer.toHexString((int) (newValue.getGreen() * 255)) + Integer.toHexString((int) (newValue.getBlue() * 255)); style = style.substring(0, indexOf + 6) + hexColor + style.substring(indexOf + 12); ellipse.setAttribute("style", style); } else if (attributeValue != null && attributeValue.equals("peinture")) { final Element path = element.getChild("path", root.getNamespace()); String style = path.getAttributeValue("style"); int indexOf = style.indexOf("fill:#"); DecimalFormat df = new DecimalFormat("##"); hexColor = Integer.toHexString((int) (newValue.getRed() * 255)) + Integer.toHexString((int) (newValue.getGreen() * 255)) + Integer.toHexString((int) (newValue.getBlue() * 255)); style = style.substring(0, indexOf + 6) + hexColor + style.substring(indexOf + 12); path.setAttribute("style", style); } } if (hexColor != null) { SVGConverter conv = new SVGConverter(); conv.setWidth(32.0f); conv.setHeight(32.0f); conv.setMediaType("image/png"); File tmpSVGFile = File.createTempFile("skycolor", ".svg"); File tmpPNGFile = File.createTempFile("skycolor", ".png"); //convert svg to png conv.setSources(new String[] { tmpSVGFile.toURI().toURL().toString() }); conv.setDst(tmpPNGFile); XMLOutputter output = new XMLOutputter(Format.getPrettyFormat()); output.output(document, new BufferedOutputStream(new FileOutputStream(tmpSVGFile))); conv.execute(); //change sky icon Image image = new Image(tmpPNGFile.toURI().toURL().toString()); imageviewSkyColor.setImage(image); } } catch (Exception ex) { java.util.logging.Logger.getLogger(Viewer3DFrameController.class.getName()).log(Level.SEVERE, null, ex); } if (viewer3D != null) { viewer3D.getJoglContext().setWorldColor(new Vec3F((float) newValue.getRed(), (float) newValue.getGreen(), (float) newValue.getBlue())); viewer3D.getJoglContext().refresh(); } } }); comboboxGradient.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { String gradient = newValue; Color[] gradientColor = ColorGradient.GRADIENT_RAINBOW; for (int i = 0; i < Util.AVAILABLE_GRADIENT_COLORS.size(); i++) { if (Util.AVAILABLE_GRADIENT_COLOR_NAMES.get(i).equals(gradient)) { gradientColor = Util.AVAILABLE_GRADIENT_COLORS.get(i); i = Util.AVAILABLE_GRADIENT_COLOR_NAMES.size() - 1; } } //recalculate voxel color with the new gradient voxelSpace.updateColorValue(gradientColor); //update instance color buffer to gpu voxelSpace.updateInstanceColorBuffer(); viewer3D.getJoglContext().refresh(); } }); colorPickerBackgroundColor.setValue(new javafx.scene.paint.Color(0.8, 0.8, 0.8, 1)); colorpickerLightingAmbientColor.setValue(new javafx.scene.paint.Color(1.0, 1.0, 1.0, 1)); colorpickerLightingDiffuseColor.setValue(new javafx.scene.paint.Color(1.0, 1.0, 1.0, 1)); colorpickerLightingSpecularColor.setValue(new javafx.scene.paint.Color(1.0, 1.0, 1.0, 1)); colorpickerLightingAmbientColor.valueProperty().addListener(new ChangeListener<javafx.scene.paint.Color>() { @Override public void changed(ObservableValue<? extends javafx.scene.paint.Color> observable, javafx.scene.paint.Color oldValue, javafx.scene.paint.Color newValue) { viewer3D.getJoglContext().getScene().setLightAmbientValue(new Vec3F((float) newValue.getRed(), (float) newValue.getGreen(), (float) newValue.getBlue())); viewer3D.getJoglContext().refresh(); } }); colorpickerLightingDiffuseColor.valueProperty().addListener(new ChangeListener<javafx.scene.paint.Color>() { @Override public void changed(ObservableValue<? extends javafx.scene.paint.Color> observable, javafx.scene.paint.Color oldValue, javafx.scene.paint.Color newValue) { viewer3D.getJoglContext().getScene().setLightDiffuseValue(new Vec3F((float) newValue.getRed(), (float) newValue.getGreen(), (float) newValue.getBlue())); viewer3D.getJoglContext().refresh(); } }); colorpickerLightingSpecularColor.valueProperty() .addListener(new ChangeListener<javafx.scene.paint.Color>() { @Override public void changed(ObservableValue<? extends javafx.scene.paint.Color> observable, javafx.scene.paint.Color oldValue, javafx.scene.paint.Color newValue) { viewer3D.getJoglContext().getScene() .setLightSpecularValue(new Vec3F((float) newValue.getRed(), (float) newValue.getGreen(), (float) newValue.getBlue())); viewer3D.getJoglContext().refresh(); } }); comboBoxAttributeToShow.getSelectionModel().selectedItemProperty() .addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { try { voxelSpace.resetAttributValueRange(); voxelSpace.changeCurrentAttribut(newValue); voxelSpace.updateVao(); voxelSpace.updateInstanceColorBuffer(); viewer3D.getJoglContext().refresh(); textFieldMinValue.getEditor() .setText(String.valueOf(voxelSpace.getRealAttributValueMin())); textFieldMaxValue.getEditor() .setText(String.valueOf(voxelSpace.getRealAttributValueMax())); } catch (Exception e) { } } }); final InstanceLightedShader ils = new InstanceLightedShader(); final InstanceShader is = new InstanceShader(); checkMenuItemEnableLighting.selectedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (newValue) { voxelSpace.setShader(ils); } else { voxelSpace.setShader(is); } viewer3D.getJoglContext().refresh(); } }); /*textFieldFilterValues.setOnKeyReleased(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { if(event.getCode() == KeyCode.ENTER){ updateValuesFilter(); } } });*/ checkboxStretched.selectedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (newValue) { voxelSpace.setStretched(true); voxelSpace.updateValue(); voxelSpace.updateInstanceColorBuffer(); viewer3D.getJoglContext().refresh(); } else { voxelSpace.setStretched(false); voxelSpace.updateValue(); voxelSpace.updateInstanceColorBuffer(); viewer3D.getJoglContext().refresh(); } } }); /* textfieldCameraNear.textProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { try{ float near = Float.valueOf(newValue); TrackballCamera camera = joglContext.getScene().getCamera(); if(radiobuttonOrthographicCamera.isSelected()){ joglContext.getScene().getCamera().setOrthographic(camera.getLeft(), camera.getRight(), camera.getTop(), camera.getBottom(), near, camera.getFarOrtho()); joglContext.updateCamera(); joglContext.refresh(); }else{ joglContext.getScene().getCamera().setPerspective(camera.getFovy(), camera.getAspect(), near, camera.getFarPersp()); joglContext.updateCamera(); joglContext.refresh(); } joglContext.refresh(); }catch(Exception e){} } }); textfieldCameraFar.textProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { try{ float far = Float.valueOf(newValue); TrackballCamera camera = joglContext.getScene().getCamera(); if(radiobuttonOrthographicCamera.isSelected()){ camera.setOrthographic(camera.getLeft(), camera.getRight(), camera.getTop(), camera.getBottom(), camera.getNearOrtho(), far); joglContext.updateCamera(); joglContext.refresh(); }else{ camera.setPerspective(camera.getFovy(), camera.getAspect(), camera.getNearPersp(), far); joglContext.updateCamera(); joglContext.refresh(); } joglContext.refresh(); }catch(Exception e){} } }); */ comboBoxScalarField.setItems(comboBoxAttributeToShow.getItems()); comboBoxScalarField.getItems().addListener(new ListChangeListener<String>() { @Override public void onChanged(ListChangeListener.Change<? extends String> c) { if (c.getList().size() > 0) { comboBoxScalarField.getSelectionModel().selectFirst(); } } }); checkMenuItemShowColorScale.selectedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { viewer3D.getScene().getSceneObject("color scale").setVisible(newValue); viewer3D.getJoglContext().refresh(); } }); ToggleGroup group = new ToggleGroup(); radiobuttonDisplay.setToggleGroup(group); radiobuttonDontDisplay.setToggleGroup(group); CombinedFilter combFilter1 = new CombinedFilter(new Filter("x", 0.0f, Filter.EQUAL), null, CombinedFilter.AND); CombinedFilter combFilter2 = new CombinedFilter(new Filter("x", Float.NaN, Filter.EQUAL), null, CombinedFilter.AND); listviewFilters.getItems().add(new CombinedFilterItem("PadBVTotal", false, combFilter1.getFilter1(), combFilter1.getFilter2(), combFilter1.getType())); listviewFilters.getItems().add(new CombinedFilterItem("PadBVTotal", false, combFilter2.getFilter1(), combFilter2.getFilter2(), combFilter2.getType())); }
From source file:fr.inria.diverse.trace.commons.PluginXMLHelper.java
License:Open Source License
public void saveDocument(IFile pluginXmlFile) { try {/*from w ww .j a va 2s . com*/ XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat()); ByteArrayOutputStream stream = new ByteArrayOutputStream(); sortie.output(document, stream); InputStream inputStream = new ByteArrayInputStream(stream.toByteArray()); pluginXmlFile.setContents(inputStream, IResource.FORCE, null); } catch (IOException e) { //Activator.error(e.getMessage(), e); } catch (CoreException 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;//w ww . jav a 2 s. c o 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 ecrit un fichier a partir du document JDOM doc en utilisant la methode createFilename pour obtenir chemin et nom du fichier * @param doc - Un document JDOM avec lequel creer le fichier * @return true//from w ww. ja v a 2s . c o m */ public boolean saveFile(Document doc) { /** * Creation du fichier */ /** * Creation du contenu du fichier a partir de la base et ajout d'un "segment" de trace */ // Date actuelle Date now = new Date(); // Format de la date SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); // Creation de la chaine de la date actuelle a partir de l'objet Date now et du format (SimpleDateFormat). String dateNow = new String(sdf.format(now)); /** * Try/Catch pour : * 1 - IOException a cause de : * - File.createNewFile() * - FileOutputStream.write() * - FileOutputStream.close() * 2 - FileNotFoundException a cause de : * - FileOutputStream(File) // Instanciation */ // Partie enregistrement dans Fichier XMLOutputter xmlOutput = new XMLOutputter(Format.getPrettyFormat()); try { // Si il y a un media externe et si le media externe n'est pas en lecture seule if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) && !Environment.MEDIA_MOUNTED_READ_ONLY.equals(Environment.getExternalStorageState())) { FILE_EXT = true; // Creation du repertoire (pour si c'est la premiere fois par exemple) File trackFile = new File(EXT_FILES_DIR); trackFile.mkdir(); // Sauvegarde du repertoire et du nom de fichier dans des attributs de classe FILE_NAME = createFilename(EXT_FILES_DIR, dateNow); // Creation du nom de fichier a utilise en fonction du contenu du repertoire // Reutilisation de trackFile pour creer le fichier (objet java) trackFile = new File(EXT_FILES_DIR + FILE_NAME); // Creation du fichier trackFile.createNewFile(); // Ouverture d'un flux sortant vers le fichier FileOutputStream output = new FileOutputStream(trackFile); // Ecriture dans le fichier avec le flux et les octets de la chaine gpxFile xmlOutput.output(doc, output); // fermeture du flux d'ecriture si il existe if (output != null) output.close(); } else { FILE_EXT = false; /* Sinon utilisation du stockage interne */ // Sauvegarde du repertoire et du nom de fichier dans des attributs de classe FILE_NAME = createFilename(getFilesDir().getAbsolutePath(), dateNow); // Creation du nom de fichier a utilise en fonction du contenu du repertoire // Ouverture d'un flux sortant vers le fichier - Fichier lisible par tout le monde car fichier pour l'utilisateur FileOutputStream output = openFileOutput(FILE_NAME, MODE_WORLD_READABLE); // Ecriture dans le fichier avec le flux et les octets de la chaine gpxFile xmlOutput.output(doc, output); // fermeture du flux d'ecriture si il existe if (output != null) output.close(); } //Log.v(TAG, "File name : "+FILE_NAME); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return true; }
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//from w w w. java 2 s.co m */ 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 w w w .j a v a 2 s. c om*/ 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.CrExperience2.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: if (!jTextField1.isEnabled() && go == 1) { int option = JOptionPane.showConfirmDialog(rootPane, "Voulez-vous enregistr ?"); if (option == 0) { try { Element configs = new Element("config"); Element emplacement = new Element("emplacement"); configs.addContent(emplacement); Element emplacementQuestion = new Element("EmplacementQuestion"); emplacementQuestion.setText("" + position); emplacement.addContent(emplacementQuestion); Element font = new Element("fons"); font.setText(jComboBox3.getSelectedItem().toString()); emplacement.addContent(font); Element couleur = new Element("couleur"); couleur.setText(jButton10.getForeground().getRed() + "/" + jButton10.getForeground().getGreen() + "/" + jButton10.getForeground().getBlue()); Element taille = new Element("taille"); taille.setText(jComboBox4.getSelectedItem().toString()); emplacement.addContent(couleur); emplacement.addContent(taille); if (jToggleButton1.isSelected()) { Element ecran = new Element("ecran"); Element couleur2 = new Element("couleur"); couleur2.setText(jButton12.getForeground().getRed() + "/" + jButton12.getForeground().getGreen() + "/" + jButton12.getForeground().getBlue()); ecran.addContent(couleur2); if (jRadioButton12.isSelected()) { Attribute type = new Attribute("type", "fixe"); ecran.setAttribute(type); Element fixe = new Element("fixe"); fixe.setText(textField1.getText()); ecran.addContent(fixe); } else if (jRadioButton13.isSelected()) { Attribute type = new Attribute("type", "aleatoire"); ecran.setAttribute(type); Element aleatoire = new Element("aleatoire"); Element de = new Element("de"); de.setText(textField2.getText()); Element a = new Element("a"); a.setText(textField3.getText()); aleatoire.addContent(de); aleatoire.addContent(a); ecran.addContent(aleatoire); }// w w w. j a va2s.c om configs.addContent(ecran); } Element consigne = new Element("consigne"); Element text = new Element("text"); text.setText(jTextArea3.getText()); consigne.addContent(text); Element font2 = new Element("fons"); font2.setText(jComboBox1.getSelectedItem().toString()); consigne.addContent(font2); Element couleur3 = new Element("couleur"); couleur3.setText(jButton13.getForeground().getRed() + "/" + jButton13.getForeground().getGreen() + "/" + jButton13.getForeground().getBlue()); consigne.addContent(couleur3); Element taille1 = new Element("taille"); taille1.setText(jComboBox2.getSelectedItem().toString()); consigne.addContent(taille1); configs.addContent(consigne); experience.addContent(configs); //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")); jTextArea2.setText(""); this.setVisible(false); CrExperience1 cr = new CrExperience1(); cr.setVisible(true); cr.setLocationRelativeTo(null); } catch (java.io.IOException e) { } } else { } } else { JOptionPane.showMessageDialog(rootPane, "Entrez un ID et veuillez le vrfifier SVP! ou Remplissez bien le formulaire !"); } }
From source file:Frames.CrExperience2.java
private void jButton24ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton24ActionPerformed // TODO add your handling code here: if (!jTextField1.isEnabled() && go == 1) { int option = JOptionPane.showConfirmDialog(rootPane, "Voulez-vous enregistr ?"); if (option == 0) { try { Element configs = new Element("config"); Element emplacement = new Element("emplacement"); configs.addContent(emplacement); Element emplacementQuestion = new Element("EmplacementQuestion"); emplacementQuestion.setText("" + position); emplacement.addContent(emplacementQuestion); Element font = new Element("fons"); font.setText(jComboBox3.getSelectedItem().toString()); emplacement.addContent(font); Element couleur = new Element("couleur"); couleur.setText(jButton10.getForeground().getRed() + "/" + jButton10.getForeground().getGreen() + "/" + jButton10.getForeground().getBlue()); Element taille = new Element("taille"); taille.setText(jComboBox4.getSelectedItem().toString()); emplacement.addContent(couleur); emplacement.addContent(taille); if (jToggleButton1.isSelected()) { Element ecran = new Element("ecran"); Element couleur2 = new Element("couleur"); couleur2.setText(jButton12.getForeground().getRed() + "/" + jButton12.getForeground().getGreen() + "/" + jButton12.getForeground().getBlue()); ecran.addContent(couleur2); if (jRadioButton12.isSelected()) { Attribute type = new Attribute("type", "fixe"); ecran.setAttribute(type); Element fixe = new Element("fixe"); System.out.println("BOn"); fixe.setText(textField1.getText()); ecran.addContent(fixe); } else if (jRadioButton13.isSelected()) { Attribute type = new Attribute("type", "aleatoire"); ecran.setAttribute(type); Element aleatoire = new Element("aleatoire"); Element de = new Element("de"); de.setText(textField2.getText()); Element a = new Element("a"); a.setText(textField3.getText()); aleatoire.addContent(de); aleatoire.addContent(a); ecran.addContent(aleatoire); }// w w w. j a va 2s . c o m configs.addContent(ecran); } Element consigne = new Element("consigne"); Element text = new Element("text"); text.setText(jTextArea3.getText()); consigne.addContent(text); Element font2 = new Element("fons"); font2.setText(jComboBox1.getSelectedItem().toString()); consigne.addContent(font2); Element couleur3 = new Element("couleur"); couleur3.setText(jButton13.getForeground().getRed() + "/" + jButton13.getForeground().getGreen() + "/" + jButton13.getForeground().getBlue()); consigne.addContent(couleur3); Element taille1 = new Element("taille"); taille1.setText(jComboBox2.getSelectedItem().toString()); consigne.addContent(taille1); configs.addContent(consigne); experience.addContent(configs); //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")); jTextArea2.setText(""); this.setVisible(false); CrExperience1 cr = new CrExperience1(); cr.setVisible(true); cr.setLocationRelativeTo(null); } catch (java.io.IOException e) { } } else { } } else { JOptionPane.showMessageDialog(rootPane, "Entrez un ID et veuillez le vrfifier SVP! ou Remplissez bien le formulaire !"); } }