List of usage examples for java.io Writer toString
public String toString()
From source file:com.mirth.connect.connectors.ws.WebServiceDispatcher.java
private String sourceToXmlString(Source source) throws TransformerConfigurationException, TransformerException { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); Writer writer = new StringWriter(); transformer.transform(source, new StreamResult(writer)); return writer.toString(); }
From source file:com.xpn.xwiki.internal.template.InternalTemplateManager.java
public String renderNoException(String template) { Writer writer = new StringWriter(); renderNoException(template, writer); return writer.toString(); }
From source file:org.apache.torque.generator.template.velocity.VelocityOutlet.java
/** * Executes the generation process; the result is returned. * * @param controllerState the current controller state. * * @return the result of the generation, not null. * * @see org.apache.torque.generator.outlet.Outlet#execute(ControllerState) *//* www. ja va2 s. co m*/ @Override public OutletResult execute(ControllerState controllerState) throws GeneratorException { if (log.isDebugEnabled()) { log.debug("Start executing VelocityOutlet " + getName()); } try { try { Properties properties = new Properties(); properties.put(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, Log4JLogChute.class.getName()); properties.put(RuntimeConstants.RUNTIME_LOG, ""); Velocity.init(properties); } catch (Exception e) { throw new GeneratorException("Could not initialize velocity", e); } SourceElement sourceElement = controllerState.getSourceElement(); String inputElementName = getInputElementName(); if (inputElementName != null && !inputElementName.equals(sourceElement.getName())) { throw new GeneratorException("Input element name, " + sourceElement.getName() + ", is not the expected name, " + getInputElementName() + ", for outlet " + getName()); } Context context = createVelocityContext(controllerState); Writer writer = new StringWriter(); try { Velocity.evaluate(context, writer, "VelocityTemplateOutlet:" + getName(), getContent(controllerState)); writer.flush(); writer.close(); } catch (Exception e) { log.error("error during execution of outlet " + getName() + " : " + e.getMessage(), e); throw new GeneratorException( "Error during execution of outlet " + getName() + " : " + e.getMessage(), e); } return new OutletResult(writer.toString()); } finally { if (log.isDebugEnabled()) { log.debug("End executing VelocityOutlet " + getName()); } } }
From source file:ddf.security.realm.sts.StsRealm.java
/** * Creates a binary security token based on the provided credential. *///from ww w . ja va2 s . com private String getBinarySecurityToken(String credential) { BinarySecurityTokenType binarySecurityTokenType = new BinarySecurityTokenType(); binarySecurityTokenType.setValueType("#CAS"); binarySecurityTokenType.setEncodingType(WSConstants.SOAPMESSAGE_NS + "#Base64Binary"); binarySecurityTokenType.setId("CAS"); binarySecurityTokenType.setValue(Base64.encode(credential.getBytes())); JAXBElement<BinarySecurityTokenType> binarySecurityTokenElement = new JAXBElement<BinarySecurityTokenType>( new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "BinarySecurityToken"), BinarySecurityTokenType.class, binarySecurityTokenType); Writer writer = new StringWriter(); JAXB.marshal(binarySecurityTokenElement, writer); String binarySecurityToken = writer.toString(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Binary Security Token: " + binarySecurityToken); } return binarySecurityToken; }
From source file:com.xpn.xwiki.internal.template.InternalTemplateManager.java
public String renderFromSkin(String templateName, Skin skin) throws Exception { Writer writer = new StringWriter(); renderFromSkin(templateName, skin, writer); return writer.toString(); }
From source file:com.xpn.xwiki.internal.template.InternalTemplateManager.java
private String evaluateContent(Template template, DefaultTemplateContent content) throws Exception { Writer writer = new StringWriter(); evaluateContent(template, content, writer); return writer.toString(); }
From source file:org.alfresco.repo.batch.BatchProcessor.java
/** * {@inheritDoc}// w w w . j ava 2 s. com */ public synchronized String getLastError() { if (this.lastError == null) { return null; } Writer buff = new StringWriter(1024); PrintWriter out = new PrintWriter(buff); this.lastError.printStackTrace(out); out.close(); return buff.toString(); }
From source file:com.claude.sharecam.util.CountryMaster.java
private CountryMaster(Context context) { mContext = context;//from w w w . ja v a2 s. c o m Resources res = mContext.getResources(); // builds country data from json InputStream is = res.openRawResource(R.raw.countries); Writer writer = new StringWriter(); char[] buffer = new char[1024]; try { Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); int n; while ((n = reader.read(buffer)) != -1) { writer.write(buffer, 0, n); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } String jsonString = writer.toString(); JSONArray json = new JSONArray(); try { json = new JSONArray(jsonString); } catch (JSONException e) { e.printStackTrace(); } mCountryList = new String[json.length()]; for (int i = 0; i < json.length(); i++) { JSONObject node = json.optJSONObject(i); if (node != null) { Country country = new Country(); country.mCountryIso = node.optString("iso"); country.mDialPrefix = node.optString("tel"); country.mCountryName = getCountryName(node.optString("iso")); mCountries.add(country); mCountryList[i] = country.mCountryIso; } } }
From source file:org.atricore.idbus.kernel.main.mediation.camel.component.binding.AbstractMediationHttpBinding.java
protected String marshal(Object obj, String msgQName, String msgLocalName, String[] userPackages) throws Exception { JAXBContext jaxbContext = createJAXBContext(obj, userPackages); JAXBElement jaxbRequest = new JAXBElement(new QName(msgQName, msgLocalName), obj.getClass(), obj); Writer writer = new StringWriter(); // Support XMLDsig jaxbContext.createMarshaller().marshal(jaxbRequest, writer); return writer.toString(); }
From source file:com.fer.hr.service.olap.ThinQueryService.java
public ResultSet drillthrough(String queryName, List<Integer> cellPosition, Integer maxrows, String returns) { OlapStatement stmt = null;//from www. j av a 2s. c o m try { QueryContext queryContext = context.get(queryName); ThinQuery query = queryContext.getOlapQuery(); CellSet cs = queryContext.getOlapResult(); SaikuCube cube = query.getCube(); final OlapConnection con = olapDiscoverService.getNativeConnection(cube.getConnection()); stmt = con.createStatement(); SelectNode sn = (new DefaultMdxParserImpl().parseSelect(query.getMdx())); String select = null; StringBuilder buf = new StringBuilder(); if (sn.getWithList() != null && sn.getWithList().size() > 0) { buf.append("WITH \n"); StringWriter sw = new StringWriter(); ParseTreeWriter ptw = new ParseTreeWriter(sw); final PrintWriter pw = ptw.getPrintWriter(); for (ParseTreeNode with : sn.getWithList()) { with.unparse(ptw); pw.println(); } buf.append(sw.toString()); } buf.append("SELECT ("); for (int i = 0; i < cellPosition.size(); i++) { List<Member> members = cs.getAxes().get(i).getPositions().get(cellPosition.get(i)).getMembers(); for (int k = 0; k < members.size(); k++) { Member m = members.get(k); if (k > 0 || i > 0) { buf.append(", "); } buf.append(m.getUniqueName()); } } buf.append(") ON COLUMNS \r\n"); buf.append("FROM [").append(cube.getName()).append("]\r\n"); final Writer writer = new StringWriter(); sn.getFilterAxis().unparse(new ParseTreeWriter(new PrintWriter(writer))); if (StringUtils.isNotBlank(writer.toString())) { buf.append("WHERE ").append(writer.toString()); } select = buf.toString(); if (maxrows > 0) { select = "DRILLTHROUGH MAXROWS " + maxrows + " " + select + "\r\n"; } else { select = "DRILLTHROUGH " + select + "\r\n"; } if (StringUtils.isNotBlank(returns)) { select += "\r\n RETURN " + returns; } log.debug("Drill Through for query (" + queryName + ") : \r\n" + select); return stmt.executeQuery(select); } catch (Exception e) { throw new SaikuServiceException("Error DRILLTHROUGH: " + queryName, e); } finally { try { if (stmt != null) stmt.close(); } catch (Exception e) { } } }