directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r803048 - in /directory/studio/trunk/apacheds-configuration/src/main: java/org/apache/directory/studio/apacheds/configuration/editor/ java/org/apache/directory/studio/apacheds/configuration/model/ java/org/apache/directory/studio/apacheds/c...
Date Tue, 11 Aug 2009 10:00:28 GMT
Author: pamarcelot
Date: Tue Aug 11 10:00:28 2009
New Revision: 803048

URL: http://svn.apache.org/viewvc?rev=803048&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/apacheds-configuration/src/main/resources/org/apache/directory/studio/apacheds/configuration/template.xslt
Modified:
    directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditor.java
    directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/AbstractServerXmlIO.java
    directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerXmlIO.java
    directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v150/ServerXmlIOV150.java
    directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v151/ServerXmlIOV151.java
    directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v152/ServerXmlIOV152.java
    directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v153/ServerXmlIOV153.java
    directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v154/ServerXmlIOV154.java

Modified: directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditor.java?rev=803048&r1=803047&r2=803048&view=diff
==============================================================================
--- directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditor.java
(original)
+++ directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditor.java
Tue Aug 11 10:00:28 2009
@@ -482,8 +482,9 @@
      *      the {@link FileEditorInput}
      * @throws ServerConfigurationWriterException 
      * @throws CoreException 
+     * @throws IOException 
      */
-    private void saveConfiguration( FileEditorInput fei, IProgressMonitor monitor ) throws
CoreException
+    private void saveConfiguration( FileEditorInput fei, IProgressMonitor monitor ) throws
CoreException, IOException
     {
         String xml = serverXmlIO.toXml( serverConfiguration );
         fei.getFile().setContents( new ByteArrayInputStream( xml.getBytes() ), true, true,
monitor );

Modified: directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/AbstractServerXmlIO.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/AbstractServerXmlIO.java?rev=803048&r1=803047&r2=803048&view=diff
==============================================================================
--- directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/AbstractServerXmlIO.java
(original)
+++ directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/AbstractServerXmlIO.java
Tue Aug 11 10:00:28 2009
@@ -30,19 +30,12 @@
 import javax.naming.NamingException;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttributes;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.stream.StreamSource;
 
 import org.apache.directory.shared.ldap.ldif.LdifReader;
 import org.apache.directory.shared.ldap.util.StringTools;
-import org.apache.directory.studio.apacheds.configuration.ApacheDSConfigurationPlugin;
 import org.apache.directory.studio.apacheds.configuration.StudioEntityResolver;
 import org.dom4j.Document;
 import org.dom4j.Element;
-import org.dom4j.io.DocumentResult;
-import org.dom4j.io.DocumentSource;
 import org.dom4j.io.SAXReader;
 import org.eclipse.osgi.util.NLS;
 
@@ -254,36 +247,6 @@
     }
 
 
-    /**
-     * XML Pretty Printer XSLT Tranformation
-     * 
-     * @param document
-     *      the Dom4j Document
-     * @return
-     *      the stylized Document
-     * @throws TransformerException 
-     */
-    public static Document styleDocument( Document document ) throws TransformerException
-    {
-        // load the transformer using JAXP
-        TransformerFactory factory = TransformerFactory.newInstance();
-        Transformer transformer = null;
-
-        transformer = factory.newTransformer( new StreamSource( ApacheDSConfigurationPlugin.class
-            .getResourceAsStream( "template.xslt" ) ) ); //$NON-NLS-1$
-
-        // now lets style the given document
-        DocumentSource source = new DocumentSource( document );
-        DocumentResult result = new DocumentResult();
-
-        transformer.transform( source, result );
-
-        // return the transformed document
-        Document transformedDoc = result.getDocument();
-        return transformedDoc;
-    }
-
-
     /* (non-Javadoc)
      * @see org.apache.directory.studio.apacheds.configuration.model.ServerXmlIO#isValid(java.io.InputStream)
      */

Modified: directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerXmlIO.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerXmlIO.java?rev=803048&r1=803047&r2=803048&view=diff
==============================================================================
--- directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerXmlIO.java
(original)
+++ directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerXmlIO.java
Tue Aug 11 10:00:28 2009
@@ -20,6 +20,7 @@
 package org.apache.directory.studio.apacheds.configuration.model;
 
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.Reader;
 
@@ -79,6 +80,8 @@
      *      the server configuration
      * @return
      *      the corresponding XML representation
+     * @throws IOException 
+     *      if an error occurs when converting the server configuration as XML
      */
-    public String toXml( ServerConfiguration serverConfiguration );
+    public String toXml( ServerConfiguration serverConfiguration ) throws IOException;
 }

Modified: directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v150/ServerXmlIOV150.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v150/ServerXmlIOV150.java?rev=803048&r1=803047&r2=803048&view=diff
==============================================================================
--- directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v150/ServerXmlIOV150.java
(original)
+++ directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v150/ServerXmlIOV150.java
Tue Aug 11 10:00:28 2009
@@ -20,7 +20,10 @@
 package org.apache.directory.studio.apacheds.configuration.model.v150;
 
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -30,7 +33,6 @@
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttributes;
-import javax.xml.transform.TransformerException;
 
 import org.apache.directory.studio.apacheds.configuration.StudioEntityResolver;
 import org.apache.directory.studio.apacheds.configuration.model.AbstractServerXmlIO;
@@ -40,7 +42,9 @@
 import org.dom4j.Document;
 import org.dom4j.DocumentHelper;
 import org.dom4j.Element;
+import org.dom4j.io.OutputFormat;
 import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
 
 
 /**
@@ -317,8 +321,7 @@
         }
         else
         {
-            throw new ServerXmlIOException(
-                Messages.getString("ServerXmlIOV150.0") ); //$NON-NLS-1$
+            throw new ServerXmlIOException( Messages.getString( "ServerXmlIOV150.0" ) );
//$NON-NLS-1$
         }
 
         // Other Partitions
@@ -650,7 +653,7 @@
     /* (non-Javadoc)
      * @see org.apache.directory.studio.apacheds.configuration.model.ServerXmlIO#toXml(org.apache.directory.studio.apacheds.configuration.model.ServerConfiguration)
      */
-    public String toXml( ServerConfiguration serverConfiguration )
+    public String toXml( ServerConfiguration serverConfiguration ) throws IOException
     {
         Document document = DocumentHelper.createDocument();
         Element root = document.addElement( "beans" ); //$NON-NLS-1$
@@ -670,20 +673,22 @@
         // CustomEditors Bean
         createCustomEditorsBean( root );
 
-        Document stylizedDocument = null;
-        try
-        {
-            stylizedDocument = styleDocument( document );
-        }
-        catch ( TransformerException e )
-        {
-            // Will never occur
-        }
-
-        stylizedDocument.addDocType( "beans", "-//SPRING//DTD BEAN//EN", //$NON-NLS-1$ //$NON-NLS-2$
+        // Adding specific doctype
+        document.addDocType( "beans", "-//SPRING//DTD BEAN//EN", //$NON-NLS-1$ //$NON-NLS-2$
             "http://www.springframework.org/dtd/spring-beans.dtd" ); //$NON-NLS-1$
 
-        return stylizedDocument.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();
     }
 
 

Modified: directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v151/ServerXmlIOV151.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v151/ServerXmlIOV151.java?rev=803048&r1=803047&r2=803048&view=diff
==============================================================================
--- directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v151/ServerXmlIOV151.java
(original)
+++ directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v151/ServerXmlIOV151.java
Tue Aug 11 10:00:28 2009
@@ -20,7 +20,10 @@
 package org.apache.directory.studio.apacheds.configuration.model.v151;
 
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -30,7 +33,6 @@
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttributes;
-import javax.xml.transform.TransformerException;
 
 import org.apache.directory.studio.apacheds.configuration.StudioEntityResolver;
 import org.apache.directory.studio.apacheds.configuration.model.AbstractServerXmlIO;
@@ -40,7 +42,9 @@
 import org.dom4j.Document;
 import org.dom4j.DocumentHelper;
 import org.dom4j.Element;
+import org.dom4j.io.OutputFormat;
 import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
 
 
 /**
@@ -888,7 +892,7 @@
     /* (non-Javadoc)
      * @see org.apache.directory.studio.apacheds.configuration.model.ServerXmlIO#toXml(org.apache.directory.studio.apacheds.configuration.model.ServerConfiguration)
      */
-    public String toXml( ServerConfiguration serverConfiguration )
+    public String toXml( ServerConfiguration serverConfiguration ) throws IOException
     {
         Document document = DocumentHelper.createDocument();
         Element root = document.addElement( "beans" ); //$NON-NLS-1$
@@ -925,21 +929,23 @@
 
         // CustomEditors Bean
         createCustomEditorsBean( root );
-
-        Document stylizedDocument = null;
-        try
-        {
-            stylizedDocument = styleDocument( document );
-        }
-        catch ( TransformerException e )
-        {
-            // Will never occur
-        }
-
-        stylizedDocument.addDocType( "beans", "-//SPRING//DTD BEAN//EN", //$NON-NLS-1$ //$NON-NLS-2$
+        
+        // Adding specific doctype
+        document.addDocType( "beans", "-//SPRING//DTD BEAN//EN", //$NON-NLS-1$ //$NON-NLS-2$
             "http://www.springframework.org/dtd/spring-beans.dtd" ); //$NON-NLS-1$
 
-        return stylizedDocument.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();
     }
 
 

Modified: directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v152/ServerXmlIOV152.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v152/ServerXmlIOV152.java?rev=803048&r1=803047&r2=803048&view=diff
==============================================================================
--- directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v152/ServerXmlIOV152.java
(original)
+++ directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v152/ServerXmlIOV152.java
Tue Aug 11 10:00:28 2009
@@ -20,7 +20,10 @@
 package org.apache.directory.studio.apacheds.configuration.model.v152;
 
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -29,7 +32,6 @@
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
-import javax.xml.transform.TransformerException;
 
 import org.apache.directory.studio.apacheds.configuration.StudioEntityResolver;
 import org.apache.directory.studio.apacheds.configuration.model.AbstractServerXmlIO;
@@ -41,7 +43,9 @@
 import org.dom4j.Element;
 import org.dom4j.Namespace;
 import org.dom4j.QName;
+import org.dom4j.io.OutputFormat;
 import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
 import org.eclipse.osgi.util.NLS;
 
 
@@ -1353,7 +1357,7 @@
     /* (non-Javadoc)
      * @see org.apache.directory.studio.apacheds.configuration.model.ServerXmlIO#toXml(org.apache.directory.studio.apacheds.configuration.model.ServerConfiguration)
      */
-    public String toXml( ServerConfiguration serverConfiguration )
+    public String toXml( ServerConfiguration serverConfiguration ) throws IOException
     {
         // Creating the document
         Document document = DocumentHelper.createDocument();
@@ -1407,17 +1411,18 @@
         // CustomEditorConfigurer Bean
         createCustomEditorConfigurerBean( root );
 
-        Document stylizedDocument = null;
-        try
-        {
-            stylizedDocument = styleDocument( document );
-        }
-        catch ( TransformerException e )
-        {
-            // Will never occur
-        }
-
-        return stylizedDocument.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();
     }
 
 

Modified: directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v153/ServerXmlIOV153.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v153/ServerXmlIOV153.java?rev=803048&r1=803047&r2=803048&view=diff
==============================================================================
--- directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v153/ServerXmlIOV153.java
(original)
+++ directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v153/ServerXmlIOV153.java
Tue Aug 11 10:00:28 2009
@@ -20,7 +20,10 @@
 package org.apache.directory.studio.apacheds.configuration.model.v153;
 
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -29,7 +32,6 @@
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
-import javax.xml.transform.TransformerException;
 
 import org.apache.directory.studio.apacheds.configuration.StudioEntityResolver;
 import org.apache.directory.studio.apacheds.configuration.model.AbstractServerXmlIO;
@@ -41,7 +43,9 @@
 import org.dom4j.Element;
 import org.dom4j.Namespace;
 import org.dom4j.QName;
+import org.dom4j.io.OutputFormat;
 import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
 import org.eclipse.osgi.util.NLS;
 
 
@@ -1410,7 +1414,7 @@
     /* (non-Javadoc)
      * @see org.apache.directory.studio.apacheds.configuration.model.ServerXmlIO#toXml(org.apache.directory.studio.apacheds.configuration.model.ServerConfiguration)
      */
-    public String toXml( ServerConfiguration serverConfiguration )
+    public String toXml( ServerConfiguration serverConfiguration ) throws IOException
     {
         // Creating the document
         Document document = DocumentHelper.createDocument();
@@ -1464,17 +1468,18 @@
         // CustomEditorConfigurer Bean
         createCustomEditorConfigurerBean( root );
 
-        Document stylizedDocument = null;
-        try
-        {
-            stylizedDocument = styleDocument( document );
-        }
-        catch ( TransformerException e )
-        {
-            // Will never occur
-        }
-
-        return stylizedDocument.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();
     }
 
 

Modified: directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v154/ServerXmlIOV154.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v154/ServerXmlIOV154.java?rev=803048&r1=803047&r2=803048&view=diff
==============================================================================
--- directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v154/ServerXmlIOV154.java
(original)
+++ directory/studio/trunk/apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/v154/ServerXmlIOV154.java
Tue Aug 11 10:00:28 2009
@@ -20,13 +20,14 @@
 package org.apache.directory.studio.apacheds.configuration.model.v154;
 
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
-import javax.xml.transform.TransformerException;
-
 import org.apache.directory.studio.apacheds.configuration.StudioEntityResolver;
 import org.apache.directory.studio.apacheds.configuration.model.AbstractServerXmlIO;
 import org.apache.directory.studio.apacheds.configuration.model.ServerConfiguration;
@@ -37,7 +38,9 @@
 import org.dom4j.Element;
 import org.dom4j.Namespace;
 import org.dom4j.QName;
+import org.dom4j.io.OutputFormat;
 import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
 
 
 /**
@@ -1273,7 +1276,7 @@
     /* (non-Javadoc)
      * @see org.apache.directory.studio.apacheds.configuration.model.ServerXmlIO#toXml(org.apache.directory.studio.apacheds.configuration.model.ServerConfiguration)
      */
-    public String toXml( ServerConfiguration serverConfiguration )
+    public String toXml( ServerConfiguration serverConfiguration ) throws IOException
     {
         // Creating the document
         Document document = DocumentHelper.createDocument();
@@ -1327,17 +1330,18 @@
         // CustomEditorConfigurer Bean
         createCustomEditorConfigurerBean( root );
 
-        Document stylizedDocument = null;
-        try
-        {
-            stylizedDocument = styleDocument( document );
-        }
-        catch ( TransformerException e )
-        {
-            // Will never occur
-        }
+        // 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 stylizedDocument.asXML();
+        return os.toString();
     }
 
 



Mime
View raw message