List of usage examples for org.jdom2.output XMLOutputter XMLOutputter
public XMLOutputter()
XMLOutputter
with a default Format and XMLOutputProcessor . From source file:nl.nn.adapterframework.util.XmlBuilder.java
License:Apache License
public String toXML(boolean xmlHeader) { Document document = new Document(element.detach()); XMLOutputter xmlOutputter = new XMLOutputter(); xmlOutputter.setFormat(Format.getPrettyFormat().setOmitDeclaration(!xmlHeader)); return xmlOutputter.outputString(document); }
From source file:odml.core.Writer.java
License:Open Source License
/** * Writes the dom tree to the given output stream. * * @param stream the output stream/* w ww .j a va 2 s .c o m*/ * @return true if the dom tree was successfully written to the stream, false otherwise * */ private boolean writeToStream(OutputStream stream) { if (doc == null) { System.out.println("Writing to Stream failed, document is empty!"); return false; } try { org.jdom2.output.Format format = org.jdom2.output.Format.getPrettyFormat().setIndent(" "); XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); outputter.output(doc, stream); } catch (IOException ie) { System.out.println("Write to file failed: " + ie.getMessage()); return false; } System.out.println("Writing to file successful!"); return true; }
From source file:open.dolphin.message.ClaimMessageBuilder.java
private ClaimMessageBuilder() { outputter = new XMLOutputter(); outputter.getFormat().setEncoding("UTF-8").setExpandEmptyElements(false); }
From source file:org.apache.marmotta.ldpath.model.functions.xml.XPathFunction.java
License:Apache License
private LinkedList<String> doFilter(String in, Set<String> xpaths) throws IOException { LinkedList<String> result = new LinkedList<String>(); try {/*from w w w.j ava 2s . com*/ Document doc = new SAXBuilder(XMLReaders.NONVALIDATING).build(new StringReader(in)); XMLOutputter out = new XMLOutputter(); for (String xp : xpaths) { XPathExpression<Content> xpath = XPathFactory.instance().compile(xp, Filters.content()); for (Content node : xpath.evaluate(doc)) { if (node instanceof Element) { result.add(out.outputString((Element) node)); } else if (node instanceof Text) { result.add(out.outputString((Text) node)); } } } return result; } catch (JDOMException xpe) { throw new IllegalArgumentException("error while processing xpath expressions: '" + xpaths + "'", xpe); } }
From source file:org.artifactory.util.XmlUtils.java
License:Open Source License
public static String outputString(Document doc) { String convertedXml = new XMLOutputter().outputString(doc); return convertedXml; }
From source file:org.baswell.routes.JDOMBridge.java
License:Apache License
static void sendJdom2Document(Object response, HttpServletResponse servletResponse) throws IOException { new XMLOutputter().output((Document) response, servletResponse.getWriter()); }
From source file:org.baswell.routes.JDOMBridge.java
License:Apache License
static void sendJdom2Element(Object response, HttpServletResponse servletResponse) throws IOException { new XMLOutputter().output((Element) response, servletResponse.getWriter()); }
From source file:org.codice.ddf.opensearch.source.OpenSearchSource.java
License:Open Source License
private List<Metacard> processAdditionalForeignMarkups(Element element, String id) throws UnsupportedQueryException { List<Metacard> metacards = new ArrayList<>(); if (CollectionUtils.isNotEmpty(markUpSet) && markUpSet.contains(element.getName())) { XMLOutputter xmlOutputter = new XMLOutputter(); Metacard metacard = parseContent(xmlOutputter.outputString(element), id); if (metacard != null) { metacards.add(metacard);/*from w w w . ja v a 2 s .c om*/ } } return metacards; }
From source file:org.crazyt.xgogdownloader.Util.java
License:Open Source License
public final int createXML(String filepath, int chunk_size, String xml_dir) { int res = 0;//from w ww . j ava 2s. co m File infile; int filesize; int size; int chunks; int i; if (xml_dir == "") { xml_dir = ".cache/xgogdownloader/xml"; } // end of if File path = Factory.newFile(xml_dir); if (!path.exists()) { if (!path.mkdirs()) { System.out.println("Failed to create directory: " + path); } } infile = Factory.newFile(filepath); // RandomAccessFile file = new RandomAccessFile("file.txt", "rw");? // fseek/seek ftell/getFilePointer rewind/seek(0) if (infile.exists()) { filesize = (int) infile.length(); } else { System.out.println(filepath + " doesn't exist"); return res; } // end of if-else // Get filename String filename = FilenameUtils.removeExtension(infile.getName()); String filenameXML = xml_dir + "/" + filename + ".xml"; System.out.println(filename); // Determine number of chunks int remaining = filesize % chunk_size; chunks = (remaining == 0) ? filesize / chunk_size : (filesize / chunk_size) + 1; System.out.println("Filesize: " + filesize + " bytes"); System.out.println("Chunks: " + chunks); System.out.println("Chunk size: " + (chunk_size / Math.pow(2.0, 20.0)) + " MB"); Util util_md5 = new Util(); String file_md5 = util_md5.getFileHash(filepath); System.out.println("MD5: " + file_md5); Element fileElem = new Element("file"); fileElem.setAttribute(new Attribute("name", filename)); fileElem.setAttribute(new Attribute("md5", file_md5)); fileElem.setAttribute(new Attribute("chunks", String.valueOf(chunks))); fileElem.setAttribute(new Attribute("total_size", String.valueOf(filesize))); System.out.println("Getting MD5 for chunks"); for (i = 0; i < chunks; i++) { int range_begin = i * chunk_size; // fseek(infile, range_begin, SEEK_SET); if ((i == chunks - 1) && (remaining != 0)) { chunk_size = remaining; } int range_end = range_begin + chunk_size - 1; String chunk = String.valueOf(chunk_size * 4); String hash = util_md5.getChunkHash(chunk); // calculates hash of // chunk string? Element chunkElem = new Element("chunk"); chunkElem.setAttribute(new Attribute("id", String.valueOf(i))); chunkElem.setAttribute(new Attribute("from", String.valueOf(range_begin))); chunkElem.setAttribute(new Attribute("to", String.valueOf(range_begin))); chunkElem.setAttribute(new Attribute("method", "md5")); chunkElem.addContent(new Text(hash)); fileElem.addContent(chunkElem); System.out.println("Chunks hashed " + (i + 1) + " / " + chunks + "\r"); } Document doc = new Document(fileElem); System.out.println("Writing XML: " + filenameXML); try { XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); xmlOutput.output(doc, Factory.newFileWriter(filenameXML)); res = 1; } catch (IOException e) { System.out.println("Can't create " + filenameXML); return res; } return res; }
From source file:org.easycloud.las.core.util.Files.java
License:Apache License
private static void writeXmlFile(File f, Document doc) { FileOutputStream fos = null;/* www . java 2 s. c o m*/ try { fos = new FileOutputStream(f); XMLOutputter xmlo = new XMLOutputter(); xmlo.output(doc, fos); } catch (Exception e) { throw new FileOperationsException(e); } finally { if (fos != null) { try { fos.close(); } catch (Exception e) { if (LOGGER.isErrorEnabled()) { LOGGER.error(e.getMessage(), e); } } } } }