List of usage examples for java.io StringWriter toString
public String toString()
From source file:com.sportpm.mapper.JaxbMapper.java
/** * Java Collection->Xml with encoding, ?Root ElementCollection. *//*from w w w . j ava 2 s . c o m*/ @SuppressWarnings("rawtypes") public static String toXml(Collection<?> root, String rootName, Class clazz, String encoding) { try { CollectionWrapper wrapper = new CollectionWrapper(); wrapper.collection = root; JAXBElement<CollectionWrapper> wrapperElement = new JAXBElement<CollectionWrapper>(new QName(rootName), CollectionWrapper.class, wrapper); StringWriter writer = new StringWriter(); createMarshaller(clazz, encoding).marshal(wrapperElement, writer); return writer.toString(); } catch (JAXBException e) { throw Exceptions.unchecked(e); } }
From source file:Main.java
public static String domNodeToString(Node node) throws TransformerException { StringWriter writer = new StringWriter(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(new DOMSource(node), new StreamResult(writer)); return writer.toString(); }
From source file:eu.semaine.jms.JMSLogger.java
public static String toLogMessageText(long usertime, Object... objects) { StringBuilder builder = new StringBuilder(); if (usertime >= 0) { builder.append("[") .append(new SimpleDateFormat(MessageLogComponent.TIME_FORMAT).format(new Date(usertime))) .append("]"); }/*from ww w . ja va2s .c o m*/ for (Object o : objects) { if (builder.length() > 0) { builder.append(" "); } if (o instanceof Throwable) { Throwable t = (Throwable) o; StringWriter sw = new StringWriter(); t.printStackTrace(new PrintWriter(sw)); builder.append(sw.toString()); } else { builder.append(o.toString()); } } String logMessageText = builder.toString(); return logMessageText; }
From source file:Main.java
public static String transform(String xml, File stylesheet) throws TransformerException { StringWriter writer = new StringWriter(); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(new StreamSource(stylesheet)); transformer.transform(new StreamSource(xml), new StreamResult(writer)); return writer.toString(); }
From source file:Main.java
public static String transform(String xml, String stylesheet) throws TransformerException { StringWriter writer = new StringWriter(); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(new StreamSource(stylesheet)); transformer.transform(new StreamSource(xml), new StreamResult(writer)); return writer.toString(); }
From source file:org.apache.atlas.web.util.Servlets.java
public static String getRequestPayload(HttpServletRequest request) throws IOException { //request is an instance of LocalServletRequest for calls from LocalAtlasClient if (request instanceof LocalServletRequest) { return ((LocalServletRequest) request).getPayload(); }/*from w ww.j av a2 s.co m*/ StringWriter writer = new StringWriter(); IOUtils.copy(request.getInputStream(), writer); return writer.toString(); }
From source file:at.gv.egovernment.moa.id.auth.builder.LoginFormBuilder.java
public static String getTemplate(InputStream input) { String template = null;//from w w w .j ava 2 s . com try { if (input == null) { Logger.warn("No LoginFormTempaltes found. Use Generic Templates from package."); String pathLocation = "resources/templates/" + HTMLTEMPLATEFULL; input = Thread.currentThread().getContextClassLoader().getResourceAsStream(pathLocation); } StringWriter writer = new StringWriter(); IOUtils.copy(input, writer); template = writer.toString(); template = template.replace(AUTH_URL, SERVLET); template = template.replace(BKU_ONLINE, IOAAuthParameters.ONLINEBKU); template = template.replace(BKU_HANDY, IOAAuthParameters.HANDYBKU); template = template.replace(BKU_LOCAL, IOAAuthParameters.LOCALBKU); } catch (Exception e) { Logger.error("Failed to read template", e); } finally { try { input.close(); } catch (IOException e) { Logger.warn("SendAssertionTemplate inputstream can not be closed.", e); } } return template; }
From source file:Main.java
public static String getStringFromDocument(Document doc) throws Exception { DOMSource domSource = new DOMSource(doc); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.transform(domSource, result); return writer.toString(); }
From source file:Main.java
/** * Converts a dom element to a String//from w ww. j a v a 2 s . c o m * * @param node * @return the dom as a String */ public static String writeDomToString(Element node) { DOMImplementation domImplementation = node.getOwnerDocument().getImplementation(); if (domImplementation.hasFeature("LS", "3.0") && domImplementation.hasFeature("Core", "2.0")) { DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementation.getFeature("LS", "3.0"); LSSerializer lsSerializer = domImplementationLS.createLSSerializer(); LSOutput lsOutput = domImplementationLS.createLSOutput(); lsOutput.setEncoding("UTF-8"); StringWriter stringWriter = new StringWriter(); lsOutput.setCharacterStream(stringWriter); lsSerializer.write(node, lsOutput); return stringWriter.toString(); } else { throw new RuntimeException("DOM 3.0 LS and/or DOM 2.0 Core not supported."); } }
From source file:$.JaxbMapper.java
/** * Java Collection->Xml with encoding, ?Root ElementCollection. */// w w w . j a v a 2s . c o m public static String toXml(Collection<?> root, String rootName, Class clazz, String encoding) { try { CollectionWrapper wrapper = new CollectionWrapper(); wrapper.collection = root; JAXBElement<CollectionWrapper> wrapperElement = new JAXBElement<CollectionWrapper>(new QName(rootName), CollectionWrapper.class, wrapper); StringWriter writer = new StringWriter(); createMarshaller(clazz, encoding).marshal(wrapperElement, writer); return writer.toString(); } catch (JAXBException e) { throw Exceptions.unchecked(e); } }