nameParts[0];
// create the directory, if it does not exist
File directory = new File(jsServiceDirectory);
if (!directory.exists() && !directory.mkdirs()) {
throw new CarbonException("Unable to create directory " + directory.getName());
}
if ("js".equals(type)) {
contentsFilePath = jsServiceDirectory + File.separator + nameParts[1] +
MashupConstants.JS_SERVICE_EXTENSION;
} else {
File resourcesDirectory =
new File(jsServiceDirectory, nameParts[1] + ".resources");
File webResourcesDirectory = new File(resourcesDirectory, "www");
if (!resourcesDirectory.mkdir()) {
throw new CarbonException(
"Unable to create directory " + resourcesDirectory.getName());
}
if (!webResourcesDirectory.mkdir()) {
throw new CarbonException(
"Unable to create directory " + webResourcesDirectory.getName());
}
if ("html".equals(type)) {
contentsFilePath = webResourcesDirectory + File.separator + "index.html";
} else if ("gadget".equals(type)) {
contentsFilePath = webResourcesDirectory + File.separator + "gadget.xml";
}
}
File file = new File(contentsFilePath);
try {
file.createNewFile();
} catch (IOException e) {
throw new CarbonException(
"Error while creating the file for the new service " + serviceName, e);
}
} else {
if (!"js".equals(type)) {
File resourcesDirectory = (File) axisService.
getParameterValue(MashupConstants.RESOURCES_FOLDER);
File webResourcesDirectory = new File(resourcesDirectory, "www");
if (!resourcesDirectory.exists() && !resourcesDirectory.mkdir()) {
throw new CarbonException(
"Unable to create directory " + resourcesDirectory.getName());
}
if (!webResourcesDirectory.exists() && !webResourcesDirectory.mkdir()) {
throw new CarbonException(
"Unable to create directory " + webResourcesDirectory.getName());
}
if ("html".equals(type)) {
contentsFilePath = webResourcesDirectory + File.separator + "index.html";
} else if ("gadget".equals(type)) {
contentsFilePath = webResourcesDirectory + File.separator + "gadget.xml";
}
File file = new File(contentsFilePath);
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
throw new CarbonException(
"Error while creating the file for the new service " +
serviceName, e);
}
}
} else {
contentsFilePath =
(String) axisService.getParameterValue(MashupConstants.SERVICE_JS);
}
}
//Writing the file with the source provided
BufferedWriter out = new BufferedWriter(new FileWriter(contentsFilePath));
out.write(contents);
out.flush();
out.close();
success = true;
} catch (AxisFault axisFault) {
throw new CarbonException("Cannot save service Source", axisFault);
} catch (IOException e) {
throw new CarbonException("Cannot save service Source", e);
}
return success;
}