List of usage examples for java.io StringWriter toString
public String toString()
From source file:Main.java
/** * Performs XSL transformation./*ww w. ja v a2s .co m*/ * @param xmlDoc Document * @param xslDoc Document * @throws TransformerConfigurationException * @throws TransformerException * @return String The output text. */ public static String xslTransform(Document xmlDoc, Document xslDoc) throws TransformerConfigurationException, TransformerException { DOMSource source = new DOMSource(xmlDoc); DOMSource xslSrc = new DOMSource(xslDoc); TransformerFactory xformFactory = TransformerFactory.newInstance(); Transformer transformer = xformFactory.newTransformer(xslSrc); java.io.StringWriter sw = new java.io.StringWriter(); StreamResult outXml = new StreamResult(sw); transformer.transform(source, outXml); return sw.toString(); }
From source file:Main.java
private static String getNodeValue(NodeList nodeList) throws TransformerFactoryConfigurationError, TransformerException { final Transformer serializer = TransformerFactory.newInstance().newTransformer(); serializer.setURIResolver(null);// w w w .ja v a 2 s.co m final StringBuilder buf = new StringBuilder(); for (int i = 0; i < nodeList.getLength(); i++) { final StringWriter sw = new StringWriter(); serializer.transform(new DOMSource(nodeList.item(i)), new StreamResult(sw)); String xml = sw.toString(); final Matcher matcher = HEADER_PATTERN.matcher(xml); if (matcher.matches()) { xml = matcher.group(1); } buf.append(xml); buf.append("\n"); } return buf.toString(); }
From source file:org.n52.oss.util.Util.java
public static String entityToString(Response response) throws JsonGenerationException, JsonMappingException, IOException { StringWriter writer = new StringWriter(); MapperFactory.getMapper().writeValue(writer, response.getEntity()); return writer.toString(); }
From source file:Main.java
static public String outputTextDoc(Node outputNode) { StringWriter out = new StringWriter(); PrintWriter pOut = new PrintWriter(out); outputNode(outputNode, pOut, 0);// w ww.j av a 2 s . co m return (out.toString()); }
From source file:Main.java
public static String nodeToString(Node node) { try {//from w w w. j a v a 2s. c o m Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(node); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); transformer.transform(source, result); return writer.toString(); } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:Main.java
/** * a debug method//from w w w .j a va 2 s . c o m * * @param node A node to be dumped to a string * @param omitDeclaration A boolean whether to omit the XML declaration * @return A string representation of the node. * @throws Exception If anything goes wrong. Error handling omitted. */ public static String dumpNode(Node node, boolean omitDeclaration) throws Exception { Transformer xformer = TransformerFactory.newInstance().newTransformer(); if (omitDeclaration) { xformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); } StringWriter sw = new StringWriter(); Result result = new StreamResult(sw); Source source = new DOMSource(node); xformer.transform(source, result); return sw.toString(); }
From source file:com.bootcamp.utils.FreeMarkers.java
public static String renderString(String templateString, Map<String, ?> model) { try {// ww w . j av a 2 s . com StringWriter result = new StringWriter(); Template t = new Template("name", new StringReader(templateString), new Configuration()); t.process(model, result); return result.toString(); } catch (Exception e) { throw Exceptions.unchecked(e); } }
From source file:com.flipkart.phantom.task.utils.StringUtils.java
/** * always encode in UTF8. does NOT close your input stream. client need to close it. * @param inputStream/*from ww w . j a va2 s . c om*/ * @return String encoded using UTF-8 scheme. * @throws Exception, any exception encountered. Will not check for any null condition. */ public static String inputStream2String(InputStream inputStream) throws Exception { StringWriter writer = new StringWriter(); IOUtils.copy(inputStream, writer, "UTF-8"); String theString = writer.toString(); return theString; }
From source file:Main.java
public static String nodeToString(Node node) throws TransformerException { StringWriter sw = new StringWriter(); Transformer t = TransformerFactory.newInstance().newTransformer(); t.transform(new DOMSource(node), new StreamResult(sw)); return sw.toString(); }
From source file:com.enjoyxstudy.selenium.autoexec.util.TemplateUtils.java
/** * @param input/* w ww .j a v a2 s . c o m*/ * @param context * @return string */ public static String merge(String input, Map<String, Object> context) { StringWriter writer = new StringWriter(); merge(input, context, writer); return writer.toString(); }