Refine search
public String elementOutput(Element e) { return "\n\t" + new XMLOutputter().outputString(e); }
public void modifyOutputStream( JarOutputStream jos ) throws IOException { jos.putNextEntry( new JarEntry( resource ) ); new XMLOutputter( Format.getPrettyFormat() ).output( doc, jos ); doc = null; } }
/** * Print out a <code>{@link Comment}</code>. * * @param comment * <code>Comment</code> to output. * @param out * <code>OutputStream</code> to use. * @throws IOException * if there's any problem writing. * @throws NullPointerException * if the specified content is null. */ public final void output(Comment comment, OutputStream out) throws IOException { output(comment, makeWriter(out, myFormat)); // output() flushes }
/** * Return a string representing a {@link CDATA} node. * <p> * <b>Warning</b>: a String is Unicode, which may not match the outputter's * specified encoding. * * @param cdata * <code>CDATA</code> to format. * @return the input content formatted as an XML String. * @throws NullPointerException * if the specified content is null. */ public final String outputString(CDATA cdata) { StringWriter out = new StringWriter(); try { output(cdata, out); // output() flushes } catch (IOException e) { // swallow - will never happen. } return out.toString(); }
public static String documentToString(Document xml, Format format) throws IOException { StringWriter vsw = new StringWriter(); XMLOutputter xout = new XMLOutputter(format); xout.output(xml, vsw); return vsw.toString(); }
@Override public String toString() { final Document document = new Document( root ); final XMLOutputter outputter = new XMLOutputter( Format.getPrettyFormat() ); final StringWriter writer = new StringWriter(); try { outputter.output( document, writer ); } catch ( final IOException e ) { e.printStackTrace(); } return writer.toString(); }
/** * Output xml * @param eRoot - the root element * @param lang - the language which should be filtered or null for no filter * @return a string representation of the XML * @throws IOException */ private static String writeXML(Element eRoot, String lang) throws IOException { StringWriter sw = new StringWriter(); if (lang != null) { // <label xml:lang="en" text="part" /> XPathExpression<Element> xpE = XPathFactory.instance().compile("//label[@xml:lang!='" + lang + "']", Filters.element(), null, Namespace.XML_NAMESPACE); for (Element e : xpE.evaluate(eRoot)) { e.getParentElement().removeContent(e); } } XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat()); Document docOut = new Document(eRoot.detach()); xout.output(docOut, sw); return sw.toString(); }
@Override public String toString(Format format) { try { Element e = marshal(); XMLOutputter out = new XMLOutputter(Format.formatted.equals(format) ? org.jdom2.output.Format.getPrettyFormat() : org.jdom2.output.Format.getRawFormat()); StringWriter writer = new StringWriter(); out.output(e, writer); return writer.toString(); } catch (Exception exc) { throw new OAIImplementationException(exc); } }
/** * {@inheritDoc} */ public String getString() throws IOException { Element rootElement = m_document.getRootElement(); processChildren( rootElement ); m_document.setContext( m_context ); XMLOutputter output = new XMLOutputter(); StringWriter out = new StringWriter(); Format fmt = Format.getRawFormat(); fmt.setExpandEmptyElements( false ); fmt.setLineSeparator( LINEBREAK ); output.setFormat( fmt ); output.outputElementContent( m_document.getRootElement(), out ); return out.toString(); } }
private void writeOneItem( InvDataset ds, OutputStream out) throws IOException { Element rootElem = new Element("dc", defNS); Document doc = new Document(rootElem); writeDataset( ds, rootElem); rootElem.addNamespaceDeclaration(XMLEntityResolver.xsiNS); // rootElem.setAttribute("schemaLocation", schemaLocation, XMLEntityResolver.xsiNS); rootElem.setAttribute("schemaLocation", defNS.getURI()+" "+schemaLocation, XMLEntityResolver.xsiNS); // Output the document, use standard formatter //XMLOutputter fmt = new XMLOutputter(" ", true); XMLOutputter fmt = new XMLOutputter( Format.getPrettyFormat()); fmt.output( doc, out); }
static private org.jdom2.Document getCapabilities(String endpoint) throws IOException { org.jdom2.Document doc; InputStream in = null; try { in = CdmRemote.sendQuery(endpoint, "req=capabilities"); SAXBuilder builder = new SAXBuilder(false); doc = builder.build(in); // closes in when done ?? } catch (Throwable t) { throw new IOException(t); } finally { //if (in != null) // in.close(); } if (showXML) { System.out.printf("*** endpoint = %s %n", endpoint); XMLOutputter xmlOut = new XMLOutputter(); System.out.printf("*** CdmrFeatureDataset/showParsedXML = %n %s %n", xmlOut.outputString(doc)); } return doc; }
public TableConfig readConfigXML(String fileLocation, FeatureType wantFeatureType, NetcdfDataset ds, Formatter errlog) throws IOException { org.jdom2.Document doc; try { SAXBuilder builder = new SAXBuilder(false); if (debugURL) System.out.println(" PointConfig URL = <" + fileLocation + ">"); doc = builder.build(fileLocation); } catch (JDOMException e) { throw new IOException(e.getMessage()); } if (debugXML) System.out.println(" SAXBuilder done"); if (showParsedXML) { XMLOutputter xmlOut = new XMLOutputter(); System.out.println("*** PointConfig/showParsedXML = \n" + xmlOut.outputString(doc) + "\n*******"); } Element configElem = doc.getRootElement(); String featureType = configElem.getAttributeValue("featureType"); Element tableElem = configElem.getChild("table"); TableConfig tc = parseTableConfig(ds, tableElem, null); tc.featureType = FeatureType.valueOf(featureType); return tc; }
private InputStream convert2XmlDecoder(InputStream is) throws IOException { org.jdom2.Document doc; try { SAXBuilder builder = new SAXBuilder(false); doc = builder.build(is); } catch (JDOMException e) { throw new IOException(e.getMessage()); } finally { if (is != null) is.close(); } if (debugConvert) { XMLOutputter xmlOut = new XMLOutputter(); System.out.println("***XMLStore.convert2XmlDecoder = \n" + xmlOut.outputString(doc) + "\n*******"); } Element root = doc.getRootElement(); org.jdom2.Document convertDoc = new Document(); Element convertRoot = new Element("java"); convertRoot.setAttribute("version", "1.4.1_01"); convertRoot.setAttribute("class", "java.beans.XMLDecoder"); convertDoc.setRootElement(convertRoot); add(root, convertRoot); XMLOutputter xmlOut = new XMLOutputter(); xmlOut.setFormat(Format.getPrettyFormat()); if (debugConvert) { System.out.printf("%n************************************%n"); System.out.println("***Convert2Version2 converted = \n" + xmlOut.outputString(convertDoc) + "\n*******"); } return new StringBufferInputStream(xmlOut.outputString(convertDoc)); }
final SAXBuilder sxb = new SAXBuilder(); document = sxb.build(fichierContext); context = document.getRootElement(); } else { LOG.debug("Le fichier context n'existe pas dans la webapps : {}.", fichierContext.getAbsolutePath()); context = new Element("Context"); document = new Document(context); context.setAttribute(docBase); context.setAttribute(workDir); final XMLOutputter xmlContextFile = new XMLOutputter(Format.getPrettyFormat()); xmlContextFile.output(document, baos); xmlContextFile.output(document, fichierContextTemporaireOutputStream); fichierContextTemporaireOutputStream.close(); return fichierContextTemporaire;
/** * Converts the navigation.xml to the old format. */ private static byte[] convertToOldFormat(byte[] xml) throws JDOMException, IOException { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(new ByteArrayInputStream(xml)); Element rootElement = doc.getRootElement(); rootElement.setAttribute("href", rootElement.getName()); List<Element> children = rootElement.getChildren(); for (Element menu : children) { String id = menu.getAttributeValue("id"); menu.setName(id); menu.setAttribute("href", id); menu.removeAttribute("id"); } XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); ByteArrayOutputStream bout = new ByteArrayOutputStream(xml.length); out.output(doc, bout); return bout.toByteArray(); }
/** * Write to root Element to a writer. * * @param root Root Element to write. * @param writer Writer to write to. * @throws IOException if the writer fails to write. */ protected void write(Element root, Writer writer) throws IOException { XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); outputter.output(new Document(root), writer); }
public GeniaPosParser(File xmlFile) throws IOException, JDOMException { this(); SAXBuilder builder = new SAXBuilder(); builder.setDTDHandler(null); root = builder.build(xmlFile).getRootElement(); articles = root.getChildren("article").iterator(); outputter = new XMLOutputter(); }
protected void writeXML(AvailableResources t, HttpOutputMessage outputMessage) throws IOException { Element root = new Element("list"); final Document doc = new Document(root); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); t.stream().map(name -> new Element(t.getName()).addContent(name)).forEach(root::addContent); try (OutputStream os = outputMessage.getBody()) { outputter.output(doc, os); } } }
public void writeXMLexplicit(NetcdfFile ncfile, OutputStream os, String location) throws IOException { if (ncfile instanceof NetcdfDataset) ncd = (NetcdfDataset) ncfile; else ncd = new NetcdfDataset(ncfile, false); fmt = new XMLOutputter(Format.getPrettyFormat()); Document doc = makeDocument(location); Element root = doc.getRootElement(); root.addContent( new Element("explicit", ncNS)); fmt.output(doc, os); }
@Test @Ignore("WMS not working") public void checkWMSDates() throws JDOMException, IOException { String endpoint = TestOnLocalServer.withHttpPath("/wms/cdmUnitTest/ncss/climatology/PF5_SST_Climatology_Monthly_1985_2001.nc?service=WMS&version=1.3.0&request=GetCapabilities"); byte[] result = TestOnLocalServer.getContent(endpoint, 200, ContentType.xml); Reader in = new StringReader( new String(result, CDM.utf8Charset)); SAXBuilder sb = new SAXBuilder(); Document doc = sb.build(in); if (show) { XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat()); fmt.output(doc, System.out); } XPath xPath = XPath.newInstance("//wms:Dimension"); xPath.addNamespace("wms", doc.getRootElement().getNamespaceURI()); Element dimNode = (Element) xPath.selectSingleNode(doc); //List<String> content = Arrays.asList(dimNode.getText().trim().split(",")); List<String> content = new ArrayList<>(); for (String d : Arrays.asList(dimNode.getText().trim().split(","))) { // System.out.printf("Date= %s%n", d); CalendarDate cd = CalendarDate.parseISOformat(null, d); content.add(cd.toString()); } assertEquals(expectedDatesAsDateTime, content); }