From d28bbd41c5282cf7178f50949c05d22c593ebf13 Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Tue, 5 Jun 2007 17:51:30 +0000 Subject: [PATCH] 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 --- config/alfresco/web-client-config-dialogs.xml | 4 + .../alfresco/web/bean/wcm/AVMEditBean.java | 107 +++------- .../web/bean/wcm/EditXmlInlineDialog.java | 188 ++++++++++++++++++ source/web/WEB-INF/faces-config-beans.xml | 25 +++ .../web/WEB-INF/faces-config-navigation.xml | 12 -- source/web/jsp/wcm/edit-xml-inline.jsp | 145 +------------- 6 files changed, 249 insertions(+), 232 deletions(-) create mode 100644 source/java/org/alfresco/web/bean/wcm/EditXmlInlineDialog.java diff --git a/config/alfresco/web-client-config-dialogs.xml b/config/alfresco/web-client-config-dialogs.xml index 2b35316965..2445499e73 100644 --- a/config/alfresco/web-client-config-dialogs.xml +++ b/config/alfresco/web-client-config-dialogs.xml @@ -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"/> + + diff --git a/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java b/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java index cfe4cb802b..25072800fe 100644 --- a/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java +++ b/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java @@ -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 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 diffList = new ArrayList(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)) diff --git a/source/java/org/alfresco/web/bean/wcm/EditXmlInlineDialog.java b/source/java/org/alfresco/web/bean/wcm/EditXmlInlineDialog.java new file mode 100644 index 0000000000..155e2c954d --- /dev/null +++ b/source/java/org/alfresco/web/bean/wcm/EditXmlInlineDialog.java @@ -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 diffList = new ArrayList(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"); + } +} diff --git a/source/web/WEB-INF/faces-config-beans.xml b/source/web/WEB-INF/faces-config-beans.xml index 10c4f495ee..94f54b122d 100644 --- a/source/web/WEB-INF/faces-config-beans.xml +++ b/source/web/WEB-INF/faces-config-beans.xml @@ -2766,6 +2766,31 @@ + + + The bean that backs up the Edit Xml XForms dialog + + EditXmlInlineDialog + org.alfresco.web.bean.wcm.EditXmlInlineDialog + session + + avmService + #{AVMService} + + + avmSyncService + #{AVMSyncService} + + + avmEditBean + #{AVMEditBean} + + + filePickerBean + #{FilePickerBean} + + + The bean that backs up the Snapshot Sandbox Dialog diff --git a/source/web/WEB-INF/faces-config-navigation.xml b/source/web/WEB-INF/faces-config-navigation.xml index 57e26a4578..f16264246e 100644 --- a/source/web/WEB-INF/faces-config-navigation.xml +++ b/source/web/WEB-INF/faces-config-navigation.xml @@ -263,14 +263,6 @@ - - /jsp/dialog/edit-xml-inline.jsp - - checkoutFile - /jsp/dialog/checkout-file.jsp - - - /jsp/dialog/checkout-file.jsp @@ -912,10 +904,6 @@ editAvmFile /jsp/wcm/edit-file.jsp - - editAvmXmlInline - /jsp/wcm/edit-xml-inline.jsp - updateAvmFile /jsp/wcm/update-file.jsp diff --git a/source/web/jsp/wcm/edit-xml-inline.jsp b/source/web/jsp/wcm/edit-xml-inline.jsp index 0373f0b134..f83110a81f 100644 --- a/source/web/jsp/wcm/edit-xml-inline.jsp +++ b/source/web/jsp/wcm/edit-xml-inline.jsp @@ -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" %> - - + + - - - <%-- load a bundle of properties with I18N strings --%> - - - - - <%-- Main outer table --%> - - - <%-- Title bar --%> - - - - - <%-- Main area --%> - - <%-- Shelf --%> - - - <%-- Work Area --%> - - -
- <%@ include file="../parts/titlebar.jsp" %> -
- <%@ include file="../parts/shelf.jsp" %> - - - <%-- Breadcrumb --%> - <%@ include file="../parts/breadcrumb.jsp" %> - - <%-- Status and Actions --%> - - - - - - - <%-- separator row with gradient shadow --%> - - - - - - - <%-- Details --%> - - - - - - - <%-- Error Messages --%> - - - - - - - <%-- separator row with bottom panel graphics --%> - - - - - - -
- - <%-- Status and Actions inner contents table --%> - <%-- Generally this consists of an icon, textual summary and actions for the current object --%> - - - - - -
- -
''
-
-
- -
- - - <%-- Inline editor --%> - - - -
- <% PanelGenerator.generatePanelStart(out, request.getContextPath(), "white", "white"); %> - - - - <% PanelGenerator.generatePanelEnd(out, request.getContextPath(), "white"); %> - - <% PanelGenerator.generatePanelStart(out, request.getContextPath(), "greyround", "#F5F5F5"); %> - - - - - - - - -
- -
- -
- <% PanelGenerator.generatePanelEnd(out, request.getContextPath(), "greyround"); %> -
-
- <%-- messages tag to show messages not handled by other specific message tags --%> - -
-
- -
- -
-
+ \ No newline at end of file