Example usage for org.jdom2.output Format getPrettyFormat

List of usage examples for org.jdom2.output Format getPrettyFormat

Introduction

In this page you can find the example usage for org.jdom2.output Format getPrettyFormat.

Prototype

public static Format getPrettyFormat() 

Source Link

Document

Returns a new Format object that performs whitespace beautification with 2-space indents, uses the UTF-8 encoding, doesn't expand empty elements, includes the declaration and encoding, and uses the default entity escape strategy.

Usage

From source file:Frames.CrExperience3.java

private int creerConfig() throws DataConversionException {
    int x = 0;/*from w ww  .  j a v a  2 s  .  co  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:Frames.CrExperience3.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");
                        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);
                    }/*www.  j  ava 2  s  .com*/

                    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("Exp3/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.CrExperience3.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  ww. 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("Exp3/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:gestetu05.GestionnaireUtilisateur.java

synchronized void enregistreXML(String fichier) {
    try {/*from  w ww .  j  a v  a 2  s  .  c om*/
        //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(fichier));
    } catch (java.io.IOException e) {
    }
}

From source file:gestores.IODocumentos.java

public static boolean exportarDocumento(Documento documento, String URL) {
    try {/* w  w  w . jav  a 2s .  c  om*/
        Element documentoXML = new Element("documento");
        documentoXML.addContent(new Element("URL").setText(documento.getURL()));
        documentoXML.addContent(new Element("nombre").setText(documento.getNombreDocumento()));
        documentoXML.addContent(new Element("carpeta").setText(documento.getURLDirectorioPadre()));

        for (Palabra palabra : documento.getVocabularioArrayList()) {
            Element xmlPalabra = new Element("palabra");
            xmlPalabra.addContent(new Element("nombre").setText(palabra.getPalabra()));
            xmlPalabra.addContent(new Element("frecuencia").setText(Integer.toString(palabra.getFrecuencia())));

            documentoXML.addContent(xmlPalabra);
        }

        URL += "\\" + documento.getNombreDocumento() + ".xml";

        Document archivoDeSalida = new Document(documentoXML);

        XMLOutputter xmlOutput = new XMLOutputter();
        xmlOutput.setFormat(Format.getPrettyFormat());
        xmlOutput.output(archivoDeSalida, new FileWriter(URL));

        return true;
    } catch (IOException e) {
        return false;
    }
}

From source file:gestores.IOMapeadorURLs.java

public static void exportarMapeadorSAX(MapeadorDeURLs mapeador, String URL) throws IOException {

    ArrayList<Mapeo> mapeos = mapeador.getMapeosOrdenadosPorCodigoMapping();

    Element documentoXML = new Element(Configuracion.marcaElementoRootMapeador);

    for (Mapeo elemento : mapeos) {
        Element mapeo = new Element(Configuracion.marcaMapeoMapeador);
        mapeo.addContent(new Element(Configuracion.marcaURLMapeador).setText(elemento.getURL()));
        mapeo.addContent(//from  ww  w .ja  v  a  2 s .  c  o  m
                new Element(Configuracion.marcaMappingMapeador).setText(Integer.toString(elemento.getMap())));

        documentoXML.addContent(mapeo);
    }

    Document archivoDeSalida = new Document(documentoXML);

    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(Format.getPrettyFormat());
    xmlOutput.output(archivoDeSalida, new FileWriter(URL));

}

From source file:gestores.IOPosteo.java

private static void exportarSAX(Posteo posteo, String URL) throws IOException {
    Element elementoRaiz = obtenerEstructuraDeExportacionDeListas(posteo);

    Document archivoDeSalida = new Document(elementoRaiz);

    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(Format.getPrettyFormat());
    xmlOutput.output(archivoDeSalida, new FileWriter(URL));

}

From source file:gestores.IOVocabularioGeneral.java

private static void exportarVocabularioSAX(VocabularioGeneral vocabulario, String URL) throws IOException {

    Element documentoXML = new Element(Configuracion.marcaElementoRootVocabulario);

    ArrayList<EntradaVocabularioGeneral> entradas = vocabulario.getEntradasDelVocabulario();
    Collections.sort(entradas);//w  ww  . j  av  a  2s  .  c o m

    for (EntradaVocabularioGeneral entrada : entradas) {
        Element entradaXML = new Element(Configuracion.marcaEntradaVocabulario);
        entradaXML.addContent(new Element(Configuracion.marcaPalabraVocabulario).setText(entrada.getPalabra()));
        entradaXML.addContent(new Element(Configuracion.marcaFrecuenciaVocabulario)
                .setText(Integer.toString(entrada.getFrecuencia())));
        entradaXML.addContent(new Element(Configuracion.marcaFrecuenciaMaximaVocabulario)
                .setText(Integer.toString(entrada.getFrecuenciaMaxima())));
        entradaXML.addContent(new Element(Configuracion.marcaCantidadDocumentosVocabulario)
                .setText(Integer.toString(entrada.getDocumentosEnQueAparece())));

        documentoXML.addContent(entradaXML);
    }

    /*if(nombreDelArchivo == null || nombreDelArchivo.equals("")){
        nombreDelArchivo = "vocabularioGeneral.xml";
    }*/

    Document archivoDeSalida = new Document(documentoXML);

    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(Format.getPrettyFormat());
    xmlOutput.output(archivoDeSalida, new FileWriter(URL));

}

From source file:hintahaku.Asetukset.java

private static void tallenna() {
    Element juuri = new Element("asetukset");
    juuri.setAttribute("info", "Hintahaku-asetukset");
    juuri.setAttribute("pvm", new SimpleDateFormat("d.M.y H:mm:ss").format(Calendar.getInstance().getTime()));

    if (suodatintiedosto != null) {
        juuri.addContent(new Element("suodatintiedosto").setText(suodatintiedosto.toString()));
    }/*from ww w .jav a2 s  .  c o m*/
    if (viimeisinSuodatinKansio != null) {
        juuri.addContent(new Element("viimeisinSuodatinKansio").setText(viimeisinSuodatinKansio.toString()));
    }
    if (viimeisinKokoonpanoKansio != null) {
        juuri.addContent(
                new Element("viimeisinKokoonpanoKansio").setText(viimeisinKokoonpanoKansio.toString()));
    }

    Document xml = new Document(juuri);
    try (BufferedWriter writer = Files.newBufferedWriter(tiedosto)) {
        new XMLOutputter(Format.getPrettyFormat()).output(xml, writer);
    } catch (IOException ex) {
    }
}

From source file:hintahaku.HintahakuFrame.java

private void tallenna(Path tallennettava) {
    Element juuri = new Element("kokoonpano");
    juuri.setAttribute("info", "Tallennettu Hintahaku-kokoonpano");
    juuri.setAttribute("pvm", new SimpleDateFormat("d.M.y H:mm:ss").format(Calendar.getInstance().getTime()));

    for (KokoonpanoTuote tuote : Kokoonpano.getTuotteet()) {
        Element tuoteEl = new Element("tuote");
        tuoteEl.addContent(new Element("url").setText(tuote.getUrl()));
        tuoteEl.addContent(new Element("mr").setText(Integer.toString(tuote.getMaara())));
        juuri.addContent(tuoteEl);/*from  ww w . j  av  a  2 s. c o m*/
    }

    org.jdom2.Document xml = new org.jdom2.Document(juuri);
    try (BufferedWriter writer = Files.newBufferedWriter(tallennettava)) {
        new XMLOutputter(Format.getPrettyFormat()).output(xml, writer);
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(null, "Tiedoston tallentaminen eponnistui!", "Virhe!",
                JOptionPane.ERROR_MESSAGE);
        return;
    }
    Kokoonpano.setTiedosto(tallennettava);
    jLabel11.setText("Avattu: " + tallennettava.getFileName().toString());
    jButton7.setEnabled(false);
}