tempDataList = fileItemsMap.get("jsFilename");
}
JSServiceUploadClient serviceUploaderClient =
new JSServiceUploadClient(configurationContext, serverURL, cookie);
MashupServiceAdminClient client =
new MashupServiceAdminClient(cookie, serverURL, configurationContext);
List<JSServiceUploadData> jsServiceDataList = new ArrayList<JSServiceUploadData>();
ArchiveManipulator archiveManipulator = new ArchiveManipulator();
String[] serviceNames = new String[tempDataList.size()];
ArrayList<File> tempFiles = new ArrayList<File>();
try {
for (int i = 0; i < tempDataList.size(); i++) {
FileItemData fileData = tempDataList.get(i);
String fileName = getFileName(fileData.getFileItem().getName());
checkServiceFileExtensionValidity(fileName, ALLOWED_FILE_EXTENSIONS);
JSServiceUploadData tempData = new JSServiceUploadData();
tempData.setFileName(fileName);
tempData.setDataHandler(fileData.getDataHandler());
if (fileName.endsWith(".zip")) {
//validating the content of the zip file.
File zipFile = ((DeferredFileOutputStream) fileData.getFileItem().
getOutputStream()).getFile();
fileData.getFileItem().write(zipFile);
tempFiles.add(zipFile);
String[] files = archiveManipulator.check(zipFile.getAbsolutePath());
boolean jsFile = false;
boolean resourceFolder = false;
//validates the structure of zip file. i.e. zip file shoud contains only one
//.js file in the root folder and no other file types, but directories.
for (String file : files) {
if (file.indexOf("/") == -1) {
String extension = file.substring(file.indexOf(".") + 1);
String jsName = file.substring(0, (file.indexOf(".")));
if ("js".equals(extension)) {
if (jsFile) {
message = getFileName(fileData.getFileItem().getName()) +
" file should contain only " +
"one '.js' file in the root folder";
log.error(message);
CarbonUIMessage
.sendCarbonUIMessage(message, CarbonUIMessage.ERROR,
request, response,
getContextRoot(request) + "/" + webContext +
"/js_service/upload.jsp");
return false;
}
serviceNames[i] = username + "/" + jsName;
jsFile = true;
} else if ("resources".equals(extension)) {
if(resourceFolder) {
message = getFileName(fileData.getFileItem().getName()) +
" file contains an invalid file in the root folder : " +
file;
log.error(message);
CarbonUIMessage.sendCarbonUIMessage(message, CarbonUIMessage.ERROR,
request, response,
getContextRoot(request) + "/" + webContext +
"/js_service/upload.jsp");
return false;
}
resourceFolder = true;
} else {
message =getFileName( fileData.getFileItem().getName()) +
" file contains an invalid file in the root folder : " +
file;
log.error(message);
CarbonUIMessage.sendCarbonUIMessage(message, CarbonUIMessage.ERROR,
request, response,
getContextRoot(request) + "/" + webContext +
"/js_service/upload.jsp");
return false;
}
}
}
if (!jsFile) {
message =
getFileName(fileData.getFileItem().getName()) + " file doesn't contain a '.js'" +
" file in the root folder";
log.error(message);
CarbonUIMessage.sendCarbonUIMessage(message, CarbonUIMessage.ERROR, request,
response, getContextRoot(request) + "/" + webContext +
"/js_service/upload.jsp");
return false;
}
jsServiceDataList.add(tempData);
} else {
message = "File with extension " + fileName + " is not supported!";
CarbonUIMessage
.sendCarbonUIMessage(message, CarbonUIMessage.ERROR, request, response,
getContextRoot(request) + "/" + webContext + "/js_service/upload.jsp");
log.error(message);
return false;
}
}
String[] existingServices = client.doesServicesExists(serviceNames);
if (existingServices != null && existingServices.length != 0) {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < existingServices.length; i++) {
String existingService =
existingServices[i].substring(existingServices[i].indexOf("/") + 1);