List of usage examples for org.jdom2.output Format getPrettyFormat
public static Format getPrettyFormat()
From source file:org.fiware.cybercaptor.server.rest.RestJsonConfiguration.java
License:Open Source License
/** * Generic function to build the HTTP Reponse for operational cost parameters (snort rule, firewall rule, patch...) * * @param request the HTTP Request * @param costParameterFileName the filename of the file to get * @return the HTTP response//from ww w. j a v a 2s . c om */ private Response buildResponseForOperationalCostParameters(HttpServletRequest request, String costParameterFileName) { String costParametersFolderPath = ProjectProperties.getProperty("cost-parameters-path"); OperationalCostParameters operationalCostParameters = new OperationalCostParameters(); try { operationalCostParameters.loadFromXMLFile(costParametersFolderPath + "/" + costParameterFileName); } catch (Exception e) { return RestApplication.returnErrorMessage(request, "The operational cost parameters " + "can not be load: " + e.getMessage()); } XMLOutputter output = new XMLOutputter(Format.getPrettyFormat()); return RestApplication.returnJsonObject(request, XML.toJSONObject(output.outputString(operationalCostParameters.toDomElement()))); }
From source file:org.fiware.cybercaptor.server.scoring.gui.Launch.java
License:Open Source License
/** * Save the list of attack paths into a XML file * * @param filePath the paths where the list XML of attack paths can be written * @param AttackPaths list of attack paths * @throws Exception/*from www . j a va 2s . c om*/ */ protected static void saveToXmlFile(String filePath, Graph[] AttackPaths) throws Exception { XMLOutputter output = new XMLOutputter(Format.getPrettyFormat()); Element MainRoot = new Element("attack_paths"); Element root; if (AttackPaths != null) { for (Graph AttackPathBuffer : AttackPaths) { Arc[] AttackPathArcs = AttackPathBuffer.getArcs(); root = new Element("attack_path"); Element scoringElement = new Element("scoring"); scoringElement.setText(String.valueOf(formulas.MinMax(formulas.globalScore(AttackPathBuffer), AttackPathBuffer.getVertices().length))); root.addContent(scoringElement); if (AttackPathArcs != null) { Element arcsElement = new Element("arcs"); for (Arc AttackPathArc : AttackPathArcs) { Element arcElement = new Element("arc"); arcsElement.addContent(arcElement); Element srcElement = new Element("src"); srcElement.setText(String.valueOf(AttackPathArc.getSource())); arcElement.addContent(srcElement); Element dstElement = new Element("dst"); dstElement.setText(String.valueOf(AttackPathArc.getDestination())); arcElement.addContent(dstElement); } root.addContent(arcsElement); MainRoot.addContent(root); } } } output.output(MainRoot, new FileOutputStream(filePath)); }
From source file:org.fnppl.opensdx.xml.Document.java
License:Open Source License
public void output(OutputStream out) { try {/*from w w w.jav a 2s . c o m*/ Format f = Format.getPrettyFormat(); f.setEncoding("UTF-8"); XMLOutputter outp = new XMLOutputter(f); outp.output(base, out); out.flush(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.fnppl.opensdx.xml.Document.java
License:Open Source License
public String toString() { try {//from w w w.j a va 2s .c o m Format f = Format.getPrettyFormat(); f.setEncoding("UTF-8"); XMLOutputter outp = new XMLOutputter(f); StringWriter sw = new StringWriter(); outp.output(base, sw); sw.flush(); return sw.toString(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:org.fnppl.opensdx.xml.Document.java
License:Open Source License
public byte[] toByteArray() { try {/*from w ww . jav a 2s . c om*/ Format f = Format.getPrettyFormat(); f.setEncoding("UTF-8"); XMLOutputter outp = new XMLOutputter(f); return outp.outputString(base).getBytes("UTF-8"); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:org.gemoc.xdsmlframework.ide.ui.builder.pde.PluginXMLHelper.java
License:Open Source License
public void saveDocument(IFile pluginXmlFile) { try {/*w ww. j a va2s . c o m*/ XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat()); ByteArrayOutputStream stream = new ByteArrayOutputStream(); sortie.output(document, stream); InputStream inputStream = new ByteArrayInputStream(stream.toByteArray()); pluginXmlFile.setContents(inputStream, IResource.FORCE, null); } catch (IOException e) { Activator.error(e.getMessage(), e); } catch (CoreException e) { Activator.error(e.getMessage(), e); } }
From source file:org.geoserver.backuprestore.tasklet.AbstractCatalogBackupRestoreTasklet.java
License:Open Source License
/** * This method dumps the current Backup index: - List of Workspaces - List of Stores - List of * Layers/* w w w. j a va2s.c o m*/ * * @param sourceFolder * @throws IOException */ protected void dumpBackupIndex(Resource sourceFolder) throws IOException { Element root = new Element("Index"); Document doc = new Document(); for (WorkspaceInfo ws : getCatalog().getWorkspaces()) { if (!filteredResource(ws, false)) { Element workspace = new Element("Workspace"); workspace.addContent(new Element("Name").addContent(ws.getName())); root.addContent(workspace); for (DataStoreInfo ds : getCatalog().getStoresByWorkspace(ws.getName(), DataStoreInfo.class)) { if (!filteredResource(ds, ws, true, StoreInfo.class)) { Element store = new Element("Store"); store.setAttribute("type", "DataStoreInfo"); store.addContent(new Element("Name").addContent(ds.getName())); workspace.addContent(store); for (FeatureTypeInfo ft : getCatalog().getFeatureTypesByDataStore(ds)) { if (!filteredResource(ft, ws, true, ResourceInfo.class)) { for (LayerInfo ly : getCatalog().getLayers(ft)) { if (!filteredResource(ly, ws, true, LayerInfo.class)) { Element layer = new Element("Layer"); layer.setAttribute("type", "VECTOR"); layer.addContent(new Element("Name").addContent(ly.getName())); store.addContent(layer); } } } } } } for (CoverageStoreInfo cs : getCatalog().getStoresByWorkspace(ws.getName(), CoverageStoreInfo.class)) { if (!filteredResource(cs, ws, true, StoreInfo.class)) { Element store = new Element("Store"); store.setAttribute("type", "CoverageStoreInfo"); store.addContent(new Element("Name").addContent(cs.getName())); workspace.addContent(store); for (CoverageInfo ci : getCatalog().getCoveragesByCoverageStore(cs)) { if (!filteredResource(ci, ws, true, ResourceInfo.class)) { for (LayerInfo ly : getCatalog().getLayers(ci)) { if (!filteredResource(ly, ws, true, LayerInfo.class)) { Element layer = new Element("Layer"); layer.setAttribute("type", "RASTER"); layer.addContent(new Element("Name").addContent(ly.getName())); store.addContent(layer); } } } } } } } } if (filterIsValid()) { Element filter = new Element("Filters"); if (getFilters().length > 0 && getFilters()[0] != null) { Element wsFilter = new Element("Filter"); wsFilter.setAttribute("type", "WorkspaceInfo"); wsFilter.addContent(new Element("ECQL").addContent(ECQL.toCQL(getFilters()[0]))); filter.addContent(wsFilter); } if (getFilters().length > 1 && getFilters()[1] != null) { Element siFilter = new Element("Filter"); siFilter.setAttribute("type", "StoreInfo"); siFilter.addContent(new Element("ECQL").addContent(ECQL.toCQL(getFilters()[1]))); filter.addContent(siFilter); } if (getFilters().length > 2 && getFilters()[2] != null) { Element liFilter = new Element("Filter"); liFilter.setAttribute("type", "LayerInfo"); liFilter.addContent(new Element("ECQL").addContent(ECQL.toCQL(getFilters()[2]))); filter.addContent(liFilter); } root.addContent(filter); } doc.setRootElement(root); XMLOutputter outter = new XMLOutputter(); outter.setFormat(Format.getPrettyFormat()); outter.output(doc, new FileWriter(sourceFolder.get(BR_INDEX_XML).file())); }
From source file:org.goobi.managedbeans.ProcessBean.java
License:Open Source License
/** * Create the database information xml file and send it to the servlet output stream *///from ww w . j av a 2 s . c om public void downloadProcessDatebaseInformation() { FacesContext facesContext = FacesContextHelper.getCurrentFacesContext(); if (!facesContext.getResponseComplete()) { org.jdom2.Document doc = new ExportXmlLog().createExtendedDocument(myProzess); String outputFileName = myProzess.getId() + "_db_export.xml"; HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse(); ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext(); String contentType = servletContext.getMimeType(outputFileName); response.setContentType(contentType); response.setHeader("Content-Disposition", "attachment;filename=\"" + outputFileName + "\""); try { ServletOutputStream out = response.getOutputStream(); XMLOutputter outp = new XMLOutputter(); outp.setFormat(Format.getPrettyFormat()); outp.output(doc, out); out.flush(); } catch (IOException e) { Helper.setFehlerMeldung("could not export database information: ", e); } facesContext.responseComplete(); } }
From source file:org.goobi.production.export.ExportXmlLog.java
License:Open Source License
/** * This method exports the production metadata as xml to a given stream. * // w w w. ja v a 2 s.c om * @param process the process to export * @param os the OutputStream to write the contents to * @throws IOException * @throws ExportFileException */ @Override public void startExport(Process process, OutputStream os, String xslt) throws IOException { try { Document doc = createDocument(process, true); XMLOutputter outp = new XMLOutputter(); outp.setFormat(Format.getPrettyFormat()); outp.output(doc, os); os.close(); } catch (Exception e) { throw new IOException(e); } }
From source file:org.goobi.production.export.ExportXmlLog.java
License:Open Source License
/** * This method transforms the xml log using a xslt file and opens a new window with the output file * /*from ww w .j a v a 2s . c o m*/ * @param out ServletOutputStream * @param doc the xml document to transform * @param filename the filename of the xslt * @throws XSLTransformException * @throws IOException */ public void XmlTransformation(OutputStream out, Document doc, String filename) throws XSLTransformException, IOException { Document docTrans = new Document(); if (filename != null && filename.equals("")) { XSLTransformer transformer; transformer = new XSLTransformer(filename); docTrans = transformer.transform(doc); } else { docTrans = doc; } Format format = Format.getPrettyFormat(); format.setEncoding("utf-8"); XMLOutputter xmlOut = new XMLOutputter(format); xmlOut.output(docTrans, out); }