List of usage examples for org.jdom2.output Format getPrettyFormat
public static Format getPrettyFormat()
From source file:model.advertisement.AbstractAdvertisement.java
License:Open Source License
@Override /**//from w w w. ja va 2s . c o m * Return a string, XML-Formatted, representing this instance. */ public String toString() { org.jdom2.Element document = this.getRootElement(); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); String xmlString = outputter.outputString(document); return xmlString; }
From source file:model.advertisement.AbstractAdvertisement.java
License:Open Source License
public String getDocumentString() { org.jdom2.Document document = this.getDocument(); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); String xmlString = outputter.outputString(document); return xmlString; }
From source file:model.data.manager.Manager.java
License:Open Source License
/** * TODO FONCTION BCP TROP LONGUE LOL/*from w w w. jav a 2s. c o m*/ */ @Override public void saving(String path) { String currentPublicKey = userManager.getCurrentUser().getKeys().getPublicKey().toString(16); AsymKeysImpl keys = userManager.getCurrentUser().getKeys().copy(); keys.decryptPrivateKey(userManager.getCurrentUser().getClearPwd()); // Recovery all local data in a new Manager Manager manager = new Manager(null); manager.recovery(path); if (path == null || path.isEmpty()) path = VARIABLES.ManagerFilePath; // Element Root Element root = new Element(Manager.class.getName()); // ArrayList are used for adding data in local file. ArrayList<User> users = new ArrayList<User>(); ArrayList<Item> items = this.userManager.getUserItems(currentPublicKey); ArrayList<UserMessage> messages = null; // TODO this.getUserMessages(currentPublicKey); ArrayList<Conversations> conversations = new ArrayList<Conversations>(); ArrayList<Favorites> favorites = new ArrayList<Favorites>(); HashMap<String, ArrayList<Contrat>> deals = new HashMap<String, ArrayList<Contrat>>(); Conversations converC = this.messageManager.getUserConversations(currentPublicKey); if (converC != null) conversations.add(converC); ArrayList<Contrat> arrayDealsC = this.contratManager.getDealsCurrentUser(); if (arrayDealsC != null) deals.put(currentPublicKey, arrayDealsC); Favorites favoC = this.favoriteManager.getFavoritesCurrentUser(); if (favoC != null) { favoC.encrypt(userManager.getCurrentUser().getClearPwd()); favoC.sign(keys); favorites.add(favoC); } // Element users users.add(this.userManager.getCurrentUser()); Element usersElement = new Element("users"); usersElement.addContent(this.userManager.getCurrentUser().getRootElement()); for (User user : manager.userManager.getUsers()) { String userKey = user.getKeys().getPublicKey().toString(16); if (!user.getKeys().getPublicKey().toString(16).equals(currentPublicKey)) { usersElement.addContent(user.getRootElement()); users.add(user); // Filling ArrayList items for (Item i : this.userManager.getUserItems(userKey)) { if (!items.contains(i)) items.add(i); } for (Item i : manager.userManager.getUserItems(userKey)) { if (!items.contains(i)) items.add(i); } // Filling ArrayList messages /* TODO for (Message m : this.getUserMessages(userKey)) { if(!messages.contains(m)) messages.add(m); } for (Message m : manager.getUserMessages(userKey)) { if(!messages.contains(m)) messages.add(m); } */ // Filling ArrayList conversations Conversations c; c = this.messageManager.getUserConversations(userKey); if (c != null && !conversations.contains(c)) conversations.add(c); c = manager.messageManager.getUserConversations(userKey); if (c != null && !conversations.contains(c)) conversations.add(c); // Filling ArrayList favorites Favorites f; f = this.favoriteManager.getUserFavorites(userKey); if (f != null && !favorites.contains(f)) { favorites.add(f); } f = manager.favoriteManager.getUserFavorites(userKey); if (f != null && !favorites.contains(f)) favorites.add(f); // Filling ArrayList deals if (!deals.containsKey(userKey)) deals.put(userKey, new ArrayList<Contrat>()); for (Contrat d : this.contratManager.getUserDeals(userKey)) { if (!deals.get(userKey).contains(d)) deals.get(userKey).add(d); } for (Contrat d : manager.contratManager.getUserDeals(userKey)) { if (!deals.get(userKey).contains(d)) deals.get(userKey).add(d); } } } // Element items Element itemsElement = new Element("items"); for (Item i : items) { itemsElement.addContent(i.getRootElement()); } // Element messages Element messagesElement = new Element("messages"); /* TODO FIX BUG for (Message m : messages) { messagesElement.addContent(m.getRootElement()); } */ // Element ReceivedMessages Element conversationsElement = new Element("ReceivedMessages"); for (Conversations c : conversations) { conversationsElement.addContent(c.getRootElement()); } // Element Favorites Element favoritesElement = new Element("favorites"); for (Favorites f : favorites) { favoritesElement.addContent(f.getRootElement()); } // Element Deals Element dealsElement = new Element("deals"); for (User u : users) { String userKey = u.getKeys().getPublicKey().toString(16); for (Contrat d : deals.get(userKey)) { Element ownerElement = new Element("owner"); Element dealElement = new Element("deal"); ownerElement.addContent(userKey); dealElement.addContent(ownerElement); dealElement.addContent(d.getRootElement()); dealsElement.addContent(dealElement); } } // Adding all elements in root element root.addContent(usersElement); root.addContent(itemsElement); root.addContent(messagesElement); root.addContent(conversationsElement); root.addContent(favoritesElement); root.addContent(dealsElement); // Writing in file Document doc = new Document(root); XMLOutputter xmlOutput = new XMLOutputter(); Format format = Format.getPrettyFormat(); format.setEncoding("UTF8"); xmlOutput.setFormat(format); try { xmlOutput.output(doc, new FileWriter(path)); } catch (IOException e) { Printer.printError(this, "saving", "saving : " + e.toString()); } finally { Printer.printInfo(this, "saving", "Data saved localy"); } }
From source file:model.data.RendezVousIp.java
License:Open Source License
@Override protected void putValues() { XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); addValue("ips", out.outputString(ips)); }
From source file:Model.Model.java
public void createXML() { try {/*from w ww . j a v a 2 s.com*/ addSubConjuntosToFirstState(); Element structure = new Element("structure"); Document doc = new Document(structure); structure.addContent(new Element("type").setText("fa")); Element automaton = new Element("automaton"); for (int i = 0; i < subConjuntos.size(); i++) { Element state = new Element("state"); state.setAttribute(new Attribute("id", subConjuntos.get(i).get(0).getIdStateFrom())); state.setAttribute(new Attribute("name", "q" + subConjuntos.get(i).get(0).getIdStateFrom())); for (int j = 0; j < transicionesAFD.size(); j++) { if (subConjuntos.get(i).get(0).getIdStateFrom() == transicionesAFD.get(j).getIdStateFrom()) { if (transicionesAFD.get(j).isEsEstadoInicial() || subConjuntos.get(i).get(0).isEsEstadoInicial()) { state.addContent(new Element("initial")); } if (transicionesAFD.get(j).isEsEstadoFinal()) { state.addContent(new Element("final")); } if (!isNotInSubconjuntos(transicionesAFD.get(j).getIdStateTo()).isEmpty()) { transicionesAFD.get(j) .setIdStateTo(isNotInSubconjuntos(transicionesAFD.get(j).getIdStateTo())); } Element transition = new Element("transition"); transition.addContent(new Element("from").setText(transicionesAFD.get(j).getIdStateFrom())); transition.addContent(new Element("to").setText(transicionesAFD.get(j).getIdStateTo())); transition.addContent(new Element("read").setText(transicionesAFD.get(j).getLetter())); automaton.addContent(transition); } } automaton.addContent(state); } doc.getRootElement().addContent(automaton); XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); String[] parts = urlFile.split(Pattern.quote(".")); String a = parts[0]; xmlOutput.output(doc, new FileWriter(a + "Transform.jff")); } catch (Exception ex) { System.out.println(ex.getMessage()); } }
From source file:Model.ServidorXMLFIle.java
public static boolean saveUserInServerDataBase(String Hora, String Nombre, String Cantidad, String Protocolo) { Document doc;/*from ww w . java 2 s .c om*/ Element root, newChild; SAXBuilder builder = new SAXBuilder(); try { doc = builder.build(UtilCliente.USERS_XML_PATH); root = doc.getRootElement(); newChild = new Element(UtilCliente.SERVER_TAG); newChild.setAttribute(UtilCliente.HORA_TAG, Hora); newChild.setAttribute(UtilCliente.NOMBRE_TAG, Nombre); newChild.setAttribute(UtilCliente.CANTIDAD_TAG, Cantidad); newChild.setAttribute(UtilCliente.PRIMITIVA_TAG, Protocolo); root.addContent(newChild); try { Format format = Format.getPrettyFormat(); XMLOutputter out = new XMLOutputter(format); FileOutputStream file = new FileOutputStream(UtilCliente.USERS_XML_PATH); out.output(doc, file); file.flush(); file.close(); } catch (Exception e) { e.printStackTrace(); } } catch (JDOMParseException e) { System.out.println(UtilCliente.ERROR_XML_EMPTY_FILE); e.printStackTrace(); } catch (JDOMException e) { System.out.println(UtilCliente.ERROR_XML_PROCESSING_FILE); e.printStackTrace(); } catch (IOException e) { System.out.println(UtilCliente.ERROR_XML_PROCESSING_FILE); e.printStackTrace(); } return true; }
From source file:Modelo.CrearXml.java
public void crearArchivoXml(LinkedList<EmpleadoContrato> lista) { try {//from w ww . java2 s . c o m Element empleadoContrato = new Element("EmpleadoContrato"); Document doc = new Document(empleadoContrato); for (int i = 0; i < lista.size(); i++) { Element empleado = new Element("empleado"); empleado.setAttribute(new Attribute("id", lista.get(i).getId())); empleado.addContent(new Element("Nombre").setText(lista.get(i).getNombre())); empleado.addContent(new Element("Telefono").setText(lista.get(i).getTelefono())); empleado.addContent(new Element("Numero de Contrato").setText(lista.get(i).getNumContrato())); empleado.addContent(new Element("Actividad").setText(lista.get(i).getActividad())); doc.getRootElement().addContent(empleado); } // new XMLOutputter().output(doc, System.out); XMLOutputter xmlOutput = new XMLOutputter(); // display nice nice xmlOutput.setFormat(Format.getPrettyFormat()); xmlOutput.output(doc, new FileWriter("empleadoC.xml")); System.out.println("File Saved!"); } catch (IOException io) { System.out.println(io.getMessage()); } }
From source file:Modelo.FileRead.java
public void escribir() { try {//w w w. j av a 2s . c om Element company = new Element("familias"); for (int i = 0; i < fam.size(); i++) { Element familia = new Element("Familia"); Familia aux = fam.get(i); familia.setAttribute(new Attribute("nombre", aux.getNombre())); ArrayList<MiembroFamilia> mf = fam.get(i).getMiembros(); for (int j = 0; j < mf.size(); j++) { Element miembro = new Element("MiembroFamilia"); miembro.addContent(new Element("nombre").setText(mf.get(j).getNombre())); miembro.addContent(new Element("rut").setText(mf.get(j).getRut())); miembro.addContent(new Element("clave").setText(mf.get(j).getClave())); familia.addContent(miembro); } ArrayList<Fotografia> f = fam.get(i).getFotos(); for (int j = 0; j < f.size(); j++) { Element fotos = new Element("Fotografia"); fotos.addContent(new Element("path").setText(f.get(j).getPath())); fotos.addContent(new Element("comentario").setText(f.get(j).getComentario())); familia.addContent(fotos); } company.addContent(familia); } // new XMLOutputter().output(doc, System.out); XMLOutputter xmlOutput = new XMLOutputter(); // display nice nice xmlOutput.setFormat(Format.getPrettyFormat()); xmlOutput.output(new Document(company), new FileOutputStream(file)); } catch (Exception e) { System.out.println(e.getMessage()); } }
From source file:modelo.manejoXML.java
/** * @crea un fichero xml con los articulos visualizados y los guarda en la ruta especificada * @see controlador.controlador_visualizarProductos * @param lista lista de productos visualizados * @param arNom nombre del fichero xml// ww w. j av a 2 s . c o m * @param ruta ruta del fichero xml * @throws IOException */ public void crearXML(Articulo[] lista, String arNom, String ruta) throws IOException { try { Element articulos = new Element("Articulos"); Document doc = new Document(articulos); for (int i = 0; i < lista.length; i++) { Element articulo = new Element("articulo"); Attribute atributo = new Attribute("codigo", Integer.toString(lista[i].getCodigo())); articulo.setAttribute(atributo); Element nombre = new Element("nombre"); nombre.setText(lista[i].getNombre()); Element familia = new Element("familia"); familia.setText(lista[i].getFamilia()); Element precio = new Element("precio"); precio.setText(Float.toString(lista[i].getPrecio())); Element cantidad = new Element("cantidad"); cantidad.setText(Integer.toString(lista[i].getCantidad())); articulo.addContent(nombre); articulo.addContent(familia); articulo.addContent(precio); articulo.addContent(cantidad); doc.getRootElement().addContent(articulo); } XMLOutputter xmloutput = new XMLOutputter(); xmloutput.setFormat(Format.getPrettyFormat()); xmloutput.output(doc, new FileWriter(ruta + "\\" + arNom + ".xml")); } catch (IOException ex) { throw ex; } }
From source file:Modelo.ProductorXMLFIle.java
public static boolean saveUserInServerDataBase(String Hora, String Nombre, String Cantidad) { Document doc;/*w w w .j a va 2 s . c o m*/ Element root, newChild; SAXBuilder builder = new SAXBuilder(); try { doc = builder.build(UtilProductor.USERS_XML_PATH); root = doc.getRootElement(); newChild = new Element(UtilProductor.SERVER_TAG); newChild.setAttribute(UtilProductor.HORA_TAG, Hora); newChild.setAttribute(UtilProductor.NOMBRE_TAG, Nombre); newChild.setAttribute(UtilProductor.CANTIDAD_TAG, Cantidad); root.addContent(newChild); try { Format format = Format.getPrettyFormat(); XMLOutputter out = new XMLOutputter(format); FileOutputStream file = new FileOutputStream(UtilProductor.USERS_XML_PATH); out.output(doc, file); file.flush(); file.close(); } catch (Exception e) { e.printStackTrace(); } } catch (JDOMParseException e) { System.out.println(UtilProductor.ERROR_XML_EMPTY_FILE); e.printStackTrace(); } catch (JDOMException e) { System.out.println(UtilProductor.ERROR_XML_PROCESSING_FILE); e.printStackTrace(); } catch (IOException e) { System.out.println(UtilProductor.ERROR_XML_PROCESSING_FILE); e.printStackTrace(); } return true; }