List of usage examples for org.jdom2.output Format getPrettyFormat
public static Format getPrettyFormat()
From source file:Modelo.ServidorXMLFIle.java
public static boolean saveUserInServerDataBase(String Hora, String Nombre, String Cantidad, String Protocolo) { Document doc;/*from w w w .j a v a2s . c o m*/ Element root, newChild; SAXBuilder builder = new SAXBuilder(); try { doc = builder.build(Util.USERS_XML_PATH); root = doc.getRootElement(); newChild = new Element(Util.SERVER_TAG); newChild.setAttribute(Util.HORA_TAG, Hora); newChild.setAttribute(Util.NOMBRE_TAG, Nombre); newChild.setAttribute(Util.CANTIDAD_TAG, Cantidad); newChild.setAttribute(Util.PRIMITIVA_TAG, Protocolo); root.addContent(newChild); try { Format format = Format.getPrettyFormat(); XMLOutputter out = new XMLOutputter(format); FileOutputStream file = new FileOutputStream(Util.USERS_XML_PATH); out.output(doc, file); file.flush(); file.close(); } catch (Exception e) { e.printStackTrace(); } } catch (JDOMParseException e) { System.out.println(Util.ERROR_XML_EMPTY_FILE); e.printStackTrace(); } catch (JDOMException e) { System.out.println(Util.ERROR_XML_PROCESSING_FILE); e.printStackTrace(); } catch (IOException e) { System.out.println(Util.ERROR_XML_PROCESSING_FILE); e.printStackTrace(); } return true; }
From source file:msi.gama.doc.util.UnifyDoc.java
License:Open Source License
public static void unify(boolean local) { try {/*from w ww. jav a 2 s . co m*/ WorkspaceManager ws = new WorkspaceManager(".", local); HashMap<String, File> hmFiles = ws.getProductDocFiles(); Document doc = mergeFiles(hmFiles); System.out.println("" + hmFiles); XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat()); sortie.output(doc, new FileOutputStream(Constants.DOCGAMA_GLOBAL_FILE)); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:msi.gama.doc.util.UnifyDoc.java
License:Open Source License
public static void unifyAllProjects(boolean local) { try {/*from w w w . ja v a2s . co m*/ WorkspaceManager ws = new WorkspaceManager(".", local); HashMap<String, File> hmFiles = local ? ws.getAllDocFilesLocal() : ws.getAllDocFiles(); Document doc = mergeFiles(hmFiles); System.out.println("" + hmFiles); XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat()); sortie.output(doc, new FileOutputStream(Constants.DOCGAMA_GLOBAL_FILE)); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:mx.com.pixup.portal.dao.ArtistaGenerateDaoJdbc.java
public void generateXML() { //querys//from www. ja va 2 s .com String sql = "select * from artista"; try { //seccion de preparacion de la query Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement.executeQuery(); //seccion de nodo raiz Element artistas = new Element("artistas"); this.xmlLogico.setRootElement(artistas); while (resultSet.next()) { //aqu se hace la magia para el XML Element artista = new Element("artista"); Attribute id = new Attribute("id", Integer.toString(resultSet.getInt("id"))); artista.setAttribute(id); Element nombre_artistico = new Element("nombre_artistico"); nombre_artistico.setText(resultSet.getString("nombre_artistico")); artista.addContent(nombre_artistico); Element descripcion = new Element("descripcion"); descripcion.setText(resultSet.getString("descripcion")); artista.addContent(descripcion); artistas.addContent(artista); } //se genera el xml fsico this.xmlFisico.setFormat(Format.getPrettyFormat()); this.xmlFisico.output(xmlLogico, archivoFisico); } catch (Exception e) { //*** se quit el return porque el mtodo es void System.out.println(e.getMessage()); } }
From source file:mx.com.pixup.portal.dao.DiscoPaisGenerateDaoJdbc.java
public void generateXML() { //querys//from w w w . j a va 2 s . c o m String sql = "SELECT id_idioma, id_disquera, pais.id as id_pais, pais.nombre as pais,\n" + "disco.titulo FROM disco\n" + "INNER JOIN pais ON pais.id = disco.id_pais"; try { //seccion de preparacion de la query Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement.executeQuery(); //seccion de nodo raiz Element discos = new Element("discos"); this.xmlLogico.setRootElement(discos); while (resultSet.next()) { //Elementos de Segundo Orden Element disco = new Element("disco"); Attribute idioma = new Attribute("idioma", Integer.toString(resultSet.getInt("id_idioma"))); disco.setAttribute(idioma); Attribute disquera = new Attribute("disquera", Integer.toString(resultSet.getInt("id_disquera"))); disco.setAttribute(disquera); //Elementos de Tercer Orden Element pais = new Element("pais"); Attribute id = new Attribute("id", Integer.toString(resultSet.getInt("id_pais"))); pais.setAttribute(id); pais.setText(resultSet.getString("pais")); disco.addContent(pais); Element titulo = new Element("titulo"); titulo.setText(resultSet.getString("titulo")); disco.addContent(titulo); discos.addContent(disco); //aqu se hace la magia para el XML } //se genera el xml fsico this.xmlFisico.setFormat(Format.getPrettyFormat()); this.xmlFisico.output(this.xmlLogico, this.archivoFisico); } catch (Exception e) { //*** se quit el return porque el mtodo es void System.out.println(e.getMessage()); } }
From source file:negocio.Metodos.java
public void escribirXML(Document doc) { XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); try {/*from ww w. j a v a 2 s .c o m*/ /*escribimos el documento en el file*/ xmlOutput.output(doc, new FileWriter(rutaJDOM)); } catch (IOException ex) { System.out.println("Error al escribir el documento"); } }
From source file:neon.common.files.XMLTranslator.java
License:Open Source License
@Override public void translate(Document document, OutputStream output) throws IOException { XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); outputter.output(document, output);/*from www .j a va2s.c o m*/ }
From source file:neon.editor.tools.SVGConverter.java
License:Open Source License
private static void save(Element shapes, int width, int height) throws IOException { Element root = new Element("map"); root.setAttribute("id", "aneirin"); root.setAttribute("name", "Aneirin"); root.setAttribute("uid", "1"); root.setAttribute("module", "aneirin"); Element size = new Element("size"); size.setAttribute("width", Integer.toString(width)); size.setAttribute("height", Integer.toString(height)); root.addContent(size);//from w w w . j a v a 2s. c o m int dx = 0; int dy = 13700; Element terrain = new Element("terrain"); root.addContent(terrain); Element base = new Element("region"); base.setAttribute("x", "0"); base.setAttribute("y", "0"); base.setAttribute("w", Integer.toString(width)); base.setAttribute("h", Integer.toString(height)); base.setAttribute("id", "sea"); terrain.addContent(base); for (Element rect : shapes.getChildren("rect", ns)) { int x = Integer.parseInt(rect.getAttributeValue("x")) + dx; int y = Integer.parseInt(rect.getAttributeValue("y")) + dy; int w = Integer.parseInt(rect.getAttributeValue("width")); int h = Integer.parseInt(rect.getAttributeValue("height")); String id = "grass"; String style = rect.getAttributeValue("style"); if (style.contains("#ffff00")) { id = "sand"; } else if (style.contains("#ff0000")) { id = "mud"; } else if (style.contains("#550000")) { id = "rock"; } else if (style.contains("#22cc51")) { id = "moss"; } else if (style.contains("#008080")) { id = "marsh"; } else if (style.contains("#bcff00")) { id = "meadow"; } Element region = new Element("region"); region.setAttribute("x", Integer.toString(x)); region.setAttribute("y", Integer.toString(y)); region.setAttribute("w", Integer.toString(w)); region.setAttribute("h", Integer.toString(h)); region.setAttribute("id", id); terrain.addContent(region); } Element elevation = new Element("elevation"); root.addContent(elevation); Element entities = new Element("entities"); root.addContent(entities); XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); outputter.output(new Document(root), new FileWriter("temp/map.xml")); }
From source file:neon.systems.files.XMLTranslator.java
License:Open Source License
public ByteArrayOutputStream translate(Document output) { ByteArrayOutputStream out = new ByteArrayOutputStream(); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); try {/*from w ww. j a v a2 s. c om*/ outputter.output(output, out); } catch (IOException e) { e.printStackTrace(); } return out; }
From source file:neon.ui.dialog.OptionDialog.java
License:Open Source License
@FXML private void save() { Document doc = new Document(); try {// w ww .j ava2 s .co m FileInputStream in = new FileInputStream("neon.ini"); doc = new SAXBuilder().build(in); in.close(); } catch (Exception e) { Engine.getLogger().severe(e.getMessage()); } Element ini = doc.getRootElement(); if (numpadButton.isSelected()) { config.setKeys(CClient.KeyboardSetting.NUMPAD); ini.getChild("keys").setText("numpad"); } else if (azertyButton.isSelected()) { config.setKeys(CClient.KeyboardSetting.AZERTY); ini.getChild("keys").setText("azerty"); } else if (qwertyButton.isSelected()) { config.setKeys(CClient.KeyboardSetting.QWERTY); ini.getChild("keys").setText("qwerty"); } else if (qwertzButton.isSelected()) { config.setKeys(CClient.KeyboardSetting.QWERTZ); ini.getChild("keys").setText("qwertz"); } XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); try { FileOutputStream out = new FileOutputStream("neon.ini"); outputter.output(doc, out); out.close(); } catch (IOException e) { Engine.getLogger().severe(e.getMessage()); } stage.close(); }