public String processFileUpload(ActionRequest request, ActionResponse response) {
final String METHOD_NAME = "processFileUpload(request,response)";
String fileName = null;
String serverFileName = null;
boolean modifyWebXml = true;
request.getPortletSession().setAttribute(PlutoAdminConstants.MESSAGE_ATTR, new PortletMessage("Deployment unsuccessful", PortletMessageType.ERROR));
// Check the request content type to see if it starts with multipart/
if (PortletDiskFileUpload.isMultipartContent(request))
{
PortletDiskFileUpload dfu = new PortletDiskFileUpload();
//maximum allowed file upload size (10 MB)
dfu.setSizeMax(10 * 1000 * 1000);
//maximum size in memory (vs disk) (100 KB)
dfu.setSizeThreshold(100 * 1000);
try
{
//get the FileItems
List fileItems = dfu.parseRequest(request);
Iterator iter = fileItems.iterator();
while (iter.hasNext())
{
FileItem item = (FileItem) iter.next();
if (item.isFormField())
{
//pass along to render request
String fieldName = item.getFieldName();
String value = item.getString();
response.setRenderParameter(fieldName, value);
if (fieldName.equalsIgnoreCase("NoWebXmlModification")) {
String noWebXmlModification = item.getString();
logWarn(METHOD_NAME, "Don't modify web.xml? " + noWebXmlModification);
if (noWebXmlModification != null) {
modifyWebXml = false;
}
}
}
else
{
//write the uploaded file to a new location
fileName = item.getName();
String contentType = item.getContentType();
long size = item.getSize();
response.setRenderParameter("size", Long.toString(size));
response.setRenderParameter("contentType", contentType);
String tempDir = System.getProperty("java.io.tmpdir");
serverFileName = getRootFilename(File.separatorChar, fileName);
File serverFile = new File(tempDir, serverFileName);
item.write(serverFile);
response.setRenderParameter("serverFileName", serverFileName);
//Add to portletentityregistry.xml
int index = serverFileName.indexOf(".war");
String context = "";
if ( index != -1) {
context = serverFileName.substring(0, index);
} else {
context = serverFileName;
}
//Check to see if a record exists
PortletEntityRegistryXao xao = new PortletEntityRegistryXao();
boolean appExists = xao.applicationExists(context);
ArrayList argList = createDeploymentArgs(serverFileName, tempDir, request, appExists, context);
Map pmap = (HashMap) request.getPortletSession().getAttribute(PlutoAdminConstants.PORTLET_MAP_ATTR);
logDebug(METHOD_NAME, "Arguments for Deploy.main():");
String[] args = arrayListToStringArray(argList);
for (int i =0; i < args.length; i++) {
logDebug(METHOD_NAME, "args["+i+"]="+args[i]);
}
org.apache.pluto.portalImpl.Deploy.main(args);
//NEW: Update web.xml with new servlet elements
if (modifyWebXml) {
updateWebXml(context);
}
if (appExists) {
request.getPortletSession().setAttribute(PlutoAdminConstants.MESSAGE_ATTR, new PortletMessage("Deployment of the new portlet app has been successful, but the portlet app record '" + context + "' already exists in portletentityregistry.xml. " +
"This may have occurred if the portlet was previously partially deployed. If that is the case, continue with this screen and the next to register the portlet in pageregistry.xml. " +
"If you are deploying a previously deployed portlet app, click on the 'Deploy War home' link below and then the 'Hot deploy . . .' link on the resulting page to see your redeployed portlet. " +
"However, caching of the old app may require that you restart Pluto to see the new changes.", PortletMessageType.INFO));
} else {
request.getPortletSession().setAttribute(PlutoAdminConstants.MESSAGE_ATTR, new PortletMessage("Deployment and addition to portletentityregistry.xml successful.", PortletMessageType.SUCCESS));
}
}
}
}
catch (FileUploadException e){
String msg = "File Upload Exception: " + e.getMessage();
logError(METHOD_NAME, msg, e);
throw new PlutoAdminException(e);
} catch (Exception e) {
String msg = "Exception: " + e.getMessage();
logError(METHOD_NAME, msg, e);
throw new PlutoAdminException(e);
}
} else {
//set an error message
request.getPortletSession().setAttribute(PlutoAdminConstants.MESSAGE_ATTR, new PortletMessage("No file appears to have been selected.", PortletMessageType.ERROR));
}
logMethodEnd(METHOD_NAME, serverFileName);
return serverFileName;
}