XForm (edit XML inline) dialog converted to from old to "new skool" dialog framework - required to allow dialog displayed in an arbituary jsp container to be called using command framework via REST url

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5855 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2007-06-05 17:51:30 +00:00
parent 54fa2dc56f
commit d28bbd41c5
6 changed files with 249 additions and 232 deletions

View File

@@ -246,6 +246,10 @@
managed-bean="MonitorDeploymentDialog"
icon="/images/icons/deploy_large.gif" title-id="monitor_deployment_title"
description-id="monitor_deployment_desc" show-ok-button="false"/>
<dialog name="editXmlInline" page="/jsp/wcm/edit-xml-inline.jsp"
managed-bean="EditXmlInlineDialog" icon="/images/icons/edit_large.gif"
title-id="title_edit_xml_inline" description-id="editfileinline_description" />
</dialogs>
</config>

View File

@@ -20,9 +20,8 @@ package org.alfresco.web.bean.wcm;
import java.io.File;
import java.io.FileNotFoundException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
@@ -34,19 +33,15 @@ import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.avmsync.AVMDifference;
import org.alfresco.service.cmr.avmsync.AVMSyncService;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.util.Pair;
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.Repository;
import org.alfresco.web.forms.Form;
@@ -58,6 +53,7 @@ import org.alfresco.web.forms.Rendition;
import org.alfresco.web.forms.RenditionImpl;
import org.alfresco.web.forms.XMLUtil;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.component.UIActionLink;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
@@ -70,6 +66,8 @@ import org.w3c.dom.Document;
*/
public class AVMEditBean
{
public static final String BEAN_NAME = "AVMEditBean";
private static final Log LOGGER = LogFactory.getLog(AVMEditBean.class);
private static final String MSG_ERROR_UPDATE = "error_update";
@@ -102,6 +100,7 @@ public class AVMEditBean
/** The FilePickerBean reference */
protected FilePickerBean filePickerBean;
// ------------------------------------------------------------------------------
// Bean property getters and setters
@@ -333,7 +332,19 @@ public class AVMEditBean
*/
public void setupEditAction(ActionEvent event)
{
this.avmBrowseBean.setupContentAction(event);
UIActionLink link = (UIActionLink)event.getComponent();
Map<String, String> params = link.getParameterMap();
String path = params.get("id");
setupEditAction(path);
}
/**
* Action handler called to calculate which editing screen to display based on the mimetype
* of a document. If appropriate, the in-line editing screen will be shown.
*/
public void setupEditAction(String path)
{
this.avmBrowseBean.setupContentAction(path, true);
// retrieve the content reader for this node
String avmPath = getAvmNode().getPath();
@@ -366,12 +377,12 @@ public class AVMEditBean
// reset the preview layer
String storeName = AVMUtil.getStoreName(avmPath);
storeName = AVMUtil.getCorrespondingPreviewStoreName(storeName);
final String path = AVMUtil.buildStoreRootPath(storeName);
final String rootPath = AVMUtil.buildStoreRootPath(storeName);
if (LOGGER.isDebugEnabled())
LOGGER.debug("reseting layer " + path);
LOGGER.debug("reseting layer " + rootPath);
this.avmSyncService.resetLayer(path);
this.avmSyncService.resetLayer(rootPath);
}
this.filePickerBean.clearUploadedFiles();
@@ -395,7 +406,7 @@ public class AVMEditBean
this.form = null;
// navigate to appropriate screen
outcome = "dialog:editAvmXmlInline";
outcome = "dialog:editXmlInline";
}
else
{
@@ -428,76 +439,6 @@ public class AVMEditBean
return outcome;
}
/**
* Action handler called to set the content of a node from an inline editing page.
*/
public String editInlineOK()
{
UserTransaction tx = null;
final AVMNode avmNode = getAvmNode();
if (avmNode == null)
{
return null;
}
final String avmPath = avmNode.getPath();
if (LOGGER.isDebugEnabled())
LOGGER.debug("saving " + avmPath);
try
{
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance());
tx.begin();
// get an updating writer that we can use to modify the content on the current node
final ContentWriter writer = this.avmService.getContentWriter(avmPath);
if (this.avmService.hasAspect(-1, avmPath, WCMAppModel.ASPECT_FORM_INSTANCE_DATA))
{
this.editorOutput = XMLUtil.toString(this.instanceDataDocument, false);
}
writer.putContent(this.editorOutput);
// commit the transaction
tx.commit();
// regenerate form content
if (this.avmService.hasAspect(-1, avmPath, WCMAppModel.ASPECT_FORM_INSTANCE_DATA))
{
this.regenerateRenditions();
}
final NodeRef[] uploadedFiles = this.filePickerBean.getUploadedFiles();
if (LOGGER.isDebugEnabled())
LOGGER.debug("updating " + uploadedFiles.length + " uploaded files");
final List<AVMDifference> diffList = new ArrayList<AVMDifference>(uploadedFiles.length);
for (NodeRef uploadedFile : uploadedFiles)
{
final String path = AVMNodeConverter.ToAVMVersionPath(uploadedFile).getSecond();
diffList.add(new AVMDifference(-1, path,
-1, AVMUtil.getCorrespondingPathInMainStore(path),
AVMDifference.NEWER));
}
this.avmSyncService.update(diffList, null, true, true, true, true, null, null);
// Possibly notify virt server
AVMUtil.updateVServerWebapp(avmNode.getPath(), false);
this.resetState();
return 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(), CheckinCheckoutBean.MSG_ERROR_UPDATE) + err.getMessage());
return null;
}
}
/**
* Action called upon completion of the Update File page
*/
@@ -562,7 +503,7 @@ public class AVMEditBean
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
}
private void resetState()
/*package*/ void resetState()
{
// clean up and clear action context
clearUpload();
@@ -593,7 +534,7 @@ public class AVMEditBean
ctx.getExternalContext().getSessionMap().remove(FileUploadBean.FILE_UPLOAD_BEAN_NAME);
}
private void regenerateRenditions()
/*package*/ void regenerateRenditions()
{
final String avmPath = this.getAvmNode().getPath();
final FormInstanceData fid = new FormInstanceDataImpl(AVMNodeConverter.ToNodeRef(-1, avmPath))

View File

@@ -0,0 +1,188 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing
*/
package org.alfresco.web.bean.wcm;
import java.util.ArrayList;
import java.util.List;
import javax.faces.context.FacesContext;
import org.alfresco.model.WCMAppModel;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.avmsync.AVMDifference;
import org.alfresco.service.cmr.avmsync.AVMSyncService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.dialog.BaseDialogBean;
import org.alfresco.web.forms.XMLUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author Kevin Roast
*/
public class EditXmlInlineDialog extends BaseDialogBean
{
private static final Log logger = LogFactory.getLog(EditXmlInlineDialog.class);
/** AVM Edit Bean reference */
private AVMEditBean avmEditBean;
/** AVM service bean reference */
protected AVMService avmService;
/** AVM sync service bean reference */
protected AVMSyncService avmSyncService;
/** The FilePickerBean reference */
protected FilePickerBean filePickerBean;
/**
* @param avmEditBean The AVMEditBean to set.
*/
public void setAvmEditBean(AVMEditBean avmEditBean)
{
this.avmEditBean = avmEditBean;
}
/**
* @param avmService The AVMService to set.
*/
public void setAvmService(final AVMService avmService)
{
this.avmService = avmService;
}
/**
* @param avmSyncService The AVMSyncService to set.
*/
public void setAvmSyncService(final AVMSyncService avmSyncService)
{
this.avmSyncService = avmSyncService;
}
/**
* @param filePickerBean The FilePickerBean to set.
*/
public void setFilePickerBean(final FilePickerBean filePickerBean)
{
this.filePickerBean = filePickerBean;
}
@Override
public String getContainerTitle()
{
return this.avmEditBean.getAvmNode().getName();
}
/**
* @see org.alfresco.web.bean.dialog.BaseDialogBean#finishImpl(javax.faces.context.FacesContext, java.lang.String)
*/
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception
{
AVMNode avmNode = this.avmEditBean.getAvmNode();
if (avmNode == null)
{
return null;
}
String avmPath = avmNode.getPath();
if (logger.isDebugEnabled())
logger.debug("saving " + avmPath);
// get an updating writer that we can use to modify the content on the current node
final ContentWriter writer = this.avmService.getContentWriter(avmPath);
String editorOutput = this.avmEditBean.getEditorOutput();
if (this.avmService.hasAspect(-1, avmPath, WCMAppModel.ASPECT_FORM_INSTANCE_DATA))
{
editorOutput = XMLUtil.toString(this.avmEditBean.getInstanceDataDocument(), false);
this.avmEditBean.setEditorOutput(editorOutput);
}
writer.putContent(editorOutput);
return outcome;
}
@Override
protected String doPostCommitProcessing(FacesContext context, String outcome)
{
AVMNode avmNode = this.avmEditBean.getAvmNode();
String avmPath = avmNode.getPath();
// regenerate form content
if (this.avmService.hasAspect(-1, avmPath, WCMAppModel.ASPECT_FORM_INSTANCE_DATA))
{
this.avmEditBean.regenerateRenditions();
}
final NodeRef[] uploadedFiles = this.filePickerBean.getUploadedFiles();
if (logger.isDebugEnabled())
logger.debug("updating " + uploadedFiles.length + " uploaded files");
final List<AVMDifference> diffList = new ArrayList<AVMDifference>(uploadedFiles.length);
for (NodeRef uploadedFile : uploadedFiles)
{
final String path = AVMNodeConverter.ToAVMVersionPath(uploadedFile).getSecond();
diffList.add(new AVMDifference(-1, path,
-1, AVMUtil.getCorrespondingPathInMainStore(path),
AVMDifference.NEWER));
}
this.avmSyncService.update(diffList, null, true, true, true, true, null, null);
// Possibly notify virt server
AVMUtil.updateVServerWebapp(avmNode.getPath(), false);
this.avmEditBean.resetState();
return outcome;
}
@Override
public String cancel()
{
// reset the state
this.avmEditBean.resetState();
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
}
@Override
public boolean getFinishButtonDisabled()
{
return false;
}
@Override
public String getFinishButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "save");
}
}

View File

@@ -2766,6 +2766,31 @@
</managed-property>
</managed-bean>
<managed-bean>
<description>
The bean that backs up the Edit Xml XForms dialog
</description>
<managed-bean-name>EditXmlInlineDialog</managed-bean-name>
<managed-bean-class>org.alfresco.web.bean.wcm.EditXmlInlineDialog</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>avmService</property-name>
<value>#{AVMService}</value>
</managed-property>
<managed-property>
<property-name>avmSyncService</property-name>
<value>#{AVMSyncService}</value>
</managed-property>
<managed-property>
<property-name>avmEditBean</property-name>
<value>#{AVMEditBean}</value>
</managed-property>
<managed-property>
<property-name>filePickerBean</property-name>
<value>#{FilePickerBean}</value>
</managed-property>
</managed-bean>
<managed-bean>
<description>
The bean that backs up the Snapshot Sandbox Dialog

View File

@@ -263,14 +263,6 @@
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/jsp/dialog/edit-xml-inline.jsp</from-view-id>
<navigation-case>
<from-outcome>checkoutFile</from-outcome>
<to-view-id>/jsp/dialog/checkout-file.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/jsp/dialog/checkout-file.jsp</from-view-id>
<navigation-case>
@@ -912,10 +904,6 @@
<from-outcome>editAvmFile</from-outcome>
<to-view-id>/jsp/wcm/edit-file.jsp</to-view-id>
</navigation-case>
<navigation-case>
<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>

View File

@@ -22,22 +22,14 @@
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
--%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a" %>
<%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %>
<%@ taglib uri="/WEB-INF/wcm.tld" prefix="wcm" %>
<%@ page buffer="32kb" contentType="text/html;charset=UTF-8" %>
<%@ page isELIgnored="false" %>
<%@ page import="org.alfresco.web.ui.common.PanelGenerator" %>
<r:page titleId="title_edit_xml_inline">
<f:verbatim>
<script type="text/javascript">
function _xforms_getSubmitButtons()
{
return [ document.getElementById("edit-file:save-button") ];
return [ document.getElementById("dialog:finish-button") ];
}
function _xforms_getSaveDraftButtons()
@@ -45,131 +37,10 @@ function _xforms_getSaveDraftButtons()
return [];
}
</script>
<f:view>
<%-- load a bundle of properties with I18N strings --%>
<f:loadBundle basename="alfresco.messages.webclient" var="msg"/>
<h:form acceptcharset="UTF-8" id="edit-file">
<%-- Main outer table --%>
<table cellspacing="0" cellpadding="2">
<%-- Title bar --%>
<tr>
<td colspan="2">
<%@ include file="../parts/titlebar.jsp" %>
</td>
</tr>
<%-- Main area --%>
<tr valign="top">
<%-- Shelf --%>
<td>
<%@ include file="../parts/shelf.jsp" %>
</td>
<%-- Work Area --%>
<td width="100%" height="100%">
<table cellspacing="0" cellpadding="0" width="100%" height="100%">
<%-- Breadcrumb --%>
<%@ include file="../parts/breadcrumb.jsp" %>
<%-- Status and Actions --%>
<tr>
<td style="background-image: url(<%=request.getContextPath()%>/images/parts/statuspanel_4.gif)" width="4"></td>
<td bgcolor="#dfe6ed">
<%-- Status and Actions inner contents table --%>
<%-- Generally this consists of an icon, textual summary and actions for the current object --%>
<table cellspacing="4" cellpadding="0" width="100%">
<tr>
<td width="32">
<h:graphicImage id="wizard-logo" url="/images/icons/edit_large.gif" />
</td>
<td>
<div class="mainTitle">'<h:outputText value="#{AVMEditBean.avmNode.name}" />'</div>
<div class="mainSubText"><h:outputText value="#{msg.editfileinline_description}" /></div>
</td>
</tr>
</table>
</td>
<td style="background-image: url(<%=request.getContextPath()%>/images/parts/statuspanel_6.gif)" width="4"></td>
</tr>
<%-- separator row with gradient shadow --%>
<tr>
<td><img src="<%=request.getContextPath()%>/images/parts/statuspanel_7.gif" width="4" height="9"></td>
<td style="background-image: url(<%=request.getContextPath()%>/images/parts/statuspanel_8.gif)"></td>
<td><img src="<%=request.getContextPath()%>/images/parts/statuspanel_9.gif" width="4" height="9"></td>
</tr>
<%-- Details --%>
<tr valign=top>
<td style="background-image: url(<%=request.getContextPath()%>/images/parts/whitepanel_4.gif)" width="4"></td>
<td height="100%">
<table cellspacing="0" cellpadding="3" border="0" width="100%" height="100%">
<tr>
<%-- Inline editor --%>
<td width="100%" valign="top" height="100%">
<% PanelGenerator.generatePanelStart(out, request.getContextPath(), "white", "white"); %>
</f:verbatim>
<wcm:formProcessor id="form-data-renderer"
formProcessorSession="#{AVMEditBean.formProcessorSession}"
formInstanceData="#{AVMEditBean.instanceDataDocument}"
formInstanceDataName="#{AVMEditBean.formInstanceDataName}"
form="#{AVMEditBean.form}"/>
<% PanelGenerator.generatePanelEnd(out, request.getContextPath(), "white"); %>
</td>
<td valign="top" rowspan=2>
<% PanelGenerator.generatePanelStart(out, request.getContextPath(), "greyround", "#F5F5F5"); %>
<table cellpadding="1" cellspacing="1" border="0">
<tr>
<td align="center">
<h:commandButton id="save-button" value="#{msg.save}" action="#{AVMEditBean.editInlineOK}" styleClass="dialogControls" />
</td>
</tr>
<tr><td class="dialogButtonSpacing"></td></tr>
<tr>
<td align="center">
<h:commandButton value="#{msg.cancel}" action="#{AVMEditBean.cancel}" styleClass="dialogControls" />
</td>
</tr>
</table>
<% PanelGenerator.generatePanelEnd(out, request.getContextPath(), "greyround"); %>
</td>
</tr>
</table>
</td>
<td style="background-image: url(<%=request.getContextPath()%>/images/parts/whitepanel_6.gif)" width="4"></td>
</tr>
<%-- Error Messages --%>
<tr valign="top">
<td style="background-image: url(<%=request.getContextPath()%>/images/parts/whitepanel_4.gif)" width="4"></td>
<td>
<%-- messages tag to show messages not handled by other specific message tags --%>
<h:messages globalOnly="true" styleClass="errorMessage" layout="table" />
</td>
<td style="background-image: url(<%=request.getContextPath()%>/images/parts/whitepanel_6.gif)" width="4"></td>
</tr>
<%-- separator row with bottom panel graphics --%>
<tr>
<td><img src="<%=request.getContextPath()%>/images/parts/whitepanel_7.gif" width="4" height="4"></td>
<td width="100%" align="center" style="background-image: url(<%=request.getContextPath()%>/images/parts/whitepanel_8.gif)"></td>
<td><img src="<%=request.getContextPath()%>/images/parts/whitepanel_9.gif" width="4" height="4"></td>
</tr>
</table>
</td>
</tr>
</table>
</h:form>
</f:view>
</r:page>