From 226e8405218bcd356ea14643b88dc3a919d6b7ad Mon Sep 17 00:00:00 2001 From: Ariel Backenroth Date: Thu, 19 Oct 2006 19:14:55 +0000 Subject: [PATCH] cleanup to jsps which render the xform. using a tag to render, removing all the java code. much prettier. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4168 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/web/bean/wcm/AVMEditBean.java | 49 +++++- .../web/bean/wcm/CreateWebContentWizard.java | 33 ++++ .../alfresco/web/templating/TemplateType.java | 44 +++--- .../web/ui/wcm/component/UIFormProcessor.java | 148 ++++++++++++++++++ .../web/ui/wcm/tag/FormProcessorTag.java | 99 ++++++++++++ source/web/WEB-INF/faces-config-wcm.xml | 5 + source/web/WEB-INF/wcm.tld | 42 +++++ .../create-web-content-wizard/create-xml.jsp | 37 +---- source/web/jsp/wcm/edit-xml-inline.jsp | 43 +---- 9 files changed, 406 insertions(+), 94 deletions(-) create mode 100644 source/java/org/alfresco/web/ui/wcm/component/UIFormProcessor.java create mode 100644 source/java/org/alfresco/web/ui/wcm/tag/FormProcessorTag.java diff --git a/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java b/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java index fae314762c..87a0f501a2 100644 --- a/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java +++ b/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java @@ -41,10 +41,13 @@ 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.TemplateType; +import org.alfresco.web.templating.TemplateInputMethod; import org.alfresco.web.templating.TemplatingService; import org.alfresco.web.ui.common.Utils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.w3c.dom.Document; /** * Bean backing the edit pages for a AVM node content. @@ -204,7 +207,51 @@ public class AVMEditBean return MessageFormat.format(msg, new Object[] {getFileName()}); } - + /** + * @return Returns the template type when in the context of editing an xml asset. + */ + public TemplateType getTemplateType() + { + final NodeRef ttNodeRef = (NodeRef) + this.nodeService.getProperty(this.getAvmNode().getNodeRef(), + WCMModel.PROP_FORM_DERIVED_FROM); + final TemplatingService ts = TemplatingService.getInstance(); + return ts.getTemplateType(ttNodeRef); + } + + /** + * @return Returns the wrapper instance data for feeding the xml + * content to the form processor. + */ + public TemplateInputMethod.InstanceData getInstanceData() + { + final TemplateType tt = this.getTemplateType(); + final TemplateInputMethod tim = tt.getInputMethods().get(0); + return new TemplateInputMethod.InstanceData() + { + private final TemplatingService ts = TemplatingService.getInstance(); + + public Document getContent() + { + try + { + final String content = AVMEditBean.this.getEditorOutput(); + return content != null ? this.ts.parseXML(content) : null; + } + catch (Exception e) + { + e.printStackTrace(); + return null; + } + } + + public void setContent(final Document d) + { + AVMEditBean.this.setEditorOutput(this.ts.writeXMLToString(d)); + } + }; + } + // ------------------------------------------------------------------------------ // Action event handlers diff --git a/source/java/org/alfresco/web/bean/wcm/CreateWebContentWizard.java b/source/java/org/alfresco/web/bean/wcm/CreateWebContentWizard.java index 2b57e1cc7e..1383aa56c7 100644 --- a/source/java/org/alfresco/web/bean/wcm/CreateWebContentWizard.java +++ b/source/java/org/alfresco/web/bean/wcm/CreateWebContentWizard.java @@ -47,10 +47,12 @@ import org.alfresco.web.bean.content.BaseContentWizard; import org.alfresco.web.data.IDataContainer; import org.alfresco.web.data.QuickSort; import org.alfresco.web.templating.OutputUtil; +import org.alfresco.web.templating.TemplateInputMethod; import org.alfresco.web.templating.TemplateType; import org.alfresco.web.templating.TemplatingService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.w3c.dom.Document; /** * Bean implementation for the "Create Web Content Wizard" dialog @@ -303,6 +305,37 @@ public class CreateWebContentWizard extends BaseContentWizard { this.templateTypeName = templateTypeName; } + + /** + * @return Returns the wrapper instance data for feeding the xml + * content to the form processor. + */ + public TemplateInputMethod.InstanceData getInstanceData() + { + return new TemplateInputMethod.InstanceData() + { + private final TemplatingService ts = TemplatingService.getInstance(); + + public Document getContent() + { + try + { + final String content = CreateWebContentWizard.this.getContent(); + return content != null ? this.ts.parseXML(content) : null; + } + catch (Exception e) + { + e.printStackTrace(); + return null; + } + } + + public void setContent(final Document d) + { + CreateWebContentWizard.this.setContent(ts.writeXMLToString(d)); + } + }; + } /** * @return Returns the summary data for the wizard. diff --git a/source/java/org/alfresco/web/templating/TemplateType.java b/source/java/org/alfresco/web/templating/TemplateType.java index 2f91f028cf..9a8f9b1e20 100644 --- a/source/java/org/alfresco/web/templating/TemplateType.java +++ b/source/java/org/alfresco/web/templating/TemplateType.java @@ -24,37 +24,39 @@ import java.util.List; /** * Encapsulation of a template type. + * + * @author Ariel Backenroth */ public interface TemplateType - extends Serializable + extends Serializable { - /** the name of the template, which must be unique within the TemplatingService */ - public String getName(); + /** the name of the template, which must be unique within the TemplatingService */ + public String getName(); - /** the root tag to use within the schema */ - public String getRootTagName(); + /** the root tag to use within the schema */ + public String getRootTagName(); - /** the xml schema for this template type */ - public Document getSchema(); + /** the xml schema for this template type */ + public Document getSchema(); public NodeRef getNodeRef(); - //XXXarielb not used currently and not sure if it's necessary... - // public void addInputMethod(final TemplateInputMethod in); + //XXXarielb not used currently and not sure if it's necessary... + // public void addInputMethod(final TemplateInputMethod in); - /** - * Provides a set of input methods for this template. - */ - public List getInputMethods(); + /** + * Provides a set of input methods for this template. + */ + public List getInputMethods(); - /** - * adds an output method to this template type. - */ - public void addOutputMethod(TemplateOutputMethod output); + /** + * adds an output method to this template type. + */ + public void addOutputMethod(TemplateOutputMethod output); - /** - * Provides the set of output methods for this template. - */ - public List getOutputMethods(); + /** + * Provides the set of output methods for this template. + */ + public List getOutputMethods(); } diff --git a/source/java/org/alfresco/web/ui/wcm/component/UIFormProcessor.java b/source/java/org/alfresco/web/ui/wcm/component/UIFormProcessor.java new file mode 100644 index 0000000000..e4675f3658 --- /dev/null +++ b/source/java/org/alfresco/web/ui/wcm/component/UIFormProcessor.java @@ -0,0 +1,148 @@ +/* + * 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.ui.wcm.component; + +import java.io.IOException; + +import javax.faces.context.FacesContext; +import javax.faces.context.ResponseWriter; +import javax.faces.el.ValueBinding; + +import org.alfresco.web.templating.*; +import org.alfresco.web.ui.common.component.SelfRenderingComponent; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * @author Ariel Backenroth + */ +public class UIFormProcessor extends SelfRenderingComponent +{ + private static final Log LOGGER = LogFactory.getLog(UIFormProcessor.class); + + + private TemplateInputMethod.InstanceData formInstanceData = null; + + private TemplateType form = null; + + + + // ------------------------------------------------------------------------------ + // Component implementation + + /** + * @see javax.faces.component.UIComponent#getFamily() + */ + public String getFamily() + { + return "org.alfresco.faces.FormProcessor"; + } + + public void restoreState(FacesContext context, Object state) + { + final Object values[] = (Object[])state; + // standard component attributes are restored by the super class + super.restoreState(context, values[0]); + this.formInstanceData = (TemplateInputMethod.InstanceData)values[1]; + this.form = (TemplateType)values[2]; + } + + public Object saveState(FacesContext context) + { + final Object values[] = { + // standard component attributes are saved by the super class + super.saveState(context), + this.formInstanceData, + this.form + }; + return values; + } + + /** + * @see javax.faces.component.UIComponentBase#encodeBegin(javax.faces.context.FacesContext) + */ + @SuppressWarnings("unchecked") + public void encodeBegin(final FacesContext context) + throws IOException + { + if (isRendered() == false) + { + return; + } + + final ResponseWriter out = context.getResponseWriter(); + final TemplateType form = this.getForm(); + final TemplateInputMethod.InstanceData formInstanceData = this.getFormInstanceData(); + final TemplateInputMethod tim = form.getInputMethods().get(0); + tim.generate(formInstanceData, form, out); + } + + // ------------------------------------------------------------------------------ + // Strongly typed component property accessors + + /** + * Returns the instance data to render + * + * @return The instance data to render + */ + public TemplateInputMethod.InstanceData getFormInstanceData() + { + final ValueBinding vb = getValueBinding("formInstanceData"); + if (vb != null) + { + this.formInstanceData = (TemplateInputMethod.InstanceData)vb.getValue(getFacesContext()); + } + + return this.formInstanceData; + } + + /** + * Sets the instance data to render + * + * @param formInstanceData The instance data to render + */ + public void setFormInstanceData(final TemplateInputMethod.InstanceData formInstanceData) + { + this.formInstanceData = formInstanceData; + } + + /** + * Returns the form + * + * @return The form + */ + public TemplateType getForm() + { + final ValueBinding vb = getValueBinding("form"); + if (vb != null) + { + this.form = (TemplateType)vb.getValue(getFacesContext()); + } + + return this.form; + } + + /** + * Sets the form + * + * @param form The form + */ + public void setForm(final TemplateType form) + { + this.form = form; + } +} diff --git a/source/java/org/alfresco/web/ui/wcm/tag/FormProcessorTag.java b/source/java/org/alfresco/web/ui/wcm/tag/FormProcessorTag.java new file mode 100644 index 0000000000..771206661b --- /dev/null +++ b/source/java/org/alfresco/web/ui/wcm/tag/FormProcessorTag.java @@ -0,0 +1,99 @@ +/* + * 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.ui.wcm.tag; + +import javax.faces.application.Application; +import javax.faces.component.UIComponent; +import javax.faces.el.MethodBinding; +import javax.faces.el.ValueBinding; +import org.alfresco.web.ui.common.tag.BaseComponentTag; + +/** + * @author Ariel Backenroth + */ +public class FormProcessorTag extends BaseComponentTag +{ + /** + * @see javax.faces.webapp.UIComponentTag#getComponentType() + */ + public String getComponentType() + { + return "org.alfresco.faces.FormProcessor"; + } + + /** + * @see javax.faces.webapp.UIComponentTag#getRendererType() + */ + public String getRendererType() + { + return null; + } + + /** + * @see javax.faces.webapp.UIComponentTag#setProperties(javax.faces.component.UIComponent) + */ + protected void setProperties(final UIComponent component) + { + super.setProperties(component); + final Application app = this.getFacesContext().getApplication(); + if (this.instanceData != null) + { + assert isValueReference(this.instanceData); + final ValueBinding vb = app.createValueBinding(this.instanceData); + component.setValueBinding("formInstanceData", vb); + } + if (this.templateType != null) + { + assert this.isValueReference(this.templateType); + final ValueBinding vb = app.createValueBinding(this.templateType); + component.setValueBinding("form", vb); + } + } + + /** + * @see org.alfresco.web.ui.common.tag.HtmlComponentTag#release() + */ + public void release() + { + super.release(); + this.instanceData = null; + this.templateType = null; + } + + /** + * Set the instance data + * + * @param instanceData the instance data for the processor + */ + public void setFormInstanceData(final String instanceData) + { + this.instanceData = instanceData; + } + + /** + * Sets the tempalte type + * + * @param templateType the tempalteType for the processor. + */ + public void setForm(final String templateType) + { + this.templateType = templateType; + } + + private String instanceData; + private String templateType; +} diff --git a/source/web/WEB-INF/faces-config-wcm.xml b/source/web/WEB-INF/faces-config-wcm.xml index d0601dfabc..fae5a99c32 100644 --- a/source/web/WEB-INF/faces-config-wcm.xml +++ b/source/web/WEB-INF/faces-config-wcm.xml @@ -8,6 +8,11 @@ org.alfresco.faces.UserSandboxes org.alfresco.web.ui.wcm.component.UIUserSandboxes + + + org.alfresco.faces.FormProcessor + org.alfresco.web.ui.wcm.component.UIFormProcessor + diff --git a/source/web/WEB-INF/wcm.tld b/source/web/WEB-INF/wcm.tld index ae08fd8fc3..a68a22140e 100644 --- a/source/web/WEB-INF/wcm.tld +++ b/source/web/WEB-INF/wcm.tld @@ -43,5 +43,47 @@ true + + + formProcessor + org.alfresco.web.ui.wcm.tag.FormProcessorTag + JSP + Form Processor + Renders a form + + + id + false + true + The component identifier for this component + + + + formInstanceData + true + true + The instance data for the form processor + + + + form + true + true + The form to use to render this form. + + + + binding + false + true + The value binding expression linking this component to a property in a backing bean + + + + rendered + false + true + + diff --git a/source/web/jsp/wcm/create-web-content-wizard/create-xml.jsp b/source/web/jsp/wcm/create-web-content-wizard/create-xml.jsp index 44c54d85c4..1f71034ff5 100644 --- a/source/web/jsp/wcm/create-web-content-wizard/create-xml.jsp +++ b/source/web/jsp/wcm/create-web-content-wizard/create-xml.jsp @@ -18,11 +18,7 @@ <%@ 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.wcm.AVMConstants" %> -<%@ page import="org.alfresco.web.app.Application" %> -<%@ page import="org.alfresco.web.templating.*" %> -<%@ page import="org.alfresco.web.bean.wcm.CreateWebContentWizard" %> -<%@ page import="org.w3c.dom.Document" %> +<%@ taglib uri="/WEB-INF/wcm.tld" prefix="wcm" %> -<% -final CreateWebContentWizard wiz = (CreateWebContentWizard) - Application.getWizardManager().getBean(); -TemplateType tt = wiz.getTemplateType(); -TemplateInputMethod tim = tt.getInputMethods().get(0); -final TemplatingService ts = TemplatingService.getInstance(); -final TemplateInputMethod.InstanceData instanceData = new TemplateInputMethod.InstanceData() -{ - public Document getContent() - { - try - { - return (wiz.getContent() != null ? ts.parseXML(wiz.getContent()) : null); - } - catch (Exception e) - { - e.printStackTrace(); - return null; - } - } - - public void setContent(final Document d) - { - wiz.setContent(ts.writeXMLToString(d)); - } -}; -tim.generate(instanceData, tt, out); -%> + diff --git a/source/web/jsp/wcm/edit-xml-inline.jsp b/source/web/jsp/wcm/edit-xml-inline.jsp index e7bf35007e..f51c7806b6 100644 --- a/source/web/jsp/wcm/edit-xml-inline.jsp +++ b/source/web/jsp/wcm/edit-xml-inline.jsp @@ -19,48 +19,11 @@ <%@ 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" %> -<%@ page import="org.alfresco.web.bean.wcm.*, - org.alfresco.model.WCMModel, - org.alfresco.service.cmr.repository.*, - org.alfresco.web.bean.content.*, - org.alfresco.web.templating.*" %> -<%@ page import="java.io.*" %> -<%@ page import="org.alfresco.web.app.Application" %> -<%@ page import="org.alfresco.web.templating.*" %> -<%@ page import="org.w3c.dom.Document" %> -<% -final AVMBrowseBean browseBean = (AVMBrowseBean)session.getAttribute("AVMBrowseBean"); -NodeRef nr = browseBean.getAvmActionNode().getNodeRef(); -final AVMEditBean editBean = (AVMEditBean)session.getAttribute("AVMEditBean"); -final NodeRef ttNodeRef = (NodeRef)browseBean.getNodeService().getProperty(nr, WCMModel.PROP_FORM_DERIVED_FROM); -final TemplatingService ts = TemplatingService.getInstance(); -final TemplateType tt = ts.getTemplateType(ttNodeRef); -TemplateInputMethod tim = tt.getInputMethods().get(0); -final TemplateInputMethod.InstanceData instanceData = new TemplateInputMethod.InstanceData() -{ - public Document getContent() - { - try - { - return editBean.getEditorOutput() != null ? ts.parseXML(editBean.getEditorOutput()) : null; - } - catch (Exception e) - { - e.printStackTrace(); - return null; - } - } - - public void setContent(final Document d) - { - editBean.setEditorOutput(ts.writeXMLToString(d)); - } -}; -%>