use of org.alfresco.web.bean.FileUploadBean in project acs-community-packaging by Alfresco.
the class ImportDialog method getFileName.
/**
* @return Returns the name of the file
*/
public String getFileName() {
// try and retrieve the file and filename from the file upload bean
// representing the file we previously uploaded.
FacesContext ctx = FacesContext.getCurrentInstance();
FileUploadBean fileBean = (FileUploadBean) ctx.getExternalContext().getSessionMap().get(FileUploadBean.FILE_UPLOAD_BEAN_NAME);
if (fileBean != null) {
this.fileName = fileBean.getFileName();
this.file = fileBean.getFile();
}
return this.fileName;
}
use of org.alfresco.web.bean.FileUploadBean in project acs-community-packaging by Alfresco.
the class AddContentDialog method setFileName.
/**
* @param fileName The name of the file
*/
public void setFileName(String fileName) {
this.fileName = fileName;
// we also need to keep the file upload bean in sync
FacesContext ctx = FacesContext.getCurrentInstance();
FileUploadBean fileBean = (FileUploadBean) ctx.getExternalContext().getSessionMap().get(FileUploadBean.FILE_UPLOAD_BEAN_NAME);
if (fileBean != null) {
fileBean.setFileName(this.fileName);
}
}
use of org.alfresco.web.bean.FileUploadBean in project acs-community-packaging by Alfresco.
the class UploadFileServlet method service.
/**
* @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@SuppressWarnings("unchecked")
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...");
FacesContext context = FacesContext.getCurrentInstance();
Map<Object, Object> session = context.getExternalContext().getSessionMap();
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);
}
// ADB-41: Ignore non-existent files i.e. 0 byte streams.
if (allowZeroByteFiles() == true || item.getSize() > 0) {
// 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() + " size " + tempFile.length() + " bytes created from upload filename: " + filename);
}
} else {
if (logger.isWarnEnabled())
logger.warn("Ignored file '" + filename + "' as there was no content, this is either " + "caused by uploading an empty file or a file path that does not exist on the client.");
}
}
}
}
session.put(FileUploadBean.getKey(uploadId), bean);
if (bean.getFile() == null && uploadId != null && logger.isWarnEnabled()) {
logger.warn("no file uploaded for upload id: " + uploadId);
}
if (returnPage == null || returnPage.length() == 0) {
throw new AlfrescoRuntimeException("return-page parameter has not been supplied");
}
JSONObject json;
try {
json = new JSONObject(returnPage);
if (json.has("id") && json.has("args")) {
// finally redirect
if (logger.isDebugEnabled()) {
logger.debug("Sending back javascript response " + returnPage);
}
response.setContentType(MimetypeMap.MIMETYPE_HTML);
response.setCharacterEncoding("utf-8");
// work-around for WebKit protection against embedded javascript on POST body response
response.setHeader("X-XSS-Protection", "0");
final PrintWriter out = response.getWriter();
out.println("<html><body><script type=\"text/javascript\">");
out.println("window.parent.upload_complete_helper(");
out.println("'" + json.getString("id") + "'");
out.println(", ");
out.println(json.getJSONObject("args"));
out.println(");");
out.println("</script></body></html>");
out.close();
}
} catch (JSONException e) {
// finally redirect
if (logger.isDebugEnabled())
logger.debug("redirecting to: " + returnPage);
response.sendRedirect(returnPage);
}
if (logger.isDebugEnabled())
logger.debug("upload complete");
} catch (Throwable error) {
handleUploadException(request, response, error, returnPage);
}
}
use of org.alfresco.web.bean.FileUploadBean in project acs-community-packaging by Alfresco.
the class AddContentDialog method getFileName.
/**
* @return Returns the name of the file
*/
public String getFileName() {
// try and retrieve the file and filename from the file upload bean
// representing the file we previously uploaded.
FacesContext ctx = FacesContext.getCurrentInstance();
FileUploadBean fileBean = (FileUploadBean) ctx.getExternalContext().getSessionMap().get(FileUploadBean.FILE_UPLOAD_BEAN_NAME);
if (fileBean != null) {
this.file = fileBean.getFile();
this.fileName = fileBean.getFileName();
}
return this.fileName;
}
use of org.alfresco.web.bean.FileUploadBean in project acs-community-packaging by Alfresco.
the class CheckinCheckoutDialog method setFileName.
/**
* @param fileName The name of the file
*/
public void setFileName(String fileName) {
property.setFileName(fileName);
// we also need to keep the file upload bean in sync
FacesContext ctx = FacesContext.getCurrentInstance();
FileUploadBean fileBean = (FileUploadBean) ctx.getExternalContext().getSessionMap().get(FileUploadBean.FILE_UPLOAD_BEAN_NAME);
if (fileBean != null) {
fileBean.setFileName(property.getFileName());
}
}
Aggregations