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:it.cnr.ilc.clavius.manager.TranscriptionManager.java
public Document getDoc(String resourceIdentificator) throws Exception { //Controllare se il file esiste gi! in caso contrario si legge da Exist! String TeiString = null;//from w w w. jav a 2 s . com try { TeiString = ExistManager.FromRemoteFileToString(BASE_URL.concat(resourceIdentificator).concat("/") .concat(resourceIdentificator).concat(DOC_SUFFIX)); } catch (FileNotFoundException fe) { System.err.println(fe.getMessage()); TeiString = ExistManager.FromRemoteFileToString(LOCAL_URL.concat(resourceIdentificator).concat("/") .concat(resourceIdentificator).concat(DOC_SUFFIX)); } if (null == TeiString) { TeiString = ""; } teiDoc.setTeiDocument(builder.build(new StringReader(TeiString))); //SERVER //HandleConstants.setWorkDir("/home/clavius/wapp/" + resourceIdentificator + "/"); //WINDOWS HandleConstants.setWorkDir("C:/tmp/Clavius/integrazioneWebApp/" + resourceIdentificator + "/"); HandleConstants.setTeiFile(resourceIdentificator.concat(DOC_SUFFIX)); HelperIO.fromDomToFile(teiDoc.getTeiDocument(), HandleConstants.getWorkDir() + HandleConstants.getTeiFile()); Element rootText = getTeiDoc().getText().clone(); return new Document(rootText); }
From source file:jcodecollector.io.PackageManager.java
License:Apache License
public static boolean exportSnippets(File file, String category) { ArrayList<Snippet> array = null; if (category == null) { array = DBMS.getInstance().getAllSnippets(); } else {// w w w .ja va 2 s .com array = DBMS.getInstance().getSnippets(category); } Element root = new Element("jcc-snippets-package"); root.setAttribute("version", GeneralInfo.APPLICATION_VERSION); Iterator<Snippet> iterator = array.iterator(); while (iterator.hasNext()) { Snippet snippet = iterator.next(); Element element = new Element("snippet"); Element category_xml = new Element("category"); category_xml.setText(snippet.getCategory()); element.addContent(category_xml); Element name_xml = new Element("name"); name_xml.setText(snippet.getName()); element.addContent(name_xml); String[] tags = snippet.getTags(); for (String tag : tags) { Element tag_xml = new Element("tag"); tag_xml.setText(tag); element.addContent(tag_xml); } Element syntax_xml = new Element("syntax"); syntax_xml.setText(snippet.getSyntax()); element.addContent(syntax_xml); Element code_xml = new Element("code"); code_xml.setText(snippet.getCode()); element.addContent(code_xml); Element comment_xml = new Element("comment"); comment_xml.setText(snippet.getComment()); element.addContent(comment_xml); root.addContent(element); } try { XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); outputter.output(new Document(root), new FileOutputStream(file)); return true; } catch (Exception ex) { ex.printStackTrace(); return false; } }
From source file:jcodecollector.io.XMLManagerOldVersion.java
License:Apache License
public static boolean createPackage(File file, String name) { ArrayList<Snippet> array = DBMS.getInstance().getSnippets(name); Element root_xml = new Element("jcc-snippets-package"); boolean success; Iterator<Snippet> iterator = array.iterator(); while (iterator.hasNext()) { Snippet snippet = iterator.next(); Element element = new Element("snippet"); Element category_xml = new Element("category"); category_xml.setText(snippet.getCategory()); element.addContent(category_xml); Element name_xml = new Element("name"); name_xml.setText(snippet.getName()); element.addContent(name_xml);/*from w ww. ja v a 2 s . com*/ String[] tags = snippet.getTags(); for (String tag : tags) { Element tag_xml = new Element("tag"); tag_xml.setText(tag); element.addContent(tag_xml); } Element syntax_xml = new Element("syntax"); syntax_xml.setText(snippet.getSyntax()); element.addContent(syntax_xml); Element code_xml = new Element("code"); code_xml.setText(snippet.getCode()); element.addContent(code_xml); Element comment_xml = new Element("comment"); comment_xml.setText(snippet.getComment()); element.addContent(comment_xml); Element locked_xml = new Element("locked"); locked_xml.setText(String.valueOf(snippet.isLocked())); element.addContent(locked_xml); root_xml.addContent(element); } try { XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); outputter.output(new Document(root_xml), new FileOutputStream(file)); success = true; } catch (Exception ex) { ex.printStackTrace(); success = false; } return success; }
From source file:json.JSONConverter.java
License:Apache License
/** * . Converts the built JSONObject//from w w w .java 2s.co m */ public void convert() { try { filter(jo); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } document = new Document(tree.get(0)); }
From source file:lu.list.itis.dkd.aig.resolution.Template.java
License:Apache License
/** * Method used for extracting the QTI item husk from an item template. * * @throws TemplateParseException// www .ja va 2 s. c om * TODO */ private void extractItem(final Document document) throws TemplateParseException { Element qtiRoot; try { final XPathExpression<Element> xpath = XPathFactory.instance().compile(Externalization.QTI_XPATH, Filters.element()); qtiRoot = xpath.evaluateFirst(document); } catch (final NullPointerException | IllegalArgumentException | IllegalStateException e) { throw new TemplateParseException("Compiling the Xpath expression to resolve the QTI root node failed!", //$NON-NLS-1$ e); } itemLayer = DocumentConverter.convertDocumentToString(new Document(qtiRoot.detach())); itemLayer = itemLayer.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", ""); //$NON-NLS-1$ //$NON-NLS-2$ }
From source file:model.data.manager.Manager.java
License:Open Source License
/** * TODO FONCTION BCP TROP LONGUE LOL/*from w w w.j a va 2 s .co 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.Model.java
public void createXML() { try {/* w w w . ja v a 2 s . c o m*/ 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:modelo.ArchivoXmlUsuario.java
private ArchivoXmlUsuario(String ruta, String nombreRaiz) throws IOException { this.raiz = new Element(nombreRaiz); this.documento = new Document(raiz); this.ruta = ruta; guardar();/* w ww. j av a 2 s . c o m*/ }
From source file:Modelo.CrearXml.java
public void crearArchivoXml(LinkedList<EmpleadoContrato> lista) { try {//from w w w . ja v a 2 s . c om 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 {//from w w w .jav a2 s . c o m 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()); } }