form.getTextParameterValues("scriptLanguage")[0];
String mediaType = form.getTextParameterValues("mediaType")[0];
String producedType =
form.getTextParameterValues("producedType")[0];
ScriptLanguageDescription sld =
extractLanguageAndVersion(scriptLanguageAndVersion);
String fileChoice = form.getTextParameterValues("fileChoice")[0];
String scriptName = "unnamed";
byte[] scriptFileBytes = new byte[0];
if(fileChoice.equals("file")) {
FormFile formFile =
form.getFormFileParameterValues("scriptFile")[0];
scriptFileBytes = formFile.getContent();
if (scriptFileBytes == null || (scriptFileBytes.length == 0)) {
String message = "no script uploaded";
logger.warn(message);
throw new WebApplicationException(Response.status(
Status.BAD_REQUEST).entity(message).build());
}
scriptName = formFile.getFileName();
if(mediaType.trim().equals("")) {
mediaType = formFile.getMediaType().toString();
}
} else if(fileChoice.equals("text")) {
if(form.getTextParameterValues("scriptCode").length > 0) {
scriptFileBytes = form.getTextParameterValues("scriptCode")[0].
getBytes();
}
if(form.getTextParameterValues("scriptName").length > 0) {
scriptName = form.getTextParameterValues("scriptName")[0];
if(scriptName.trim().equals("")) {
scriptName = "unnamed";
}
}
if(mediaType.trim().equals("")) {
mediaType = "text/plain";
}
}
if(!scriptExecutionUri.trim().equals("")) {
if(!saveExecutionUri(scriptExecutionUri, scriptUri)) {
logger.warn("The execution URI {} is already used.",
scriptExecutionUri);
return Response.status(Status.BAD_REQUEST).build();
}
}
saveScript(scriptUri, scriptFileBytes, scriptName,
sld.getLanguage(), sld.getVersion(), mediaType, producedType);
return RedirectUtil.createSeeOtherResponse("script-overview", uriInfo);
}