public static void saveProjects()
{
try
{
// Saving the projects to the temp projects file
OutputFormat outformat = OutputFormat.createPrettyPrint();
outformat.setEncoding( "UTF-8" );
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" );
FileUtils.writeStringToFile( getProjectsFile(), content, "UTF-8" );
}
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" );
XMLWriter writer = new XMLWriter( new FileOutputStream( getProjectsFile() ), outformat );
writer.write( ProjectsExporter.toDocument( Activator.getDefault().getProjectsHandler().getProjects()
.toArray( new Project[0] ) ) );
writer.flush();
}