You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2007/09/17 15:02:10 UTC
svn commit: r576406 - in
/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor:
PluginUtils.java model/io/ProjectsExporter.java
model/io/ProjectsImporter.java view/wizards/ExportProjectsWizard.java
Author: pamarcelot
Date: Mon Sep 17 06:02:06 2007
New Revision: 576406
URL: http://svn.apache.org/viewvc?rev=576406&view=rev
Log:
Fix for DIRSTUDIO-201 (Project Name mess up if it contains non-ascii chars).
Modified:
directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/PluginUtils.java
directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/ProjectsExporter.java
directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/ProjectsImporter.java
directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportProjectsWizard.java
Modified: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/PluginUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/PluginUtils.java?rev=576406&r1=576405&r2=576406&view=diff
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/PluginUtils.java (original)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/PluginUtils.java Mon Sep 17 06:02:06 2007
@@ -20,10 +20,11 @@
package org.apache.directory.studio.schemaeditor;
-import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileWriter;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
@@ -43,6 +44,8 @@
import org.apache.directory.studio.schemaeditor.model.io.XMLSchemaFileImportException;
import org.apache.directory.studio.schemaeditor.model.io.XMLSchemaFileImporter;
import org.apache.directory.studio.schemaeditor.view.ViewUtils;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.XMLWriter;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
@@ -174,14 +177,24 @@
*/
public static void saveProjects()
{
- ProjectsHandler projectsHandler = Activator.getDefault().getProjectsHandler();
- File projectsFile = getProjectsFile();
-
try
{
- BufferedWriter buffWriter = new BufferedWriter( new FileWriter( projectsFile ) );
- buffWriter.write( ProjectsExporter.toXml( projectsHandler.getProjects().toArray( new Project[0] ) ) );
- buffWriter.close();
+ OutputFormat outformat = OutputFormat.createPrettyPrint();
+ outformat.setEncoding( "UTF-8" );
+ XMLWriter writer = new XMLWriter( new FileOutputStream( getProjectsFile() ), outformat );
+ writer.write( ProjectsExporter.toDocument( Activator.getDefault().getProjectsHandler().getProjects()
+ .toArray( new Project[0] ) ) );
+ writer.flush();
+ }
+ catch ( UnsupportedEncodingException e )
+ {
+ PluginUtils.logError( "An error occured when saving the projects.", e );
+ ViewUtils.displayErrorMessageBox( "Projects Saving Error", "An error occured when saving the projects." );
+ }
+ catch ( FileNotFoundException e )
+ {
+ PluginUtils.logError( "An error occured when saving the projects.", e );
+ ViewUtils.displayErrorMessageBox( "Projects Saving Error", "An error occured when saving the projects." );
}
catch ( IOException e )
{
Modified: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/ProjectsExporter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/ProjectsExporter.java?rev=576406&r1=576405&r2=576406&view=diff
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/ProjectsExporter.java (original)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/ProjectsExporter.java Mon Sep 17 06:02:06 2007
@@ -20,15 +20,9 @@
package org.apache.directory.studio.schemaeditor.model.io;
+import java.io.UnsupportedEncodingException;
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.studio.schemaeditor.Activator;
import org.apache.directory.studio.schemaeditor.model.Project;
import org.apache.directory.studio.schemaeditor.model.ProjectType;
import org.apache.directory.studio.schemaeditor.model.Schema;
@@ -36,8 +30,6 @@
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
-import org.dom4j.io.DocumentResult;
-import org.dom4j.io.DocumentSource;
/**
@@ -59,15 +51,15 @@
/**
- * Converts the given project to its code representation
- * in XML file format.
- *
+ * Converts the given project to its representation
+ * in Dom4J Document.
+ *
* @param project
* the project to convert
* @return
- * the corresponding code representation
+ * the corresponding Dom4j Document representation
*/
- public static String toXml( Project project )
+ public static Document toDocument( Project project )
{
// Creating the Document
Document document = DocumentHelper.createDocument();
@@ -75,20 +67,20 @@
// Adding the project
addProject( project, document );
- return styleDocument( document ).asXML();
+ return document;
}
/**
- * Converts the given projects to their code representation
- * in XML file format.
+ * Converts the given projects to their representation
+ * in Dom4J Document.
*
* @param projects
* the projects to convert
* @return
- * the corresponding code representation
+ * the corresponding Dom4j Document representation
*/
- public static String toXml( Project[] projects )
+ public static Document toDocument( Project[] projects )
{
// Creating the Document
Document document = DocumentHelper.createDocument();
@@ -102,7 +94,7 @@
}
}
- return styleDocument( document ).asXML();
+ return document;
}
@@ -125,7 +117,15 @@
String name = project.getName();
if ( ( name != null ) && ( !name.equals( "" ) ) )
{
- element.addAttribute( NAME_TAG, name );
+ try
+ {
+ element.addAttribute( NAME_TAG, new String ( name.getBytes("UTF-8"), "UTF-8") );
+ }
+ catch ( UnsupportedEncodingException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
// Type
@@ -158,45 +158,5 @@
XMLSchemaFileExporter
.addSchemas( project.getSchemaHandler().getSchemas().toArray( new Schema[0] ), element );
}
- }
-
-
- /**
- * 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;
}
}
Modified: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/ProjectsImporter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/ProjectsImporter.java?rev=576406&r1=576405&r2=576406&view=diff
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/ProjectsImporter.java (original)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/ProjectsImporter.java Mon Sep 17 06:02:06 2007
@@ -191,7 +191,6 @@
for ( SchemaConnector sc : schemaConnectors )
{
if ( sc.getId().equalsIgnoreCase( schemaConnectorId ) )
- ;
{
schemaConnector = sc;
}
Modified: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportProjectsWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportProjectsWizard.java?rev=576406&r1=576405&r2=576406&view=diff
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportProjectsWizard.java (original)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportProjectsWizard.java Mon Sep 17 06:02:06 2007
@@ -20,9 +20,10 @@
package org.apache.directory.studio.schemaeditor.view.wizards;
-import java.io.BufferedWriter;
-import java.io.FileWriter;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import org.apache.directory.studio.schemaeditor.Activator;
@@ -30,6 +31,8 @@
import org.apache.directory.studio.schemaeditor.model.Project;
import org.apache.directory.studio.schemaeditor.model.io.ProjectsExporter;
import org.apache.directory.studio.schemaeditor.view.ViewUtils;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.XMLWriter;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -90,10 +93,26 @@
try
{
- BufferedWriter buffWriter = new BufferedWriter( new FileWriter( exportDirectory + "/"
- + project.getName() + ".schemaproject" ) );
- buffWriter.write( ProjectsExporter.toXml( project ) );
- buffWriter.close();
+ OutputFormat outformat = OutputFormat.createPrettyPrint();
+ outformat.setEncoding( "UTF-8" );
+ XMLWriter writer = new XMLWriter( new FileOutputStream( exportDirectory + "/"
+ + project.getName() + ".schemaproject" ), outformat );
+ writer.write( ProjectsExporter.toDocument( project ) );
+ writer.flush();
+ }
+ catch ( UnsupportedEncodingException e )
+ {
+ PluginUtils.logError(
+ "An error occured when saving the project " + project.getName() + ".", e );
+ ViewUtils.displayErrorMessageBox( "Error", "An error occured when saving the project "
+ + project.getName() + "." );
+ }
+ catch ( FileNotFoundException e )
+ {
+ PluginUtils.logError(
+ "An error occured when saving the project " + project.getName() + ".", e );
+ ViewUtils.displayErrorMessageBox( "Error", "An error occured when saving the project "
+ + project.getName() + "." );
}
catch ( IOException e )
{