// get a writer for the workspace configuration file
if (workspaceConfigDirectory != null) {
// a configuration directoy had been specified; create workspace
// configuration in virtual repository file system rather than
// on disk
FileSystem fs = fsc.getFileSystem();
String configDir = workspaceConfigDirectory
+ FileSystem.SEPARATOR + name;
String configFile = configDir + FileSystem.SEPARATOR + WORKSPACE_XML;
try {
// Create the directory
fs.createFolder(configDir);
configWriter = new OutputStreamWriter(
fs.getOutputStream(configFile));
} catch (FileSystemException e) {
throw new ConfigurationException(
"failed to create workspace configuration at path "
+ configFile, e);
}
} else {
File file = new File(directory, WORKSPACE_XML);
try {
configWriter = new FileWriter(file);
} catch (IOException e) {
throw new ConfigurationException(
"failed to create workspace configuration at path "
+ file.getPath(), e);
}
}
// Create the workspace.xml file using the configuration template and
// the configuration writer.
try {
template.setAttribute("name", name);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(
new DOMSource(template), new StreamResult(configWriter));
} catch (TransformerConfigurationException e) {
throw new ConfigurationException(
"Cannot create a workspace configuration writer", e);
} catch (TransformerException e) {
throw new ConfigurationException(
"Cannot create a workspace configuration file", e);
} finally {
try {
configWriter.close();
} catch (IOException ignore) {}
}
// Load the created workspace configuration.
WorkspaceConfig wc;
if (workspaceConfigDirectory != null) {
FileSystem fs = fsc.getFileSystem();
String configDir = workspaceConfigDirectory
+ FileSystem.SEPARATOR + name;
wc = loadWorkspaceConfig(fs, configDir);
} else {
wc = loadWorkspaceConfig(directory);