Author: pamarcelot
Date: Mon Dec 17 09:58:50 2007
New Revision: 604946
URL: http://svn.apache.org/viewvc?rev=604946&view=rev
Log:
Part of a fix for DIRSTUDIO-224 (Can't Open Schema View with JDK 6.0).
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/OpenLdapSchemaFileImporter.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/model/io/XMLSchemaFileImporter.java
directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportProjectsWizard.java
directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizard.java
directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromXmlWizard.java
directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromXmlWizardPage.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=604946&r1=604945&r2=604946&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 Dec 17 09:58:50 2007
@@ -21,9 +21,13 @@
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.net.URISyntaxException;
import java.net.URL;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -147,20 +151,27 @@
public static void loadProjects()
{
ProjectsHandler projectsHandler = Activator.getDefault().getProjectsHandler();
+ // PluginUtils.logInfo( null, "ProjectsHandler : {0}", projectsHandler );//
TODO Remove
File projectsFile = getProjectsFile();
+ // PluginUtils.logInfo( null, "projectsFile : {0}", projectsFile );// TODO
Remove
if ( projectsFile.exists() )
{
Project[] projects = null;
try
{
- projects = ProjectsImporter.getProjects( projectsFile.getAbsolutePath() );
+ projects = ProjectsImporter.getProjects( new FileInputStream( projectsFile
), projectsFile
+ .getAbsolutePath() );
}
catch ( ProjectsImportException e )
{
- PluginUtils.logError( "An error occured when loading the projects.", e );
- ViewUtils.displayErrorMessageBox( "Projects Loading Error",
- "An error occured when loading the projects." );
+ handleErrorWhileLoadingProjects( projectsFile, e );
+ return;
+ }
+ catch ( FileNotFoundException e )
+ {
+ handleErrorWhileLoadingProjects( projectsFile, e );
+ return;
}
for ( Project project : projects )
@@ -172,6 +183,21 @@
/**
+ * This method is called when an exception is raised when trying to load the Projects
file.
+ *
+ * @param projectsFile
+ * the Projects file
+ * @param e
+ * the exception raised
+ */
+ private static void handleErrorWhileLoadingProjects( File projectsFile, Exception e )
+ {
+ PluginUtils.logError( "An error occured when loading the projects.", e );
+ ViewUtils.displayErrorMessageBox( "Projects Loading Error", "An error occured when
loading the projects." );
+ }
+
+
+ /**
* Saves the projects in the Projects File.
*/
public static void saveProjects()
@@ -210,6 +236,24 @@
/**
+ * Logs the given message and exception with the ERROR status level.
+ *
+ * @param message
+ * the message
+ * @param exception
+ * the exception
+ */
+ public static void logInfo( Throwable exception, String message, Object... args )
+ {
+ String msg = MessageFormat.format( message, args );
+ Activator.getDefault().getLog()
+ .log(
+ new Status( Status.ERROR, Activator.getDefault().getBundle().getSymbolicName(),
Status.OK, msg,
+ exception ) );
+ }
+
+
+ /**
* Logs the given message and exception with the WARNING status level.
*
* @param message
@@ -250,10 +294,23 @@
}
else
{
- schema = XMLSchemaFileImporter.getSchema( url.toString() );
+ schema = XMLSchemaFileImporter.getSchema( new FileInputStream( new File(
url.toURI() ) ), url
+ .toString() );
}
}
catch ( XMLSchemaFileImportException e )
+ {
+ PluginUtils.logError( "An error occured when loading the schema " + schemaName
+ ".", e );
+ ViewUtils.displayErrorMessageBox( "Projects Saving Error", "An error occured
when loading the schema "
+ + schemaName + "." );
+ }
+ catch ( FileNotFoundException e )
+ {
+ PluginUtils.logError( "An error occured when loading the schema " + schemaName
+ ".", e );
+ ViewUtils.displayErrorMessageBox( "Projects Saving Error", "An error occured
when loading the schema "
+ + schemaName + "." );
+ }
+ catch ( URISyntaxException e )
{
PluginUtils.logError( "An error occured when loading the schema " + schemaName
+ ".", e );
ViewUtils.displayErrorMessageBox( "Projects Saving Error", "An error occured
when loading the schema "
Modified: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/OpenLdapSchemaFileImporter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/OpenLdapSchemaFileImporter.java?rev=604946&r1=604945&r2=604946&view=diff
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/OpenLdapSchemaFileImporter.java
(original)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/OpenLdapSchemaFileImporter.java
Mon Dec 17 09:58:50 2007
@@ -23,7 +23,6 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.net.MalformedURLException;
import java.text.ParseException;
import java.util.List;
@@ -47,6 +46,8 @@
/**
* Extracts the Schema from the given path.
*
+ * @param inputStream
+ * the {@link InputStream} of the file.
* @param path
* the path of the file.
* @return
@@ -54,34 +55,8 @@
* @throws OpenLdapSchemaFileImportException
* if an error occurrs when importing the schema
*/
- public static Schema getSchema( String path ) throws OpenLdapSchemaFileImportException
+ public static Schema getSchema( InputStream inputStream, String path ) throws OpenLdapSchemaFileImportException
{
- File file = new File( path );
-
- // Checking the file properties
- if ( !file.exists() )
- {
- throw new OpenLdapSchemaFileImportException( "The file '" + path + "' does not
exist." );
- }
- else if ( !file.canRead() )
- {
- throw new OpenLdapSchemaFileImportException( "The file '" + path + "' can not
be read." );
- }
-
- InputStream in = null;
- try
- {
- in = file.toURL().openStream();
- }
- catch ( MalformedURLException e )
- {
- throw new OpenLdapSchemaFileImportException( "The file '" + path + "' can not
be read correctly." );
- }
- catch ( IOException e )
- {
- throw new OpenLdapSchemaFileImportException( "The file '" + path + "' can not
be read correctly." );
- }
-
OpenLdapSchemaParser parser = null;
try
{
@@ -94,7 +69,7 @@
try
{
- parser.parse( in );
+ parser.parse( inputStream );
}
catch ( IOException e )
{
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=604946&r1=604945&r2=604946&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 Dec 17 09:58:50 2007
@@ -20,6 +20,7 @@
package org.apache.directory.studio.schemaeditor.model.io;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
@@ -58,6 +59,8 @@
/**
* Extract the project from the given path
*
+ * @param inputStream
+ * the {@link InputStream} of the file
* @param path
* the path of the file
* @return
@@ -65,7 +68,7 @@
* @throws ProjectsImportException
* if an error occurs when importing the project
*/
- public static Project getProject( String path ) throws ProjectsImportException
+ public static Project getProject( InputStream inputStream, String path ) throws ProjectsImportException
{
Project project = new Project();
@@ -73,7 +76,7 @@
Document document = null;
try
{
- document = reader.read( path );
+ document = reader.read( inputStream );
}
catch ( DocumentException e )
{
@@ -93,8 +96,10 @@
/**
- * Extract the projects from the given path
+ * Extract the projects from the given input stream
*
+ * @param inputStream
+ * the {@link InputStream} of the file
* @param path
* the path of the file
* @return
@@ -102,7 +107,7 @@
* @throws ProjectsImportException
* if an error occurs when importing the project
*/
- public static Project[] getProjects( String path ) throws ProjectsImportException
+ public static Project[] getProjects( InputStream inputStream, String path ) throws ProjectsImportException
{
List<Project> projects = new ArrayList<Project>();
@@ -110,10 +115,11 @@
Document document = null;
try
{
- document = reader.read( path );
+ document = reader.read( inputStream );
}
catch ( DocumentException e )
{
+ PluginUtils.logError("The file '" + path + "' can not be read correctly.", e);
throw new ProjectsImportException( "The file '" + path + "' can not be read correctly."
);
}
@@ -263,19 +269,21 @@
/**
* Gets the type of file.
*
+ * @param inputStream
+ * the {@link InputStream} of the file
* @param path
* the path of the file
* @return
* the type of the file
* @throws ProjectsImportException
*/
- public static ProjectFileType getProjectFileType( String path ) throws ProjectsImportException
+ public static ProjectFileType getProjectFileType( InputStream inputStream, String path
) throws ProjectsImportException
{
SAXReader reader = new SAXReader();
Document document = null;
try
{
- document = reader.read( path );
+ document = reader.read( inputStream );
}
catch ( DocumentException e )
{
Modified: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/XMLSchemaFileImporter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/XMLSchemaFileImporter.java?rev=604946&r1=604945&r2=604946&view=diff
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/XMLSchemaFileImporter.java
(original)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/XMLSchemaFileImporter.java
Mon Dec 17 09:58:50 2007
@@ -21,6 +21,7 @@
import java.io.File;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -87,6 +88,8 @@
/**
* Extracts the Schemas from the given path.
*
+ * @param inputStream
+ * the {@link InputStream} of the file
* @param path
* the path of the file.
* @return
@@ -94,13 +97,13 @@
* @throws XMLSchemaFileImportException
* if an error occurs when importing the schema
*/
- public static Schema[] getSchemas( String path ) throws XMLSchemaFileImportException
+ public static Schema[] getSchemas(InputStream inputStream, String path ) throws XMLSchemaFileImportException
{
SAXReader reader = new SAXReader();
Document document = null;
try
{
- document = reader.read( path );
+ document = reader.read( inputStream );
}
catch ( DocumentException e )
{
@@ -120,6 +123,8 @@
/**
* Extracts the Schema from the given path.
*
+ * @param inputStream
+ * the {@link InputStream} of the file
* @param path
* the path of the file.
* @return
@@ -127,13 +132,13 @@
* @throws XMLSchemaFileImportException
* if an error occurs when importing the schema
*/
- public static Schema getSchema( String path ) throws XMLSchemaFileImportException
+ public static Schema getSchema(InputStream inputStream, String path ) throws XMLSchemaFileImportException
{
SAXReader reader = new SAXReader();
Document document = null;
try
{
- document = reader.read( path );
+ document = reader.read( inputStream );
}
catch ( DocumentException e )
{
@@ -812,13 +817,13 @@
* the type of the file
* @throws XMLSchemaFileImportException
*/
- public static SchemaFileType getSchemaFileType( String path ) throws XMLSchemaFileImportException
+ public static SchemaFileType getSchemaFileType( InputStream inputStream, String path
) throws XMLSchemaFileImportException
{
SAXReader reader = new SAXReader();
Document document = null;
try
{
- document = reader.read( path );
+ document = reader.read( inputStream );
}
catch ( DocumentException e )
{
Modified: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportProjectsWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportProjectsWizard.java?rev=604946&r1=604945&r2=604946&view=diff
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportProjectsWizard.java
(original)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportProjectsWizard.java
Mon Dec 17 09:58:50 2007
@@ -21,6 +21,8 @@
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.lang.reflect.InvocationTargetException;
import org.apache.directory.studio.schemaeditor.Activator;
@@ -91,10 +93,18 @@
monitor.subTask( projectFile.getName() );
try
{
- Project project = ProjectsImporter.getProject( projectFile.getAbsolutePath()
);
+ Project project = ProjectsImporter.getProject( new FileInputStream(
projectFile ),
+ projectFile.getAbsolutePath() );
projectsHandler.addProject( project );
}
catch ( ProjectsImportException e )
+ {
+ PluginUtils.logError( "An error occured when importing project
" + projectFile.getName()
+ + ".", e );
+ ViewUtils.displayErrorMessageBox( "Import Error",
+ "An error occured when importing project " + projectFile.getName()
+ "." );
+ }
+ catch ( FileNotFoundException e )
{
PluginUtils.logError( "An error occured when importing project
" + projectFile.getName()
+ ".", e );
Modified: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizard.java?rev=604946&r1=604945&r2=604946&view=diff
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizard.java
(original)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizard.java
Mon Dec 17 09:58:50 2007
@@ -21,6 +21,8 @@
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.lang.reflect.InvocationTargetException;
import org.apache.directory.studio.schemaeditor.Activator;
@@ -97,10 +99,17 @@
monitor.subTask( schemaFile.getName() );
try
{
- Schema schema = OpenLdapSchemaFileImporter.getSchema( schemaFile.getAbsolutePath()
);
+ Schema schema = OpenLdapSchemaFileImporter.getSchema( new FileInputStream(
schemaFile), schemaFile.getAbsolutePath() );
schemaHandler.addSchema( schema );
}
catch ( OpenLdapSchemaFileImportException e )
+ {
+ PluginUtils.logError( "An error occured when importing the schema
" + schemaFile.getName()
+ + ".", e );
+ ViewUtils.displayErrorMessageBox( "Error", "An error occured
when importing the schema "
+ + schemaFile.getName() + "." );
+ }
+ catch ( FileNotFoundException e )
{
PluginUtils.logError( "An error occured when importing the schema
" + schemaFile.getName()
+ ".", e );
Modified: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromXmlWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromXmlWizard.java?rev=604946&r1=604945&r2=604946&view=diff
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromXmlWizard.java
(original)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromXmlWizard.java
Mon Dec 17 09:58:50 2007
@@ -21,6 +21,8 @@
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.lang.reflect.InvocationTargetException;
import org.apache.directory.studio.schemaeditor.Activator;
@@ -82,7 +84,7 @@
page.saveDialogSettings();
// Getting the schemas to be imported
- final String[] selectedSchemasFiles = page.getSelectedSchemaFiles();
+ final File[] selectedSchemasFiles = page.getSelectedSchemaFiles();
schemaChecker.disableModificationsListening();
try
{
@@ -92,20 +94,23 @@
{
monitor.beginTask( "Importing schemas: ", selectedSchemasFiles.length
);
- for ( String schemaFile : selectedSchemasFiles )
+ for ( File schemaFile : selectedSchemasFiles )
{
- monitor.subTask( new File( schemaFile ).getName() );
+ monitor.subTask( schemaFile.getName() );
try
{
- SchemaFileType schemaFileType = XMLSchemaFileImporter.getSchemaFileType(
schemaFile );
+ SchemaFileType schemaFileType = XMLSchemaFileImporter.getSchemaFileType(
new FileInputStream( schemaFile ),
+ schemaFile.getAbsolutePath() );
switch ( schemaFileType )
{
case SINGLE:
- Schema importedSchema = XMLSchemaFileImporter.getSchema(
schemaFile );
+ Schema importedSchema = XMLSchemaFileImporter.getSchema(
new FileInputStream( schemaFile ),
+ schemaFile.getAbsolutePath() );
schemaHandler.addSchema( importedSchema );
break;
case MULTIPLE:
- Schema[] schemas = XMLSchemaFileImporter.getSchemas(
schemaFile );
+ Schema[] schemas = XMLSchemaFileImporter.getSchemas(
new FileInputStream( schemaFile ), schemaFile
+ .getAbsolutePath() );
for ( Schema schema : schemas )
{
schemaHandler.addSchema( schema );
@@ -114,6 +119,12 @@
}
}
catch ( XMLSchemaFileImportException e )
+ {
+ PluginUtils.logError( "An error occured when importing the schema
" + schemaFile + ".", e );
+ ViewUtils.displayErrorMessageBox( "Error", "An error occured
when saving the schema "
+ + schemaFile + "." );
+ }
+ catch ( FileNotFoundException e )
{
PluginUtils.logError( "An error occured when importing the schema
" + schemaFile + ".", e );
ViewUtils.displayErrorMessageBox( "Error", "An error occured
when saving the schema "
Modified: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromXmlWizardPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromXmlWizardPage.java?rev=604946&r1=604945&r2=604946&view=diff
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromXmlWizardPage.java
(original)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromXmlWizardPage.java
Mon Dec 17 09:58:50 2007
@@ -327,17 +327,17 @@
* @return
* the selected schema files
*/
- public String[] getSelectedSchemaFiles()
+ public File[] getSelectedSchemaFiles()
{
Object[] selectedSchemaFile = schemaFilesTableViewer.getCheckedElements();
- List<String> schemaFiles = new ArrayList<String>();
+ List<File> schemaFiles = new ArrayList<File>();
for ( Object schemaFile : selectedSchemaFile )
{
- schemaFiles.add( ( ( File ) schemaFile ).getAbsolutePath() );
+ schemaFiles.add( ( File ) schemaFile );
}
- return schemaFiles.toArray( new String[0] );
+ return schemaFiles.toArray( new File[0] );
}
|