List of usage examples for org.jdom2 Document Document
public Document()
From source file:org.xflatdb.xflat.transaction.ThreadContextTransactionManager.java
License:Apache License
private void loadJournal() throws IOException, JDOMException { transactionJournal = journalWrapper.readFile(); if (transactionJournal == null) { transactionJournal = new Document(); transactionJournal.setRootElement(new Element("transactionJournal")); }// w w w .j a v a 2 s .c o m }
From source file:org.yawlfoundation.yawl.elements.YDecomposition.java
License:Open Source License
public YDecomposition(String id, YSpecification specification) { _id = id;// www.j a v a 2 s . c om _specification = specification; _inputParameters = new HashMap<String, YParameter>(); _outputParameters = new HashMap<String, YParameter>(); _enablementParameters = new HashMap<String, YParameter>(); _outputExpressions = new HashSet<String>(); _data = new Document(); _attributes = new YAttributeMap(); _data.setRootElement(new Element(getRootDataElementName())); }
From source file:org.yawlfoundation.yawl.elements.YDecomposition.java
License:Open Source License
/** * This method returns the list of data from a decomposition. According to * its declared output parameters. Only useful for Beta 4 and above. * The data inside this decomposition is groomed so to speak so that the * output data is returned in sequence. Furthermore no internal variables, \ * or input only parameters are returned. * @return a JDom Document of the output data. *///from w ww . j ava2 s . c om public Document getOutputData() { //create a new output document to return Document outputDoc = new Document(); Element root = _data.getRootElement(); outputDoc.setRootElement(new Element(root.getName())); //now prepare a list of output params to iterate over. List<YParameter> outputParamsList = new ArrayList<YParameter>(getOutputParameters().values()); Collections.sort(outputParamsList); for (YParameter parameter : outputParamsList) { Element child = root.getChild(parameter.getPreferredName()); outputDoc.getRootElement().addContent(child.clone()); } return outputDoc; }
From source file:org.yawlfoundation.yawl.elements.YTask.java
License:Open Source License
public void prepareDataDocsForTaskOutput() { if (null == getDecompositionPrototype()) { return;// w ww. j av a 2 s. c om } _groupedMultiInstanceOutputData = new Document(); _groupedMultiInstanceOutputData .setRootElement(new Element(getDecompositionPrototype().getRootDataElementName())); _localVariableNameToReplaceableOutputData = new HashMap<String, Element>(); }
From source file:org.yawlfoundation.yawl.scheduling.Case.java
License:Open Source License
/** * Gets the value for an XPath expression for an Element at a specified depth * in the case's data//from www . j a v a2s . c o m * * @param depth the depth of the Element to use from the case data * @param xPath the XPath expression * @return the result of the XPath evaluation, or null if the depth exceeds the * depth of the case data's Elements, or if the XPath expression evaluates to null, * or if the Element result of the XPath expression contains no text */ public String getText(int depth, String xPath) { if (depth < getData().size()) { try { Element depthElement = getData().get(depth).clone(); _log.debug("Reading " + xPath + " from " + Utils.element2String(depthElement, true)); Element xpathResult = XMLUtils.getElement(new Document().setRootElement(depthElement), xPath); if (xpathResult != null) { return xpathResult.getText(); } } catch (Exception e) { // fall through to return null } } return null; }
From source file:parcelhub.utilities.ParcelXMLFileWriter.java
License:Open Source License
/** * Creates the XML file which stores our parcel information. *///from www . jav a2 s . c o m public void createXMLFile() { Element root = new Element("Parcels"); Document xmlDatabase = new Document(); for (int i = 0; i < parcels.size(); i++) { Parcel parcelObj = parcels.get(i); Element parcelXML = new Element("Parcel"); parcelXML.addContent(new Element("parcelID").addContent(parcelObj.getParcelID())); parcelXML.addContent(new Element("name").addContent(parcelObj.getNameReciever())); parcelXML.addContent(new Element("address").addContent(parcelObj.getAddress())); parcelXML.addContent(new Element("date").addContent(parcelObj.getDate())); parcelXML.addContent(new Element("city").addContent(parcelObj.getCity())); parcelXML.addContent(new Element("state").addContent(parcelObj.getState())); parcelXML.addContent(new Element("zip").addContent(parcelObj.getZip())); root.addContent(parcelXML); } xmlDatabase.setRootElement(root); XMLOutputter outter = new XMLOutputter(); outter.setFormat(Format.getPrettyFormat()); try { outter.output(xmlDatabase, new FileWriter(new File(fileName))); } catch (IOException ex) { Logger.getLogger(ParcelXMLFileWriter.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:per.sunmes.kfat.sys.FileUtil.java
public static void exportProject() { AnimationProjectInfo project = SysData.instance().getProject(); if (project == null) { return;/*from w w w. j a v a2 s . c o m*/ } Document document = new Document(); Element rootElement = new Element("kfa"); document.addContent(rootElement); rootElement.setAttribute("name", project.name); for (AnimationInfo ai : project.animations) { Element aiElement = new Element("animation"); aiElement.setAttribute("name", ai.name); rootElement.addContent(aiElement); for (FrameInfo fi : ai.frames) { Element fiElement = new Element("frame"); fiElement.setAttribute("id", String.valueOf(fi.id)); aiElement.addContent(fiElement); for (ImagePartInfo ipi : fi.parts) { Element ipiElement = new Element("part"); ipiElement.setAttribute("img", ipi.imageName); ipiElement.setAttribute("x", String.valueOf(ipi.x)); ipiElement.setAttribute("y", String.valueOf(ipi.y)); ipiElement.setAttribute("flipx", String.valueOf(ipi.flipX)); ipiElement.setAttribute("flipy", String.valueOf(ipi.flipY)); fiElement.addContent(ipiElement); } for (Rectangle rect : fi.rectangles) { Element rectElement = new Element("rectangle"); rectElement.setAttribute("x", String.valueOf(rect.x)); rectElement.setAttribute("y", String.valueOf(rect.y)); rectElement.setAttribute("width", String.valueOf(rect.width)); rectElement.setAttribute("height", String.valueOf(rect.height)); fiElement.addContent(rectElement); } } } XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); String outFile = String.format("%s/out/%s.xml", project.projectDirectory, project.name); try { outputter.output(document, new FileOutputStream(outFile)); JOptionPane.showMessageDialog(null, String.format("[%s],?!", outFile)); } catch (IOException ex) { Logger.getLogger(FileUtil.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:pl.edu.pwr.iiar.zak.thermalKit.util.ReadDesign.java
License:Open Source License
public void showDesign(String filename) throws JDOMException, IOException { try {//from w ww .j a v a 2 s .co m System.out.println("Converting NCD file to XDL..."); FileConverter.convertNCD2XDL(filename); } catch (NullPointerException e) { System.out.println("Please indicate correct ncd file!"); System.exit(0); } Design design = new Design(); design.loadXDLFile(filename.substring(0, filename.length() - 3) + "xdl"); Device device = design.getDevice(); Document writer = new Document(); Element rootElement = new Element("device"); writer.addContent(rootElement); rootElement.setAttribute(new Attribute("version", "0.2")); rootElement.setAttribute(new Attribute("name", device.getPartName())); Element size = new Element("size"); rootElement.addContent(size); size.setAttribute(new Attribute("cols", String.format("%d", device.getColumns()))); size.setAttribute(new Attribute("rows", String.format("%d", device.getRows()))); Element clbsize = new Element("clbsize"); rootElement.addContent(clbsize); clbsize.setAttribute(new Attribute("width", "0.00025")); clbsize.setAttribute(new Attribute("height", "0.0002")); int old_z = -1; int k = 0; String progress_bar = "|/-\\"; for (int row = 0; row < device.getColumns(); row++) { if (print) { System.out.format("%d\t", row + 1); } for (int col = 0; col < device.getRows(); col++) { System.out.println(String.format("Col: %d, Row: %d", col, row)); System.out.println(design.getDevice().getTile(col, row).getName()); if (design.getDevice().getTile(col, row).getName().contains("CLB")) { try { boolean used = false; for (PrimitiveSite ps : design.getDevice().getTile(col, row).getPrimitiveSites()) { if (design.isPrimitiveSiteUsed(ps)) { used = true; } } if (used) { if (print) { System.out.print("@"); } rootElement.addContent(addElement(row, col, "unit")); } else { if (print) { System.out.print("*"); } } k++; } catch (Exception e) { if (print) { System.out.print("#"); } rootElement.addContent(addElement(row, col, "obstacle")); } } else { rootElement.addContent(addElement(row, col, "obstacle")); if (print) { System.out.print("#"); } } } if (print) { System.out.println(); } else { int z = (int) ((row / 177.0) * 100); if (old_z != z) { System.out.write(progressBar(z, 50).getBytes()); old_z = z; } } } System.out.format("\nNumber of CLB tiles %d\n", k); System.out.format("Number of columns %d; Number of rows %d\n", design.getDevice().getColumns(), design.getDevice().getRows()); System.out.println("Creating XML file with device floorplan..."); XMLOutputter xml = new XMLOutputter(); xml.setFormat(Format.getPrettyFormat()); String path = "floorplan.xml"; if (!print) { PrintWriter xmlWriter = new PrintWriter(path, "UTF-8"); xmlWriter.print(xml.outputString(writer)); xmlWriter.close(); System.out.println("FPGA description saved in floorplan.xml!"); } }
From source file:princetonPlainsboro.EcritureXML.java
private Document createJDOM(DossierMedical dossier) { Document jdomDoc = new Document(); // racine/* w w w . ja v a2s . co m*/ Element rootElement = new Element("dossiers"); jdomDoc.setRootElement(rootElement); //ajoute les fiches de soin for (FicheDeSoins fiche : dossier.getFiches()) { Element DOMfiche = new Element("ficheDeSoins"); //Date: DOMfiche.addContent(convertDate(fiche.getDate())); //Medecin DOMfiche.addContent(convertMedecin(fiche.getMedecin())); //Patient DOMfiche.addContent(convertPatient(fiche.getPatient())); //Actes for (Acte acte : fiche.getActes()) { DOMfiche.addContent(convertActe(acte)); } // ajoute la nouvelle fiche de soin au document rootElement.addContent(DOMfiche); } return jdomDoc; }
From source file:prueba.Prueba.java
public static void write() throws IOException { //Se crea un numero documento Document document = new Document(); //Se abre el buffer para la lectura por consola BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Ingrese el nombre del elemento raiz(root):"); String raiz = br.readLine();/* w w w .ja v a 2s .c o m*/ //Se asigna el elemento raiz Element root = new Element(raiz); System.out.print("Numero de atributos a crear en su archivo XML:"); int numeroElementos = Integer.parseInt(br.readLine()); //Creacion del vector que contendra los elementos del xml String[] elementos = new String[numeroElementos]; //Creacion del vector que contendra los contenidos del xml String[] contenidos = new String[numeroElementos]; for (int i = 0; i < numeroElementos; i++) { System.out.print("Nombre del atributo (" + (i + 1) + "):"); elementos[i] = br.readLine(); } for (int i = 0; i < numeroElementos; i++) { System.out.print("Digite el contenido del elemento(" + elementos[i] + "):"); contenidos[i] = br.readLine(); } for (int i = 0; i < numeroElementos; i++) { Element element = new Element(elementos[i]); element.setText(contenidos[i]); root.addContent(element); } document.setRootElement(root); XMLOutputter outputter = new XMLOutputter(); outputter.output(document, new FileOutputStream(new File("src/file.xml"))); }