mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
- 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
This commit is contained in:
@@ -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
|
||||
|
@@ -83,11 +83,23 @@
|
||||
<action-listener>#{AddAvmContentDialog.start}</action-listener>
|
||||
</action>
|
||||
|
||||
<!-- Update document -->
|
||||
<action id="update_file">
|
||||
<label-id>update</label-id>
|
||||
<image>/images/icons/update.gif</image>
|
||||
<action-listener>#{AVMBrowseBean.setupContentAction}</action-listener>
|
||||
<action>dialog:updateAvmFile</action>
|
||||
<params>
|
||||
<param name="id">#{actionContext.path}</param>
|
||||
</params>
|
||||
</action>
|
||||
|
||||
<!-- Actions for a document in the AVM Browse screen -->
|
||||
|
||||
<!-- Actions for a file in the AVM Browse screen -->
|
||||
<action-group id="avm_file_browse">
|
||||
<show-link>false</show-link>
|
||||
<action idref="edit_file" />
|
||||
<action idref="update_file" />
|
||||
<action idref="preview_file" />
|
||||
<action idref="delete_file" />
|
||||
</action-group>
|
||||
@@ -99,10 +111,11 @@
|
||||
<action idref="delete_folder" />
|
||||
</action-group>
|
||||
|
||||
<!-- Actions for a document in Modified Files list -->
|
||||
<!-- Actions for a file in Modified Files list -->
|
||||
<action-group id="avm_file_modified">
|
||||
<show-link>false</show-link>
|
||||
<action idref="edit_file" />
|
||||
<action idref="update_file" />
|
||||
<action idref="submit" />
|
||||
<action idref="preview_file" />
|
||||
<action idref="delete_file" />
|
||||
|
@@ -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;
|
||||
@@ -45,10 +50,15 @@ import org.alfresco.web.ui.common.Utils;
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -900,6 +900,10 @@
|
||||
<from-outcome>editAvmXmlInline</from-outcome>
|
||||
<to-view-id>/jsp/wcm/edit-xml-inline.jsp</to-view-id>
|
||||
</navigation-case>
|
||||
<navigation-case>
|
||||
<from-outcome>updateAvmFile</from-outcome>
|
||||
<to-view-id>/jsp/wcm/update-file.jsp</to-view-id>
|
||||
</navigation-case>
|
||||
<navigation-case>
|
||||
<from-outcome>cancel</from-outcome>
|
||||
<to-view-id>/jsp/wcm/browse-sandbox.jsp</to-view-id>
|
||||
|
Reference in New Issue
Block a user