- 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:
Kevin Roast
2006-09-28 13:56:24 +00:00
parent 0f3f56e7d8
commit d23d1eb588
4 changed files with 138 additions and 5 deletions

View File

@@ -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_folder=Create Folder
create_avm_folder_info=Create a new folder in the website. 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. 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 Wizard messages
new_user_title=New User Wizard new_user_title=New User Wizard

View File

@@ -83,11 +83,23 @@
<action-listener>#{AddAvmContentDialog.start}</action-listener> <action-listener>#{AddAvmContentDialog.start}</action-listener>
</action> </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"> <action-group id="avm_file_browse">
<show-link>false</show-link> <show-link>false</show-link>
<action idref="edit_file" /> <action idref="edit_file" />
<action idref="update_file" />
<action idref="preview_file" /> <action idref="preview_file" />
<action idref="delete_file" /> <action idref="delete_file" />
</action-group> </action-group>
@@ -99,10 +111,11 @@
<action idref="delete_folder" /> <action idref="delete_folder" />
</action-group> </action-group>
<!-- Actions for a document in Modified Files list --> <!-- Actions for a file in Modified Files list -->
<action-group id="avm_file_modified"> <action-group id="avm_file_modified">
<show-link>false</show-link> <show-link>false</show-link>
<action idref="edit_file" /> <action idref="edit_file" />
<action idref="update_file" />
<action idref="submit" /> <action idref="submit" />
<action idref="preview_file" /> <action idref="preview_file" />
<action idref="delete_file" /> <action idref="delete_file" />

View File

@@ -16,6 +16,9 @@
*/ */
package org.alfresco.web.bean.wcm; package org.alfresco.web.bean.wcm;
import java.io.File;
import java.text.MessageFormat;
import javax.faces.context.FacesContext; import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent; import javax.faces.event.ActionEvent;
import javax.transaction.UserTransaction; 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.Application;
import org.alfresco.web.app.servlet.DownloadContentServlet; import org.alfresco.web.app.servlet.DownloadContentServlet;
import org.alfresco.web.bean.CheckinCheckoutBean; 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.bean.repository.Repository;
import org.alfresco.web.templating.OutputUtil; import org.alfresco.web.templating.OutputUtil;
import org.alfresco.web.templating.TemplatingService; import org.alfresco.web.templating.TemplatingService;
@@ -44,11 +49,16 @@ import org.alfresco.web.ui.common.Utils;
* @author Kevin Roast * @author Kevin Roast
*/ */
public class AVMEditBean 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 String editorOutput = null;
private File file;
private String fileName;
/** AVM service bean reference */ /** AVM service bean reference */
protected AVMService avmService; protected AVMService avmService;
@@ -161,6 +171,34 @@ public class AVMEditBean
this.editorOutput = editorOutput; 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 // Action event handlers
@@ -288,12 +326,89 @@ public class AVMEditBean
return outcome; 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() private void resetState()
{ {
// clean up and clear action context // clean up and clear action context
//clearUpload(); clearUpload();
this.avmBrowseBean.setAvmNode(null); this.avmBrowseBean.setAvmNode(null);
setDocumentContent(null); setDocumentContent(null);
setEditorOutput(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);
}
} }

View File

@@ -900,6 +900,10 @@
<from-outcome>editAvmXmlInline</from-outcome> <from-outcome>editAvmXmlInline</from-outcome>
<to-view-id>/jsp/wcm/edit-xml-inline.jsp</to-view-id> <to-view-id>/jsp/wcm/edit-xml-inline.jsp</to-view-id>
</navigation-case> </navigation-case>
<navigation-case>
<from-outcome>updateAvmFile</from-outcome>
<to-view-id>/jsp/wcm/update-file.jsp</to-view-id>
</navigation-case>
<navigation-case> <navigation-case>
<from-outcome>cancel</from-outcome> <from-outcome>cancel</from-outcome>
<to-view-id>/jsp/wcm/browse-sandbox.jsp</to-view-id> <to-view-id>/jsp/wcm/browse-sandbox.jsp</to-view-id>