List of usage examples for org.dom4j.io OutputFormat createCompactFormat
public static OutputFormat createCompactFormat()
From source file:org.pentaho.platform.web.http.api.resources.XactionUtil.java
License:Open Source License
@SuppressWarnings({ "unchecked", "rawtypes" }) public static String executeXml(RepositoryFile file, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, IPentahoSession userSession) throws Exception { try {/* w ww . j a v a 2s.co m*/ HttpSessionParameterProvider sessionParameters = new HttpSessionParameterProvider(userSession); HttpRequestParameterProvider requestParameters = new HttpRequestParameterProvider(httpServletRequest); Map parameterProviders = new HashMap(); parameterProviders.put("request", requestParameters); //$NON-NLS-1$ parameterProviders.put("session", sessionParameters); //$NON-NLS-1$ List messages = new ArrayList(); IParameterProvider requestParams = new HttpRequestParameterProvider(httpServletRequest); httpServletResponse.setContentType("text/xml"); //$NON-NLS-1$ httpServletResponse.setCharacterEncoding(LocaleHelper.getSystemEncoding()); boolean forcePrompt = "true".equalsIgnoreCase(requestParams.getStringParameter("prompt", "false")); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ OutputStream contentStream = new ByteArrayOutputStream(); SimpleOutputHandler outputHandler = new SimpleOutputHandler(contentStream, false); IRuntimeContext runtime = null; try { runtime = executeInternal(file, requestParams, httpServletRequest, outputHandler, parameterProviders, userSession, forcePrompt, messages); Document responseDoc = SoapHelper.createSoapResponseDocument(runtime, outputHandler, contentStream, messages); OutputFormat format = OutputFormat.createCompactFormat(); format.setSuppressDeclaration(true); format.setEncoding("utf-8"); //$NON-NLS-1$ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); XMLWriter writer = new XMLWriter(outputStream, format); writer.write(responseDoc); writer.flush(); return outputStream.toString("utf-8"); //$NON-NLS-1$ } finally { if (runtime != null) { runtime.dispose(); } } } catch (Exception e) { logger.warn(Messages.getInstance().getString("XactionUtil.XML_OUTPUT_NOT_SUPPORTED")); //$NON-NLS-1$ throw e; } }
From source file:org.pentaho.platform.web.http.api.resources.XactionUtil.java
License:Open Source License
@SuppressWarnings({ "unchecked", "rawtypes" }) public static String doParameter(final RepositoryFile file, IParameterProvider parameterProvider, final IPentahoSession userSession) throws IOException { ActionSequenceJCRHelper helper = new ActionSequenceJCRHelper(); final IActionSequence actionSequence = helper.getActionSequence(file.getPath(), PentahoSystem.loggingLevel, RepositoryFilePermission.READ); final Document document = DocumentHelper.createDocument(); try {// w ww . ja v a2 s. c o m final Element parametersElement = document.addElement("parameters"); // noinspection unchecked final Map<String, IActionParameter> params = actionSequence .getInputDefinitionsForParameterProvider(IParameterProvider.SCOPE_REQUEST); for (final Map.Entry<String, IActionParameter> entry : params.entrySet()) { final String paramName = entry.getKey(); final IActionParameter paramDef = entry.getValue(); final String value = paramDef.getStringValue(); final Class type; // yes, the actual type-code uses equals-ignore-case and thus allows the user // to specify type information in a random case. sTrInG is equal to STRING is equal to the value // defined as constant (string) if (IActionParameter.TYPE_LIST.equalsIgnoreCase(paramDef.getType())) { type = String[].class; } else { type = String.class; } final String label = paramDef.getSelectionDisplayName(); final String[] values; if (StringUtils.isEmpty(value)) { values = new String[0]; } else { values = new String[] { value }; } createParameterElement(parametersElement, paramName, type, label, "user", "parameters", values); } createParameterElement(parametersElement, "path", String.class, null, "system", "system", new String[] { file.getPath() }); createParameterElement(parametersElement, "prompt", String.class, null, "system", "system", new String[] { "yes", "no" }); createParameterElement(parametersElement, "instance-id", String.class, null, "system", "system", new String[] { parameterProvider.getStringParameter("instance-id", null) }); // no close, as far as I know tomcat does not like it that much .. OutputFormat format = OutputFormat.createCompactFormat(); format.setSuppressDeclaration(true); format.setEncoding("utf-8"); //$NON-NLS-1$ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); XMLWriter writer = new XMLWriter(outputStream, format); writer.write(document); writer.flush(); return outputStream.toString("utf-8"); } catch (Exception e) { logger.warn(Messages.getInstance().getString("HttpWebService.ERROR_0003_UNEXPECTED"), e); return null; } }
From source file:org.snipsnap.snip.attachment.Attachments.java
License:Open Source License
private String toString(Element attElement) { OutputFormat outputFormat = OutputFormat.createCompactFormat(); ByteArrayOutputStream out = new ByteArrayOutputStream(); try {//from w w w .ja v a2 s . c o m XMLWriter xmlWriter = new XMLWriter(out, outputFormat); xmlWriter.write(attElement); xmlWriter.flush(); } catch (IOException e) { Logger.warn("Attachments: unable to serialize", e); } try { String enc = Application.get().getConfiguration().getEncoding(); return out.toString(enc == null ? "UTF-8" : enc); } catch (UnsupportedEncodingException e) { return out.toString(); } }
From source file:org.snipsnap.xmlrpc.SnipSnapHandler.java
License:Open Source License
public String getSnipAsXml(String name) { Snip snip = space.load(name);// w w w .j a va2 s .com ByteArrayOutputStream out = new ByteArrayOutputStream(); OutputFormat outputFormat = OutputFormat.createCompactFormat(); outputFormat.setEncoding("UTF-8"); try { XMLWriter writer = new XMLWriter(out, outputFormat); writer.write(SnipSerializer.getInstance().serialize(snip)); writer.flush(); } catch (IOException e) { e.printStackTrace(); } return out.toString(); }
From source file:org.talend.mdm.webapp.base.server.util.XmlUtil.java
License:Open Source License
public static void write(Document document, String filePath, String printMode, String encoding) throws IOException { OutputFormat format;/* w w w . j a v a 2 s . co m*/ if (printMode.toLowerCase().equals("pretty")) { //$NON-NLS-1$ // Pretty print the document format = OutputFormat.createPrettyPrint(); } else if (printMode.toLowerCase().equals("compact")) { //$NON-NLS-1$ // Compact format format = OutputFormat.createCompactFormat(); } else { format = null; } format.setEncoding(encoding); // lets write to a file XMLWriter writer = new XMLWriter(new FileOutputStream(filePath), format); writer.write(document); writer.close(); if (logger.isDebugEnabled()) { logger.debug("New xml file has bean exported on " + filePath); //$NON-NLS-1$ } }
From source file:org.unitime.banner.queueprocessor.util.ClobTools.java
License:Apache License
public static Clob documentToCLOB(Document document, Connection conn) throws IOException, SQLException { Clob clob = conn.createClob(); XMLWriter writer = new XMLWriter(clob.setCharacterStream(1l), OutputFormat.createCompactFormat()); writer.write(document);/*from w ww .j a va2 s. c o m*/ writer.flush(); writer.close(); return clob; }
From source file:org.unitime.commons.hibernate.blob.XmlBlobType.java
License:Open Source License
public void nullSafeSet(PreparedStatement ps, Object value, int index, SessionImplementor session) throws SQLException, HibernateException { if (value == null) { ps.setNull(index, sqlTypes()[0]); } else {//from ww w. j av a 2 s.com try { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); XMLWriter writer = new XMLWriter(new GZIPOutputStream(bytes), OutputFormat.createCompactFormat()); writer.write((Document) value); writer.flush(); writer.close(); ps.setBinaryStream(index, new ByteArrayInputStream(bytes.toByteArray(), 0, bytes.size()), bytes.size()); } catch (IOException e) { throw new HibernateException(e.getMessage(), e); } } }
From source file:org.unitime.commons.hibernate.blob.XmlBlobType.java
License:Open Source License
public Serializable disassemble(Object value) throws HibernateException { try {/*w w w . ja v a2 s . c o m*/ if (value == null) return null; ByteArrayOutputStream out = new ByteArrayOutputStream(); XMLWriter writer = new XMLWriter(new GZIPOutputStream(out), OutputFormat.createCompactFormat()); writer.write((Document) value); writer.flush(); writer.close(); return out.toByteArray(); } catch (UnsupportedEncodingException e) { throw new HibernateException(e.getMessage(), e); } catch (IOException e) { throw new HibernateException(e.getMessage(), e); } }
From source file:org.unitime.commons.hibernate.blob.XmlClobType.java
License:Open Source License
public void nullSafeSet(PreparedStatement ps, Object value, int index, SessionImplementor session) throws SQLException, HibernateException { if (value == null) { ps.setNull(index, sqlTypes()[0]); } else {/*from w ww . j ava 2 s .c o m*/ try { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); XMLWriter writer = new XMLWriter(bytes, OutputFormat.createCompactFormat()); writer.write((Document) value); writer.flush(); writer.close(); ps.setCharacterStream(index, new CharArrayReader(bytes.toString().toCharArray(), 0, bytes.size()), bytes.size()); } catch (IOException e) { throw new HibernateException(e.getMessage(), e); } } }
From source file:org.unitime.commons.hibernate.blob.XmlClobType.java
License:Open Source License
public Serializable disassemble(Object value) throws HibernateException { try {/*from w w w . j av a2 s . c o m*/ if (value == null) return null; ByteArrayOutputStream out = new ByteArrayOutputStream(); XMLWriter writer = new XMLWriter(out, OutputFormat.createCompactFormat()); writer.write((Document) value); writer.flush(); writer.close(); return out.toByteArray(); } catch (UnsupportedEncodingException e) { throw new HibernateException(e.getMessage(), e); } catch (IOException e) { throw new HibernateException(e.getMessage(), e); } }