From d23d1eb588b985f644bd4c031af51c86689c62ba Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Thu, 28 Sep 2006 13:56:24 +0000 Subject: [PATCH] - Update File action implemented for sandox Modified Files list and website browse screens - Cycle of actions required for upload/edit/update is complete git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3962 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/messages/webclient.properties | 1 + .../web-client-config-wcm-actions.xml | 17 ++- .../alfresco/web/bean/wcm/AVMEditBean.java | 121 +++++++++++++++++- .../web/WEB-INF/faces-config-navigation.xml | 4 + 4 files changed, 138 insertions(+), 5 deletions(-) diff --git a/config/alfresco/messages/webclient.properties b/config/alfresco/messages/webclient.properties index 3c0f76b7ac..e42d6787a9 100644 --- a/config/alfresco/messages/webclient.properties +++ b/config/alfresco/messages/webclient.properties @@ -846,6 +846,7 @@ create_web_content_desc=This wizard helps you to create a new content item for a create_folder=Create Folder create_avm_folder_info=Create a new folder in the website. add_avm_content_dialog_desc=This dialog helps you to add content to a folder. +update_avm_file_desc=Update a file in the website with content from your computer. # New User Wizard messages new_user_title=New User Wizard diff --git a/config/alfresco/web-client-config-wcm-actions.xml b/config/alfresco/web-client-config-wcm-actions.xml index 19eab743a0..de7926c7ff 100644 --- a/config/alfresco/web-client-config-wcm-actions.xml +++ b/config/alfresco/web-client-config-wcm-actions.xml @@ -83,11 +83,23 @@ #{AddAvmContentDialog.start} + + + update + /images/icons/update.gif + #{AVMBrowseBean.setupContentAction} + dialog:updateAvmFile + + #{actionContext.path} + + - + + false + @@ -99,10 +111,11 @@ - + false + diff --git a/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java b/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java index 33174e5e30..afea390396 100644 --- a/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java +++ b/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java @@ -16,6 +16,9 @@ */ package org.alfresco.web.bean.wcm; +import java.io.File; +import java.text.MessageFormat; + import javax.faces.context.FacesContext; import javax.faces.event.ActionEvent; import javax.transaction.UserTransaction; @@ -33,6 +36,8 @@ import org.alfresco.web.app.AlfrescoNavigationHandler; import org.alfresco.web.app.Application; import org.alfresco.web.app.servlet.DownloadContentServlet; import org.alfresco.web.bean.CheckinCheckoutBean; +import org.alfresco.web.bean.FileUploadBean; +import org.alfresco.web.bean.repository.Node; import org.alfresco.web.bean.repository.Repository; import org.alfresco.web.templating.OutputUtil; import org.alfresco.web.templating.TemplatingService; @@ -44,11 +49,16 @@ import org.alfresco.web.ui.common.Utils; * @author Kevin Roast */ public class AVMEditBean -{ - private String documentContent = null; +{ + private static final String MSG_ERROR_UPDATE = "error_update"; + private static final String MSG_UPLOAD_SUCCESS = "file_upload_success"; + private String documentContent = null; private String editorOutput = null; + private File file; + private String fileName; + /** AVM service bean reference */ protected AVMService avmService; @@ -161,6 +171,34 @@ public class AVMEditBean this.editorOutput = editorOutput; } + /** + * @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; + } + + /** + * @return Returns the message to display when a file has been uploaded + */ + public String getFileUploadSuccessMsg() + { + String msg = Application.getMessage(FacesContext.getCurrentInstance(), MSG_UPLOAD_SUCCESS); + return MessageFormat.format(msg, new Object[] {getFileName()}); + } + // ------------------------------------------------------------------------------ // Action event handlers @@ -288,12 +326,89 @@ public class AVMEditBean return outcome; } + /** + * Action called upon completion of the Update File page + */ + public String updateFileOK() + { + String outcome = null; + + UserTransaction tx = null; + + AVMNode node = getAvmNode(); + if (node != null && this.getFileName() != null) + { + try + { + FacesContext context = FacesContext.getCurrentInstance(); + tx = Repository.getUserTransaction(context); + tx.begin(); + + // get an updating writer that we can use to modify the content on the current node + ContentWriter writer = this.contentService.getWriter(node.getNodeRef(), ContentModel.PROP_CONTENT, true); + + // also update the mime type in case a different type of file is uploaded + String mimeType = Repository.getMimeTypeForFileName(context, this.fileName); + writer.setMimetype(mimeType); + + writer.putContent(this.file); + + // commit the transaction + tx.commit(); + + // clear action context + resetState(); + + outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME; + } + catch (Throwable err) + { + // rollback the transaction + try { if (tx != null) {tx.rollback();} } catch (Exception tex) {} + Utils.addErrorMessage(Application.getMessage( + FacesContext.getCurrentInstance(), MSG_ERROR_UPDATE) + err.getMessage(), err); + } + } + + return outcome; + } + + /** + * Deals with the cancel button being pressed on the upload file page + */ + public String cancel() + { + // reset the state + resetState(); + + return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME; + } + private void resetState() { // clean up and clear action context - //clearUpload(); + clearUpload(); this.avmBrowseBean.setAvmNode(null); setDocumentContent(null); setEditorOutput(null); } + + /** + * Clear form state and upload file bean + */ + private void clearUpload() + { + // delete the temporary file we uploaded earlier + if (this.file != null) + { + this.file.delete(); + } + + this.file = null; + this.fileName = null; + + // remove the file upload bean from the session + FacesContext ctx = FacesContext.getCurrentInstance(); + ctx.getExternalContext().getSessionMap().remove(FileUploadBean.FILE_UPLOAD_BEAN_NAME); + } } diff --git a/source/web/WEB-INF/faces-config-navigation.xml b/source/web/WEB-INF/faces-config-navigation.xml index 27c336f612..06daff1657 100644 --- a/source/web/WEB-INF/faces-config-navigation.xml +++ b/source/web/WEB-INF/faces-config-navigation.xml @@ -900,6 +900,10 @@ editAvmXmlInline /jsp/wcm/edit-xml-inline.jsp + + updateAvmFile + /jsp/wcm/update-file.jsp + cancel /jsp/wcm/browse-sandbox.jsp