From: Nico K. <nkl...@us...> - 2008-01-04 20:56:40
|
Update of /cvsroot/mmapps/mmapps/mmcommons/src/java/net/sf/mmapps/commons/util In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv28272/mmcommons/src/java/net/sf/mmapps/commons/util Modified Files: XmlUtil.java Log Message: Handle utf-8 characters without depending on -Dfile.encoding Index: XmlUtil.java =================================================================== RCS file: /cvsroot/mmapps/mmapps/mmcommons/src/java/net/sf/mmapps/commons/util/XmlUtil.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** XmlUtil.java 20 Sep 2007 18:24:27 -0000 1.6 --- XmlUtil.java 4 Jan 2008 20:56:36 -0000 1.7 *************** *** 2,9 **** import java.io.ByteArrayInputStream; ! import java.io.ByteArrayOutputStream; ! import java.io.IOException; import java.io.InputStream; - import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.util.*; --- 2,7 ---- import java.io.ByteArrayInputStream; ! import java.io.CharArrayWriter; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.util.*; *************** *** 82,105 **** */ private static String serializeDocument(Document doc, Properties format) { ! OutputStream bos = null; try { ! bos = new ByteArrayOutputStream(); TransformerFactory tfactory = TransformerFactory.newInstance(); Transformer serializer = tfactory.newTransformer(); serializer.setOutputProperties(format); ! serializer.transform(new DOMSource(doc), new StreamResult(bos)); ! return bos.toString(); } catch( Exception e ) { logger.error(e.getMessage()); logger.debug(e); } finally { ! try { ! if( bos != null ) bos.close(); ! } ! catch( IOException e ) { ! logger.error( "[serializeDocument()] Could not close OutputStream!" ); ! } } return ""; --- 80,99 ---- */ private static String serializeDocument(Document doc, Properties format) { ! CharArrayWriter caw = null; try { ! caw = new CharArrayWriter(); TransformerFactory tfactory = TransformerFactory.newInstance(); Transformer serializer = tfactory.newTransformer(); serializer.setOutputProperties(format); ! serializer.transform(new DOMSource(doc), new StreamResult(caw)); ! caw.flush(); ! return caw.toString(); } catch( Exception e ) { logger.error(e.getMessage()); logger.debug(e); } finally { ! if( caw != null ) caw.close(); } return ""; *************** *** 114,120 **** */ public static String serializeDocumentFragment(DocumentFragment docfrag) { ! OutputStream bos = null; try { ! bos = new ByteArrayOutputStream(); Properties format = getXmlOutput(false, false, true, true); --- 108,114 ---- */ public static String serializeDocumentFragment(DocumentFragment docfrag) { ! CharArrayWriter caw =null; try { ! caw = new CharArrayWriter(); Properties format = getXmlOutput(false, false, true, true); *************** *** 122,138 **** Transformer serializer = tfactory.newTransformer(); serializer.setOutputProperties(format); ! serializer.transform(new DOMSource(docfrag), new StreamResult(bos)); ! return bos.toString(); } catch( Exception e ) { logger.error( e.getMessage() ); logger.debug(e); } finally { ! try { ! if( bos != null ) bos.close(); ! } ! catch( IOException e ) { ! logger.error( "[serializeDocument()] Could not close OutputStream!" ); ! } } return ""; --- 116,128 ---- Transformer serializer = tfactory.newTransformer(); serializer.setOutputProperties(format); ! serializer.transform(new DOMSource(docfrag), new StreamResult(caw)); ! caw.flush(); ! return caw.toString(); } catch( Exception e ) { logger.error( e.getMessage() ); logger.debug(e); } finally { ! if( caw != null ) caw.close(); } return ""; *************** *** 159,165 **** */ public static String serializeElement(Element element, boolean omitxml) { ! OutputStream bos = null; try { ! bos = new ByteArrayOutputStream(); Properties format = getXmlOutput(false, false, omitxml, omitxml); --- 149,155 ---- */ public static String serializeElement(Element element, boolean omitxml) { ! CharArrayWriter caw = null; try { ! caw = new CharArrayWriter(); Properties format = getXmlOutput(false, false, omitxml, omitxml); *************** *** 167,183 **** Transformer serializer = tfactory.newTransformer(); serializer.setOutputProperties(format); ! serializer.transform(new DOMSource(element), new StreamResult(bos)); ! return bos.toString(); } catch( Exception e ) { logger.error(e.getMessage()); logger.debug(e); } finally { ! try { ! if( bos != null ) bos.close(); ! } ! catch( IOException e ) { ! logger.error( "[serializeDocument()] Could not close OutputStream!" ); ! } } return ""; --- 157,169 ---- Transformer serializer = tfactory.newTransformer(); serializer.setOutputProperties(format); ! serializer.transform(new DOMSource(element), new StreamResult(caw)); ! caw.flush(); ! return caw.toString(); } catch( Exception e ) { logger.error(e.getMessage()); logger.debug(e); } finally { ! if( caw != null ) caw.close(); } return ""; |