List of usage examples for org.jdom2 Document Document
public Document(List<? extends Content> content)
Document
, with the supplied list of content, and a DocType
declaration only if the content contains a DocType instance. From source file:gestores.IODocumentos.java
public static boolean exportarDocumento(Documento documento, String URL) { try {/* ww w .j a v a 2 s.com*/ 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 w ww . j ava 2s .c om 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);//from ww w .jav a 2 s .com 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 w ww. j a v a 2 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.Suodattimet.java
public static void tallennaNimella(Path tiedosto) throws IOException { Element juuri = new Element("suodattimet"); juuri.setAttribute("info", "Hintahaku-suodattimet"); juuri.setAttribute("pvm", new SimpleDateFormat("d.M.y H:mm:ss").format(Calendar.getInstance().getTime())); for (Kauppa kauppa : kaupatEventList) { Element kauppaxml = new Element("kauppa"); kauppaxml.addContent(new Element("nimi").setText(kauppa.getKaupanNimi())); kauppaxml.addContent(new Element("voiNoutaa").setText(Boolean.toString(kauppa.isVoiNoutaa()))); kauppaxml.addContent(new Element("suodataPois").setText(Boolean.toString(kauppa.isSuodataPois()))); juuri.addContent(kauppaxml);//from w w w . ja va 2s .co m } Document xml = new Document(juuri); try (BufferedWriter writer = Files.newBufferedWriter(tiedosto)) { new XMLOutputter(Format.getPrettyFormat()).output(xml, writer); } Suodattimet.tiedosto = tiedosto; }
From source file:ilarkesto.integration.jdom.JDom.java
License:Open Source License
public static void save(Element root, File file, String encoding) { Document doc = new Document(root); save(doc, file, encoding);/*from w w w.j a v a2 s. c o m*/ }
From source file:information.Information.java
License:Open Source License
public static void generarXML() { Document documento;// w ww .j av a2s .c o m Element raiz = new Element("Salones"); documento = new Document(raiz); for (Salon salon : salons) { Element salone = new Element("Salon"); salone.setAttribute("Nombre", salon.getName()); for (Room sala : salon.getRooms()) { Element salae = new Element("Sala"); salae.setAttribute("Nombre", sala.getName()); salae.setAttribute("Horizontal", Boolean.toString(sala.isHorizontal())); salae.addContent(new Element("SufijoIP").setText(Integer.toString(sala.getRoomIPSufix()))); for (Row fila : sala.getRows()) { Element filae = new Element("Fila"); for (ServerComputer equipo : fila.getComputers()) { Element equipoe = new Element("Equipo"); equipoe.setAttribute("Numero", Integer.toString(equipo.getComputerNumber())); equipoe.addContent(new Element("IP").setText(equipo.getIP())); equipoe.addContent(new Element("Mac").setText(equipo.getMac())); equipoe.addContent(new Element("Hostname").setText(equipo.getHostname())); for (String[] resultados : equipo.getResults()) { String orden = resultados[0]; String resultado = resultados[1]; Element resultadoe = new Element("Ejecucion"); resultadoe.addContent(new Element("Orden").setText(orden)); resultadoe.addContent(new Element("Resultado").setText(resultado)); equipoe.addContent(resultadoe); } filae.addContent(equipoe); } salae.addContent(filae); } salone.addContent(salae); } raiz.addContent(salone); } XMLOutputter xmlOutput = new XMLOutputter(); try { xmlOutput.output(documento, System.out); xmlOutput.setFormat(Format.getPrettyFormat()); xmlOutput.output(documento, new FileWriter(informationPath)); } catch (IOException ex) { Logger.getLogger(Information.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:io.LoadSave.java
License:Open Source License
/** * Saves the current status to a .oger file *///from w ww .j a v a 2s .c o m public static void save() { // get the selected file File file = IODialog.showSaveDialog(".oger", true); // not canceled if (file != null) { DefaultTreeModel treeModel = RoomTreeModel.getInstance(); ParticipantTableModel participantModel = ParticipantTableModel.getInstance(); // Create the XML root Element Element root = new Element("root"); // Create a JDOM Document based on the root Element Document document = new Document(root); List<Participant> participants = participantModel.getParticipants(); // Participants Element allParticipantsElement = new Element("allParticipants"); for (Participant p : participants) { Element participantElement = new Element("participant"); Attribute firstNameAttribute = new Attribute("firstName", p.getFirstName()); participantElement.setAttribute(firstNameAttribute); Attribute lastNameAttribute = new Attribute("lastName", p.getLastName()); participantElement.setAttribute(lastNameAttribute); Attribute mailAttribute = new Attribute("mail", p.geteMailAdress()); participantElement.setAttribute(mailAttribute); Attribute groupAttribute = new Attribute("group", Integer.toString(p.getGroupNumber())); participantElement.setAttribute(groupAttribute); allParticipantsElement.addContent(participantElement); } root.addContent(allParticipantsElement); // Slots with reviews Element allSlotsElement = new Element("Slots"); // all slots SlotNode currentSlotNode; RoomNode currentRoomNode; DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) treeModel.getRoot(); DateFormat dateFormatter = new SimpleDateFormat("dd.MM.yy"); DateFormat beginFormatter = new SimpleDateFormat("HH:mm"); DateFormat endFormatter = new SimpleDateFormat("HH:mm"); ; for (Enumeration<SlotNode> enumSlots = rootNode.children(); enumSlots.hasMoreElements();) { currentSlotNode = (SlotNode) enumSlots.nextElement(); Slot currentSlot = (Slot) currentSlotNode.getUserObject(); Element slotElement = new Element("Slot"); String date = dateFormatter.format(currentSlot.getDate().getTime()); Attribute dateAttribute = new Attribute("Date", date); slotElement.setAttribute(dateAttribute); String begin = beginFormatter.format(currentSlot.getBeginTime().getTime()); Attribute beginAttribute = new Attribute("Begin", begin); slotElement.setAttribute(beginAttribute); String end = endFormatter.format(currentSlot.getEndTime().getTime()); Attribute endAttribute = new Attribute("End", end); slotElement.setAttribute(endAttribute); // all rooms Element allRoomsElement = new Element("AllRooms"); for (Enumeration<RoomNode> enumRooms = currentSlotNode.children(); enumRooms.hasMoreElements();) { currentRoomNode = (RoomNode) enumRooms.nextElement(); Room currentRoom = (Room) currentRoomNode.getUserObject(); Element roomElement = new Element("Room"); Attribute beamerAttribute; if (currentRoom.hasBeamer()) { beamerAttribute = new Attribute("Beamer", "true"); } else { beamerAttribute = new Attribute("Beamer", "false"); } roomElement.setAttribute(beamerAttribute); Attribute idAttribute = new Attribute("ID", currentRoom.getRoomID()); roomElement.setAttribute(idAttribute); String beginRoom = beginFormatter.format(currentRoom.getBeginTime().getTime()); Attribute beginRoomAttribute = new Attribute("Begin", beginRoom); roomElement.setAttribute(beginRoomAttribute); String endRoom = endFormatter.format(currentRoom.getEndTime().getTime()); Attribute endRoomAttribute = new Attribute("End", endRoom); roomElement.setAttribute(endRoomAttribute); allRoomsElement.addContent(roomElement); } slotElement.addContent(allRoomsElement); allSlotsElement.addContent(slotElement); } root.addContent(allSlotsElement); try { // output XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat()); xmlOutputter.output(document, new FileOutputStream(file)); Main.setSaved(true); } catch (java.io.IOException e) { JOptionPane.showMessageDialog(null, e.getLocalizedMessage()); } } }
From source file:io.smartspaces.master.server.services.internal.support.JdomMasterDomainModelCreator.java
License:Apache License
/** * Create a description of the entire space domain. * * @param activityRepository/*from ww w .j a v a 2s . com*/ * the repository for activity entities * @param controllerRepository * the repository for controller entities * @param resourceRepository * the repository for resources * @param automationRepository * the repository for automation entities * * @return the XML description */ public String newModel(ActivityRepository activityRepository, SpaceControllerRepository controllerRepository, ResourceRepository resourceRepository, AutomationRepository automationRepository) { try { Element rootElement = new Element(ELEMENT_NAME_DESCRIPTION_ROOT_ELEMENT); Document document = new Document(rootElement); rootElement.addContent(newSpaceControllerEntries(controllerRepository)); rootElement.addContent(newActivityEntries(activityRepository)); rootElement.addContent(newLiveActivityEntries(activityRepository)); rootElement.addContent(newLiveActivityGroupEntries(activityRepository)); rootElement.addContent(newSpaceEntries(activityRepository)); rootElement.addContent(newResourceEntries(resourceRepository)); rootElement.addContent(newNamedScriptEntries(automationRepository)); StringWriter out = new StringWriter(); Format format = Format.getPrettyFormat(); XMLOutputter outputter = new XMLOutputter(format); outputter.output(document, out); return out.toString(); } catch (IOException e) { throw new SmartSpacesException("Could not create domain model", e); } }