protected void buildQuery(OutputStream out, XmlProvider xmlstarter) { Document ribclQ = makeDocument(xmlstarter); Map<String, String> properties = new HashMap<String, String>(); properties.put(OutputKeys.INDENT, "no"); properties.put(OutputKeys.OMIT_XML_DECLARATION, "yes"); properties.put(OutputKeys.ENCODING, encoding); try { Util.serialize(ribclQ, out, null, properties); } catch (TransformerException | IOException e) { throw new RuntimeException("Unable to serialize in memory", e); } }
prop.put(OutputKeys.DOCTYPE_PUBLIC, "-//jrds//DTD Host//EN"); prop.put(OutputKeys.DOCTYPE_SYSTEM, "urn:jrds:host"); Util.serialize(hostDom, response.getOutputStream(), null, prop); } catch (IOException | ParserConfigurationException | TransformerException e) { logger.error(e);
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { DocumentBuilder dbuilder; try { dbuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); JrdsDocument hostDom = new JrdsDocument(dbuilder.newDocument()); hostDom.doRootElement("div"); for(DiscoverAgent da: getHostsList().getDiscoverAgent()) { logger.debug(jrds.Util.delayedFormatString("Adding discover agent %s", da)); da.doHtmlDiscoverFields(hostDom); } resp.setContentType(CONTENT_TYPE); Map<String, String> prop = new HashMap<String, String>(1); prop.put(OutputKeys.OMIT_XML_DECLARATION, "no"); prop.put(OutputKeys.INDENT, "yes"); prop.put("{http://xml.apache.org/xslt}indent-amount", "4"); Util.serialize(hostDom, resp.getOutputStream(), null, prop); } catch (ParserConfigurationException e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Parser configuration error"); } catch (TransformerException e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Transformer exception error"); } }
prop.put(OutputKeys.DOCTYPE_PUBLIC, "-//jrds//DTD Graph Description//EN"); prop.put(OutputKeys.DOCTYPE_SYSTEM, "urn:jrds:graphdesc"); Util.serialize(d, res.getOutputStream(), null, prop); } catch (ParserConfigurationException | TransformerException e) { res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
prop.put(OutputKeys.INDENT, "yes"); prop.put("{http://xml.apache.org/xslt}indent-amount", "4"); jrds.Util.serialize(pd.dumpAsXml(), System.out, null, prop); System.out.println();
prop.put(OutputKeys.STANDALONE, "yes"); prop.put("{http://xml.apache.org/xslt}indent-amount", "4"); jrds.Util.serialize(doc, System.out, null, prop); System.out.println(externalStarters);
@Test public void testSerialization1() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); Document d; d = Tools.parseRessource("customgraph.xml"); Util.serialize(d, out, null, null); }
@Test public void testSerialization2() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); Document d; Map<String, String> prop; String outBuffer; d = Tools.parseRessource("goodhost1.xml"); prop = new HashMap<String, String>(); prop.put("omit-xml-declaration", "yes"); Util.serialize(d, out, null, prop); outBuffer = out.toString(); logger.debug(outBuffer); Assert.assertFalse(outBuffer.contains("<?xml")); }
@Test public void construct() throws Exception { Document actionDocument = Tools.parseRessource("action.xml"); Element e1 = actionDocument.createElementNS("http://jakarta.apache.org/log4j/", "log4j:configuration"); e1.setAttribute("debug", "true"); Element action = (Element) actionDocument.removeChild(actionDocument.getDocumentElement()); actionDocument.appendChild(e1); e1.appendChild(action); String name = "jrds.Logger thresold." + action.getAttribute("name"); action.setAttribute("name", name); Element loggerElem = actionDocument.createElement("logger"); loggerElem.setAttribute("name", name); Element appenderRef = actionDocument.createElement("appender-ref"); appenderRef.setAttribute("ref", name); e1.appendChild(loggerElem); loggerElem.appendChild(appenderRef); jrds.Util.serialize(actionDocument, System.out, null, null); DOMConfigurator.configure(actionDocument.getDocumentElement()); PropertyPrinter printer = new PropertyPrinter(new PrintWriter(System.out)); printer.print(new PrintWriter(System.out)); }
prop.put(OutputKeys.ENCODING, "UTF-8"); try (OutputStream fos = new FileOutputStream(xmlpath)) { jrds.Util.serialize(n.getOwnerDocument(), fos, null, prop);
@Test public void testSerialization3() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); Document d; Map<String, String> prop; String outBuffer; d = Tools.parseRessource("customgraph.xml"); String publicId = d.getDoctype().getPublicId(); String systemId = d.getDoctype().getSystemId(); prop = new HashMap<String, String>(); Util.serialize(d, out, null, prop); outBuffer = out.toString(); logger.debug("out buffer for testSerialization3: \n" + outBuffer + "\n"); // It should have auto-detected the doc type Assert.assertTrue(outBuffer.contains(publicId)); Assert.assertTrue(outBuffer.contains(systemId)); logger.debug(outBuffer.contains(d.getXmlEncoding())); Assert.assertTrue("Output encoding " + d.getXmlEncoding() + " not found", outBuffer.contains(d.getXmlEncoding())); }
prop.put(OutputKeys.INDENT, "yes"); prop.put("{http://xml.apache.org/xslt}indent-amount", "4"); jrds.Util.serialize(gddom, os, null, prop); logger.trace(new String(os.toByteArray(), "UTF-8")); prop.put(OutputKeys.INDENT, "yes"); prop.put("{http://xml.apache.org/xslt}indent-amount", "4"); jrds.Util.serialize(gddom, os, null, prop); logger.trace(new String(os.toByteArray(), "UTF-8"));