Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Right-click on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: Gail Buffington <gbuffing@ke...> - 2002-04-19 13:06:12
|
xmlSource is a stream containing UTF-8 data. It appears that the output does not contain the proper UTF-8 characters. Can anyone give me an idea on how to get this translate method to output UTF-8 correctly? I've been working on this for a while and would greatly appreciate any help you could give me. Thanks a lot! Gail Buffington Keithley Instruments public static final String translate( StreamSource xslSource, StreamSource xmlSource, boolean isStale ) throws Exception { String thisClass = "com.i2.cm.ps.utils.XSLTUtils"; String thisMethod = ".translate() : "; if (X2Util.Logger.isDebugEnabled(XSLTUtils.class)) X2Util.Logger.debug(XSLTUtils.class, thisClass + thisMethod + "Entering"); long beginTime = System.currentTimeMillis(); long stopTime; long lastStopTime = beginTime; //transform the xml string data String transformedData = "Error retrieving xml data."; if (null != xslSource) { try { // Use the static TransformerFactory.newInstance() method to instantiate // a TransformerFactory. The javax.xml.transform.TransformerFactory // system property setting determines the actual class to instantiate -- // org.apache.xalan.transformer.TransformerImpl. TransformerFactory tFactory = TransformerFactory.newInstance(); stopTime = System.currentTimeMillis(); if (X2Util.Logger.isInfoEnabled(XSLTUtils.class)) X2Util.Logger.info(XSLTUtils.class, thisClass + thisMethod + "Creating tFactory took " + (stopTime - lastStopTime) + " milliseconds."); lastStopTime = stopTime; stopTime = System.currentTimeMillis(); // Use the TransformerFactory to instantiate a Transformer that will work with // the stylesheet you specify. This method call also processes the stylesheet // into a compiled Templates object. String sourceId = xslSource.getSystemId(); Transformer transformer = null; if( isStale || !transformCache.containsKey(sourceId)) { if (X2Util.Logger.isDebugEnabled(XSLTUtils.class)) X2Util.Logger.debug(XSLTUtils.class, thisClass + thisMethod + "isStale = " + isStale + " SourceId= " + sourceId + " Cache hit = " + transformCache.contains(sourceId) + " xmlSource = " + xmlSource); transformer = tFactory.newTransformer(xslSource); transformCache.put(sourceId,transformer); stopTime = System.currentTimeMillis(); if (X2Util.Logger.isInfoEnabled(XSLTUtils.class)) X2Util.Logger.info(XSLTUtils.class, thisClass + thisMethod + "Creating transformer took " + (stopTime - lastStopTime) + " milliseconds."); } else { if (X2Util.Logger.isDebugEnabled(XSLTUtils.class)) X2Util.Logger.debug(XSLTUtils.class, thisClass + thisMethod + "isStale = " + isStale + " SourceId= " + sourceId + " Cache hit = true"); transformer = (Transformer)transformCache.get(sourceId); stopTime = System.currentTimeMillis(); if (X2Util.Logger.isInfoEnabled(XSLTUtils.class)) X2Util.Logger.info(XSLTUtils.class, thisClass + thisMethod + "Retrieving transformer took " + (stopTime - lastStopTime) + " milliseconds."); } lastStopTime = stopTime; // Use the Transformer to apply the associated Templates object to an XML document // (foo.xml) and write the output to a file (foo.out). StringWriter output = new StringWriter(); transformer.transform(xmlSource, new StreamResult(output)); stopTime = System.currentTimeMillis(); if (X2Util.Logger.isInfoEnabled(XSLTUtils.class)) X2Util.Logger.info(XSLTUtils.class, thisClass + thisMethod + "Transformation took " + (stopTime - lastStopTime) + " milliseconds."); lastStopTime = stopTime; transformedData = output.toString(); output.close(); output = null; } catch (TransformerConfigurationException tce) { if (X2Util.Logger.isErrorEnabled(XSLTUtils.class)) X2Util.Logger.error(XSLTUtils.class, thisClass + thisMethod + "Transformer Configuration Exception : \n" + tce.getMessageAndLocation()); if (X2Util.Logger.isDebugEnabled(XSLTUtils.class)) transformedData = "Transformer Configuration Exception : \n" + DataToolBox.XMLEncode(tce.getMessageAndLocation()); } catch (TransformerException te) { if (X2Util.Logger.isErrorEnabled(XSLTUtils.class)) X2Util.Logger.error(XSLTUtils.class, thisClass + thisMethod + "Transformer Exception : \n" + te.getMessageAndLocation()); if (X2Util.Logger.isDebugEnabled(XSLTUtils.class)) transformedData = "Transformer Exception : \n" + DataToolBox.XMLEncode(te.getMessageAndLocation()); } catch (Throwable e) { if (X2Util.Logger.isErrorEnabled(XSLTUtils.class)) X2Util.Logger.error(XSLTUtils.class, thisClass + thisMethod + "Exception : " + e.getMessage()); } } stopTime = System.currentTimeMillis(); if (X2Util.Logger.isInfoEnabled(XSLTUtils.class)) X2Util.Logger.info(XSLTUtils.class, thisClass + thisMethod + "Total time: " + (stopTime - beginTime) + " milliseconds."); if (X2Util.Logger.isDebugEnabled(XSLTUtils.class)) X2Util.Logger.debug(XSLTUtils.class, thisClass + thisMethod + "Exiting"); return transformedData; } |