Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 65894 invoked from network); 11 Aug 2009 10:14:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 11 Aug 2009 10:14:34 -0000 Received: (qmail 6127 invoked by uid 500); 11 Aug 2009 10:14:41 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 6070 invoked by uid 500); 11 Aug 2009 10:14:40 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 6061 invoked by uid 99); 11 Aug 2009 10:14:40 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Aug 2009 10:14:40 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Aug 2009 10:14:30 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 48B8723888EC; Tue, 11 Aug 2009 10:14:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r803052 - in /directory/studio/trunk/schemaeditor/src/main: java/org/apache/directory/studio/schemaeditor/model/io/XMLSchemaFileExporter.java resources/org/apache/directory/studio/schemaeditor/ Date: Tue, 11 Aug 2009 10:14:09 -0000 To: commits@directory.apache.org From: pamarcelot@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090811101409.48B8723888EC@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: pamarcelot Date: Tue Aug 11 10:14:08 2009 New Revision: 803052 URL: http://svn.apache.org/viewvc?rev=803052&view=rev Log: Fix for DIRSTUDIO-521 (Replace the XSLT transformation by the use of the Dom4J OutputFormat class for XML pretty print). Removed: directory/studio/trunk/schemaeditor/src/main/resources/org/apache/directory/studio/schemaeditor/ Modified: directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/XMLSchemaFileExporter.java Modified: directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/XMLSchemaFileExporter.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/XMLSchemaFileExporter.java?rev=803052&r1=803051&r2=803052&view=diff ============================================================================== --- directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/XMLSchemaFileExporter.java (original) +++ directory/studio/trunk/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/XMLSchemaFileExporter.java Tue Aug 11 10:14:08 2009 @@ -20,17 +20,13 @@ package org.apache.directory.studio.schemaeditor.model.io; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; import java.util.List; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.stream.StreamSource; - import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum; import org.apache.directory.shared.ldap.schema.UsageEnum; -import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.model.AttributeTypeImpl; import org.apache.directory.studio.schemaeditor.model.MatchingRuleImpl; import org.apache.directory.studio.schemaeditor.model.ObjectClassImpl; @@ -40,8 +36,8 @@ import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Element; -import org.dom4j.io.DocumentResult; -import org.dom4j.io.DocumentSource; +import org.dom4j.io.OutputFormat; +import org.dom4j.io.XMLWriter; /** @@ -96,8 +92,9 @@ * the schema to convert * @return * the corresponding source code representation + * @throws IOException */ - public static String toXml( Schema schema ) + public static String toXml( Schema schema ) throws IOException { // Creating the Document Document document = DocumentHelper.createDocument(); @@ -105,7 +102,18 @@ // Adding the schema addSchema( schema, document ); - return styleDocument( document ).asXML(); + // Creating the output stream we're going to put the XML in + OutputStream os = new ByteArrayOutputStream(); + OutputFormat outformat = OutputFormat.createPrettyPrint(); + outformat.setEncoding( "UTF-8" ); //$NON-NLS-1$ + + // Writing the XML. + XMLWriter writer = new XMLWriter( os, outformat ); + writer.write( document ); + writer.flush(); + writer.close(); + + return os.toString(); } @@ -117,15 +125,27 @@ * the array of schemas to convert * @return * the corresponding source code representation + * @throws IOException */ - public static String toXml( Schema[] schemas ) + public static String toXml( Schema[] schemas ) throws IOException { // Creating the Document and the 'root' Element Document document = DocumentHelper.createDocument(); addSchemas( schemas, document ); - return styleDocument( document ).asXML(); + // Creating the output stream we're going to put the XML in + OutputStream os = new ByteArrayOutputStream(); + OutputFormat outformat = OutputFormat.createPrettyPrint(); + outformat.setEncoding( "UTF-8" ); //$NON-NLS-1$ + + // Writing the XML. + XMLWriter writer = new XMLWriter( os, outformat ); + writer.write( document ); + writer.flush(); + writer.close(); + + return os.toString(); } @@ -553,44 +573,4 @@ syntaxNode.addAttribute( HUMAN_READABLE_TAG, BOOLEAN_FALSE ); } } - - - /** - * XML Pretty Printer XSLT Transformation - * - * @param document - * the Dom4j Document - * @return - */ - private static Document styleDocument( Document document ) - { - // load the transformer using JAXP - TransformerFactory factory = TransformerFactory.newInstance(); - Transformer transformer = null; - try - { - transformer = factory.newTransformer( new StreamSource( Activator.class - .getResourceAsStream( "XmlFileFormat.xslt" ) ) ); - } - catch ( TransformerConfigurationException e1 ) - { - // Will never occur - } - - // now lets style the given document - DocumentSource source = new DocumentSource( document ); - DocumentResult result = new DocumentResult(); - try - { - transformer.transform( source, result ); - } - catch ( TransformerException e ) - { - // Will never occur - } - - // return the transformed document - Document transformedDoc = result.getDocument(); - return transformedDoc; - } }