try
{
// Saving the projects to the temp projects file
OutputFormat outformat = OutputFormat.createPrettyPrint();
outformat.setEncoding( "UTF-8" ); //$NON-NLS-1$
XMLWriter writer = new XMLWriter( new FileOutputStream( getTempProjectsFile() ), outformat );
writer.write( ProjectsExporter.toDocument( Activator.getDefault().getProjectsHandler().getProjects()
.toArray( new Project[0] ) ) );
writer.flush();
// Copying the temp projects file to the final location
String content = FileUtils.readFileToString( getTempProjectsFile(), "UTF-8" ); //$NON-NLS-1$
FileUtils.writeStringToFile( getProjectsFile(), content, "UTF-8" ); //$NON-NLS-1$
}
catch ( IOException e )
{
// If an error occurs when saving to the temp projects file or
// when copying the temp projects file to the final location,
// we try to save the projects directly to the final location.
try
{
OutputFormat outformat = OutputFormat.createPrettyPrint();
outformat.setEncoding( "UTF-8" ); //$NON-NLS-1$
XMLWriter writer = new XMLWriter( new FileOutputStream( getProjectsFile() ), outformat );
writer.write( ProjectsExporter.toDocument( Activator.getDefault().getProjectsHandler().getProjects()
.toArray( new Project[0] ) ) );
writer.flush();
}
catch ( IOException e2 )
{
// If another error occur, we display an error
reportError( Messages.getString( "PluginUtils.ErrorSavingProject" ), e2, Messages