public String writeCluster(Cluster cluster) { Document doc = new Document(new Element(CLUSTER_ELMT)); doc.getRootElement().addContent(new Element(CLUSTER_NAME_ELMT).setText(cluster.getName())); boolean displayZones = cluster.getZones().size() > 1; if(displayZones) { for(Zone n: cluster.getZones()) doc.getRootElement().addContent(mapZone(n)); } for(Node n: cluster.getNodes()) doc.getRootElement().addContent(mapServer(n, displayZones)); XMLOutputter serializer = new XMLOutputter(Format.getPrettyFormat()); return serializer.outputString(doc.getRootElement()); }
@Override public void writeSolution(Solution_ solution, File outputFile) { try (OutputStream out = new BufferedOutputStream(new FileOutputStream(outputFile))) { Document document = new Document(); XmlOutputBuilder<Solution_> xmlOutputBuilder = createXmlOutputBuilder(); xmlOutputBuilder.setDocument(document); xmlOutputBuilder.setSolution(solution); xmlOutputBuilder.writeSolution(); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); outputter.output(document, out); logger.info("Exported: {}", outputFile); } catch (IOException e) { throw new IllegalArgumentException("Could not write the file (" + outputFile.getName() + ").", e); } catch (JDOMException e) { throw new IllegalArgumentException("Could not format the XML file (" + outputFile.getName() + ").", e); } }
@Override public void actionPerformed(@NotNull AnActionEvent event) { final VirtualFileWrapper wrapper = FileChooserFactory.getInstance().createSaveFileDialog( new FileSaverDescriptor( IgnoreBundle.message("action.exportTemplates.wrapper"), "", FILE_EXTENSION ), templatesListPanel ).save(null, null); if (wrapper != null) { final List<IgnoreSettings.UserTemplate> items = getCurrentItems(); final org.jdom.Document document = new org.jdom.Document( IgnoreSettings.createTemplatesElement(items) ); try { JDOMUtil.writeDocument(document, wrapper.getFile(), Constants.NEWLINE); Messages.showInfoMessage(templatesListPanel, IgnoreBundle.message("action.exportTemplates.success", items.size()), IgnoreBundle.message("action.exportTemplates.success.title")); } catch (IOException e) { Messages.showErrorDialog( templatesListPanel, IgnoreBundle.message("action.exportTemplates.error") ); } } }
public void writeStartDocument() throws XMLStreamException { document = new Document(new Element("root")); }
/** * Costruttore base della classe dom. */ public LangDOM() { this._doc = new Document(); Element elementRoot = new Element("Langs"); this._doc.setRootElement(elementRoot); }
public void reset() { super.reset(); this.document = new Document(); this.currentElement = null; }
public static String writeElementToString(final Element e) { try { final StringWriter sw = new StringWriter(); final Document document = new Document((Element) e.clone()); final XMLOutputter outputter = new XMLOutputter(); outputter.output(document, sw); return sw.getBuffer().toString(); } catch (final IOException ioe) { LOGGER.info("write error", ioe); } return null; }
public static void writeElementToStream(final Element e, final OutputStream os) { try { final BufferedOutputStream bos = new BufferedOutputStream(os); final Document document = new Document((Element) e.clone()); final XMLOutputter outputter = new XMLOutputter(); outputter.output(document, bos); bos.flush(); } catch (final IOException ioe) { LOGGER.info("write error", ioe); } }
public static void writeElementToWriter(final Element e, final Writer writer) { try { final Document document = new Document((Element) e.clone()); final XMLOutputter outputter = new XMLOutputter(); outputter.output(document, writer); } catch (final IOException ioe) { LOGGER.info("write error", ioe); } }
private static void printDocument(Element e) { try { Document doc = new Document(e); XMLOutputter xo = new XMLOutputter(Format.getPrettyFormat()); System.out.println(xo.outputString(doc)); } catch (Exception ex) { // } }
public static void writeElementToStreamPretty(final Element e, final OutputStream os) { try { final BufferedOutputStream bos = new BufferedOutputStream(os); final Document document = new Document((Element) e.clone()); final XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); outputter.output(document, bos); bos.flush(); } catch (final IOException ioe) { LOGGER.info("write error", ioe); } }
protected Document createDocument(Element root) { Document doc = new Document(root); DocType docType = new DocType(RSS091NetscapeParser.ELEMENT_NAME, RSS091NetscapeParser.PUBLIC_ID, RSS091NetscapeParser.SYSTEM_ID); doc.setDocType(docType); return doc; }
/** * Saving an XML element to a file. */ public static void save (final String fileName, final org.jdom.Element elt) throws java.io.IOException { elt.detach(); final org.jdom.Document doc = new org.jdom.Document(elt); save(fileName, doc); }
/** * * @return * @throws MobyException */ public static Document createDomDocument() throws MobyException { Document d = new Document(); d.setBaseURI(MOBY_NS.getURI()); return d; }
/** * Turns a detached JDOM element into a byte array (makes sure it comes back * detached afterwards). */ public static byte[] toByteArray (final org.jdom.Element elt) throws OpenWfeException { final byte[] result = toByteArray(new org.jdom.Document(elt)); elt.detach(); return result; }
protected Document createDocument(Element root) { Document doc = new Document(root); DocType docType = new DocType(RSS091NetscapeParser.ELEMENT_NAME, RSS091NetscapeParser.PUBLIC_ID, RSS091NetscapeParser.SYSTEM_ID); doc.setDocType(docType); return doc; }
/** * Create an XML document for the Widget * @param widget * @return a Document representing the Widget's config.xml */ private Document createWidgetDocument(W3CWidget widget){ widget = replacePaths(widget); return new Document(((IElement) widget).toXml()); }
public String extractXml(IPage page) { Document doc = new Document(); Element elementRoot = new Element("config"); doc.setRootElement(elementRoot); this.fillDocument(doc, page); return this.getXMLDocument(doc); }
protected DataCiteResponse sendMetadataPostRequest(String doi, Element metadataRoot) throws DOIIdentifierException { Format format = Format.getCompactFormat(); format.setEncoding("UTF-8"); XMLOutputter xout = new XMLOutputter(format); return sendMetadataPostRequest(doi, xout.outputString(new Document(metadataRoot))); }
@Override public void serialize( @NotNull T object, @NotNull OutputStream out, @Nullable C context ) throws IOException { Document document = new Document(); //Add the format version document.addContent( new ProcessingInstruction( PI_TARGET_FORMAT, getFormatVersion().toString() ) ); //Create the root Element root = new Element( getDefaultElementName() ); document.setRootElement( root ); serialize( root, object, context ); new XMLOutputter( Format.getPrettyFormat().setLineSeparator( LINE_SEPARATOR ) ).output( document, out ); }