mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged V2.0 to HEAD
5144: Original HEAD revision 5141 that was reverted WCM-317 WCM-302 WCM-333 WCM-270 WCM-312 WCM-305 WCM-298 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5326 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -33,6 +33,7 @@ import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
import javax.faces.context.FacesContext;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.model.WCMAppModel;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
@@ -41,6 +42,7 @@ import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.TemplateException;
|
||||
import org.alfresco.service.cmr.repository.TemplateService;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowService;
|
||||
@@ -145,8 +147,8 @@ public class FormImpl
|
||||
final String parentAVMPath,
|
||||
final String webappName)
|
||||
{
|
||||
final String outputPathPattern = this.getOutputPathPattern();
|
||||
|
||||
final String outputPathPattern = (FreeMarkerUtil.buildNamespaceDeclaration(formInstanceData) +
|
||||
this.getOutputPathPattern());
|
||||
final Map<String, Object> root = new HashMap<String, Object>();
|
||||
root.put("webapp", webappName);
|
||||
root.put("xml", NodeModel.wrap(formInstanceData));
|
||||
@@ -155,9 +157,30 @@ public class FormImpl
|
||||
|
||||
final TemplateService templateService = this.getServiceRegistry().getTemplateService();
|
||||
|
||||
String result = templateService.processTemplateString(null,
|
||||
outputPathPattern,
|
||||
new SimpleHash(root));
|
||||
String result = null;
|
||||
try
|
||||
{
|
||||
if (LOGGER.isDebugEnabled())
|
||||
{
|
||||
|
||||
LOGGER.debug("processing " + outputPathPattern +
|
||||
" using name " + formInstanceDataName +
|
||||
" in webapp " + webappName +
|
||||
" and xml data " + XMLUtil.toString(formInstanceData));
|
||||
}
|
||||
result = templateService.processTemplateString(null,
|
||||
outputPathPattern,
|
||||
new SimpleHash(root));
|
||||
}
|
||||
catch (TemplateException te)
|
||||
{
|
||||
LOGGER.error(te.getMessage(), te);
|
||||
throw new AlfrescoRuntimeException("Error processing output path pattern " + outputPathPattern +
|
||||
" for " + formInstanceDataName +
|
||||
" in webapp " + webappName +
|
||||
":\n" + te.getMessage(),
|
||||
te);
|
||||
}
|
||||
result = AVMConstants.buildPath(parentAVMPath,
|
||||
result,
|
||||
AVMConstants.PathRelation.SANDBOX_RELATIVE);
|
||||
@@ -268,4 +291,4 @@ public class FormImpl
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -64,6 +64,11 @@ public class FormInstanceDataImpl
|
||||
this.nodeRef = nodeRef;
|
||||
}
|
||||
|
||||
public FormInstanceDataImpl(final int version, final String avmPath)
|
||||
{
|
||||
this(AVMNodeConverter.ToNodeRef(version, avmPath));
|
||||
}
|
||||
|
||||
/** the name of this rendition */
|
||||
public String getName()
|
||||
{
|
||||
|
@@ -44,17 +44,27 @@ public interface FormProcessor
|
||||
public interface Session
|
||||
{
|
||||
|
||||
/** Returns the set of file uploaded during the session. */
|
||||
public NodeRef[] getUploadedFiles();
|
||||
|
||||
/** Destroys the session and releases all resources used by it */
|
||||
public void destroy();
|
||||
|
||||
/** Returns the form used by the session. */
|
||||
public Form getForm();
|
||||
|
||||
/** Returns the current state of the form instance data */
|
||||
public Document getFormInstanceData();
|
||||
|
||||
/** Returns the name of the form instance data being modified */
|
||||
public String getFormInstanceDataName();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Exception for errors encoutered during form processing.
|
||||
*/
|
||||
public static class ProcessingException
|
||||
extends Exception
|
||||
{
|
||||
@@ -81,14 +91,23 @@ public interface FormProcessor
|
||||
* Processes a user interface for inputing data into a form.
|
||||
*
|
||||
* @param formInstanceData provides the xml instance data if available.
|
||||
* @param formInstanceDataName the name of the form instance data being modified.
|
||||
* @param form the form to generate for
|
||||
* @param out the writer to write the output to.
|
||||
*/
|
||||
public Session process(final Document formInstanceData,
|
||||
final String formInstanceDataName,
|
||||
final Form form,
|
||||
final Writer out)
|
||||
throws ProcessingException;
|
||||
|
||||
/**
|
||||
* Processes a user interface for inputing data into a form.
|
||||
*
|
||||
* @param session the session to use.
|
||||
* @param form the form to generate for
|
||||
* @param out the writer to write the output to.
|
||||
*/
|
||||
public void process(final Session session,
|
||||
final Writer out)
|
||||
throws ProcessingException;
|
||||
|
66
source/java/org/alfresco/web/forms/FreeMarkerUtil.java
Normal file
66
source/java/org/alfresco/web/forms/FreeMarkerUtil.java
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* 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.forms;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.LinkedList;
|
||||
import javax.xml.XMLConstants;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* FreeMarker utility functions.
|
||||
*
|
||||
* @author Ariel Backenroth
|
||||
*/
|
||||
public class FreeMarkerUtil
|
||||
{
|
||||
public static String buildNamespaceDeclaration(final Document xml)
|
||||
{
|
||||
final Element docEl = xml.getDocumentElement();
|
||||
final NamedNodeMap attributes = docEl.getAttributes();
|
||||
final StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i < attributes.getLength(); i++)
|
||||
{
|
||||
final Node a = attributes.item(i);
|
||||
if (a.getNodeName().startsWith(XMLConstants.XMLNS_ATTRIBUTE))
|
||||
{
|
||||
final String prefix = a.getNodeName().substring((XMLConstants.XMLNS_ATTRIBUTE + ":").length());
|
||||
final String uri = a.getNodeValue();
|
||||
if (result.length() != 0)
|
||||
{
|
||||
result.append(",\n");
|
||||
}
|
||||
result.append("\"").append(prefix).append("\":\"").append(uri).append("\"");
|
||||
}
|
||||
}
|
||||
return "<#ftl ns_prefixes={\n" + result.toString() + "}>\n";
|
||||
}
|
||||
}
|
@@ -23,11 +23,17 @@
|
||||
package org.alfresco.web.forms;
|
||||
|
||||
import freemarker.ext.dom.NodeModel;
|
||||
import freemarker.template.*;
|
||||
import freemarker.template.SimpleDate;
|
||||
import freemarker.template.SimpleHash;
|
||||
import freemarker.template.SimpleScalar;
|
||||
import freemarker.template.TemplateHashModel;
|
||||
import freemarker.template.TemplateModel;
|
||||
import freemarker.template.TemplateModelException;
|
||||
import java.io.*;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.*;
|
||||
import javax.faces.context.FacesContext;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.model.WCMAppModel;
|
||||
import org.alfresco.repo.avm.AVMNodeConverter;
|
||||
@@ -35,7 +41,15 @@ import org.alfresco.repo.domain.PropertyValue;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.avm.AVMService;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.repository.*;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.TemplateException;
|
||||
import org.alfresco.service.cmr.repository.TemplateNode;
|
||||
import org.alfresco.service.cmr.repository.TemplateService;
|
||||
import org.alfresco.service.namespace.*;
|
||||
import org.alfresco.service.cmr.remote.AVMRemote;
|
||||
import org.alfresco.web.app.Application;
|
||||
@@ -163,24 +177,40 @@ public class RenderingEngineTemplateImpl
|
||||
root.put("name", formInstanceDataName.replaceAll("(.+)\\..*", "$1"));
|
||||
root.put("extension",
|
||||
sr.getMimetypeService().getExtension(this.getMimetypeForRendition()));
|
||||
|
||||
Document formInstanceDataDocument = null;
|
||||
try
|
||||
{
|
||||
root.put("xml", NodeModel.wrap(formInstanceData.getDocument()));
|
||||
formInstanceDataDocument = formInstanceData.getDocument();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.error(e);
|
||||
throw new AlfrescoRuntimeException(e.getMessage(), e);
|
||||
}
|
||||
|
||||
root.put("xml", NodeModel.wrap(formInstanceDataDocument));
|
||||
root.put("node", new TemplateNode(((FormInstanceDataImpl)formInstanceData).getNodeRef(), sr, null));
|
||||
root.put("date", new SimpleDate(new Date(), SimpleDate.DATETIME));
|
||||
|
||||
final TemplateService templateService = sr.getTemplateService();
|
||||
final String outputPathPattern = this.getOutputPathPattern();
|
||||
String result = templateService.processTemplateString(null,
|
||||
outputPathPattern,
|
||||
new SimpleHash(root));
|
||||
final String outputPathPattern = (FreeMarkerUtil.buildNamespaceDeclaration(formInstanceDataDocument) +
|
||||
this.getOutputPathPattern());
|
||||
String result = null;
|
||||
try
|
||||
{
|
||||
result = templateService.processTemplateString(null,
|
||||
outputPathPattern,
|
||||
new SimpleHash(root));
|
||||
}
|
||||
catch (final TemplateException te)
|
||||
{
|
||||
LOGGER.error(te.getMessage(), te);
|
||||
throw new AlfrescoRuntimeException("Error processing output path pattern " + outputPathPattern +
|
||||
" for " + formInstanceDataName +
|
||||
" in webapp " + webappName +
|
||||
":\n" + te.getMessage(),
|
||||
te);
|
||||
}
|
||||
final String parentAVMPath = AVMNodeConverter.SplitBase(formInstanceDataAVMPath)[0];
|
||||
result = AVMConstants.buildPath(parentAVMPath,
|
||||
result,
|
||||
@@ -367,10 +397,10 @@ public class RenderingEngineTemplateImpl
|
||||
throws IOException,
|
||||
SAXException
|
||||
{
|
||||
if (arguments.length > 1)
|
||||
if (arguments.length > 2)
|
||||
{
|
||||
throw new IllegalArgumentException("expected zero or one arguments to parseXMLDocuments. got " +
|
||||
arguments.length);
|
||||
throw new IllegalArgumentException("expected exactly one or two arguments to " +
|
||||
"parseXMLDocuments. got " + arguments.length);
|
||||
}
|
||||
if (! (arguments[0] instanceof String))
|
||||
{
|
||||
|
@@ -1718,7 +1718,7 @@ public class Schema2XForms
|
||||
// e.g. Please provide a valid value for 'Address'. 'Address' is a mandatory decimal field.
|
||||
//
|
||||
final Element alertElement = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
|
||||
NamespaceConstants.XFORMS_PREFIX + ":alert");
|
||||
NamespaceConstants.XFORMS_PREFIX + ":alert");
|
||||
formControl.appendChild(alertElement);
|
||||
this.setXFormsId(alertElement);
|
||||
|
||||
@@ -2452,29 +2452,41 @@ public class Schema2XForms
|
||||
NamespaceConstants.XFORMS_PREFIX + ":required",
|
||||
(o.minimum != 0) + "()");
|
||||
}
|
||||
else if (controlType instanceof XSComplexTypeDefinition)
|
||||
{
|
||||
// make all complex types not required since it helps with validation - otherwise
|
||||
// chiba seems to expect a nodevalue for the container element
|
||||
bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS,
|
||||
NamespaceConstants.XFORMS_PREFIX + ":required",
|
||||
"false()");
|
||||
|
||||
}
|
||||
|
||||
//no more minOccurs & maxOccurs element: add a constraint if maxOccurs>1:
|
||||
//count(.) <= maxOccurs && count(.) >= minOccurs
|
||||
final String nodeset = bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS,
|
||||
"nodeset");
|
||||
String minConstraint = null;
|
||||
String maxConstraint = null;
|
||||
|
||||
if (o.minimum > 1)
|
||||
{
|
||||
//if 0 or 1 -> no constraint (managed by "required")
|
||||
minConstraint = "count(.) >= " + o.minimum;
|
||||
bindElement.setAttributeNS(NamespaceService.ALFRESCO_URI,
|
||||
NamespaceService.ALFRESCO_PREFIX + ":minimum",
|
||||
String.valueOf(o.minimum));
|
||||
minConstraint = "count(../" + nodeset + ") >= " + o.minimum;
|
||||
}
|
||||
bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS,
|
||||
NamespaceConstants.XFORMS_PREFIX + ":minOccurs",
|
||||
String.valueOf(o.minimum));
|
||||
if (o.maximum > 1)
|
||||
{
|
||||
//if 1 or unbounded -> no constraint
|
||||
maxConstraint = "count(.) <= " + o.maximum;
|
||||
bindElement.setAttributeNS(NamespaceService.ALFRESCO_URI,
|
||||
NamespaceService.ALFRESCO_PREFIX + ":maximum",
|
||||
String.valueOf(o.maximum));
|
||||
maxConstraint = "count(../" + nodeset + ") <= " + o.maximum;
|
||||
}
|
||||
|
||||
bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS,
|
||||
NamespaceConstants.XFORMS_PREFIX + ":maxOccurs",
|
||||
o.isUnbounded() ? "unbounded" : String.valueOf(o.maximum));
|
||||
|
||||
final String constraint = (minConstraint != null && maxConstraint != null
|
||||
? minConstraint + " and " + maxConstraint
|
||||
: (minConstraint != null
|
||||
|
@@ -103,6 +103,7 @@ public class XFormsBean
|
||||
{
|
||||
|
||||
private final Document formInstanceData;
|
||||
private final String formInstanceDataName;
|
||||
private final Form form;
|
||||
|
||||
private ChibaBean chibaBean;
|
||||
@@ -111,10 +112,12 @@ public class XFormsBean
|
||||
private final List<XMLEvent> eventLog = new LinkedList<XMLEvent>();
|
||||
|
||||
public XFormsSession(final Document formInstanceData,
|
||||
final String formInstanceDataName,
|
||||
final Form form,
|
||||
final String baseUrl)
|
||||
{
|
||||
this.formInstanceData = formInstanceData;
|
||||
this.formInstanceDataName = formInstanceDataName;
|
||||
this.form = form;
|
||||
this.schema2XForms = new Schema2XForms("/ajax/invoke/XFormsBean.handleAction",
|
||||
Schema2XForms.SubmitMethod.POST,
|
||||
@@ -153,6 +156,11 @@ public class XFormsBean
|
||||
{
|
||||
return this.formInstanceData;
|
||||
}
|
||||
|
||||
public String getFormInstanceDataName()
|
||||
{
|
||||
return this.formInstanceDataName;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@@ -265,12 +273,14 @@ public class XFormsBean
|
||||
* event listeners.
|
||||
*/
|
||||
public XFormsSession createSession(final Document formInstanceData,
|
||||
final String formInstanceDataName,
|
||||
final Form form)
|
||||
{
|
||||
if (LOGGER.isDebugEnabled())
|
||||
{
|
||||
LOGGER.debug("initializing xforms session with form " + form.getName() +
|
||||
" and instance data " + formInstanceData);
|
||||
" and instance data " + formInstanceDataName +
|
||||
" (" + formInstanceData + ")");
|
||||
}
|
||||
|
||||
final FacesContext facesContext = FacesContext.getCurrentInstance();
|
||||
@@ -282,7 +292,7 @@ public class XFormsBean
|
||||
request.getServerName() + ':' +
|
||||
request.getServerPort() +
|
||||
request.getContextPath());
|
||||
return this.new XFormsSession(formInstanceData, form, baseUrl);
|
||||
return this.new XFormsSession(formInstanceData, formInstanceDataName, form, baseUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -84,6 +84,7 @@ public class XFormsProcessor
|
||||
}
|
||||
|
||||
public Session process(final Document instanceDataDocument,
|
||||
final String formInstanceDataName,
|
||||
final Form form,
|
||||
final Writer out)
|
||||
throws FormProcessor.ProcessingException
|
||||
@@ -93,7 +94,7 @@ public class XFormsProcessor
|
||||
final XFormsBean xforms = (XFormsBean)
|
||||
FacesHelper.getManagedBean(fc, "XFormsBean");
|
||||
final Session result =
|
||||
xforms.createSession(instanceDataDocument, form);
|
||||
xforms.createSession(instanceDataDocument, formInstanceDataName, form);
|
||||
this.process(result, out);
|
||||
return result;
|
||||
}
|
||||
@@ -150,6 +151,9 @@ public class XFormsProcessor
|
||||
js.append("alfresco_xforms_constants.XFORMS_UI_DIV_ID = '").
|
||||
append(xformsUIDivId).
|
||||
append("';\n");
|
||||
js.append("alfresco_xforms_constants.FORM_INSTANCE_DATA_NAME = '").
|
||||
append(session.getFormInstanceDataName()).
|
||||
append("';\n");
|
||||
for (String[] ns : JS_NAMESPACES)
|
||||
{
|
||||
js.append("alfresco_xforms_constants.").
|
||||
|
Reference in New Issue
Block a user