List of usage examples for org.dom4j.io OutputFormat createPrettyPrint
public static OutputFormat createPrettyPrint()
From source file:com.dreikraft.axbo.sound.SoundPackageUtil.java
private static void writePackageInfoZipEntry(final SoundPackage soundPackage, final ZipOutputStream out) throws UnsupportedEncodingException, IOException { // write xml to temporary byte array, because of stripping problems, when // directly writing to encrypted stream ByteArrayOutputStream bOut = new ByteArrayOutputStream(); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(ENCODING);/* w ww .j a v a 2 s . c o m*/ XMLWriter writer = new XMLWriter(bOut, format); writer.setEscapeText(true); writer.write(createPackageInfoXml(soundPackage)); writer.close(); // write temporary byte array to encrypet zip entry ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray()); writeZipEntry(PACKAGE_INFO, out, bIn); }
From source file:com.dtolabs.client.services.JobDefinitionSerializer.java
License:Apache License
private static void serializeDocToFile(final File file, final Document doc) throws IOException { final OutputFormat format = OutputFormat.createPrettyPrint(); final XMLWriter writer = new XMLWriter(new FileOutputStream(file), format); writer.write(doc);//w w w . j a v a2 s . co m writer.flush(); }
From source file:com.dtolabs.client.services.RundeckAPICentralDispatcher.java
License:Apache License
public Collection<IStoredJob> listStoredJobs(final IStoredJobsQuery iStoredJobsQuery, final OutputStream output, final JobDefinitionFileFormat fformat) throws CentralDispatcherException { final HashMap<String, String> params = new HashMap<String, String>(); final String nameMatch = iStoredJobsQuery.getNameMatch(); String groupMatch = iStoredJobsQuery.getGroupMatch(); final String projectFilter = iStoredJobsQuery.getProjectFilter(); final String idlistFilter = iStoredJobsQuery.getIdlist(); final String expectedContentType; if (null != fformat) { params.put("format", fformat.getName()); expectedContentType = fformat == JobDefinitionFileFormat.xml ? "text/xml" : "text/yaml"; } else {//ww w . j a v a 2 s. c o m params.put("format", JobDefinitionFileFormat.xml.getName()); expectedContentType = "text/xml"; } if (null != nameMatch) { params.put("jobFilter", nameMatch); } if (null != groupMatch) { final Matcher matcher = Pattern.compile("^/*(.+?)/*$").matcher(groupMatch); if (matcher.matches()) { //strip leading and trailing slashes groupMatch = matcher.group(1); } params.put("groupPath", groupMatch); } if (null != projectFilter) { params.put("project", projectFilter); } if (null != idlistFilter) { params.put("idlist", idlistFilter); } //2. send request via ServerService final WebserviceResponse response; try { response = serverService.makeRundeckRequest(RUNDECK_API_JOBS_EXPORT_PATH, params, null, null, expectedContentType, null); } catch (MalformedURLException e) { throw new CentralDispatcherServerRequestException("Failed to make request", e); } checkErrorResponse(response); //if xml, do local validation and listing if (null == fformat || fformat == JobDefinitionFileFormat.xml) { validateJobsResponse(response); //////////////////// //parse result list of queued items, return the collection of QueuedItems /////////////////// final Document resultDoc = response.getResultDoc(); final Node node = resultDoc.selectSingleNode("/joblist"); final ArrayList<IStoredJob> list = new ArrayList<IStoredJob>(); if (null == node) { return list; } final List items = node.selectNodes("job"); if (null != items && items.size() > 0) { for (final Object o : items) { final Node node1 = (Node) o; final Node uuid = node1.selectSingleNode("uuid"); final Node id1 = node1.selectSingleNode("id"); final String id = null != uuid ? uuid.getStringValue() : id1.getStringValue(); final String name = node1.selectSingleNode("name").getStringValue(); final String url = createJobURL(id); final Node gnode = node1.selectSingleNode("group"); final String group = null != gnode ? gnode.getStringValue() : null; final String description = node1.selectSingleNode("description").getStringValue(); list.add(StoredJobImpl.create(id, name, url, group, description, projectFilter)); } } if (null != output) { //write output doc to the outputstream final OutputFormat format = OutputFormat.createPrettyPrint(); try { final XMLWriter writer = new XMLWriter(output, format); writer.write(resultDoc); writer.flush(); } catch (IOException e) { throw new CentralDispatcherServerRequestException(e); } } return list; } else if (fformat == JobDefinitionFileFormat.yaml) { //do rough yaml parse final Collection<Map> mapCollection; //write to temp file File temp; InputStream tempIn; try { temp = File.createTempFile("listStoredJobs", ".yaml"); temp.deleteOnExit(); OutputStream os = new FileOutputStream(temp); try { Streams.copyStream(response.getResultStream(), os); } finally { os.close(); } tempIn = new FileInputStream(temp); try { mapCollection = validateJobsResponseYAML(response, tempIn); } finally { tempIn.close(); } } catch (IOException e) { throw new CentralDispatcherServerRequestException(e); } final ArrayList<IStoredJob> list = new ArrayList<IStoredJob>(); if (null == mapCollection || mapCollection.size() < 1) { return list; } for (final Map map : mapCollection) { final Object uuidobj = map.get("uuid"); final Object idobj = map.get("id"); final String id = null != uuidobj ? uuidobj.toString() : idobj.toString(); final String name = (String) map.get("name"); final String group = map.containsKey("group") ? (String) map.get("group") : null; final String desc = map.containsKey("description") ? (String) map.get("description") : ""; final String url = createJobURL(id); list.add(StoredJobImpl.create(id, name, url, group, desc, projectFilter)); } if (null != output) { //write output doc to the outputstream try { tempIn = new FileInputStream(temp); try { Streams.copyStream(tempIn, output); } finally { tempIn.close(); } temp.delete(); } catch (IOException e) { throw new CentralDispatcherServerRequestException(e); } } return list; } return null; }
From source file:com.dtolabs.client.services.RundeckAPICentralDispatcher.java
License:Apache License
/** * Utility to serialize Document as a String for debugging * * @param document document/*from ww w .j av a 2s. c o m*/ * * @return xml string * * @throws java.io.IOException if error occurs */ private static String serialize(final Document document) throws IOException { final OutputFormat format = OutputFormat.createPrettyPrint(); final StringWriter sw = new StringWriter(); final XMLWriter writer = new XMLWriter(sw, format); writer.write(document); writer.flush(); sw.flush(); return sw.toString(); }
From source file:com.dtolabs.client.services.RundeckAPICentralDispatcher.java
License:Apache License
/** * Utility to serialize Document to a stream * * @param document document//from w w w. j av a 2 s . c o m * * * @throws java.io.IOException if error occurs */ private static void serialize(final Document document, final OutputStream stream) throws IOException { final OutputFormat format = OutputFormat.createPrettyPrint(); final XMLWriter writer = new XMLWriter(stream, format); writer.write(document); writer.flush(); }
From source file:com.dtolabs.client.services.RundeckCentralDispatcher.java
License:Apache License
public Collection<IStoredJob> listStoredJobs(final IStoredJobsQuery iStoredJobsQuery, final OutputStream output, final JobDefinitionFileFormat fformat) throws CentralDispatcherException { final HashMap<String, String> params = new HashMap<String, String>(); final String nameMatch = iStoredJobsQuery.getNameMatch(); String groupMatch = iStoredJobsQuery.getGroupMatch(); final String projectFilter = iStoredJobsQuery.getProjectFilter(); final String idlistFilter = iStoredJobsQuery.getIdlist(); if (null != output && null != fformat) { params.put("format", fformat.getName()); } else {//w w w . ja v a 2 s . c o m params.put("format", JobDefinitionFileFormat.xml.getName()); } if (null != nameMatch) { params.put("jobFilter", nameMatch); } if (null != groupMatch) { final Matcher matcher = Pattern.compile("^/*(.+?)/*$").matcher(groupMatch); if (matcher.matches()) { //strip leading and trailing slashes groupMatch = matcher.group(1); } params.put("groupPath", groupMatch); } if (null != projectFilter) { params.put("projFilter", projectFilter); } if (null != idlistFilter) { params.put("idlist", idlistFilter); } //2. send request via ServerService final WebserviceResponse response; try { response = serverService.makeRundeckRequest(RUNDECK_LIST_STORED_JOBS_PATH, params, null, null); } catch (MalformedURLException e) { throw new CentralDispatcherServerRequestException("Failed to make request", e); } //if xml, do local validation and listing if (null == fformat || fformat == JobDefinitionFileFormat.xml) { validateJobsResponse(response); //////////////////// //parse result list of queued items, return the collection of QueuedItems /////////////////// final Document resultDoc = response.getResultDoc(); final Node node = resultDoc.selectSingleNode("/joblist"); final ArrayList<IStoredJob> list = new ArrayList<IStoredJob>(); if (null == node) { return list; } final List items = node.selectNodes("job"); if (null != items && items.size() > 0) { for (final Object o : items) { final Node node1 = (Node) o; final String id = node1.selectSingleNode("id").getStringValue(); final String name = node1.selectSingleNode("name").getStringValue(); final String url = createJobURL(id); final Node gnode = node1.selectSingleNode("group"); final String group = null != gnode ? gnode.getStringValue() : null; final String description = node1.selectSingleNode("description").getStringValue(); list.add(StoredJobImpl.create(id, name, url, group, description, projectFilter)); } } if (null != output) { //write output doc to the outputstream final OutputFormat format = OutputFormat.createPrettyPrint(); try { final XMLWriter writer = new XMLWriter(output, format); writer.write(resultDoc); writer.flush(); } catch (IOException e) { throw new CentralDispatcherServerRequestException(e); } } return list; } else if (fformat == JobDefinitionFileFormat.yaml) { //do rought yaml parse final Collection<Map> mapCollection = validateJobsResponseYAML(response); final ArrayList<IStoredJob> list = new ArrayList<IStoredJob>(); if (null == mapCollection || mapCollection.size() < 1) { return list; } for (final Map map : mapCollection) { final String id = map.get("id").toString(); final String name = (String) map.get("name"); final String group = map.containsKey("group") ? (String) map.get("group") : null; final String desc = map.containsKey("description") ? (String) map.get("description") : ""; final String url = createJobURL(id); list.add(StoredJobImpl.create(id, name, url, group, desc, projectFilter)); } if (null != output) { //write output doc to the outputstream try { final Writer writer = new OutputStreamWriter(output); writer.write(response.getResults()); writer.flush(); } catch (IOException e) { throw new CentralDispatcherServerRequestException(e); } } return list; } return null; }
From source file:com.dtolabs.rundeck.core.cli.util.MvnPomInfoTool.java
License:Apache License
void storeDocument(Document doc) throws IOException { OutputFormat format = OutputFormat.createPrettyPrint(); OutputStream os;/*from w ww . j av a 2s . c o m*/ FileOutputStream fos = null; if ("-".equals(destfile)) { os = System.out; } else { fos = new FileOutputStream(destfile); os = fos; } XMLWriter writer = new XMLWriter(os, format); writer.write(doc); if (null != fos) { fos.close(); } }
From source file:com.dtolabs.shared.resources.ResourceXMLGenerator.java
License:Apache License
/** * Write Document to a file//from w w w . j a v a2 s . c o m * * @param output stream * @param doc document * * @throws IOException on error */ private static void serializeDocToStream(final OutputStream output, final Document doc) throws IOException { final OutputFormat format = OutputFormat.createPrettyPrint(); final XMLWriter writer = new XMLWriter(output, format); writer.write(doc); writer.flush(); }
From source file:com.easyjf.generator.AllGenerator.java
License:Apache License
private void genXml(AllProcessor processor) { for (String templateFile : this.xmlfiles.keySet()) { tg.setProcess(processor);/*w w w. jav a 2 s . com*/ String fileName = (String) xmlfiles.get(templateFile); File targetFile = new File(fileName); tg.setTargetDir(""); tg.setTemplateDir(templateDir); tg.setTemplateName(templateFile); if (targetFile.exists()) { tg.setTargetName(fileName + "_tmp"); tg.generator(false); try { Document doc = this.getDocument(fileName + "_tmp"); Document document = this.getDocument(fileName); String existNode = "/easyjf-web/modules/module[@name='" + this.lowerBeanName + "']"; Node node = "mvc.xml".equals(templateFile) ? document.selectSingleNode(existNode) : findBean(document, this.lowerBeanName + ("dao.xml".equals(templateFile) ? "Dao" : "Service")); if (node == null) { String appendNode = "/easyjf-web/modules", cnode = appendNode + "/module"; if (!"mvc.xml".equals(templateFile)) appendNode = "/beans"; Element moduleE = (Element) document.selectSingleNode(appendNode); Node n = "mvc.xml".equals(templateFile) ? doc.selectSingleNode(cnode) : findBean(doc, this.lowerBeanName + ("dao.xml".equals(templateFile) ? "Dao" : "Service")); if (moduleE != null && n != null) { n.detach(); moduleE.add(n); } OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter output = new XMLWriter(new FileWriter(new File(fileName)), format); output.write(document); output.close(); } new File(fileName + "_tmp").deleteOnExit(); new File(fileName + "_tmp").delete(); } catch (Exception e) { // e.printStackTrace(); } System.out.println( I18n.getLocaleMessage("generator.Successfully.add.to.configuration.information.to.a.file") + fileName); } else { System.out.println( I18n.getLocaleMessage("generator.Successful.configuration.file.generation") + fileName); tg.setTargetName(fileName); new File(fileName + "_tmp").deleteOnExit(); new File(fileName + "_tmp").delete(); tg.generator(false); } } }
From source file:com.ethercis.vehr.response.XmlHttpResponse.java
License:Apache License
public void respond(Object data, String path) { if (data instanceof String) { writer.println((String) data); writer.close();/*from w ww . j a v a2s . co m*/ } else if (data instanceof Document) { Document document = (Document) data; String xml = document.asXML().replaceAll(Constants.URI_TAG, path); //massaging... OutputFormat outputFormat = OutputFormat.createPrettyPrint(); StringWriter stringWriter = new StringWriter(); XMLWriter xmlWriter = new XMLWriter(stringWriter, outputFormat); try { Document document1 = DocumentHelper.parseText(xml); xmlWriter.write(document1); } catch (Exception e) { throw new IllegalArgumentException("Could not encode content:" + e); } writer.println(stringWriter.toString()); writer.close(); } }