Merged DEV/FORMS to HEAD (Merging r13070 through r13210)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13211 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Neil McErlean
2009-02-12 16:17:32 +00:00
parent d4aafeaf54
commit c819d08ddc
3 changed files with 73 additions and 11 deletions

View File

@@ -25,7 +25,7 @@
package org.alfresco.repo.forms; package org.alfresco.repo.forms;
import java.io.InputStream; import java.io.InputStream;
import java.util.HashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang.NotImplementedException; import org.apache.commons.lang.NotImplementedException;
@@ -44,7 +44,7 @@ public class FormData
*/ */
public FormData() public FormData()
{ {
this.data = new HashMap<String, FieldData>(8); this.data = new LinkedHashMap<String, FieldData>(8);
} }
/** /**
@@ -82,6 +82,7 @@ public class FormData
/* /*
* @see java.lang.Object#toString() * @see java.lang.Object#toString()
*/ */
@Override
public String toString() public String toString()
{ {
StringBuilder buffer = new StringBuilder(super.toString()); StringBuilder buffer = new StringBuilder(super.toString());
@@ -163,6 +164,7 @@ public class FormData
/* /*
* @see java.lang.Object#toString() * @see java.lang.Object#toString()
*/ */
@Override
public String toString() public String toString()
{ {
StringBuilder buffer = new StringBuilder(super.toString()); StringBuilder buffer = new StringBuilder(super.toString());

View File

@@ -29,6 +29,8 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.alfresco.repo.forms.AssociationFieldDefinition; import org.alfresco.repo.forms.AssociationFieldDefinition;
import org.alfresco.repo.forms.Form; import org.alfresco.repo.forms.Form;
@@ -36,6 +38,7 @@ import org.alfresco.repo.forms.FormData;
import org.alfresco.repo.forms.FormException; import org.alfresco.repo.forms.FormException;
import org.alfresco.repo.forms.PropertyFieldDefinition; import org.alfresco.repo.forms.PropertyFieldDefinition;
import org.alfresco.repo.forms.AssociationFieldDefinition.Direction; import org.alfresco.repo.forms.AssociationFieldDefinition.Direction;
import org.alfresco.repo.forms.FormData.FieldData;
import org.alfresco.repo.forms.PropertyFieldDefinition.FieldConstraint; import org.alfresco.repo.forms.PropertyFieldDefinition.FieldConstraint;
import org.alfresco.service.cmr.dictionary.AssociationDefinition; import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.Constraint; import org.alfresco.service.cmr.dictionary.Constraint;
@@ -72,6 +75,13 @@ public class NodeHandler extends AbstractHandler
protected DictionaryService dictionaryService; protected DictionaryService dictionaryService;
protected NamespaceService namespaceService; protected NamespaceService namespaceService;
/**
* A regular expression which can be used to match property/association names.
* These names will look like <code>"prop:cm:name"</code>.
* The pattern can also be used to extract the "cm" and the "name" parts.
*/
private Pattern propertyNamePattern = Pattern.compile("prop:(.*){1}?:(.*){1}?");
/** /**
* Sets the node service * Sets the node service
* *
@@ -131,14 +141,51 @@ public class NodeHandler extends AbstractHandler
*/ */
public void handlePersist(Object item, FormData data) public void handlePersist(Object item, FormData data)
{ {
if (logger.isDebugEnabled())
logger.debug("Persisting form for: " + item + " with data: " + data);
// cast to the expected NodeRef representation // cast to the expected NodeRef representation
NodeRef nodeRef = (NodeRef)item; NodeRef nodeRef = (NodeRef)item;
// TODO: persist data using node service Map<QName, Serializable> submittedProperties = extractSubmittedPropsFrom(data);
// The call to addProperties changes the repo values of those properties
// included in the Map, but leaves any other property values unchanged.
//
// Compare setProperties(..), which causes the deletion of properties that
// are not included in the Map.
this.nodeService.addProperties(nodeRef, submittedProperties);
}
private Map<QName, Serializable> extractSubmittedPropsFrom(FormData data)
{
Map<QName, Serializable> result = new HashMap<QName, Serializable>();
for (String dataKey : data.getData().keySet())
{
FieldData nextFieldData = data.getData().get(dataKey);
if (nextFieldData.isFile())
{
//TODO Implement support for file-based submits.
}
else
{
String nextDataName = nextFieldData.getName();
Matcher m = this.propertyNamePattern.matcher(nextDataName);
// Only "prop:" properties are handled here
if (m.matches())
{
String qNamePrefix = m.group(1);
String localName = m.group(2);
QName fullQName = QName.createQName(qNamePrefix, localName, namespaceService);
// These values are all Strings. The repo does most of the data
// conversion work for us.
Object nextDataObject = nextFieldData.getValue();
// This cast should be safe as all dataObjects are Strings.
result.put(fullQName, (Serializable)nextDataObject);
}
//TODO Implement support for "assoc:" properties.
}
}
return result;
} }
/** /**

View File

@@ -29,6 +29,8 @@ import org.alfresco.repo.forms.FormData;
import org.alfresco.repo.forms.FormService; import org.alfresco.repo.forms.FormService;
import org.alfresco.repo.jscript.BaseScopableProcessorExtension; import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
import org.alfresco.service.ServiceRegistry; import org.alfresco.service.ServiceRegistry;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/** /**
* Script object representing the form service. * Script object representing the form service.
@@ -37,6 +39,7 @@ import org.alfresco.service.ServiceRegistry;
*/ */
public class ScriptFormService extends BaseScopableProcessorExtension public class ScriptFormService extends BaseScopableProcessorExtension
{ {
private static Log logger = LogFactory.getLog(ScriptFormService.class);
/** Service Registry */ /** Service Registry */
private ServiceRegistry serviceRegistry; private ServiceRegistry serviceRegistry;
@@ -85,11 +88,21 @@ public class ScriptFormService extends BaseScopableProcessorExtension
*/ */
public void saveForm(String item, Object postData) public void saveForm(String item, Object postData)
{ {
FormData data = null; FormData dataForFormService = null;
if (postData instanceof FormData)
{
dataForFormService = (FormData)postData;
// Note on data conversion. The Repo will handle conversion of String-based
// data into the types required by the model.
// convert the post data into a repo FormData object //TODO Do we need special handling for submission of false booleans?
data = new FormData(); }
else
{
// TODO Need to add handling of other POST submit types here. JSON, args.
dataForFormService = new FormData();
}
formService.saveForm(item, data); formService.saveForm(item, dataForFormService);
} }
} }