diff --git a/source/java/org/alfresco/repo/forms/processor/AbstractFilter.java b/source/java/org/alfresco/repo/forms/processor/AbstractFilter.java index 803142a6cf..730ae5b323 100644 --- a/source/java/org/alfresco/repo/forms/processor/AbstractFilter.java +++ b/source/java/org/alfresco/repo/forms/processor/AbstractFilter.java @@ -32,7 +32,7 @@ import org.apache.commons.logging.LogFactory; * * @author Gavin Cornwell */ -public abstract class AbstractFilter implements Filter +public abstract class AbstractFilter implements Filter { private static final Log logger = LogFactory.getLog(AbstractFilter.class); diff --git a/source/java/org/alfresco/repo/forms/processor/Filter.java b/source/java/org/alfresco/repo/forms/processor/Filter.java index 16b509bd75..147c8db6f6 100644 --- a/source/java/org/alfresco/repo/forms/processor/Filter.java +++ b/source/java/org/alfresco/repo/forms/processor/Filter.java @@ -36,7 +36,7 @@ import org.alfresco.repo.forms.FormData; * * @author Gavin Cornwell */ -public interface Filter +public interface Filter { /** * Determines whether the filter is active @@ -61,7 +61,7 @@ public interface Filter * @param @param context Map representing optional context that * can be used during retrieval of the form */ - public void beforeGenerate(Object item, List fields, List forcedFields, + public void beforeGenerate(ItemType item, List fields, List forcedFields, Form form, Map context); /** @@ -80,7 +80,7 @@ public interface Filter * @param context Map representing optional context that * can be used during retrieval of the form */ - public void afterGenerate(Object item, List fields, List forcedFields, + public void afterGenerate(ItemType item, List fields, List forcedFields, Form form, Map context); /** @@ -95,7 +95,7 @@ public interface Filter * @param item The item to persist the form data for * @param data The form data */ - public void beforePersist(Object item, FormData data); + public void beforePersist(ItemType item, FormData data); /** * Callback used to indicate that the given form data was just persisted @@ -112,5 +112,5 @@ public interface Filter * @param persistedObject The object created or modified as a result of * the form persistence */ - public void afterPersist(Object item, FormData data, Object persistedObject); + public void afterPersist(ItemType item, FormData data, PersistType persistedObject); } diff --git a/source/java/org/alfresco/repo/forms/processor/FilterRegistry.java b/source/java/org/alfresco/repo/forms/processor/FilterRegistry.java index 58147f400e..e6e7ac43f2 100644 --- a/source/java/org/alfresco/repo/forms/processor/FilterRegistry.java +++ b/source/java/org/alfresco/repo/forms/processor/FilterRegistry.java @@ -22,6 +22,7 @@ * the FLOSS exception, and it is also available here: * http://www.alfresco.com/legal/licensing" */ + package org.alfresco.repo.forms.processor; import java.util.ArrayList; @@ -33,74 +34,71 @@ import org.apache.commons.logging.LogFactory; /** * Holds a list of filters for a type of form processor. *

- * Each filter is called before and after the processor generates and - * persists the form, thus allowing the form and the effected objects - * to be manipulated prior to generation or persistence or after the - * fact. + * Each filter is called before and after the processor generates and persists + * the form, thus allowing the form and the effected objects to be manipulated + * prior to generation or persistence or after the fact. *

*

- * Each filter is responsible for determing whether it applies to the item - * being processed. + * Each filter is responsible for determing whether it applies to the item being + * processed. *

* * @see org.alfresco.repo.forms.processor.Filter * @author Gavin Cornwell */ -public class FilterRegistry +public class FilterRegistry { private static final Log logger = LogFactory.getLog(FilterRegistry.class); - - protected List filters; - + + protected List> filters; + /** * Constructs the registry */ public FilterRegistry() { - this.filters = new ArrayList(4); + this.filters = new ArrayList>(4); } - + /** * Registers a filter * * @param filter The Filter to regsiter */ - public void addFilter(Filter filter) + public void addFilter(Filter filter) { if (filter.isActive()) { this.filters.add(filter); - - if (logger.isDebugEnabled()) - logger.debug("Registered filter: " + filter + " in registry: " + this); + + if (logger.isDebugEnabled()) logger.debug("Registered filter: " + filter + " in registry: " + this); } else if (logger.isWarnEnabled()) { logger.warn("Ignored registration of filter " + filter + " as it was marked as inactive"); } } - + /** * Returns a list of active filters * * @return List of active Filter objects */ - public List getFilters() + public List> getFilters() { - List activeFilters = new ArrayList(4); - + List> activeFilters = new ArrayList>(4); + // iterate round the filters and add each active filter to the list - for (Filter filter: this.filters) + for (Filter filter : this.filters) { if (filter.isActive()) { activeFilters.add(filter); } } - - if (logger.isDebugEnabled()) - logger.debug("Returning active filters: " + activeFilters); - + + if (logger.isDebugEnabled()) logger.debug("Returning active filters: " + activeFilters); + return activeFilters; } } diff --git a/source/java/org/alfresco/repo/forms/processor/FilteredFormProcessor.java b/source/java/org/alfresco/repo/forms/processor/FilteredFormProcessor.java index 7809e366fa..c94f406cd4 100644 --- a/source/java/org/alfresco/repo/forms/processor/FilteredFormProcessor.java +++ b/source/java/org/alfresco/repo/forms/processor/FilteredFormProcessor.java @@ -22,6 +22,7 @@ * the FLOSS exception, and it is also available here: * http://www.alfresco.com/legal/licensing" */ + package org.alfresco.repo.forms.processor; import java.util.List; @@ -34,71 +35,73 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** - * Abstract base class for all FormProcessor implementations that wish to use the - * filter mechanism. - * + * Abstract base class for all FormProcessor implementations that wish to use + * the filter mechanism. + * * @author Gavin Cornwell */ -public abstract class FilteredFormProcessor extends AbstractFormProcessor +public abstract class FilteredFormProcessor extends AbstractFormProcessor { private static final Log logger = LogFactory.getLog(FilteredFormProcessor.class); - - protected FilterRegistry filterRegistry; - + + protected FilterRegistry filterRegistry; + /** - * Sets the filter registry + * Sets the filter registry * * @param filterRegistry The FilterRegistry instance */ - public void setFilterRegistry(FilterRegistry filterRegistry) + public void setFilterRegistry(FilterRegistry filterRegistry) { this.filterRegistry = filterRegistry; - + if (logger.isDebugEnabled()) logger.debug("Set filter registry: " + this.filterRegistry + " for processor: " + this); } /* - * @see org.alfresco.repo.forms.processor.FormProcessor#generate(org.alfresco.repo.forms.Item, java.util.List, java.util.List, java.util.Map) + * @see + * org.alfresco.repo.forms.processor.FormProcessor#generate(org.alfresco + * .repo.forms.Item, java.util.List, java.util.List, java.util.Map) */ - public Form generate(Item item, List fields, List forcedFields, - Map context) + public Form generate(Item item, List fields, List forcedFields, Map context) { // get the typed object representing the item - Object typedItem = getTypedItem(item); + ItemType typedItem = getTypedItem(item); // create an empty Form Form form = new Form(item); - + // inform all regsitered filters the form is about to be generated if (this.filterRegistry != null) { - for (Filter filter: this.filterRegistry.getFilters()) + for (Filter filter : this.filterRegistry.getFilters()) { filter.beforeGenerate(typedItem, fields, forcedFields, form, context); } } - + // perform the actual generation of the form internalGenerate(typedItem, fields, forcedFields, form, context); - + // inform all regsitered filters the form has been generated if (this.filterRegistry != null) { - for (Filter filter: this.filterRegistry.getFilters()) + for (Filter filter : this.filterRegistry.getFilters()) { filter.afterGenerate(typedItem, fields, forcedFields, form, context); } } - + return form; } /** - * Persists the given form data for the given item, completed by calling + * Persists the given form data for the given item, completed by calling * each applicable registered handler * - * @see org.alfresco.repo.forms.processor.FormProcessor#persist(org.alfresco.repo.forms.Item, org.alfresco.repo.forms.FormData) + * @see org.alfresco.repo.forms.processor.FormProcessor#persist(org.alfresco.repo.forms.Item, + * org.alfresco.repo.forms.FormData) * @param item The item to save the form for * @param data The object representing the form data * @return The object persisted @@ -106,44 +109,54 @@ public abstract class FilteredFormProcessor extends AbstractFormProcessor public Object persist(Item item, FormData data) { // get the typed object representing the item - Object typedItem = getTypedItem(item); + ItemType typedItem = getTypedItem(item); // inform all regsitered filters the form is about to be persisted if (this.filterRegistry != null) { - for (Filter filter: this.filterRegistry.getFilters()) + for (Filter filter : this.filterRegistry.getFilters()) { filter.beforePersist(typedItem, data); } } - + // perform the actual persistence of the form Object persistedObject = internalPersist(typedItem, data); - + // inform all regsitered filters the form has been persisted if (this.filterRegistry != null) { - for (Filter filter: this.filterRegistry.getFilters()) + for (Filter filter : this.filterRegistry.getFilters()) { filter.afterPersist(typedItem, data, persistedObject); } } - + return persistedObject; } - + + protected void setItemType(Form form, String type) + { + form.getItem().setType(type); + } + + protected void setItemUrl(Form form, String url) + { + form.getItem().setUrl(url); + } + /** - * Returns a typed Object representing the given item. + * Returns a typed Object representing the given item. *

- * Subclasses that represent a form type will return a typed object - * that is then passed to each of it's handlers, the handlers can - * therefore safely cast the Object to the type they expect. + * Subclasses that represent a form type will return a typed object that is + * then passed to each of it's handlers, the handlers can therefore safely + * cast the Object to the type they expect. * * @param item The item to get a typed object for * @return The typed object */ - protected abstract Object getTypedItem(Item item); - + protected abstract ItemType getTypedItem(Item item); + /** * Generates the form. * @@ -151,12 +164,12 @@ public abstract class FilteredFormProcessor extends AbstractFormProcessor * @param fields Restricted list of fields to include * @param forcedFields List of fields to forcibly include * @param form The form object being generated - * @param context Map representing optional context that - * can be used during retrieval of the form + * @param context Map representing optional context that can be used during + * retrieval of the form */ - protected abstract void internalGenerate(Object item, List fields, List forcedFields, - Form form, Map context); - + protected abstract void internalGenerate(ItemType item, List fields, List forcedFields, Form form, + Map context); + /** * Persists the form data. * @@ -164,5 +177,6 @@ public abstract class FilteredFormProcessor extends AbstractFormProcessor * @param data The data to persist * @return The object that got created or modified */ - protected abstract Object internalPersist(Object item, FormData data); + protected abstract PersistType internalPersist(ItemType item, FormData data); + } diff --git a/source/java/org/alfresco/repo/forms/processor/node/ContentModelFormProcessor.java b/source/java/org/alfresco/repo/forms/processor/node/ContentModelFormProcessor.java index b253623a17..e099fbce29 100644 --- a/source/java/org/alfresco/repo/forms/processor/node/ContentModelFormProcessor.java +++ b/source/java/org/alfresco/repo/forms/processor/node/ContentModelFormProcessor.java @@ -1,3 +1,4 @@ + package org.alfresco.repo.forms.processor.node; import java.io.Serializable; @@ -53,62 +54,82 @@ import org.springframework.util.StringUtils; /** * Abstract FormProcessor implementation that provides common functionality for * form processors that deal with Alfresco content models i.e. types and nodes. - * + * * @author Gavin Cornwell */ -public abstract class ContentModelFormProcessor extends FilteredFormProcessor +public abstract class ContentModelFormProcessor extends + FilteredFormProcessor { /** Public constants */ public static final String ON = "on"; + public static final String PROP = "prop"; + public static final String ASSOC = "assoc"; + public static final String DATA_KEY_SEPARATOR = "_"; + public static final String PROP_DATA_PREFIX = PROP + DATA_KEY_SEPARATOR; + public static final String ASSOC_DATA_PREFIX = ASSOC + DATA_KEY_SEPARATOR; + public static final String ASSOC_DATA_ADDED_SUFFIX = DATA_KEY_SEPARATOR + "added"; + public static final String ASSOC_DATA_REMOVED_SUFFIX = DATA_KEY_SEPARATOR + "removed"; - + public static final String TRANSIENT_MIMETYPE = "mimetype"; + public static final String TRANSIENT_SIZE = "size"; + public static final String TRANSIENT_ENCODING = "encoding"; - + /** Protected constants */ protected static final String MSG_MIMETYPE_LABEL = "form_service.mimetype.label"; + protected static final String MSG_MIMETYPE_DESC = "form_service.mimetype.description"; + protected static final String MSG_ENCODING_LABEL = "form_service.encoding.label"; + protected static final String MSG_ENCODING_DESC = "form_service.encoding.description"; + protected static final String MSG_SIZE_LABEL = "form_service.size.label"; + protected static final String MSG_SIZE_DESC = "form_service.size.description"; - + /** Services */ protected NodeService nodeService; + protected FileFolderService fileFolderService; + protected DictionaryService dictionaryService; + protected NamespaceService namespaceService; /** - * A regular expression which can be used to match property names. - * These names will look like "prop_cm_name". - * The pattern can also be used to extract the "cm" and the "name" parts. + * A regular expression which can be used to match property names. These + * names will look like "prop_cm_name". The pattern can also be + * used to extract the "cm" and the "name" parts. */ protected Pattern propertyNamePattern = Pattern.compile(PROP_DATA_PREFIX + "(.*){1}?_(.*){1}?"); - + /** * A regular expression which can be used to match tranisent property names. - * These names will look like "prop_name". - * The pattern can also be used to extract the "name" part. + * These names will look like "prop_name". The pattern can also + * be used to extract the "name" part. */ protected Pattern transientPropertyPattern = Pattern.compile(PROP_DATA_PREFIX + "(.*){1}?"); - + /** - * A regular expression which can be used to match association names. - * These names will look like "assoc_cm_references_added". - * The pattern can also be used to extract the "cm", the "name" and the suffix parts. + * A regular expression which can be used to match association names. These + * names will look like "assoc_cm_references_added". The + * pattern can also be used to extract the "cm", the "name" and the suffix + * parts. */ - protected Pattern associationNamePattern = Pattern.compile(ASSOC_DATA_PREFIX + "(.*){1}?_(.*){1}?(_[a-zA-Z]+)"); - + protected Pattern associationNamePattern = Pattern.compile(ASSOC_DATA_PREFIX + + "(.*){1}?_(.*){1}?(_[a-zA-Z]+)"); + /** - * Sets the node service + * Sets the node service * * @param nodeService The NodeService instance */ @@ -116,9 +137,9 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor { this.nodeService = nodeService; } - + /** - * Sets the file folder service + * Sets the file folder service * * @param fileFolderService The FileFolderService instance */ @@ -136,7 +157,7 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor { this.dictionaryService = dictionaryService; } - + /** * Sets the namespace service * @@ -146,13 +167,13 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor { this.namespaceService = namespaceService; } - + /** * Sets up a field definition for the given property. *

- * NOTE: This method is static so that it can serve as a helper - * method for FormFilter implementations as adding additional - * property fields is likely to be a common extension. + * NOTE: This method is static so that it can serve as a helper method for + * FormFilter implementations as adding additional property fields is likely + * to be a common extension. *

* * @param propDef The PropertyDefinition of the field to generate @@ -164,13 +185,13 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor { generatePropertyField(propDef, form, null, null, namespaceService); } - + /** * Sets up a field definition for the given property. *

- * NOTE: This method is static so that it can serve as a helper - * method for FormFilter implementations as adding additional - * property fields is likely to be a common extension. + * NOTE: This method is static so that it can serve as a helper method for + * FormFilter implementations as adding additional property fields is likely + * to be a common extension. *

* * @param propDef The PropertyDefinition of the field to generate @@ -183,13 +204,13 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor { generatePropertyField(propDef, form, propValue, null, namespaceService); } - + /** * Sets up a field definition for the given property. *

- * NOTE: This method is static so that it can serve as a helper - * method for FormFilter implementations as adding additional - * property fields is likely to be a common extension. + * NOTE: This method is static so that it can serve as a helper method for + * FormFilter implementations as adding additional property fields is likely + * to be a common extension. *

* * @param propDef The PropertyDefinition of the field to generate @@ -200,14 +221,13 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor */ @SuppressWarnings("unchecked") public static void generatePropertyField(PropertyDefinition propDef, Form form, - Serializable propValue, FieldGroup group, - NamespaceService namespaceService) + Serializable propValue, FieldGroup group, NamespaceService namespaceService) { String propName = propDef.getName().toPrefixString(namespaceService); String[] nameParts = QName.splitPrefixedQName(propName); - PropertyFieldDefinition fieldDef = new PropertyFieldDefinition( - propName, propDef.getDataType().getName().getLocalName()); - + PropertyFieldDefinition fieldDef = new PropertyFieldDefinition(propName, propDef + .getDataType().getName().getLocalName()); + String title = propDef.getTitle(); if (title == null) { @@ -220,18 +240,19 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor fieldDef.setProtectedField(propDef.isProtected()); fieldDef.setRepeating(propDef.isMultiValued()); fieldDef.setGroup(group); - + // any property from the system model (sys prefix) should be protected - // the model doesn't currently enforce this so make sure they are not editable + // the model doesn't currently enforce this so make sure they are not + // editable if (NamespaceService.SYSTEM_MODEL_1_0_URI.equals(propDef.getName().getNamespaceURI())) { fieldDef.setProtectedField(true); } - + // define the data key name and set String dataKeyName = PROP_DATA_PREFIX + nameParts[0] + DATA_KEY_SEPARATOR + nameParts[1]; fieldDef.setDataKeyName(dataKeyName); - + // setup any parameters requried for the data type if (propDef.getDataType().getName().equals(DataTypeDefinition.PERIOD)) { @@ -243,30 +264,30 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor { periodOptions.addPeriodProvider(Period.getProvider(provider)); } - + fieldDef.setDataTypeParameters(periodOptions); } - + // setup constraints for the property List constraints = propDef.getConstraints(); if (constraints != null && constraints.size() > 0) { - List fieldConstraints = - new ArrayList(constraints.size()); - + List fieldConstraints = new ArrayList(constraints + .size()); + for (ConstraintDefinition constraintDef : constraints) { Constraint constraint = constraintDef.getConstraint(); - FieldConstraint fieldConstraint = fieldDef.new FieldConstraint( - constraint.getType(), constraint.getParameters()); + FieldConstraint fieldConstraint = new FieldConstraint(constraint.getType(), + constraint.getParameters()); fieldConstraints.add(fieldConstraint); } - + fieldDef.setConstraints(fieldConstraints); } - + form.addFieldDefinition(fieldDef); - + // add the property value to the form if (propValue != null) { @@ -276,37 +297,37 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor // separated list, this will be changed to using // a separate field for each value once we have full // UI support in place. - propValue = StringUtils.collectionToCommaDelimitedString((List)propValue); + propValue = StringUtils.collectionToCommaDelimitedString((List) propValue); } - + form.addData(dataKeyName, propValue); } } - + /** * Sets up a field definition for the given association. *

- * NOTE: This method is static so that it can serve as a helper - * method for FormFilter implementations as adding additional - * association fields is likely to be a common extension. + * NOTE: This method is static so that it can serve as a helper method for + * FormFilter implementations as adding additional association fields is + * likely to be a common extension. *

* * @param assocDef The AssociationDefinition of the field to generate * @param form The Form instance to populate * @param namespaceService NamespaceService instance */ - public static void generateAssociationField(AssociationDefinition assocDef, - Form form, NamespaceService namespaceService) + public static void generateAssociationField(AssociationDefinition assocDef, Form form, + NamespaceService namespaceService) { generateAssociationField(assocDef, form, null, null, namespaceService); } - + /** * Sets up a field definition for the given association. *

- * NOTE: This method is static so that it can serve as a helper - * method for FormFilter implementations as adding additional - * association fields is likely to be a common extension. + * NOTE: This method is static so that it can serve as a helper method for + * FormFilter implementations as adding additional association fields is + * likely to be a common extension. *

* * @param assocDef The AssociationDefinition of the field to generate @@ -315,18 +336,18 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor * @param namespaceService NamespaceService instance */ @SuppressWarnings("unchecked") - public static void generateAssociationField(AssociationDefinition assocDef, - Form form, List assocValues, NamespaceService namespaceService) + public static void generateAssociationField(AssociationDefinition assocDef, Form form, + List assocValues, NamespaceService namespaceService) { generateAssociationField(assocDef, form, assocValues, null, namespaceService); } - + /** * Sets up a field definition for the given association. *

- * NOTE: This method is static so that it can serve as a helper - * method for FormFilter implementations as adding additional - * association fields is likely to be a common extension. + * NOTE: This method is static so that it can serve as a helper method for + * FormFilter implementations as adding additional association fields is + * likely to be a common extension. *

* * @param assocDef The AssociationDefinition of the field to generate @@ -336,15 +357,13 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor * @param namespaceService NamespaceService instance */ @SuppressWarnings("unchecked") - public static void generateAssociationField(AssociationDefinition assocDef, - Form form, List assocValues, FieldGroup group, - NamespaceService namespaceService) + public static void generateAssociationField(AssociationDefinition assocDef, Form form, + List assocValues, FieldGroup group, NamespaceService namespaceService) { String assocName = assocDef.getName().toPrefixString(namespaceService); String[] nameParts = QName.splitPrefixedQName(assocName); - AssociationFieldDefinition fieldDef = new AssociationFieldDefinition(assocName, - assocDef.getTargetClass().getName().toPrefixString( - namespaceService), Direction.TARGET); + AssociationFieldDefinition fieldDef = new AssociationFieldDefinition(assocName, assocDef + .getTargetClass().getName().toPrefixString(namespaceService), Direction.TARGET); String title = assocDef.getTitle(); if (title == null) { @@ -356,90 +375,93 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor fieldDef.setEndpointMandatory(assocDef.isTargetMandatory()); fieldDef.setEndpointMany(assocDef.isTargetMany()); fieldDef.setGroup(group); - + // define the data key name and set String dataKeyName = ASSOC_DATA_PREFIX + nameParts[0] + DATA_KEY_SEPARATOR + nameParts[1]; fieldDef.setDataKeyName(dataKeyName); - + // add definition to the form form.addFieldDefinition(fieldDef); - + if (assocValues != null) { // add the association value to the form - // determine the type of association values data and extract accordingly + // determine the type of association values data and extract + // accordingly List values = new ArrayList(4); for (Object value : assocValues) { if (value instanceof ChildAssociationRef) { - values.add(((ChildAssociationRef)value).getChildRef().toString()); + values.add(((ChildAssociationRef) value).getChildRef().toString()); } else if (value instanceof AssociationRef) { - values.add(((AssociationRef)value).getTargetRef().toString()); + values.add(((AssociationRef) value).getTargetRef().toString()); } else { values.add(value.toString()); } } - + // Add the list as the value for the association. form.addData(dataKeyName, values); } } - + /** * Retrieves a logger instance to log to. * * @return Log instance to log to. */ protected abstract Log getLogger(); - + /** * Sets up the field definitions for all the requested fields. *

- * A NodeRef or TypeDefinition can be provided, however, if a NodeRef - * is provided all type information will be derived from the NodeRef - * and the TypeDefinition will be ignored. - *

- * If any of the requested fields are not present on the type and - * they appear in the forcedFields list an attempt to find a model - * definition for those fields is made so they can be included. + * A NodeRef or TypeDefinition can be provided, however, if a NodeRef is + * provided all type information will be derived from the NodeRef and the + * TypeDefinition will be ignored. + *

+ *

+ * If any of the requested fields are not present on the type and they + * appear in the forcedFields list an attempt to find a model definition for + * those fields is made so they can be included. *

* * @param nodeRef The NodeRef of the item being generated * @param typeDef The TypeDefiniton of the item being generated * @param fields Restricted list of fields to include - * @param forcedFields List of field names that should be included - * even if the field is not currently present + * @param forcedFields List of field names that should be included even if + * the field is not currently present * @param form The Form instance to populate */ - protected void generateSelectedFields(NodeRef nodeRef, TypeDefinition typeDef, + protected void generateSelectedFields(NodeRef nodeRef, TypeDefinition typeDef, List fields, List forcedFields, Form form) { // ensure a NodeRef or TypeDefinition is provided - if (nodeRef == null && typeDef == null) - { - throw new IllegalArgumentException("A NodeRef or TypeDefinition must be provided"); - } - + if (nodeRef == null && typeDef == null) { throw new IllegalArgumentException( + "A NodeRef or TypeDefinition must be provided"); } + if (getLogger().isDebugEnabled()) - getLogger().debug("Generating selected fields: " + fields + " and forcing: " + forcedFields); - + getLogger().debug( + "Generating selected fields: " + fields + " and forcing: " + forcedFields); + // get data dictionary definition for node if it is provided QName type = null; Map propValues = Collections.emptyMap(); Map propDefs = null; Map assocDefs = null; - + if (nodeRef != null) { type = this.nodeService.getType(nodeRef); - typeDef = this.dictionaryService.getAnonymousType(type, this.nodeService.getAspects(nodeRef)); - - // NOTE: the anonymous type returns all property and association defs + typeDef = this.dictionaryService.getAnonymousType(type, this.nodeService + .getAspects(nodeRef)); + + // NOTE: the anonymous type returns all property and association + // defs // for all aspects applied as well as the type propDefs = typeDef.getProperties(); assocDefs = typeDef.getAssociations(); @@ -448,7 +470,7 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor else { type = typeDef.getName(); - + // we only get the properties and associations of the actual type so // we also need to manually get properties and associations from any // mandatory aspects @@ -456,15 +478,15 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor assocDefs = new HashMap(16); propDefs.putAll(typeDef.getProperties()); assocDefs.putAll(typeDef.getAssociations()); - + List aspects = typeDef.getDefaultAspects(true); for (AspectDefinition aspect : aspects) { propDefs.putAll(aspect.getProperties()); assocDefs.putAll(aspect.getAssociations()); } - } - + } + for (String fieldName : fields) { // try and split the field name @@ -476,7 +498,7 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor boolean tryAssociation = true; String qNamePrefix = null; String localName = null; - + if (parts.length == 2) { qNamePrefix = parts[0]; @@ -484,9 +506,12 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor } else { - // if there are 3 parts to the field name the first one represents - // whether the field is a property or association i.e. prop:prefix:local - // or assoc:prefix:local, determine the prefix and ensure it's valid + // if there are 3 parts to the field name the first one + // represents + // whether the field is a property or association i.e. + // prop:prefix:local + // or assoc:prefix:local, determine the prefix and ensure + // it's valid if (PROP.equals(parts[0])) { tryAssociation = false; @@ -498,18 +523,22 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor else { if (getLogger().isWarnEnabled()) - getLogger().warn("\"" + parts[0] + "\" is an invalid prefix for requesting a property or association"); + getLogger() + .warn( + "\"" + + parts[0] + + "\" is an invalid prefix for requesting a property or association"); continue; } - + qNamePrefix = parts[1]; localName = parts[2]; } - + // create qname of field name QName fullQName = QName.createQName(qNamePrefix, localName, namespaceService); - + // try the field as a property if (tryProperty) { @@ -518,14 +547,15 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor if (propDef != null) { // generate the property field - generatePropertyField(propDef, form, propValues.get(fullQName), this.namespaceService); - + generatePropertyField(propDef, form, propValues.get(fullQName), + this.namespaceService); + // no need to try and find an association tryAssociation = false; foundField = true; } } - + // try the field as an association if (tryAssociation) { @@ -533,40 +563,48 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor if (assocDef != null) { // generate the association field - generateAssociationField(assocDef, form, - (nodeRef != null) ? retrieveAssociationValues(nodeRef, assocDef) : null, - this.namespaceService); - + generateAssociationField( + assocDef, + form, + (nodeRef != null) ? retrieveAssociationValues(nodeRef, assocDef) + : null, this.namespaceService); + foundField = true; } } - + // still not found the field, is it a force'd field? if (!foundField) { - if (forcedFields != null && forcedFields.size() > 0 && - forcedFields.contains(fieldName)) + if (forcedFields != null && forcedFields.size() > 0 + && forcedFields.contains(fieldName)) { generateForcedField(fieldName, form); } else if (getLogger().isDebugEnabled()) { - getLogger().debug("Ignoring field \"" + fieldName + - "\" as it is not defined for the current " + ((nodeRef != null) ? "node" : "type") + - " and it does not appear in the 'force' list"); + getLogger().debug( + "Ignoring field \"" + fieldName + + "\" as it is not defined for the current " + + ((nodeRef != null) ? "node" : "type") + + " and it does not appear in the 'force' list"); } } } else { // see if the fieldName is a well known transient property - if (TRANSIENT_MIMETYPE.equals(fieldName) || TRANSIENT_ENCODING.equals(fieldName) || - TRANSIENT_SIZE.equals(fieldName)) + if (TRANSIENT_MIMETYPE.equals(fieldName) || TRANSIENT_ENCODING.equals(fieldName) + || TRANSIENT_SIZE.equals(fieldName)) { - // if the node type is content or sublcass thereof generate appropriate field - if (nodeRef != null && this.dictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)) + // if the node type is content or sublcass thereof generate + // appropriate field + if (nodeRef != null + && this.dictionaryService.isSubClass(type, + ContentModel.TYPE_CONTENT)) { - ContentData content = (ContentData)this.nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT); + ContentData content = (ContentData) this.nodeService.getProperty(nodeRef, + ContentModel.PROP_CONTENT); if (content != null) { if (TRANSIENT_MIMETYPE.equals(fieldName)) @@ -591,10 +629,10 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor } } } - + /** - * Generates a field definition for the given field that is being forced - * to show. + * Generates a field definition for the given field that is being forced to + * show. * * @param fieldName Name of the field to force * @param form The Form instance to populated @@ -603,7 +641,7 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor { if (getLogger().isDebugEnabled()) getLogger().debug("Attempting to force the inclusion of field \"" + fieldName + "\""); - + String[] parts = fieldName.split(":"); if (parts.length == 2 || parts.length == 3) { @@ -612,7 +650,7 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor boolean tryAssociation = true; String qNamePrefix = null; String localName = null; - + if (parts.length == 2) { qNamePrefix = parts[0]; @@ -620,9 +658,12 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor } else { - // if there are 3 parts to the field name the first one represents - // whether the field is a property or association i.e. prop:prefix:local - // or assoc:prefix:local, determine the prefix and ensure it's valid + // if there are 3 parts to the field name the first one + // represents + // whether the field is a property or association i.e. + // prop:prefix:local + // or assoc:prefix:local, determine the prefix and ensure it's + // valid if (PROP.equals(parts[0])) { tryAssociation = false; @@ -634,18 +675,22 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor else { if (getLogger().isWarnEnabled()) - getLogger().warn("\"" + parts[0] + "\" is an invalid prefix for requesting a property or association"); + getLogger() + .warn( + "\"" + + parts[0] + + "\" is an invalid prefix for requesting a property or association"); return; } - + qNamePrefix = parts[1]; localName = parts[2]; } - + // create qname of field name QName fullQName = QName.createQName(qNamePrefix, localName, namespaceService); - + if (tryProperty) { // lookup the field as a property in the whole model @@ -654,13 +699,13 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor { // generate the property field generatePropertyField(propDef, form, this.namespaceService); - + // no need to try and find an association tryAssociation = false; foundField = true; } } - + if (tryAssociation) { // lookup the field as an association in the whole model @@ -669,15 +714,18 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor { // generate the association field generateAssociationField(assocDef, form, this.namespaceService); - + foundField = true; } } - + if (!foundField && getLogger().isDebugEnabled()) { - getLogger().debug("Ignoring field \"" + fieldName + - "\" as it is not defined for the current node and can not be found in any model"); + getLogger() + .debug( + "Ignoring field \"" + + fieldName + + "\" as it is not defined for the current node and can not be found in any model"); } } else if (getLogger().isWarnEnabled()) @@ -685,7 +733,7 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor getLogger().warn("Ignoring unrecognised field \"" + fieldName + "\""); } } - + /** * Generates the field definition for the transient mimetype property * @@ -695,19 +743,19 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor protected void generateMimetypePropertyField(ContentData content, Form form) { String dataKeyName = PROP_DATA_PREFIX + TRANSIENT_MIMETYPE; - PropertyFieldDefinition mimetypeField = new PropertyFieldDefinition( - TRANSIENT_MIMETYPE, DataTypeDefinition.TEXT.getLocalName()); + PropertyFieldDefinition mimetypeField = new PropertyFieldDefinition(TRANSIENT_MIMETYPE, + DataTypeDefinition.TEXT.getLocalName()); mimetypeField.setLabel(I18NUtil.getMessage(MSG_MIMETYPE_LABEL)); mimetypeField.setDescription(I18NUtil.getMessage(MSG_MIMETYPE_DESC)); mimetypeField.setDataKeyName(dataKeyName); form.addFieldDefinition(mimetypeField); - + if (content != null) { form.addData(dataKeyName, content.getMimetype()); } } - + /** * Generates the field definition for the transient encoding property * @@ -717,19 +765,19 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor protected void generateEncodingPropertyField(ContentData content, Form form) { String dataKeyName = PROP_DATA_PREFIX + TRANSIENT_ENCODING; - PropertyFieldDefinition encodingField = new PropertyFieldDefinition( - TRANSIENT_ENCODING, DataTypeDefinition.TEXT.getLocalName()); + PropertyFieldDefinition encodingField = new PropertyFieldDefinition(TRANSIENT_ENCODING, + DataTypeDefinition.TEXT.getLocalName()); encodingField.setLabel(I18NUtil.getMessage(MSG_ENCODING_LABEL)); encodingField.setDescription(I18NUtil.getMessage(MSG_ENCODING_DESC)); encodingField.setDataKeyName(dataKeyName); form.addFieldDefinition(encodingField); - + if (content != null) { form.addData(dataKeyName, content.getEncoding()); } } - + /** * Generates the field definition for the transient size property * @@ -739,22 +787,23 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor protected void generateSizePropertyField(ContentData content, Form form) { String dataKeyName = PROP_DATA_PREFIX + TRANSIENT_SIZE; - PropertyFieldDefinition sizeField = new PropertyFieldDefinition( - TRANSIENT_SIZE, DataTypeDefinition.LONG.getLocalName()); + PropertyFieldDefinition sizeField = new PropertyFieldDefinition(TRANSIENT_SIZE, + DataTypeDefinition.LONG.getLocalName()); sizeField.setLabel(I18NUtil.getMessage(MSG_SIZE_LABEL)); sizeField.setDescription(I18NUtil.getMessage(MSG_SIZE_DESC)); sizeField.setDataKeyName(dataKeyName); sizeField.setProtectedField(true); form.addFieldDefinition(sizeField); - + if (content != null) { form.addData(dataKeyName, new Long(content.getSize())); } } - + /** - * Retrieves the values of the given association definition on the given node. + * Retrieves the values of the given association definition on the given + * node. * * @param nodeRef The node to get the association values for * @param assocDef The association definition to look for values for @@ -765,21 +814,21 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor protected List retrieveAssociationValues(NodeRef nodeRef, AssociationDefinition assocDef) { List assocValues = null; - + // get the list of values (if any) for the association if (assocDef instanceof ChildAssociationDefinition) { - assocValues = this.nodeService.getChildAssocs(nodeRef, assocDef.getName(), + assocValues = this.nodeService.getChildAssocs(nodeRef, assocDef.getName(), RegexQNamePattern.MATCH_ALL); } else { assocValues = this.nodeService.getTargetAssocs(nodeRef, assocDef.getName()); } - + return assocValues; } - + /** * Persists the given FormData on the given NodeRef * @@ -790,29 +839,31 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor { // get the property definitions for the type of node being persisted QName type = this.nodeService.getType(nodeRef); - TypeDefinition typeDef = this.dictionaryService.getAnonymousType(type, - this.nodeService.getAspects(nodeRef)); + TypeDefinition typeDef = this.dictionaryService.getAnonymousType(type, this.nodeService + .getAspects(nodeRef)); Map assocDefs = typeDef.getAssociations(); Map childAssocDefs = typeDef.getChildAssociations(); Map propDefs = typeDef.getProperties(); - - Map propsToPersist = new HashMap(data.getNumberOfFields()); + + Map propsToPersist = new HashMap(data + .getNumberOfFields()); List assocsToPersist = new ArrayList(); - + for (FieldData fieldData : data) { // NOTE: ignore file fields for now, not supported yet! if (fieldData.isFile() == false) { String fieldName = fieldData.getName(); - + if (fieldName.startsWith(PROP_DATA_PREFIX)) { processPropertyPersist(nodeRef, propDefs, fieldData, propsToPersist); } else if (fieldName.startsWith(ASSOC_DATA_PREFIX)) { - processAssociationPersist(nodeRef, assocDefs, childAssocDefs, fieldData, assocsToPersist); + processAssociationPersist(nodeRef, assocDefs, childAssocDefs, fieldData, + assocsToPersist); } else if (getLogger().isWarnEnabled()) { @@ -820,20 +871,24 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor } } } - - // persist the properties using addProperties as this changes the repo values of - // those properties included in the Map, but leaves any other property values unchanged, - // whereas setProperties causes the deletion of properties that are not included in the Map. + + // persist the properties using addProperties as this changes the repo + // values of + // those properties included in the Map, but leaves any other property + // values unchanged, + // whereas setProperties causes the deletion of properties that are not + // included in the Map. this.nodeService.addProperties(nodeRef, propsToPersist); - + for (AbstractAssocCommand cmd : assocsToPersist) { - //TODO If there is an attempt to add and remove the same assoc in one request, - // we could drop each request and do nothing. + // TODO If there is an attempt to add and remove the same assoc in + // one request, + // we could drop each request and do nothing. cmd.updateAssociations(nodeService); } } - + /** * Processes the given field data for persistence as a property. * @@ -847,7 +902,7 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor { if (getLogger().isDebugEnabled()) getLogger().debug("Processing field " + fieldData + " for property persistence"); - + // match and extract the prefix and name parts Matcher m = this.propertyNamePattern.matcher(fieldData.getName()); if (m.matches()) @@ -855,20 +910,22 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor String qNamePrefix = m.group(1); String localName = m.group(2); QName fullQName = QName.createQName(qNamePrefix, localName, namespaceService); - + // ensure that the property being persisted is defined in the model PropertyDefinition propDef = propDefs.get(fullQName); - - // if the property is not defined on the node, check for the property in all models + + // if the property is not defined on the node, check for the + // property in all models if (propDef == null) { propDef = this.dictionaryService.getProperty(fullQName); } - + // if we have a property definition attempt the persist if (propDef != null) - { - // look for properties that have well known handling requirements + { + // look for properties that have well known handling + // requirements if (fullQName.equals(ContentModel.PROP_NAME)) { processNamePropertyPersist(nodeRef, fieldData); @@ -876,15 +933,16 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor else { Object value = fieldData.getValue(); - + // before persisting check data type of property if (propDef.isMultiValued()) { - // depending on client the value could be a comma separated + // depending on client the value could be a comma + // separated // string, a List object or a JSONArray object if (value instanceof String) { - if (((String)value).length() == 0) + if (((String) value).length() == 0) { // empty string for multi-valued properties // should be stored as null @@ -892,14 +950,15 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor } else { - // if value is a String convert to List of String - StringTokenizer tokenizer = new StringTokenizer((String)value, ","); + // if value is a String convert to List of + // String + StringTokenizer tokenizer = new StringTokenizer((String) value, ","); List list = new ArrayList(8); while (tokenizer.hasMoreTokens()) { list.add(tokenizer.nextToken()); } - + // persist the List value = list; } @@ -907,7 +966,7 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor else if (value instanceof JSONArray) { // if value is a JSONArray convert to List of Object - JSONArray jsonArr = (JSONArray)value; + JSONArray jsonArr = (JSONArray) value; int arrLength = jsonArr.length(); List list = new ArrayList(arrLength); try @@ -921,14 +980,15 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor { throw new FormException("Failed to convert JSONArray to List", je); } - + // persist the list value = list; } } else if (propDef.getDataType().getName().equals(DataTypeDefinition.BOOLEAN)) { - // check for browser representation of true, that being "on" + // check for browser representation of true, that being + // "on" if (value instanceof String && ON.equals(value)) { value = Boolean.TRUE; @@ -936,26 +996,30 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor } else if (propDef.getDataType().getName().equals(DataTypeDefinition.LOCALE)) { - value = I18NUtil.parseLocale((String)value); + value = I18NUtil.parseLocale((String) value); } - else if ((value instanceof String) && ((String)value).length() == 0) + else if ((value instanceof String) && ((String) value).length() == 0) { - // make sure empty strings stay as empty strings, everything else + // make sure empty strings stay as empty strings, + // everything else // should be represented as null - if (!propDef.getDataType().getName().equals(DataTypeDefinition.TEXT) && - !propDef.getDataType().getName().equals(DataTypeDefinition.MLTEXT)) + if (!propDef.getDataType().getName().equals(DataTypeDefinition.TEXT) + && !propDef.getDataType().getName().equals( + DataTypeDefinition.MLTEXT)) { value = null; } } - + // add the property to the map - propsToPersist.put(fullQName, (Serializable)value); + propsToPersist.put(fullQName, (Serializable) value); } } else if (getLogger().isWarnEnabled()) { - getLogger().warn("Ignoring field '" + fieldData.getName() + "' as a property definition can not be found"); + getLogger().warn( + "Ignoring field '" + fieldData.getName() + + "' as a property definition can not be found"); } } else @@ -966,7 +1030,7 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor if (tppm.matches()) { String fieldName = tppm.group(1); - + if (fieldName.equals(TRANSIENT_MIMETYPE)) { processMimetypePropertyPersist(nodeRef, fieldData, propsToPersist); @@ -977,7 +1041,8 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor } else if (fieldName.equals(TRANSIENT_SIZE)) { - // the size property is well known but should never be persisted + // the size property is well known but should never be + // persisted // as it is calculated so this is intentionally ignored } else if (getLogger().isWarnEnabled()) @@ -991,7 +1056,7 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor } } } - + /** * Processes the given field data for persistence as an association. * @@ -999,13 +1064,14 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor * @param fieldData Data to persist for the associations * @param assocCommands List of associations to be persisted */ - protected void processAssociationPersist(NodeRef nodeRef, Map assocDefs, - Map childAssocDefs, - FieldData fieldData, List assocCommands) + protected void processAssociationPersist(NodeRef nodeRef, + Map assocDefs, + Map childAssocDefs, FieldData fieldData, + List assocCommands) { if (getLogger().isDebugEnabled()) getLogger().debug("Processing field " + fieldData + " for association persistence"); - + String fieldName = fieldData.getName(); Matcher m = this.associationNamePattern.matcher(fieldName); if (m.matches()) @@ -1013,32 +1079,41 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor String qNamePrefix = m.group(1); String localName = m.group(2); String assocSuffix = m.group(3); - + QName fullQName = QName.createQName(qNamePrefix, localName, namespaceService); - - // ensure that the association being persisted is defined in the model + + // ensure that the association being persisted is defined in the + // model AssociationDefinition assocDef = assocDefs.get(fullQName); - - // TODO: if the association is not defined on the node, check for the association - // in all models, however, the source of an association can be critical so we - // can't just look up the association in the model regardless. We need to - // either check the source class of the node and the assoc def match or we - // check that the association was defined as part of an aspect (where by it's - // nature can have any source type) - + + // TODO: if the association is not defined on the node, check for + // the association + // in all models, however, the source of an association can be + // critical so we + // can't just look up the association in the model regardless. We + // need to + // either check the source class of the node and the assoc def match + // or we + // check that the association was defined as part of an aspect + // (where by it's + // nature can have any source type) + if (assocDef == null) { if (getLogger().isWarnEnabled()) { - getLogger().warn("Definition for association " + fullQName + " not recognised and not persisted."); + getLogger().warn( + "Definition for association " + fullQName + + " not recognised and not persisted."); } return; } - String value = (String)fieldData.getValue(); + String value = (String) fieldData.getValue(); String[] nodeRefs = value.split(","); - - // Each element in this array will be a new target node in association + + // Each element in this array will be a new target node in + // association // with the current node. for (String nextTargetNode : nodeRefs) { @@ -1050,26 +1125,26 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor { if (assocDef.isChild()) { - assocCommands.add(new AddChildAssocCommand(nodeRef, new NodeRef(nextTargetNode), - fullQName)); + assocCommands.add(new AddChildAssocCommand(nodeRef, new NodeRef( + nextTargetNode), fullQName)); } else { - assocCommands.add(new AddAssocCommand(nodeRef, new NodeRef(nextTargetNode), - fullQName)); + assocCommands.add(new AddAssocCommand(nodeRef, new NodeRef( + nextTargetNode), fullQName)); } } else if (assocSuffix.equals(ASSOC_DATA_REMOVED_SUFFIX)) { if (assocDef.isChild()) { - assocCommands.add(new RemoveChildAssocCommand(nodeRef, new NodeRef(nextTargetNode), - fullQName)); + assocCommands.add(new RemoveChildAssocCommand(nodeRef, new NodeRef( + nextTargetNode), fullQName)); } else { - assocCommands.add(new RemoveAssocCommand(nodeRef, new NodeRef(nextTargetNode), - fullQName)); + assocCommands.add(new RemoveAssocCommand(nodeRef, new NodeRef( + nextTargetNode), fullQName)); } } else @@ -1077,13 +1152,11 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor if (getLogger().isWarnEnabled()) { StringBuilder msg = new StringBuilder(); - msg.append("fieldName ") - .append(fieldName) - .append(" does not have one of the expected suffixes [") - .append(ASSOC_DATA_ADDED_SUFFIX) - .append(", ") - .append(ASSOC_DATA_REMOVED_SUFFIX) - .append("] and has been ignored."); + msg.append("fieldName ").append(fieldName).append( + " does not have one of the expected suffixes [") + .append(ASSOC_DATA_ADDED_SUFFIX).append(", ").append( + ASSOC_DATA_REMOVED_SUFFIX).append( + "] and has been ignored."); getLogger().warn(msg.toString()); } } @@ -1093,9 +1166,8 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor if (getLogger().isWarnEnabled()) { StringBuilder msg = new StringBuilder(); - msg.append("targetNode ") - .append(nextTargetNode) - .append(" is not a valid NodeRef and has been ignored."); + msg.append("targetNode ").append(nextTargetNode).append( + " is not a valid NodeRef and has been ignored."); getLogger().warn(msg.toString()); } } @@ -1106,7 +1178,7 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor /** * Persists the given field data as the name property - * + * * @param nodeRef The NodeRef to update the name for * @param fieldData The data representing the new name value */ @@ -1115,8 +1187,9 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor try { // if the name property changes the rename method of the file folder - // service should be called rather than updating the property directly - this.fileFolderService.rename(nodeRef, (String)fieldData.getValue()); + // service should be called rather than updating the property + // directly + this.fileFolderService.rename(nodeRef, (String) fieldData.getValue()); } catch (FileExistsException fee) { @@ -1127,10 +1200,10 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor throw new FormException("Failed to persist field '" + fieldData.getName() + "'", fnne); } } - + /** * Persists the given field data as the mimetype property - * + * * @param nodeRef The NodeRef to update the mimetype for * @param fieldData The data representing the new mimetype value * @param propsToPersist Map of properties to be persisted @@ -1138,24 +1211,25 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor protected void processMimetypePropertyPersist(NodeRef nodeRef, FieldData fieldData, Map propsToPersist) { - ContentData contentData = (ContentData)propsToPersist.get(ContentModel.PROP_CONTENT); + ContentData contentData = (ContentData) propsToPersist.get(ContentModel.PROP_CONTENT); if (contentData == null) { // content data has not been persisted yet so get it from the node - contentData = (ContentData)this.nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT); + contentData = (ContentData) this.nodeService.getProperty(nodeRef, + ContentModel.PROP_CONTENT); } - + if (contentData != null) { // update content data if we found the property - contentData = ContentData.setMimetype(contentData, (String)fieldData.getValue()); + contentData = ContentData.setMimetype(contentData, (String) fieldData.getValue()); propsToPersist.put(ContentModel.PROP_CONTENT, contentData); } } - + /** * Persists the given field data as the encoding property - * + * * @param nodeRef The NodeRef to update the encoding for * @param fieldData The data representing the new encoding value * @param propsToPersist Map of properties to be persisted @@ -1163,17 +1237,18 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor protected void processEncodingPropertyPersist(NodeRef nodeRef, FieldData fieldData, Map propsToPersist) { - ContentData contentData = (ContentData)propsToPersist.get(ContentModel.PROP_CONTENT); + ContentData contentData = (ContentData) propsToPersist.get(ContentModel.PROP_CONTENT); if (contentData == null) { // content data has not been persisted yet so get it from the node - contentData = (ContentData)this.nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT); + contentData = (ContentData) this.nodeService.getProperty(nodeRef, + ContentModel.PROP_CONTENT); } - + if (contentData != null) { // update content data if we found the property - contentData = ContentData.setEncoding(contentData, (String)fieldData.getValue()); + contentData = ContentData.setEncoding(contentData, (String) fieldData.getValue()); propsToPersist.put(ContentModel.PROP_CONTENT, contentData); } } @@ -1187,20 +1262,22 @@ public abstract class ContentModelFormProcessor extends FilteredFormProcessor abstract class AbstractAssocCommand { protected final NodeRef sourceNodeRef; + protected final NodeRef targetNodeRef; + protected final QName assocQName; - - public AbstractAssocCommand(NodeRef sourceNodeRef, NodeRef targetNodeRef, - QName assocQName) + + public AbstractAssocCommand(NodeRef sourceNodeRef, NodeRef targetNodeRef, QName assocQName) { this.sourceNodeRef = sourceNodeRef; this.targetNodeRef = targetNodeRef; this.assocQName = assocQName; } - + /** * This method should use the specified nodeService reference to effect the * update to the supplied associations. + * * @param nodeService */ protected abstract void updateAssociations(NodeService nodeService); @@ -1214,8 +1291,8 @@ abstract class AbstractAssocCommand class AddAssocCommand extends AbstractAssocCommand { private static final Log logger = LogFactory.getLog(AddAssocCommand.class); - public AddAssocCommand(NodeRef sourceNodeRef, NodeRef targetNodeRef, - QName assocQName) + + public AddAssocCommand(NodeRef sourceNodeRef, NodeRef targetNodeRef, QName assocQName) { super(sourceNodeRef, targetNodeRef, assocQName); } @@ -1223,7 +1300,8 @@ class AddAssocCommand extends AbstractAssocCommand @Override protected void updateAssociations(NodeService nodeService) { - List existingAssocs = nodeService.getTargetAssocs(sourceNodeRef, assocQName); + List existingAssocs = nodeService + .getTargetAssocs(sourceNodeRef, assocQName); for (AssociationRef assoc : existingAssocs) { if (assoc.getTargetRef().equals(targetNodeRef)) @@ -1247,16 +1325,17 @@ class AddAssocCommand extends AbstractAssocCommand class RemoveAssocCommand extends AbstractAssocCommand { private static final Log logger = LogFactory.getLog(RemoveAssocCommand.class); - public RemoveAssocCommand(NodeRef sourceNodeRef, NodeRef targetNodeRef, - QName assocQName) + + public RemoveAssocCommand(NodeRef sourceNodeRef, NodeRef targetNodeRef, QName assocQName) { super(sourceNodeRef, targetNodeRef, assocQName); } - + @Override protected void updateAssociations(NodeService nodeService) { - List existingAssocs = nodeService.getTargetAssocs(sourceNodeRef, assocQName); + List existingAssocs = nodeService + .getTargetAssocs(sourceNodeRef, assocQName); boolean assocDoesNotExist = true; for (AssociationRef assoc : existingAssocs) { @@ -1271,11 +1350,8 @@ class RemoveAssocCommand extends AbstractAssocCommand if (logger.isWarnEnabled()) { StringBuilder msg = new StringBuilder(); - msg.append("Attempt to remove non-existent association prevented. ") - .append(sourceNodeRef) - .append("|") - .append(targetNodeRef) - .append(assocQName); + msg.append("Attempt to remove non-existent association prevented. ").append( + sourceNodeRef).append("|").append(targetNodeRef).append(assocQName); logger.warn(msg.toString()); } return; @@ -1286,15 +1362,16 @@ class RemoveAssocCommand extends AbstractAssocCommand } /** - * A class representing a request to add a new child association between two nodes. + * A class representing a request to add a new child association between two + * nodes. * * @author Neil McErlean */ class AddChildAssocCommand extends AbstractAssocCommand { private static final Log logger = LogFactory.getLog(AddChildAssocCommand.class); - public AddChildAssocCommand(NodeRef sourceNodeRef, NodeRef targetNodeRef, - QName assocQName) + + public AddChildAssocCommand(NodeRef sourceNodeRef, NodeRef targetNodeRef, QName assocQName) { super(sourceNodeRef, targetNodeRef, assocQName); } @@ -1315,26 +1392,28 @@ class AddChildAssocCommand extends AbstractAssocCommand return; } } - // We are following the behaviour of the JSF client here in using the same + // We are following the behaviour of the JSF client here in using the + // same // QName value for the 3rd and 4th parameters in the below call. nodeService.addChild(sourceNodeRef, targetNodeRef, assocQName, assocQName); } } /** - * A class representing a request to remove a child association between two nodes. + * A class representing a request to remove a child association between two + * nodes. * * @author Neil McErlean */ class RemoveChildAssocCommand extends AbstractAssocCommand { private static final Log logger = LogFactory.getLog(RemoveChildAssocCommand.class); - public RemoveChildAssocCommand(NodeRef sourceNodeRef, NodeRef targetNodeRef, - QName assocQName) + + public RemoveChildAssocCommand(NodeRef sourceNodeRef, NodeRef targetNodeRef, QName assocQName) { super(sourceNodeRef, targetNodeRef, assocQName); } - + @Override protected void updateAssociations(NodeService nodeService) { @@ -1353,11 +1432,8 @@ class RemoveChildAssocCommand extends AbstractAssocCommand if (logger.isWarnEnabled()) { StringBuilder msg = new StringBuilder(); - msg.append("Attempt to remove non-existent child association prevented. ") - .append(sourceNodeRef) - .append("|") - .append(targetNodeRef) - .append(assocQName); + msg.append("Attempt to remove non-existent child association prevented. ").append( + sourceNodeRef).append("|").append(targetNodeRef).append(assocQName); logger.warn(msg.toString()); } return; diff --git a/source/java/org/alfresco/repo/forms/processor/node/FormFieldConstants.java b/source/java/org/alfresco/repo/forms/processor/node/FormFieldConstants.java new file mode 100644 index 0000000000..bdb0e9c224 --- /dev/null +++ b/source/java/org/alfresco/repo/forms/processor/node/FormFieldConstants.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * 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.repo.forms.processor.node; + +/** + * @author Nick Smith + */ +public interface FormFieldConstants +{ + /** Public constants */ + public static final String ON = "on"; + + public static final String PROP = "prop"; + + public static final String ASSOC = "assoc"; + + public static final String DATA_KEY_SEPARATOR = "_"; + + public static final String PROP_DATA_PREFIX = PROP + DATA_KEY_SEPARATOR; + + public static final String ASSOC_DATA_PREFIX = ASSOC + DATA_KEY_SEPARATOR; + + public static final String ASSOC_DATA_ADDED_SUFFIX = DATA_KEY_SEPARATOR + "added"; + + public static final String ASSOC_DATA_REMOVED_SUFFIX = DATA_KEY_SEPARATOR + "removed"; + + public static final String TRANSIENT_MIMETYPE = "mimetype"; + + public static final String TRANSIENT_SIZE = "size"; + + public static final String TRANSIENT_ENCODING = "encoding"; + +} diff --git a/source/java/org/alfresco/repo/forms/processor/node/NodeFormProcessor.java b/source/java/org/alfresco/repo/forms/processor/node/NodeFormProcessor.java index d8c655c834..d4fa251702 100644 --- a/source/java/org/alfresco/repo/forms/processor/node/NodeFormProcessor.java +++ b/source/java/org/alfresco/repo/forms/processor/node/NodeFormProcessor.java @@ -22,6 +22,7 @@ * the FLOSS exception, and it is also available here: * http://www.alfresco.com/legal/licensing" */ + package org.alfresco.repo.forms.processor.node; import java.io.Serializable; @@ -44,18 +45,20 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** - * FormProcessor implementation that can generate and persist Form objects - * for repository nodes. - * + * FormProcessor implementation that can generate and persist Form objects for + * repository nodes. + * * @author Gavin Cornwell */ -public class NodeFormProcessor extends ContentModelFormProcessor +public class NodeFormProcessor extends ContentModelFormProcessor { /** Logger */ private static Log logger = LogFactory.getLog(NodeFormProcessor.class); - + /* - * @see org.alfresco.repo.forms.processor.node.ContentModelFormProcessor#getLogger() + * @see + * org.alfresco.repo.forms.processor.node.ContentModelFormProcessor#getLogger + * () */ @Override protected Log getLogger() @@ -64,10 +67,12 @@ public class NodeFormProcessor extends ContentModelFormProcessor } /* - * @see org.alfresco.repo.forms.processor.FilteredFormProcessor#getTypedItem(org.alfresco.repo.forms.Item) + * @see + * org.alfresco.repo.forms.processor.FilteredFormProcessor#getTypedItem( + * org.alfresco.repo.forms.Item) */ @Override - protected Object getTypedItem(Item item) + protected NodeRef getTypedItem(Item item) { // create NodeRef representation, the id could already be in a valid // NodeRef format or it may be in a URL friendly format @@ -89,25 +94,22 @@ public class NodeFormProcessor extends ContentModelFormProcessor catch (IllegalArgumentException iae) { // ignored for now, dealt with below - + if (logger.isDebugEnabled()) logger.debug("NodeRef creation failed for: " + item.getId(), iae); } } - } - - // check we have a valid node ref - if (nodeRef == null) - { - throw new FormNotFoundException(item, - new IllegalArgumentException(item.getId())); } - + + // check we have a valid node ref + if (nodeRef == null) { throw new FormNotFoundException(item, new IllegalArgumentException( + item.getId())); } + // check the node itself exists if (this.nodeService.exists(nodeRef) == false) { - throw new FormNotFoundException(item, - new InvalidNodeRefException("Node does not exist: " + nodeRef, nodeRef)); + throw new FormNotFoundException(item, new InvalidNodeRefException( + "Node does not exist: " + nodeRef, nodeRef)); } else { @@ -115,27 +117,25 @@ public class NodeFormProcessor extends ContentModelFormProcessor return nodeRef; } } - + /* - * @see org.alfresco.repo.forms.processor.FilteredFormProcessor#internalGenerate(java.lang.Object, java.util.List, java.util.List, org.alfresco.repo.forms.Form, java.util.Map) + * @see + * org.alfresco.repo.forms.processor.FilteredFormProcessor#internalGenerate + * (java.lang.Object, java.util.List, java.util.List, + * org.alfresco.repo.forms.Form, java.util.Map) */ @Override - protected void internalGenerate(Object item, List fields, List forcedFields, + protected void internalGenerate(NodeRef item, List fields, List forcedFields, Form form, Map context) { - if (logger.isDebugEnabled()) - logger.debug("Generating form for: " + item); - - // cast to the expected NodeRef representation - NodeRef nodeRef = (NodeRef)item; - + if (logger.isDebugEnabled()) logger.debug("Generating form for: " + item); + // generate the form for the node - generateNode(nodeRef, fields, forcedFields, form); - - if (logger.isDebugEnabled()) - logger.debug("Generated form: " + form); + generateNode(item, fields, forcedFields, form); + + if (logger.isDebugEnabled()) logger.debug("Generated form: " + form); } - + /** * Sets up the Form object for the given NodeRef * @@ -144,7 +144,8 @@ public class NodeFormProcessor extends ContentModelFormProcessor * @param forcedFields List of fields to forcibly include * @param form The Form instance to populate */ - protected void generateNode(NodeRef nodeRef, List fields, List forcedFields, Form form) + protected void generateNode(NodeRef nodeRef, List fields, List forcedFields, + Form form) { // set the type and URL of the item QName type = this.nodeService.getType(nodeRef); @@ -154,7 +155,7 @@ public class NodeFormProcessor extends ContentModelFormProcessor builder.append(nodeRef.getStoreRef().getIdentifier()).append("/"); builder.append(nodeRef.getId()); form.getItem().setUrl(builder.toString()); - + if (fields != null && fields.size() > 0) { generateSelectedFields(nodeRef, null, fields, forcedFields, form); @@ -167,7 +168,7 @@ public class NodeFormProcessor extends ContentModelFormProcessor generateTransientFields(nodeRef, form); } } - + /** * Sets up the field definitions for all the node's properties. * @@ -178,20 +179,20 @@ public class NodeFormProcessor extends ContentModelFormProcessor { // get data dictionary definition for node QName type = this.nodeService.getType(nodeRef); - TypeDefinition typeDef = this.dictionaryService.getAnonymousType(type, - this.nodeService.getAspects(nodeRef)); - - // iterate round the property definitions for the node and create + TypeDefinition typeDef = this.dictionaryService.getAnonymousType(type, this.nodeService + .getAspects(nodeRef)); + + // iterate round the property definitions for the node and create // the equivalent field definition and setup the data for the property Map propDefs = typeDef.getProperties(); Map propValues = this.nodeService.getProperties(nodeRef); for (PropertyDefinition propDef : propDefs.values()) { - generatePropertyField(propDef, form, propValues.get(propDef.getName()), + generatePropertyField(propDef, form, propValues.get(propDef.getName()), this.namespaceService); } } - + /** * Sets up the field definitions for all the node's associations. * @@ -202,19 +203,18 @@ public class NodeFormProcessor extends ContentModelFormProcessor { // get data dictionary definition for the node QName type = this.nodeService.getType(nodeRef); - TypeDefinition typeDef = this.dictionaryService.getAnonymousType(type, - this.nodeService.getAspects(nodeRef)); - + TypeDefinition typeDef = this.dictionaryService.getAnonymousType(type, this.nodeService + .getAspects(nodeRef)); + // iterate round the association defintions and setup field definition Map assocDefs = typeDef.getAssociations(); for (AssociationDefinition assocDef : assocDefs.values()) { - generateAssociationField(assocDef, form, - retrieveAssociationValues(nodeRef, assocDef), + generateAssociationField(assocDef, form, retrieveAssociationValues(nodeRef, assocDef), this.namespaceService); } } - + /** * Sets up the field definitions for any transient fields that may be * useful, for example, 'mimetype', 'size' and 'encoding'. @@ -224,41 +224,40 @@ public class NodeFormProcessor extends ContentModelFormProcessor */ protected void generateTransientFields(NodeRef nodeRef, Form form) { - // if the node is content add the 'mimetype', 'size' and 'encoding' fields. + // if the node is content add the 'mimetype', 'size' and 'encoding' + // fields. QName type = this.nodeService.getType(nodeRef); if (this.dictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)) { - ContentData content = (ContentData)this.nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT); + ContentData content = (ContentData) this.nodeService.getProperty(nodeRef, + ContentModel.PROP_CONTENT); if (content != null) { // setup mimetype field generateMimetypePropertyField(content, form); - + // setup encoding field generateEncodingPropertyField(content, form); - + // setup size field generateSizePropertyField(content, form); } } } - + /* - * @see org.alfresco.repo.forms.processor.FilteredFormProcessor#internalPersist(java.lang.Object, org.alfresco.repo.forms.FormData) + * @see + * org.alfresco.repo.forms.processor.FilteredFormProcessor#internalPersist + * (java.lang.Object, org.alfresco.repo.forms.FormData) */ @Override - protected Object internalPersist(Object item, FormData data) + protected NodeRef internalPersist(NodeRef item, FormData data) { - if (logger.isDebugEnabled()) - logger.debug("Persisting form for: " + item); - - // cast to the expected NodeRef representation - NodeRef nodeRef = (NodeRef)item; - + if (logger.isDebugEnabled()) logger.debug("Persisting form for: " + item); + // persist the node - persistNode(nodeRef, data); - + persistNode(item, data); + return item; } } - diff --git a/source/java/org/alfresco/repo/forms/processor/node/TypeFormProcessor.java b/source/java/org/alfresco/repo/forms/processor/node/TypeFormProcessor.java index 8b9e4f9d82..169bd09d76 100644 --- a/source/java/org/alfresco/repo/forms/processor/node/TypeFormProcessor.java +++ b/source/java/org/alfresco/repo/forms/processor/node/TypeFormProcessor.java @@ -22,6 +22,7 @@ * the FLOSS exception, and it is also available here: * http://www.alfresco.com/legal/licensing" */ + package org.alfresco.repo.forms.processor.node; import java.io.Serializable; @@ -49,37 +50,42 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** - * FormProcessor implementation that can generate and persist Form objects - * for types in the Alfresco content model. - * + * FormProcessor implementation that can generate and persist Form objects for + * types in the Alfresco content model. + * * @author Gavin Cornwell */ -public class TypeFormProcessor extends ContentModelFormProcessor +public class TypeFormProcessor extends ContentModelFormProcessor { /** Logger */ private static Log logger = LogFactory.getLog(TypeFormProcessor.class); - - protected static final String NAME_PROP_DATA = PROP + DATA_KEY_SEPARATOR + "cm" + DATA_KEY_SEPARATOR + "name"; - + + protected static final String NAME_PROP_DATA = PROP + DATA_KEY_SEPARATOR + "cm" + + DATA_KEY_SEPARATOR + "name"; + public static final String DESTINATION = "alf_destination"; - + /* - * @see org.alfresco.repo.forms.processor.node.ContentModelFormProcessor#getLogger() + * @see + * org.alfresco.repo.forms.processor.node.ContentModelFormProcessor#getLogger + * () */ @Override protected Log getLogger() { return logger; } - + /* - * @see org.alfresco.repo.forms.processor.node.NodeFormProcessor#getTypedItem(org.alfresco.repo.forms.Item) + * @see + * org.alfresco.repo.forms.processor.node.NodeFormProcessor#getTypedItem + * (org.alfresco.repo.forms.Item) */ @Override - protected Object getTypedItem(Item item) + protected TypeDefinition getTypedItem(Item item) { TypeDefinition typeDef = null; - + try { // convert the prefix type into full QName representation @@ -98,7 +104,7 @@ public class TypeFormProcessor extends ContentModelFormProcessor // if item id contains _ change the first occurrence to : // as it's more than likely been converted for URL use int idx = itemId.indexOf("_"); - String parsedItemId = itemId.substring(0, idx) + ":" + itemId.substring(idx+1); + String parsedItemId = itemId.substring(0, idx) + ":" + itemId.substring(idx + 1); type = QName.createQName(parsedItemId, this.namespaceService); } else @@ -106,45 +112,39 @@ public class TypeFormProcessor extends ContentModelFormProcessor // try and create the QName using the item id as is type = QName.createQName(itemId, this.namespaceService); } - + // retrieve the type from the dictionary typeDef = this.dictionaryService.getType(type); - - if (typeDef == null) - { - throw new FormNotFoundException(item, - new IllegalArgumentException("Type does not exist: " + item.getId())); - } + + if (typeDef == null) { throw new FormNotFoundException(item, + new IllegalArgumentException("Type does not exist: " + item.getId())); } } catch (InvalidQNameException iqne) { throw new FormNotFoundException(item, iqne); } - + // return the type definition object for the requested type return typeDef; } - + /* - * @see org.alfresco.repo.forms.processor.FilteredFormProcessor#internalGenerate(java.lang.Object, java.util.List, java.util.List, org.alfresco.repo.forms.Form, java.util.Map) + * @see + * org.alfresco.repo.forms.processor.FilteredFormProcessor#internalGenerate + * (java.lang.Object, java.util.List, java.util.List, + * org.alfresco.repo.forms.Form, java.util.Map) */ @Override - protected void internalGenerate(Object item, List fields, List forcedFields, - Form form, Map context) + protected void internalGenerate(TypeDefinition item, List fields, + List forcedFields, Form form, Map context) { - if (logger.isDebugEnabled()) - logger.debug("Generating form for item: " + item); - - // cast to the expected NodeRef representation - TypeDefinition typeDef = (TypeDefinition)item; - + if (logger.isDebugEnabled()) logger.debug("Generating form for item: " + item); + // generate the form for the node - generateType(typeDef, fields, forcedFields, form); - - if (logger.isDebugEnabled()) - logger.debug("Generating form: " + form); + generateType(item, fields, forcedFields, form); + if (logger.isDebugEnabled()) logger.debug("Generating form: " + form); } - + /** * Sets up the Form object for the given NodeRef * @@ -153,12 +153,16 @@ public class TypeFormProcessor extends ContentModelFormProcessor * @param forcedFields List of fields to forcibly include * @param form The Form instance to populate */ - protected void generateType(TypeDefinition typeDef, List fields, List forcedFields, Form form) + protected void generateType(TypeDefinition typeDef, List fields, + List forcedFields, Form form) { // set the type and URL of the item form.getItem().setType(typeDef.getName().toPrefixString(this.namespaceService)); - form.getItem().setUrl("/api/classes/" + typeDef.getName().toPrefixString(this.namespaceService).replace(":", "_")); - + form.getItem().setUrl( + "/api/classes/" + + typeDef.getName().toPrefixString(this.namespaceService).replace( + ":", "_")); + if (fields != null && fields.size() > 0) { generateSelectedFields(null, typeDef, fields, forcedFields, form); @@ -168,11 +172,11 @@ public class TypeFormProcessor extends ContentModelFormProcessor // setup field definitions and data generateAllPropertyFields(typeDef, form); generateAllAssociationFields(typeDef, form); - + // TODO: generate transient properties for content types? } } - + /** * Sets up the field definitions for all the type's properties. * @@ -187,8 +191,8 @@ public class TypeFormProcessor extends ContentModelFormProcessor { generatePropertyField(propDef, form, this.namespaceService); } - - // get all default aspects for the type and iterate round their + + // get all default aspects for the type and iterate round their // property definitions too List aspects = typeDef.getDefaultAspects(true); for (AspectDefinition aspect : aspects) @@ -200,7 +204,7 @@ public class TypeFormProcessor extends ContentModelFormProcessor } } } - + /** * Sets up the field definitions for all the type's associations. * @@ -215,8 +219,8 @@ public class TypeFormProcessor extends ContentModelFormProcessor { generateAssociationField(assocDef, form, this.namespaceService); } - - // get all default aspects for the type and iterate round their + + // get all default aspects for the type and iterate round their // association definitions too List aspects = typeDef.getDefaultAspects(true); for (AspectDefinition aspect : aspects) @@ -230,23 +234,21 @@ public class TypeFormProcessor extends ContentModelFormProcessor } /* - * @see org.alfresco.repo.forms.processor.node.NodeFormProcessor#internalPersist(java.lang.Object, org.alfresco.repo.forms.FormData) + * @see + * org.alfresco.repo.forms.processor.node.NodeFormProcessor#internalPersist + * (java.lang.Object, org.alfresco.repo.forms.FormData) */ @Override - protected Object internalPersist(Object item, FormData data) + protected NodeRef internalPersist(TypeDefinition item, FormData data) { - if (logger.isDebugEnabled()) - logger.debug("Persisting form for: " + item); - - // cast to the expected NodeRef representation - TypeDefinition typeDef = (TypeDefinition)item; - + if (logger.isDebugEnabled()) logger.debug("Persisting form for: " + item); + // create a new instance of the type - NodeRef nodeRef = createNode(typeDef, data); - + NodeRef nodeRef = createNode(item, data); + // persist the form data persistNode(nodeRef, data); - + // return the newly created node return nodeRef; } @@ -254,13 +256,13 @@ public class TypeFormProcessor extends ContentModelFormProcessor /** * Creates a new instance of the given type. *

- * If the form data has the name property present it is used as - * the name of the node. - *

- * The new node is placed in the location defined by the "destination" - * data item in the form data (this will usually be a hidden field), - * this will also be the NodeRef representation of the parent for the - * new node. + * If the form data has the name property present it is used as the name of + * the node. + *

+ *

+ * The new node is placed in the location defined by the "destination" data + * item in the form data (this will usually be a hidden field), this will + * also be the NodeRef representation of the parent for the new node. *

* * @param typeDef The type defintion of the type to create @@ -270,53 +272,57 @@ public class TypeFormProcessor extends ContentModelFormProcessor protected NodeRef createNode(TypeDefinition typeDef, FormData data) { NodeRef nodeRef = null; - + if (data != null) { // firstly, ensure we have a destination to create the node in NodeRef parentRef = null; FieldData destination = data.getFieldData(DESTINATION); - if (destination == null) - { - throw new FormException("Failed to persist form for '" + - typeDef.getName().toPrefixString(this.namespaceService) + - "' as '" + DESTINATION + "' data was not provided."); - } - + if (destination == null) { throw new FormException("Failed to persist form for '" + + typeDef.getName().toPrefixString(this.namespaceService) + "' as '" + + DESTINATION + "' data was not provided."); } + // create the parent NodeRef - parentRef = new NodeRef((String)destination.getValue()); - - // remove the destination data to avoid warning during persistence, this can + parentRef = new NodeRef((String) destination.getValue()); + + // remove the destination data to avoid warning during persistence, + // this can // always be retrieved by looking up the created node's parent data.removeFieldData(DESTINATION); - - // TODO: determine what association to use when creating the node in the destination, + + // TODO: determine what association to use when creating the node in + // the destination, // defaults to ContentModel.ASSOC_CONTAINS - - // if a name property is present in the form data use it as the node name, + + // if a name property is present in the form data use it as the node + // name, // otherwise generate a guid String nodeName = null; FieldData nameData = data.getFieldData(NAME_PROP_DATA); if (nameData != null) { - nodeName = (String)nameData.getValue(); - - // remove the name data otherwise 'rename' gets called in persistNode + nodeName = (String) nameData.getValue(); + + // remove the name data otherwise 'rename' gets called in + // persistNode data.removeFieldData(NAME_PROP_DATA); } if (nodeName == null || nodeName.length() == 0) { nodeName = GUID.generate(); } - + // create the node Map nodeProps = new HashMap(1); nodeProps.put(ContentModel.PROP_NAME, nodeName); - nodeRef = this.nodeService.createNode(parentRef, ContentModel.ASSOC_CONTAINS, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(nodeName)), - typeDef.getName(), nodeProps).getChildRef(); + nodeRef = this.nodeService.createNode( + parentRef, + ContentModel.ASSOC_CONTAINS, + QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName + .createValidLocalName(nodeName)), typeDef.getName(), nodeProps) + .getChildRef(); } - + return nodeRef; } }