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
This commit is contained in:
Ariel Backenroth
2006-10-19 19:14:55 +00:00
parent 1507f7387a
commit 226e840521
9 changed files with 406 additions and 94 deletions

View File

@@ -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

View File

@@ -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.

View File

@@ -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<TemplateInputMethod> getInputMethods();
/**
* Provides a set of input methods for this template.
*/
public List<TemplateInputMethod> 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<TemplateOutputMethod> getOutputMethods();
/**
* Provides the set of output methods for this template.
*/
public List<TemplateOutputMethod> getOutputMethods();
}

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -8,6 +8,11 @@
<component-type>org.alfresco.faces.UserSandboxes</component-type>
<component-class>org.alfresco.web.ui.wcm.component.UIUserSandboxes</component-class>
</component>
<component>
<component-type>org.alfresco.faces.FormProcessor</component-type>
<component-class>org.alfresco.web.ui.wcm.component.UIFormProcessor</component-class>
</component>
<!-- ==================== CONVERTERS ==================== -->

View File

@@ -43,5 +43,47 @@
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<name>formProcessor</name>
<tag-class>org.alfresco.web.ui.wcm.tag.FormProcessorTag</tag-class>
<body-content>JSP</body-content>
<display-name>Form Processor</display-name>
<description>Renders a form</description>
<attribute>
<name>id</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>The component identifier for this component</description>
</attribute>
<attribute>
<name>formInstanceData</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<description>The instance data for the form processor</description>
</attribute>
<attribute>
<name>form</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<description>The form to use to render this form.</description>
</attribute>
<attribute>
<name>binding</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>The value binding expression linking this component to a property in a backing bean</description>
</attribute>
<attribute>
<name>rendered</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>

View File

@@ -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" %>
<script type="text/javascript">
function _xforms_getSubmitButtons()
@@ -31,31 +27,6 @@ function _xforms_getSubmitButtons()
document.getElementById("wizard:finish-button") ];
}
</script>
<%
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);
%>
<wcm:formProcessor id="form-data-renderer"
formInstanceData="#{WizardManager.bean.instanceData}"
form="#{WizardManager.bean.templateType}"/>

View File

@@ -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));
}
};
%>
<r:page titleId="title_edit_xml_inline">
<script type="text/javascript">
@@ -140,7 +103,9 @@ function _xforms_getSubmitButtons()
<td width="100%" valign="top" height="100%">
<% PanelGenerator.generatePanelStart(out, request.getContextPath(), "white", "white"); %>
<% tim.generate(instanceData, tt, out); %>
<wcm:formProcessor id="form-data-renderer"
formInstanceData="#{AVMEditBean.instanceData}"
form="#{AVMEditBean.templateType}"/>
<% PanelGenerator.generatePanelEnd(out, request.getContextPath(), "white"); %>
</td>