mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
- refactoring to generate and regenerate methods to make it easier to use project level overridden properties, and to at some point (soon) make it possible to make error handling for rendering engines more robust - added a web project object to encapsulate web project properties and provide a central location for getting forms and rendering engines with web project level overridden properties - made select default workflow screen match wireframes - using the same workflowdefault type in the wcm model for web projects and forms. - using outputpathpattern aspect consistently - using commons.io to parse paths - using form name rather than noderef as parameter for selected form from content forms dashlet - fixed bug where rendition properties noderef wasn't being properly associated with renditions causing problems with regenerate - using multivalued properties to track renditions - remove weird registerRendition/registerFormInstanceData calls. no longer necessary since generateRendition and regenerate are done within forminstancedata and rendition - adding default workflow parameters as property of Form - adding a unique name property to rendering engine templates to allow for looking one up by name git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4702 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
174 lines
6.2 KiB
Java
174 lines
6.2 KiB
Java
/*
|
|
* Copyright (C) 2005 Alfresco, Inc.
|
|
*
|
|
* Licensed under the Mozilla Public License version 1.1
|
|
* with a permitted attribution clause. You may obtain a
|
|
* copy of the License at
|
|
*
|
|
* http://www.alfresco.org/legal/license.txt
|
|
*
|
|
* Unless required by applicable law or agreed to in writing,
|
|
* software distributed under the License is distributed on an
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
* either express or implied. See the License for the specific
|
|
* language governing permissions and limitations under the
|
|
* License.
|
|
*/
|
|
package org.alfresco.web.app.servlet;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.PrintWriter;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
import javax.servlet.ServletException;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
import org.alfresco.error.AlfrescoRuntimeException;
|
|
import org.alfresco.util.TempFileProvider;
|
|
import org.alfresco.web.app.Application;
|
|
import org.alfresco.web.bean.FileUploadBean;
|
|
import org.apache.commons.io.FilenameUtils;
|
|
import org.apache.commons.fileupload.FileItem;
|
|
import org.apache.commons.fileupload.RequestContext;
|
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
|
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
|
import org.apache.commons.fileupload.servlet.ServletRequestContext;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
/**
|
|
* Servlet that takes a file uploaded via a browser and represents it as an
|
|
* UploadFileBean in the session
|
|
*
|
|
* @author gavinc
|
|
*/
|
|
public class UploadFileServlet extends BaseServlet
|
|
{
|
|
private static final long serialVersionUID = -5482538466491052873L;
|
|
private static final Log logger = LogFactory.getLog(UploadFileServlet.class);
|
|
|
|
/**
|
|
* @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
|
*/
|
|
protected void service(HttpServletRequest request, HttpServletResponse response)
|
|
throws ServletException, IOException
|
|
{
|
|
String uploadId = null;
|
|
String returnPage = null;
|
|
final RequestContext requestContext = new ServletRequestContext(request);
|
|
boolean isMultipart = ServletFileUpload.isMultipartContent(requestContext);
|
|
|
|
try
|
|
{
|
|
AuthenticationStatus status = servletAuthenticate(request, response);
|
|
if (status == AuthenticationStatus.Failure)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!isMultipart)
|
|
{
|
|
throw new AlfrescoRuntimeException("This servlet can only be used to handle file upload requests, make" +
|
|
"sure you have set the enctype attribute on your form to multipart/form-data");
|
|
}
|
|
|
|
if (logger.isDebugEnabled())
|
|
logger.debug("Uploading servlet servicing...");
|
|
|
|
HttpSession session = request.getSession();
|
|
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
|
|
|
|
// ensure that the encoding is handled correctly
|
|
upload.setHeaderEncoding("UTF-8");
|
|
|
|
List<FileItem> fileItems = upload.parseRequest(request);
|
|
|
|
FileUploadBean bean = new FileUploadBean();
|
|
for (FileItem item : fileItems)
|
|
{
|
|
if(item.isFormField())
|
|
{
|
|
if (item.getFieldName().equalsIgnoreCase("return-page"))
|
|
{
|
|
returnPage = item.getString();
|
|
}
|
|
else if (item.getFieldName().equalsIgnoreCase("upload-id"))
|
|
{
|
|
uploadId = item.getString();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
String filename = item.getName();
|
|
if (filename != null && filename.length() != 0)
|
|
{
|
|
if (logger.isDebugEnabled())
|
|
{
|
|
logger.debug("Processing uploaded file: " + filename);
|
|
}
|
|
// workaround a bug in IE where the full path is returned
|
|
// IE is only available for Windows so only check for the Windows path separator
|
|
filename = FilenameUtils.getName(filename);
|
|
final File tempFile = TempFileProvider.createTempFile("alfresco", ".upload");
|
|
item.write(tempFile);
|
|
bean.setFile(tempFile);
|
|
bean.setFileName(filename);
|
|
bean.setFilePath(tempFile.getAbsolutePath());
|
|
if (logger.isDebugEnabled())
|
|
{
|
|
logger.debug("Temp file: " + tempFile.getAbsolutePath() +
|
|
" created from upload filename: " + filename);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
session.setAttribute(FileUploadBean.getKey(uploadId), bean);
|
|
|
|
if (bean.getFile() == null)
|
|
{
|
|
logger.warn("no file uploaded for upload " + uploadId);
|
|
}
|
|
if (returnPage == null || returnPage.length() == 0)
|
|
{
|
|
throw new AlfrescoRuntimeException("return-page parameter has not been supplied");
|
|
}
|
|
|
|
if (returnPage.startsWith("javascript:"))
|
|
{
|
|
returnPage = returnPage.substring("javascript:".length());
|
|
// finally redirect
|
|
if (logger.isDebugEnabled())
|
|
{
|
|
logger.debug("Sending back javascript response " + returnPage);
|
|
}
|
|
|
|
final PrintWriter out = response.getWriter();
|
|
out.println("<html><body><script type=\"text/javascript\">");
|
|
out.println(returnPage);
|
|
out.println("</script></body></html>");
|
|
out.close();
|
|
}
|
|
else
|
|
{
|
|
// finally redirect
|
|
if (logger.isDebugEnabled())
|
|
{
|
|
logger.debug("Upload servicing complete, redirecting to: " + returnPage);
|
|
}
|
|
|
|
response.sendRedirect(returnPage);
|
|
}
|
|
}
|
|
catch (Throwable error)
|
|
{
|
|
Application.handleServletError(getServletContext(), (HttpServletRequest)request,
|
|
(HttpServletResponse)response, error, logger, returnPage);
|
|
}
|
|
}
|
|
}
|