List of usage examples for java.io StringWriter write
public void write(String str)
From source file:org.xwiki.lesscss.internal.compiler.CachedIntegratedLESSCompiler.java
private void importMainSkinStyle(StringWriter source, String skin, File tempDir, List<File> tempFilesToDelete) throws LESSCompilerException, IOException { // Get the file content String mainSkinStyle = lessResourceReader .getContent(new LESSSkinFileResourceReference(MAIN_SKIN_STYLE_FILENAME), skin); // Execute velocity on it String velocityOutput = executeVelocity(mainSkinStyle, skin); // Write the file on the temp directory File mainSkinStyleFile = new File(tempDir, MAIN_SKIN_STYLE_FILENAME); FileWriter fileWriter = new FileWriter(mainSkinStyleFile); IOUtils.copy(new StringReader(velocityOutput), fileWriter); fileWriter.close();/*from w ww . j av a2s . c o m*/ // Don't forget to delete this file later tempFilesToDelete.add(mainSkinStyleFile); // Be sure it's done even if the JVM is stopped mainSkinStyleFile.deleteOnExit(); // Add the import line to the LESS resource. // We import this file to be able to use variables and mix-ins defined in it/ // But we don't want it in the output. source.write("@import (reference) \"" + MAIN_SKIN_STYLE_FILENAME + "\";\n"); // See removeMainSkinStyleUndesiredOutput() source.write(LESS_INCLUDE_SEPARATOR); }
From source file:org.eclipse.persistence.logging.AbstractSessionLog.java
/** * Return the supplement detail information including date, session, thread and connection. *//*from www .jav a2 s . c o m*/ protected String getSupplementDetailString(SessionLogEntry entry) { StringWriter writer = new StringWriter(); if (shouldPrintDate()) { writer.write(getDateString(entry.getDate())); writer.write("--"); } if (shouldPrintSession() && (entry.getSession() != null)) { writer.write(this.getSessionString(entry.getSession())); writer.write("--"); } if (shouldPrintConnection() && (entry.getConnection() != null)) { writer.write(this.getConnectionString(entry.getConnection())); writer.write("--"); } if (shouldPrintThread()) { writer.write(this.getThreadString(entry.getThread())); writer.write("--"); } return writer.toString(); }
From source file:com.nhncorp.lucy.security.xss.XssSaxFilter.java
private void serialize(Writer writer, Element element, StringWriter neloLogWriter) throws IOException { boolean hasAttrXss = false; checkRuleRemove(element);/*from w w w. ja va 2 s . c o m*/ if (element.isRemoved()) { /* if (this.isNeloLogEnabled) { neloLogWriter.write(this.neloElementRemoveMSG); neloLogWriter.write(element.getName() + "\n"); }*/ if (!this.withoutComment) { writer.write(REMOVE_TAG_INFO_START); writer.write(element.getName()); writer.write(REMOVE_TAG_INFO_END); } } else { //TODO // v1.3.3 & v1.5.2 BEFORE if (!element.isDisabled()) { if (!element.isDisabled() || this.blockingPrefixEnabled) { checkRule(element); } if (element.isDisabled()) { /* if (this.isNeloLogEnabled) { neloLogWriter.write(this.neloElementMSG); neloLogWriter.write(element.getName() + "\n"); }*/ if (this.blockingPrefixEnabled) { //BlockingPrefix ? , <, > ? Escape ? Element ?? ?? . element.setName(this.blockingPrefix + element.getName()); element.setEnabled(true); // close ? escape ?. isBlockingPrefixEnabled ?? ? . // writer.write('<'); // writer.write(element.getName()); } else { //BlockingPrefix ? , <, > ? Escape . if (!this.withoutComment) { writer.write(BAD_TAG_INFO); } writer.write("<"); writer.write(element.getName()); } } if (!element.isDisabled() && !this.withoutComment && element.existDisabledAttribute()) { writer.write(BAD_ATT_INFO_START); } Collection<Attribute> atts = element.getAttributes(); StringWriter attrSw = new StringWriter(); StringWriter attrXssSw = new StringWriter(); if (atts != null && !atts.isEmpty()) { for (Attribute att : atts) { if (!element.isDisabled() && att.isDisabled()) { hasAttrXss = true; if (!this.withoutComment) { attrXssSw.write(' '); att.serialize(attrXssSw); } } else { attrSw.write(' '); att.serialize(attrSw); } } } if (hasAttrXss) { String attrXssString = attrXssSw.toString(); /*if (this.isNeloLogEnabled) { neloLogWriter.write(this.neloAttrMSG); neloLogWriter.write(element.getName()); neloLogWriter.write(attrXssString + "\n"); }*/ if (!this.withoutComment) { writer.write(attrXssString); writer.write(BAD_ATT_INFO_END); } } if (!element.isDisabled()) { writer.write('<'); writer.write(element.getName()); } writer.write(attrSw.toString()); if (element.isStartClosed()) { writer.write(element.isDisabled() ? " />" : " />"); } else { writer.write(element.isDisabled() ? ">" : ">"); } // if (e.isClosed()) { // if (e.isDisabled() && !this.isBlockingPrefixEnabled) { // writer.write("</"); // writer.write(e.getName()); // writer.write(">"); // } else { // writer.write("</"); // writer.write(e.getName()); // writer.write('>'); // } // } } }
From source file:org.eclipse.jubula.app.testexec.core.ExecutionController.java
/** * creates the job passed to command Line client * /*from w w w . ja v a2s . co m*/ * @param configFile * File * @throws IOException * Error * @return a job configuration */ public JobConfiguration initJob(File configFile) throws IOException { if (configFile != null) { // Create JobConfiguration from XMl BufferedReader in = null; StringWriter writer = new StringWriter(); try { in = new BufferedReader(new FileReader(configFile)); String line = null; while ((line = in.readLine()) != null) { writer.write(line); } } finally { if (in != null) { in.close(); } } String xml = writer.toString(); m_job = JobConfiguration.readFromXML(xml); } else { // or create an empty JobConfiguration m_job = new JobConfiguration(); } return m_job; }
From source file:com.xmlcalabash.library.ApacheHttpRequest.java
private void doPutOrPost(EntityEnclosingMethod method, XdmNode body) { // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); for (Header header : headers) { method.addRequestHeader(header); }/*from w ww .j ava 2s.c om*/ contentType = body.getAttributeValue(_content_type); if (contentType == null) { throw new XProcException("Content-type on c:body is required."); } // FIXME: This sucks rocks. I want to write the data to be posted, not provide some way to read it String postContent = null; try { if (xmlContentType(contentType)) { Serializer serializer = makeSerializer(); Vector<XdmNode> content = new Vector<XdmNode>(); XdmSequenceIterator iter = body.axisIterator(Axis.CHILD); while (iter.hasNext()) { XdmNode node = (XdmNode) iter.next(); content.add(node); } // FIXME: set serializer properties appropriately! StringWriter writer = new StringWriter(); serializer.setOutputWriter(writer); S9apiUtils.serialize(runtime, content, serializer); writer.close(); postContent = writer.toString(); } else { StringWriter writer = new StringWriter(); XdmSequenceIterator iter = body.axisIterator(Axis.CHILD); while (iter.hasNext()) { XdmNode node = (XdmNode) iter.next(); writer.write(node.getStringValue()); } writer.close(); postContent = writer.toString(); } StringRequestEntity requestEntity = new StringRequestEntity(postContent, contentType, "UTF-8"); method.setRequestEntity(requestEntity); } catch (IOException ioe) { throw new XProcException(ioe); } catch (SaxonApiException sae) { throw new XProcException(sae); } }
From source file:com.moviejukebox.tools.WebBrowser.java
@SuppressWarnings("resource") public String request(URL url, Charset charset) throws IOException { LOG.debug("Requesting {}", url.toString()); // get the download limit for the host ThreadExecutor.enterIO(url);/*from w ww .j av a2s . c o m*/ StringWriter content = new StringWriter(10 * 1024); try { URLConnection cnx = null; try { cnx = openProxiedConnection(url); sendHeader(cnx); readHeader(cnx); InputStreamReader inputStreamReader = null; BufferedReader bufferedReader = null; try (InputStream inputStream = cnx.getInputStream()) { // If we fail to get the URL information we need to exit gracefully if (charset == null) { inputStreamReader = new InputStreamReader(inputStream, getCharset(cnx)); } else { inputStreamReader = new InputStreamReader(inputStream, charset); } bufferedReader = new BufferedReader(inputStreamReader); String line; while ((line = bufferedReader.readLine()) != null) { content.write(line); } // Attempt to force close connection // We have HTTP connections, so these are always valid content.flush(); } catch (FileNotFoundException ex) { LOG.error("URL not found: {}", url.toString()); } catch (IOException ex) { LOG.error("Error getting URL {}, {}", url.toString(), ex.getMessage()); } finally { // Close resources if (bufferedReader != null) { try { bufferedReader.close(); } catch (Exception ex) { /* ignore */ } } if (inputStreamReader != null) { try { inputStreamReader.close(); } catch (Exception ex) { /* ignore */ } } } } catch (SocketTimeoutException ex) { LOG.error("Timeout Error with {}", url.toString()); } finally { if (cnx != null) { if (cnx instanceof HttpURLConnection) { ((HttpURLConnection) cnx).disconnect(); } } } return content.toString(); } finally { content.close(); ThreadExecutor.leaveIO(); } }
From source file:org.netbeans.nbbuild.MakeJnlp2.java
private void generateFiles() throws IOException, BuildException { final Set<String> declaredLocales = new HashSet<String>(); final boolean useAllLocales; if ("*".equals(includelocales)) { useAllLocales = true;/* w w w. j a v a 2 s .co m*/ } else if ("".equals(includelocales)) { useAllLocales = false; } else { useAllLocales = false; StringTokenizer tokenizer = new StringTokenizer(includelocales, ","); while (tokenizer.hasMoreElements()) { declaredLocales.add(tokenizer.nextToken()); } } final Set<String> indirectFilePaths = new HashSet<String>(); for (FileSet fs : new FileSet[] { indirectJars, indirectFiles }) { if (fs != null) { DirectoryScanner scan = fs.getDirectoryScanner(getProject()); for (String f : scan.getIncludedFiles()) { indirectFilePaths.add(f.replace(File.pathSeparatorChar, '/')); } } } final ExecutorService executorService = Executors.newFixedThreadPool(nbThreads); final List<BuildException> exceptions = new ArrayList<BuildException>(); for (final Iterator fileIt = files.iterator(); fileIt.hasNext();) { if (!exceptions.isEmpty()) { break; } final FileResource fr = (FileResource) fileIt.next(); final File jar = fr.getFile(); if (!jar.canRead()) { throw new BuildException("Cannot read file: " + jar); } // if (optimize && checkDuplicate(jar).isPresent()) { continue; } // executorService.execute(new Runnable() { @Override public void run() { JarFile theJar = null; try { theJar = new JarFile(jar); String codenamebase = JarWithModuleAttributes .extractCodeName(theJar.getManifest().getMainAttributes()); if (codenamebase == null) { throw new BuildException("Not a NetBeans Module: " + jar); } { int slash = codenamebase.indexOf('/'); if (slash >= 0) { codenamebase = codenamebase.substring(0, slash); } } String dashcnb = codenamebase.replace('.', '-'); String title; String oneline; String shrt; String osDep = null; { String bundle = theJar.getManifest().getMainAttributes() .getValue("OpenIDE-Module-Localizing-Bundle"); Properties prop = new Properties(); if (bundle != null) { ZipEntry en = theJar.getEntry(bundle); if (en == null) { throw new BuildException("Cannot find entry: " + bundle + " in file: " + jar); } InputStream is = theJar.getInputStream(en); prop.load(is); is.close(); } title = prop.getProperty("OpenIDE-Module-Name", codenamebase); oneline = prop.getProperty("OpenIDE-Module-Short-Description", title); shrt = prop.getProperty("OpenIDE-Module-Long-Description", oneline); } { String osMan = theJar.getManifest().getMainAttributes() .getValue("OpenIDE-Module-Requires"); if (osMan != null) { if (osMan.indexOf("org.openide.modules.os.MacOSX") >= 0) { // NOI18N osDep = "Mac OS X"; // NOI18N } else if (osMan.indexOf("org.openide.modules.os.Linux") >= 0) { // NOI18N osDep = "Linux"; // NOI18N } else if (osMan.indexOf("org.openide.modules.os.Solaris") >= 0) { // NOI18N osDep = "Solaris"; // NOI18N } else if (osMan.indexOf("org.openide.modules.os.Windows") >= 0) { // NOI18N osDep = "Windows"; // NOI18N } } } Map<String, List<File>> localizedFiles = verifyExtensions(jar, theJar.getManifest(), dashcnb, codenamebase, verify, indirectFilePaths); executedLocales = localizedFiles.keySet(); new File(targetFile, dashcnb).mkdir(); File signed = new File(new File(targetFile, dashcnb), jar.getName()); // +p final JarConfigResolved jarConfig = signOrCopy(jar, signed); File jnlp = new File(targetFile, dashcnb + ".jnlp"); StringWriter writeJNLP = new StringWriter(); writeJNLP.write("<?xml version='1.0' encoding='UTF-8'?>\n"); writeJNLP.write( "<!DOCTYPE jnlp PUBLIC \"-//Sun Microsystems, Inc//DTD JNLP Descriptor 6.0//EN\" \"http://java.sun.com/dtd/JNLP-6.0.dtd\">\n"); writeJNLP.write("<jnlp spec='1.0+' codebase='" + codebase + "'>\n"); writeJNLP.write(" <information>\n"); writeJNLP.write(" <title>" + XMLUtil.toElementContent(title) + "</title>\n"); writeJNLP.write(" <vendor>NetBeans</vendor>\n"); writeJNLP.write(" <description kind='one-line'>" + XMLUtil.toElementContent(oneline) + "</description>\n"); writeJNLP.write(" <description kind='short'>" + XMLUtil.toElementContent(shrt) + "</description>\n"); writeJNLP.write(" </information>\n"); String realPermissions = permissions; if ((jarConfig != null) && (jarConfig.getExtraManifestAttributes() != null)) { String jarPermissions = jarConfig.getExtraManifestAttributes().getValue("Permissions"); if (jarPermissions != null) { if ("all-permissions".equals(jarPermissions)) { realPermissions = "<security><all-permissions/></security>\n"; } else { realPermissions = ""; } } } writeJNLP.write(realPermissions); if (osDep == null) { writeJNLP.write(" <resources>\n"); } else { writeJNLP.write(" <resources os='" + osDep + "'>\n"); } writeJNLP.write("<property name=\"jnlp.packEnabled\" value=\"" + String.valueOf(pack200) + "\"/>\n"); writeJNLP.write(constructJarHref(jar, dashcnb)); processExtensions(jar, theJar.getManifest(), writeJNLP, dashcnb, codebase, realPermissions); processIndirectJars(writeJNLP, dashcnb); processIndirectFiles(writeJNLP, dashcnb); writeJNLP.write(" </resources>\n"); if (useAllLocales || !declaredLocales.isEmpty()) { // write down locales for (Map.Entry<String, List<File>> e : localizedFiles.entrySet()) { final String locale = e.getKey(); if (!declaredLocales.isEmpty() && !declaredLocales.contains(locale)) { continue; } final List<File> allFiles = e.getValue(); writeJNLP.write(" <resources locale='" + locale + "'>\n"); for (File n : allFiles) { log("generating locale " + locale + " for " + n, Project.MSG_VERBOSE); String name = n.getName(); String clusterRootPrefix = jar.getParent() + File.separatorChar; String absname = n.getAbsolutePath(); if (absname.startsWith(clusterRootPrefix)) { name = absname.substring(clusterRootPrefix.length()) .replace(File.separatorChar, '-'); } File t = new File(new File(targetFile, dashcnb), name); signOrCopy(n, t); writeJNLP.write(constructJarHref(n, dashcnb, name)); } writeJNLP.write(" </resources>\n"); } } writeJNLP.write(" <component-desc/>\n"); writeJNLP.write("</jnlp>\n"); writeJNLP.close(); // +p Files.write(writeJNLP.toString(), jnlp, Charset.forName("UTF-8")); } catch (Exception e) { exceptions.add(new BuildException(e)); } finally { if (theJar != null) { try { theJar.close(); } catch (IOException e) { } } } } }); } executorService.shutdown(); try { executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); } catch (Exception e) { throw new BuildException(e); } if (!exceptions.isEmpty()) { throw exceptions.get(0); } }
From source file:com.netspective.sparx.theme.basic.StandardDialogSkin.java
public void appendFieldHtml(DialogContext dc, DialogField field, StringBuffer fieldsHtml, StringBuffer fieldsJSDefn, List fieldErrorMsgs) throws IOException { if (field.isInputHidden(dc)) { StringWriter writer = new StringWriter(); field.renderControlHtml(writer, dc); fieldsHtml.append(writer);// ww w. jav a 2 s . c o m // even if the field is hidden, you still need to register it in JS if (field.getName() != null) fieldsJSDefn.append(field.getJavaScriptDefn(dc)); return; } String caption = field.getCaption().getTextValue(dc); DialogFields fieldChildren = field.getChildren(); if (caption != null && fieldChildren != null && caption.equals(DialogField.GENERATE_CAPTION)) { StringBuffer generated = new StringBuffer(); for (int i = 0; i < fieldChildren.size(); i++) { DialogField childField = fieldChildren.get(i); String childCaption = childField.getCaption().getTextValue(dc); if (childCaption != null && childCaption != DialogField.CUSTOM_CAPTION) { if (generated.length() > 0) generated.append(" / "); generated.append(childField.isRequired(dc) ? "<b>" + childCaption + "</b>" : childCaption); } } caption = generated.toString(); } else { if (caption != null && field.isRequired(dc)) caption = "<b>" + caption + "</b>"; } if (captionSuffix != null && caption != null && caption.length() > 0) caption += captionSuffix; StringWriter controlHtml = new StringWriter(); field.renderControlHtml(controlHtml, dc); String popupHtml = getPopupHtml(dc, field); if (popupHtml != null) controlHtml.write(popupHtml); if (field.isHelpAvailable()) controlHtml.write(" " + field.getHelpPanel().getDialogFieldHelpHtml(dc, getTheme())); DialogField.State state = dc.getFieldStates().getState(field); DialogFieldFlags stateFlags = state.getStateFlags(); if (stateFlags.flagIsSet(DialogFieldFlags.CREATE_ADJACENT_AREA)) { String adjValue = state.getAdjacentAreaValue(); controlHtml.write(" <span id='" + field.getQualifiedName() + "_adjacent'>" + (adjValue != null ? adjValue : "") + "</span>"); } boolean haveErrors = false; StringBuffer messagesHtml = null; List errorMessages = dc.getValidationContext() .getValidationErrorsForScope(state.getValidationContextScope()); if (errorMessages.size() > 0) { messagesHtml = new StringBuffer(); messagesHtml.append("<font " + errorMsgFontAttrs + ">"); for (int i = 0; i < errorMessages.size(); i++) { String msgStr = (String) errorMessages.get(i); fieldErrorMsgs.add(msgStr); if (i > 0) messagesHtml.append("<br>"); messagesHtml.append("<a name='dc_error_msg_" + i + "'>" + msgStr + "</a>"); } messagesHtml.append("</font>"); haveErrors = true; } String hintHtml = ""; if (controlHtml.getBuffer().length() > 0) { // only show the hint when there is an input field! String hint = field.getHint().getTextValue(dc); if (hint != null) { DialogFlags dialogFlags = dc.getDialog().getDialogFlags(); if ((field.isReadOnly(dc) && dialogFlags.flagIsSet(DialogFlags.HIDE_READONLY_HINTS))) { hintHtml = ""; } else if (dialogFlags.flagIsSet(DialogFlags.HIDE_HINTS_UNTIL_FOCUS)) { // hide the hints until the field is being edited hintHtml = "<br><span id=\"" + field.getQualifiedName() + "_hint\" class=\"dialog-fields-hint-hidden\"> " + hint + "</span>"; } else { hintHtml = "<br><span id=\"" + field.getQualifiedName() + "_hint\" class=\"dialog-fields-hint\"> " + hint + "</span>"; } } } /* * each field row gets its own ID so DHTML can hide/show the row */ String rowAttr = fieldRowAttrs + " id='" + FIELDROW_PREFIX + field.getQualifiedName() + "' "; if (haveErrors) rowAttr = rowAttr + fieldRowErrorAttrs; if (caption == null) { if (field instanceof SeparatorField) fieldsHtml.append("<tr" + rowAttr + "><td class=\"dialog-fields-separator\" colspan='2'>" + controlHtml + "</td></tr>\n"); else fieldsHtml.append("<tr" + rowAttr + "><td colspan='2'>" + controlHtml + hintHtml + "</td></tr>\n"); if (haveErrors) fieldsHtml.append("<tr><td><span class=\"dialog-fields-errors\"> " + messagesHtml + "</span></td></tr>\n"); } else { String accessKey = field.getAccessKey(); if (accessKey != null && accessKey.length() > 0) { int accessKeyPos = caption.toLowerCase().indexOf(accessKey.toLowerCase()); if (accessKeyPos > 0 && accessKeyPos < caption.length() - 1) { fieldsHtml.append("<tr " + rowAttr + "><td " + getCaptionClass() + "><label for=\"" + field.getHtmlFormControlId() + "\" accesskey=\"" + field.getAccessKey() + "\">" + caption.substring(0, accessKeyPos) + "<span class=\"accesskey\">" + caption.substring(accessKeyPos, accessKeyPos + 1) + "</span>" + caption.substring(accessKeyPos + 1) + "</label></td>" + "<td " + getControlAreaClass() + ">" + controlHtml + hintHtml + "</td></tr>\n"); } else if (accessKeyPos == caption.length() - 1) { fieldsHtml.append("<tr " + rowAttr + "><td " + getCaptionClass() + "><label for=\"" + field.getHtmlFormControlId() + "\" accesskey=\"" + field.getAccessKey() + "\">" + caption.substring(0, accessKeyPos) + "<span class=\"accesskey\">" + caption.substring(accessKeyPos) + "</span></label></td>" + "<td " + getControlAreaClass() + ">" + controlHtml + hintHtml + "</td></tr>\n"); } else if (accessKeyPos == 0) { fieldsHtml.append("<tr " + rowAttr + "><td " + getCaptionClass() + "><label for=\"" + field.getHtmlFormControlId() + "\" accesskey=\"" + field.getAccessKey() + "\">" + "<span class=\"accesskey\">" + caption.substring(0, 1) + "</span>" + caption.substring(1) + "</label></td>" + "<td " + getControlAreaClass() + ">" + controlHtml + hintHtml + "</td></tr>\n"); } else { fieldsHtml.append("<tr " + rowAttr + "><td " + getCaptionClass() + ">" + caption + "</td>" + "<td " + getControlAreaClass() + ">" + controlHtml + hintHtml + "</td></tr>\n"); } } else if (caption.length() > 0) { fieldsHtml.append("<tr" + rowAttr + "><td " + getCaptionClass() + ">" + "<label for=\"" + field.getHtmlFormControlId() + "\">" + caption + "</label></td>" + "<td " + getControlAreaClass() + ">" + controlHtml + hintHtml + "</td></tr>\n"); } else { fieldsHtml.append("<tr" + rowAttr + "><td> </td>" + "<td " + getControlAreaClass() + ">" + controlHtml + hintHtml + "</td></tr>\n"); } if (haveErrors) fieldsHtml.append( "<tr><td> </td><td>" + "<span class=\"dialog-fields-errors\"> " + messagesHtml + "</span></td></tr>\n"); } if (field.getName() != null) fieldsJSDefn.append(field.getJavaScriptDefn(dc)); }
From source file:org.ambraproject.article.service.XslIngestArchiveProcessor.java
/** * Run the zip file through the xsl stylesheet * * @param zip the zip archive containing the items to ingest * @param zipInfo the document describing the zip archive (adheres to zip.dtd) * @param articleXml the stylesheet to run on <var>zipInfo</var>; this is the main script * @param doiUrlPrefix DOI URL prefix// w w w . j a va 2 s .co m * @return a document describing the fedora objects to create (must adhere to fedora.dtd) * @throws javax.xml.transform.TransformerException * if an error occurs during the processing */ private Document transformZip(ZipFile zip, String zipInfo, Document articleXml, String doiUrlPrefix) throws TransformerException, URISyntaxException { Transformer t = getTranslet(articleXml); t.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); t.setURIResolver(new ZipURIResolver(zip)); // override the doi url prefix if one is specified in the config if (doiUrlPrefix != null) t.setParameter("doi-url-prefix", doiUrlPrefix); /* * Note: it would be preferable (and correct according to latest JAXP specs) to use * t.setErrorListener(), but Saxon does not forward <xls:message>'s to the error listener. * Hence we need to use Saxon's API's in order to get at those messages. */ final StringWriter msgs = new StringWriter(); MessageWarner em = new MessageWarner(); ((Controller) t).setMessageEmitter(em); t.setErrorListener(new ErrorListener() { public void warning(TransformerException te) { log.warn("Warning received while processing zip", te); } public void error(TransformerException te) { log.warn("Error received while processing zip", te); msgs.write(te.getMessageAndLocation() + '\n'); } public void fatalError(TransformerException te) { log.warn("Fatal error received while processing zip", te); msgs.write(te.getMessageAndLocation() + '\n'); } }); Source inp = new StreamSource(new StringReader(zipInfo), "zip:/"); DOMResult res = new DOMResult(); try { t.transform(inp, res); } catch (TransformerException te) { if (msgs.getBuffer().length() > 0) { log.error(msgs.getBuffer().toString()); throw new TransformerException(msgs.toString(), te); } else throw te; } if (msgs.getBuffer().length() > 0) throw new TransformerException(msgs.toString()); return (Document) res.getNode(); }