diff --git a/config/alfresco/messages/webclient.properties b/config/alfresco/messages/webclient.properties index e7b931f8ea..bffbe1d212 100644 --- a/config/alfresco/messages/webclient.properties +++ b/config/alfresco/messages/webclient.properties @@ -239,6 +239,7 @@ create_space=Create Space add_content=Add Content create_content=Create Content create_form=Create Form +edit_form=Edit Form add_multiple_files=Add Multiple Files import_directory=Import Directory advanced_space_wizard=Advanced Space Wizard @@ -649,7 +650,9 @@ text_content=Plain Text Content html_content=HTML Content xml_content=XML Content create_form_title=Create Form Wizard +edit_form_title=Edit Form Wizard create_form_desc=This wizard helps you create a new form. +edit_form_desc=This wizard helps you edit a form. create_form_form_details_title=Step One - Specify details create_form_form_details_desc=Enter information about the web form you want to create. create_form_form_details_step1_desc=Select XML schema to use diff --git a/config/alfresco/web-client-config-actions.xml b/config/alfresco/web-client-config-actions.xml index dcce1f3818..f4c601cee8 100644 --- a/config/alfresco/web-client-config-actions.xml +++ b/config/alfresco/web-client-config-actions.xml @@ -376,9 +376,23 @@ org.alfresco.web.action.evaluator.CreateFormEvaluator create_form - /images/icons/new_content.gif + /images/icons/new_form.gif wizard:createForm + + + org.alfresco.web.action.evaluator.EditFormEvaluator + + Write,CreateChildren + + edit_form + /images/icons/edit_form.gif + wizard:editForm + #{BrowseBean.setupSpaceAction} + + #{actionContext.id} + + @@ -641,6 +655,7 @@ + diff --git a/config/alfresco/web-client-config-wizards.xml b/config/alfresco/web-client-config-wizards.xml index 088afcb13d..0d2276e663 100644 --- a/config/alfresco/web-client-config-wizards.xml +++ b/config/alfresco/web-client-config-wizards.xml @@ -345,7 +345,7 @@ - + @@ -379,6 +379,41 @@ instruction-id="content_finish_instruction" /> + + + + + + + + + + + + + + + + renderingEngineTemplates = null; + protected transient XSModel schema; + protected String schemaFileName; + protected ContentService contentService; + protected MimetypeService mimetypeService; + protected WorkflowService workflowService; + private String schemaRootElementName = null; private String formName = null; private String formTitle = null; private String formDescription = null; + private String outputPathPatternForFormInstanceData = null; private String renderingEngineTemplateTitle = null; private String renderingEngineTemplateDescription = null; - private String defaultWorkflowName = null; + private RenderingEngine renderingEngine = null; - protected ContentService contentService; - protected MimetypeService mimetypeService; - protected WorkflowService workflowService; - private transient DataModel renderingEngineTemplatesDataModel; - private List renderingEngineTemplates = null; - private String outputPathPatternForFormInstanceData = null; + protected transient DataModel renderingEngineTemplatesDataModel; + private String outputPathPatternForRendition = null; private String mimetypeForRendition = null; private transient List mimetypeChoices = null; @@ -181,7 +205,10 @@ public class CreateFormWizard protected String finishImpl(final FacesContext context, final String outcome) throws Exception { - LOGGER.debug("creating form " + this.getFormName()); + if (LOGGER.isDebugEnabled()) + { + LOGGER.debug("creating form " + this.getFormName()); + } final FormsService ts = FormsService.getInstance(); // get the node ref of the node that will contain the content @@ -224,75 +251,82 @@ public class CreateFormWizard for (RenderingEngineTemplateData retd : this.renderingEngineTemplates) { - LOGGER.debug("adding rendering engine template " + retd + - " to form " + this.getFormName()); - - NodeRef renderingEngineTemplateNodeRef = - this.fileFolderService.searchSimple(folderInfo.getNodeRef(), retd.getFileName()); - if (renderingEngineTemplateNodeRef == null) - { - try - { - fileInfo = this.fileFolderService.create(folderInfo.getNodeRef(), - retd.getFileName(), - ContentModel.TYPE_CONTENT); - if (LOGGER.isDebugEnabled()) - LOGGER.debug("Created file node for file: " + retd.getFileName()); - renderingEngineTemplateNodeRef = fileInfo.getNodeRef(); - } - catch (final FileExistsException fee) - { - LOGGER.error(fee.getName() + " already exists in " + - fee.getParentNodeRef()); - throw fee; - } - - // get a writer for the content and put the file - writer = this.contentService.getWriter(renderingEngineTemplateNodeRef, - ContentModel.PROP_CONTENT, - true); - // set the mimetype and encoding - // XXXarielb mime type of template isn't known - // writer.setMimetype("text/xml"); - writer.setEncoding("UTF-8"); - writer.putContent(retd.getFile()); - - this.nodeService.createAssociation(folderInfo.getNodeRef(), - renderingEngineTemplateNodeRef, - WCMAppModel.ASSOC_RENDERING_ENGINE_TEMPLATES); - props = new HashMap(2, 1.0f); - props.put(WCMAppModel.PROP_PARENT_RENDERING_ENGINE_NAME, - retd.getRenderingEngine().getName()); - props.put(WCMAppModel.PROP_FORM_SOURCE, folderInfo.getNodeRef()); - this.nodeService.addAspect(renderingEngineTemplateNodeRef, - WCMAppModel.ASPECT_RENDERING_ENGINE_TEMPLATE, - props); - - // apply the titled aspect - title and description - props = new HashMap(2, 1.0f); - props.put(ContentModel.PROP_TITLE, retd.getTitle()); - props.put(ContentModel.PROP_DESCRIPTION, retd.getDescription()); - this.nodeService.addAspect(renderingEngineTemplateNodeRef, - ContentModel.ASPECT_TITLED, - props); - } - - LOGGER.debug("adding rendition properties to " + renderingEngineTemplateNodeRef); - props = new HashMap(2, 1.0f); - props.put(WCMAppModel.PROP_OUTPUT_PATH_PATTERN_RENDITION, - retd.getOutputPathPatternForRendition()); - props.put(WCMAppModel.PROP_MIMETYPE_FOR_RENDITION, - retd.getMimetypeForRendition()); - this.nodeService.createNode(renderingEngineTemplateNodeRef, - WCMAppModel.ASSOC_RENDITION_PROPERTIES, - WCMAppModel.ASSOC_RENDITION_PROPERTIES, - WCMAppModel.TYPE_RENDITION_PROPERTIES, - props); + this.saveRenderingEngineTemplate(retd, folderInfo.getNodeRef()); } // return the default outcome return outcome; } + protected void saveRenderingEngineTemplate(final RenderingEngineTemplateData retd, + final NodeRef formNodeRef) + { + LOGGER.debug("adding rendering engine template " + retd + + " to form " + this.getFormName()); + + NodeRef renderingEngineTemplateNodeRef = + this.fileFolderService.searchSimple(formNodeRef, retd.getFileName()); + HashMap props; + if (renderingEngineTemplateNodeRef == null) + { + try + { + final FileInfo fileInfo = this.fileFolderService.create(formNodeRef, + retd.getFileName(), + ContentModel.TYPE_CONTENT); + if (LOGGER.isDebugEnabled()) + LOGGER.debug("Created file node for file: " + retd.getFileName()); + renderingEngineTemplateNodeRef = fileInfo.getNodeRef(); + } + catch (final FileExistsException fee) + { + LOGGER.error(fee.getName() + " already exists in " + + fee.getParentNodeRef()); + throw fee; + } + + // get a writer for the content and put the file + final ContentWriter writer = this.contentService.getWriter(renderingEngineTemplateNodeRef, + ContentModel.PROP_CONTENT, + true); + // set the mimetype and encoding + // XXXarielb mime type of template isn't known + // writer.setMimetype("text/xml"); + writer.setEncoding("UTF-8"); + writer.putContent(retd.getFile()); + + this.nodeService.createAssociation(formNodeRef, + renderingEngineTemplateNodeRef, + WCMAppModel.ASSOC_RENDERING_ENGINE_TEMPLATES); + props = new HashMap(2, 1.0f); + props.put(WCMAppModel.PROP_PARENT_RENDERING_ENGINE_NAME, + retd.getRenderingEngine().getName()); + props.put(WCMAppModel.PROP_FORM_SOURCE, formNodeRef); + this.nodeService.addAspect(renderingEngineTemplateNodeRef, + WCMAppModel.ASPECT_RENDERING_ENGINE_TEMPLATE, + props); + + // apply the titled aspect - title and description + props = new HashMap(2, 1.0f); + props.put(ContentModel.PROP_TITLE, retd.getTitle()); + props.put(ContentModel.PROP_DESCRIPTION, retd.getDescription()); + this.nodeService.addAspect(renderingEngineTemplateNodeRef, + ContentModel.ASPECT_TITLED, + props); + } + + LOGGER.debug("adding rendition properties to " + renderingEngineTemplateNodeRef); + props = new HashMap(2, 1.0f); + props.put(WCMAppModel.PROP_OUTPUT_PATH_PATTERN_RENDITION, + retd.getOutputPathPatternForRendition()); + props.put(WCMAppModel.PROP_MIMETYPE_FOR_RENDITION, + retd.getMimetypeForRendition()); + this.nodeService.createNode(renderingEngineTemplateNodeRef, + WCMAppModel.ASSOC_RENDITION_PROPERTIES, + WCMAppModel.ASSOC_RENDITION_PROPERTIES, + WCMAppModel.TYPE_RENDITION_PROPERTIES, + props); + } + @Override public void init(Map parameters) { @@ -300,6 +334,8 @@ public class CreateFormWizard this.removeUploadedSchemaFile(); this.removeUploadedRenderingEngineTemplateFile(); + this.schema = null; + this.schemaFileName = null; this.schemaRootElementName = null; this.schemaRootElementNameChoices = null; this.formName = null; @@ -331,7 +367,7 @@ public class CreateFormWizard // checking step numbers boolean disabled = false; - int step = Application.getWizardManager().getCurrentStep(); + final int step = Application.getWizardManager().getCurrentStep(); switch(step) { case 1: @@ -468,8 +504,10 @@ public class CreateFormWizard */ public String removeUploadedSchemaFile() { - clearUpload(FILE_SCHEMA); + this.clearUpload(FILE_SCHEMA); this.schemaRootElementNameChoices = null; + this.schema = null; + this.schemaFileName = null; // refresh the current page return null; @@ -491,13 +529,17 @@ public class CreateFormWizard */ public String schemaFileValueChanged(final ValueChangeEvent vce) { + if (LOGGER.isDebugEnabled()) + { + LOGGER.debug("schemaFileValueChanged(" + this.getSchemaFile() + ")"); + } if (this.getSchemaFile() != null) { - final FormsService ts = FormsService.getInstance(); try { - final Document d = ts.parseXML(this.getSchemaFile()); - final XSModel xsm = SchemaUtil.loadSchema(d); + final FormsService formsService = FormsService.getInstance(); + final Document d = formsService.parseXML(this.getSchemaFile()); + this.schema = SchemaUtil.parseSchema(d); } catch (Exception e) { @@ -512,6 +554,12 @@ public class CreateFormWizard // ------------------------------------------------------------------------------ // Bean Getters and Setters + /** Indicates whether or not the wizard is currently in edit mode */ + public boolean getEditMode() + { + return false; + } + /** * Returns the properties for current configured output methods JSF DataModel * @@ -644,15 +692,23 @@ public class CreateFormWizard { return this.getFile(FILE_SCHEMA); } + + /** + * Sets the schema file name + */ + public void setSchemaFileName(final String schemaFileName) + { + this.schemaFileName = (schemaFileName != null && schemaFileName.length() != 0 + ? schemaFileName + : null); + } /** * @return Returns the schema file or null */ public String getSchemaFileName() { - // try and retrieve the file and filename from the file upload bean - // representing the file we previously uploaded. - return this.getFileName(FILE_SCHEMA); + return this.schemaFileName; } /** @@ -693,33 +749,27 @@ public class CreateFormWizard */ public List getSchemaRootElementNameChoices() { - if (this.getSchemaFile() == null) + List result = Collections.EMPTY_LIST; + if (this.schema != null) { - return Collections.EMPTY_LIST; - } - if (this.schemaRootElementNameChoices == null) - { - this.schemaRootElementNameChoices = new LinkedList(); - final FormsService ts = FormsService.getInstance(); - try + if (this.schemaRootElementNameChoices == null) { - final Document d = ts.parseXML(this.getSchemaFile()); - final XSModel xsm = SchemaUtil.loadSchema(d); - final XSNamedMap elementsMap = xsm.getComponents(XSConstants.ELEMENT_DECLARATION); + this.schemaRootElementNameChoices = new LinkedList(); + final XSNamedMap elementsMap = this.schema.getComponents(XSConstants.ELEMENT_DECLARATION); for (int i = 0; i < elementsMap.getLength(); i++) { final XSElementDeclaration e = (XSElementDeclaration)elementsMap.item(i); this.schemaRootElementNameChoices.add(new SelectItem(e.getName(), e.getName())); } } - catch (Exception e) - { - final String msg = "unable to parse " + this.getSchemaFileName(); - this.removeUploadedSchemaFile(); - Utils.addErrorMessage(msg, e); - } + result = this.schemaRootElementNameChoices; } - return this.schemaRootElementNameChoices; + if (LOGGER.isDebugEnabled()) + { + LOGGER.debug("getSchemaRootElementNameChoices(" + this.schema + + ") = " + result.size()); + } + return result; } /** diff --git a/source/java/org/alfresco/web/bean/wcm/EditFormWizard.java b/source/java/org/alfresco/web/bean/wcm/EditFormWizard.java new file mode 100644 index 0000000000..06006dc7c6 --- /dev/null +++ b/source/java/org/alfresco/web/bean/wcm/EditFormWizard.java @@ -0,0 +1,196 @@ +/* + * Copyright (C) 2005 Alfresco, Inc. + * + * Licensed under the Mozilla Public License version 1.1 + * with a permitted attribution clause. You may obtain a + * copy of the License at + * + * http://www.alfresco.org/legal/license.txt + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + */ +package org.alfresco.web.bean.wcm; + +import java.io.Serializable; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import javax.faces.context.FacesContext; +import javax.faces.event.ActionEvent; + +import org.alfresco.model.ContentModel; +import org.alfresco.model.WCMAppModel; +import org.alfresco.repo.content.MimetypeMap; +import org.alfresco.service.cmr.model.FileInfo; +import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.repository.ContentWriter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.workflow.WorkflowDefinition; +import org.alfresco.service.namespace.QName; +import org.alfresco.service.namespace.RegexQNamePattern; +import org.alfresco.web.app.AlfrescoNavigationHandler; +import org.alfresco.web.forms.xforms.SchemaUtil; +import org.alfresco.web.forms.Form; +import org.alfresco.web.forms.FormsService; +import org.alfresco.web.forms.RenderingEngineTemplate; +import org.alfresco.web.ui.common.Utils; + +/** + * Backing bean for the Edit Form wizard. + * + * @author Ariel Backenroth + */ +public class EditFormWizard + extends CreateFormWizard +{ + + private List removedRenderingEngineTemplates; + + // ------------------------------------------------------------------------------ + // Wizard implementation + + /** + * Initialises the wizard + */ + @Override + public void init(final Map parameters) + { + super.init(parameters); + + // the editMode flag is used to disabled some wizard fields + // this.editMode = true; + + final NodeRef formNodeRef = this.browseBean.getActionSpace().getNodeRef(); + if (formNodeRef == null) + { + throw new IllegalArgumentException("Edit Form wizard requires action node context."); + } + + final Form form = FormsService.getInstance().getForm(formNodeRef); + // simple properties + this.setFormName(form.getName()); + this.setFormTitle(form.getTitle()); + this.setFormDescription(form.getDescription()); + this.setSchemaRootElementName(form.getSchemaRootElementName()); + final NodeRef schemaNodeRef = (NodeRef) + this.nodeService.getProperty(formNodeRef, WCMAppModel.PROP_XML_SCHEMA); + this.setSchemaFileName((String)this.nodeService.getProperty(schemaNodeRef, + ContentModel.PROP_NAME)); + try + { + this.schema = SchemaUtil.parseSchema(form.getSchema()); + } + catch (Throwable t) + { + final String msg = "unable to parse " + form.getName(); + Utils.addErrorMessage(msg, t); + } + final WorkflowDefinition wf = form.getDefaultWorkflow(); + if (wf != null) + { + this.defaultWorkflowName = wf.getName(); + } + this.setOutputPathPatternForFormInstanceData(form.getOutputPathPattern()); + + for (RenderingEngineTemplate ret : form.getRenderingEngineTemplates()) + { + final RenderingEngineTemplateData data = + this.new RenderingEngineTemplateData(ret); + this.renderingEngineTemplates.add(data); + } + } + + /** + * @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 + { + final NodeRef formNodeRef = this.browseBean.getActionSpace().getNodeRef(); + + // apply the name, title and description props + this.nodeService.setProperty(formNodeRef, ContentModel.PROP_NAME, this.getFormName()); + this.nodeService.setProperty(formNodeRef, ContentModel.PROP_TITLE, this.getFormTitle()); + this.nodeService.setProperty(formNodeRef, ContentModel.PROP_DESCRIPTION, this.getFormDescription()); + this.nodeService.setProperty(formNodeRef, + WCMAppModel.PROP_OUTPUT_PATH_PATTERN_FORM_INSTANCE_DATA, + this.getOutputPathPatternForFormInstanceData()); + this.nodeService.setProperty(formNodeRef, + WCMAppModel.PROP_XML_SCHEMA_ROOT_ELEMENT_NAME, + this.getSchemaRootElementName()); + final WorkflowDefinition wd = this.getDefaultWorkflowDefinition(); + if (wd != null) + { + this.nodeService.setProperty(formNodeRef, + WCMAppModel.PROP_DEFAULT_WORKFLOW_NAME, + wd.getName()); + } + + if (this.getSchemaFile() != null) + { + FileInfo fileInfo = + this.fileFolderService.create(formNodeRef, + this.getSchemaFileName(), + ContentModel.TYPE_CONTENT); + // get a writer for the content and put the file + final ContentWriter writer = this.contentService.getWriter(fileInfo.getNodeRef(), + ContentModel.PROP_CONTENT, + true); + // set the mimetype and encoding + writer.setMimetype(MimetypeMap.MIMETYPE_XML); + writer.setEncoding("UTF-8"); + writer.putContent(this.getSchemaFile()); + this.nodeService.setProperty(formNodeRef, + WCMAppModel.PROP_XML_SCHEMA, + fileInfo.getNodeRef()); + } + + for (RenderingEngineTemplateData retd : this.removedRenderingEngineTemplates) + { + this.nodeService.removeChild(formNodeRef, retd.getNodeRef()); + } + + for (RenderingEngineTemplateData retd : this.renderingEngineTemplates) + { + if (retd.getFile() != null) + { + this.saveRenderingEngineTemplate(retd, formNodeRef); + } + } + return AlfrescoNavigationHandler.CLOSE_WIZARD_OUTCOME; + } + + /** + * Action handler called when the Remove button is pressed to remove a + * rendering engine + */ + @Override + public void removeSelectedRenderingEngineTemplate(final ActionEvent event) + { + final RenderingEngineTemplateData wrapper = (RenderingEngineTemplateData) + this.renderingEngineTemplatesDataModel.getRowData(); + if (wrapper != null) + { + if (this.removedRenderingEngineTemplates == null) + { + this.removedRenderingEngineTemplates = new LinkedList(); + } + this.removedRenderingEngineTemplates.add(wrapper); + } + super.removeSelectedRenderingEngineTemplate(event); + } + + + /** Indicates whether or not the wizard is currently in edit mode */ + public boolean getEditMode() + { + return true; + } +} diff --git a/source/java/org/alfresco/web/forms/xforms/SchemaFormBuilder.java b/source/java/org/alfresco/web/forms/xforms/SchemaFormBuilder.java index de69e04ccd..3d67e60c74 100644 --- a/source/java/org/alfresco/web/forms/xforms/SchemaFormBuilder.java +++ b/source/java/org/alfresco/web/forms/xforms/SchemaFormBuilder.java @@ -255,7 +255,7 @@ public class SchemaFormBuilder final ResourceBundle resourceBundle) throws FormBuilderException { - final XSModel schema = SchemaUtil.loadSchema(schemaDocument); + final XSModel schema = SchemaUtil.parseSchema(schemaDocument); this.typeTree = SchemaUtil.buildTypeTree(schema); //refCounter = 0; diff --git a/source/java/org/alfresco/web/forms/xforms/SchemaUtil.java b/source/java/org/alfresco/web/forms/xforms/SchemaUtil.java index 495433febd..094fccabe2 100644 --- a/source/java/org/alfresco/web/forms/xforms/SchemaUtil.java +++ b/source/java/org/alfresco/web/forms/xforms/SchemaUtil.java @@ -202,7 +202,7 @@ public class SchemaUtil return SchemaUtil.DATA_TYPE_TO_NAME.get(type); } - public static XSModel loadSchema(final Document schemaDocument) + public static XSModel parseSchema(final Document schemaDocument) throws FormBuilderException { try diff --git a/source/web/WEB-INF/faces-config-beans.xml b/source/web/WEB-INF/faces-config-beans.xml index 0aab1fa59a..5a274e64fe 100644 --- a/source/web/WEB-INF/faces-config-beans.xml +++ b/source/web/WEB-INF/faces-config-beans.xml @@ -2084,6 +2084,51 @@ #{WorkflowService} + + + + The bean that backs up the Edit Form Wizard + + EditFormWizard + org.alfresco.web.bean.wcm.EditFormWizard + session + + nodeService + #{NodeService} + + + fileFolderService + #{FileFolderService} + + + searchService + #{SearchService} + + + namespaceService + #{NamespaceService} + + + navigator + #{NavigationBean} + + + browseBean + #{BrowseBean} + + + contentService + #{ContentService} + + + mimetypeService + #{MimetypeService} + + + workflowService + #{WorkflowService} + + diff --git a/source/web/jsp/wcm/create-form-wizard/details.jsp b/source/web/jsp/wcm/create-form-wizard/details.jsp index 9686cc8a45..bc1423717d 100644 --- a/source/web/jsp/wcm/create-form-wizard/details.jsp +++ b/source/web/jsp/wcm/create-form-wizard/details.jsp @@ -18,7 +18,6 @@ <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a" %> <%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %> -<%@ page import="org.alfresco.web.bean.FileUploadBean" %> <%@ page import="org.alfresco.web.bean.wcm.CreateFormWizard" %> + +