mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Initial API changes to form config with associated JS FTL to exercide it.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@12323 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,186 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 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.web.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.config.ConfigElement;
|
||||
import org.alfresco.config.ConfigException;
|
||||
import org.alfresco.config.element.ConfigElementAdapter;
|
||||
|
||||
public class ConstraintHandlersConfigElement extends ConfigElementAdapter
|
||||
{
|
||||
public static final String CONFIG_ELEMENT_ID = "constraint-handlers";
|
||||
private List<String> types = new ArrayList<String>();
|
||||
private Map<String, String> handlers = new HashMap<String, String>();
|
||||
private Map<String, String> messages = new HashMap<String, String>();
|
||||
private Map<String, String> messageIDs = new HashMap<String, String>();
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* This constructor creates an instance with the default name.
|
||||
*/
|
||||
public ConstraintHandlersConfigElement()
|
||||
{
|
||||
super(CONFIG_ELEMENT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor creates an instance with the specified name.
|
||||
*
|
||||
* @param name the name for the ConfigElement.
|
||||
*/
|
||||
public ConstraintHandlersConfigElement(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.config.ConfigElement#getChildren()
|
||||
*/
|
||||
public List<ConfigElement> getChildren()
|
||||
{
|
||||
throw new ConfigException(
|
||||
"Reading the constraint-handlers config via the generic interfaces is not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.config.ConfigElement#combine(org.alfresco.config.ConfigElement)
|
||||
*/
|
||||
public ConfigElement combine(ConfigElement configElement)
|
||||
{
|
||||
// There is an assumption here that it is only like-with-like combinations
|
||||
// that are allowed. i.e. Only an instance of a ConstraintHandlersConfigElement
|
||||
// can be combined with this.
|
||||
ConstraintHandlersConfigElement otherCHCElement = (ConstraintHandlersConfigElement) configElement;
|
||||
|
||||
ConstraintHandlersConfigElement result = new ConstraintHandlersConfigElement();
|
||||
|
||||
for (String nextType : types)
|
||||
{
|
||||
String nextValidationHandler = getValidationHandlerFor(nextType);
|
||||
String nextMessage = getMessageFor(nextType);
|
||||
String nextMessageId = getMessageIdFor(nextType);
|
||||
result.addDataMapping(nextType, nextValidationHandler, nextMessage,
|
||||
nextMessageId);
|
||||
}
|
||||
|
||||
for (String nextType : otherCHCElement.types)
|
||||
{
|
||||
String nextValidationHandler = otherCHCElement
|
||||
.getValidationHandlerFor(nextType);
|
||||
String nextMessage = otherCHCElement.getMessageFor(nextType);
|
||||
String nextMessageId = otherCHCElement.getMessageIdFor(nextType);
|
||||
result.addDataMapping(nextType, nextValidationHandler, nextMessage,
|
||||
nextMessageId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* package */void addDataMapping(String type, String validationHandler,
|
||||
String message, String messageID)
|
||||
{
|
||||
types.add(type);
|
||||
handlers.put(type, validationHandler);
|
||||
messages.put(type, message);
|
||||
messageIDs.put(type, messageID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
return types.hashCode() + 7 * handlers.hashCode() + 13
|
||||
* messages.hashCode() + 17 * messageIDs.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object otherObj)
|
||||
{
|
||||
if (otherObj == null || !otherObj.getClass().equals(this.getClass()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ConstraintHandlersConfigElement otherCHCE = (ConstraintHandlersConfigElement) otherObj;
|
||||
return this.types.equals(otherCHCE.types)
|
||||
&& this.handlers.equals(otherCHCE.handlers)
|
||||
&& this.messages.equals(otherCHCE.messages)
|
||||
&& this.messageIDs.equals(otherCHCE.messageIDs);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the registered constraint types.
|
||||
* @return an unmodifiable List of the constraint types.
|
||||
*/
|
||||
public List<String> getConstraintTypes()
|
||||
{
|
||||
return Collections.unmodifiableList(this.types);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a String identifier for the validation-handler
|
||||
* associated with the specified constraint type.
|
||||
*
|
||||
* @param type the constraint type.
|
||||
* @return a String identifier for the validation-handler.
|
||||
*/
|
||||
public String getValidationHandlerFor(String type)
|
||||
{
|
||||
return handlers.get(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a message String associated with the specified constraint
|
||||
* type.
|
||||
*
|
||||
* @param type the constraint type.
|
||||
* @return the message String for the validation-handler.
|
||||
*/
|
||||
public String getMessageFor(String type)
|
||||
{
|
||||
return messages.get(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a message-id String associated with the specified constraint
|
||||
* type.
|
||||
*
|
||||
* @param type the constraint type.
|
||||
* @return the message-id String for the validation-handler.
|
||||
*/
|
||||
public String getMessageIdFor(String type)
|
||||
{
|
||||
return messageIDs.get(type);
|
||||
}
|
||||
}
|
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2008 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 received 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.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.alfresco.config.ConfigElement;
|
||||
import org.alfresco.config.ConfigException;
|
||||
import org.alfresco.config.xml.elementreader.ConfigElementReader;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* This class is a custom element reader to parse the config file for
|
||||
* <constraint-handlers> elements.
|
||||
*
|
||||
* @author Neil McErlean.
|
||||
*/
|
||||
public class ConstraintHandlersElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ELEMENT_CONSTRAINT_HANDLERS = "constraint-handlers";
|
||||
public static final String ATTR_TYPE = "type";
|
||||
public static final String ATTR_VALIDATOR_HANDLER = "validation-handler";
|
||||
public static final String ATTR_MESSAGE = "message";
|
||||
public static final String ATTR_MESSAGE_ID = "message-id";
|
||||
|
||||
/**
|
||||
* @see org.alfresco.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
ConstraintHandlersConfigElement result = null;
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
String name = element.getName();
|
||||
if (!name.equals(ELEMENT_CONSTRAINT_HANDLERS))
|
||||
{
|
||||
throw new ConfigException(this.getClass().getName() + " can only parse " +
|
||||
ELEMENT_CONSTRAINT_HANDLERS + " elements, the element passed was '" + name + "'");
|
||||
}
|
||||
|
||||
result = new ConstraintHandlersConfigElement();
|
||||
|
||||
Iterator<Element> xmlNodes = element.elementIterator();
|
||||
while (xmlNodes.hasNext())
|
||||
{
|
||||
Element nextNode = xmlNodes.next();
|
||||
String type = nextNode.attributeValue(ATTR_TYPE);
|
||||
String validationHandler = nextNode.attributeValue(ATTR_VALIDATOR_HANDLER);
|
||||
String message = nextNode.attributeValue(ATTR_MESSAGE);
|
||||
String messageId = nextNode.attributeValue(ATTR_MESSAGE_ID);
|
||||
|
||||
result.addDataMapping(type, validationHandler, message, messageId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -1,381 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 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.web.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.config.ConfigElement;
|
||||
import org.alfresco.config.ConfigException;
|
||||
import org.alfresco.config.element.ConfigElementAdapter;
|
||||
|
||||
/**
|
||||
* Custom config element that represents <default-controls> values for the
|
||||
* client.
|
||||
*
|
||||
* @author Neil McErlean.
|
||||
*/
|
||||
public class DefaultControlsConfigElement extends ConfigElementAdapter
|
||||
{
|
||||
public static final String CONFIG_ELEMENT_ID = "default-controls";
|
||||
|
||||
private final Map<String, DefaultControl> datatypeDefCtrlMappings = new HashMap<String, DefaultControl>();
|
||||
private static final long serialVersionUID = -6758804774427314050L;
|
||||
|
||||
/**
|
||||
* This constructor creates an instance with the default name.
|
||||
*/
|
||||
public DefaultControlsConfigElement()
|
||||
{
|
||||
super(CONFIG_ELEMENT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor creates an instance with the specified name.
|
||||
*
|
||||
* @param name the name for the ConfigElement.
|
||||
*/
|
||||
public DefaultControlsConfigElement(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.config.ConfigElement#getChildren()
|
||||
*/
|
||||
public List<ConfigElement> getChildren()
|
||||
{
|
||||
throw new ConfigException(
|
||||
"Reading the default-controls config via the generic interfaces is not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.config.ConfigElement#combine(org.alfresco.config.ConfigElement)
|
||||
*/
|
||||
public ConfigElement combine(ConfigElement configElement)
|
||||
{
|
||||
// There is an assumption here that it is only like-with-like
|
||||
// combinations
|
||||
// that are allowed. i.e. Only an instance of a
|
||||
// DefaultControlsConfigElement
|
||||
// can be combined with this.
|
||||
DefaultControlsConfigElement otherDCCElement = (DefaultControlsConfigElement) configElement;
|
||||
|
||||
DefaultControlsConfigElement result = new DefaultControlsConfigElement();
|
||||
|
||||
for (String nextDataType : datatypeDefCtrlMappings.keySet())
|
||||
{
|
||||
String nextTemplate = getTemplateFor(nextDataType);
|
||||
DefaultControl nextDefaultControls = otherDCCElement.datatypeDefCtrlMappings
|
||||
.get(nextDataType);
|
||||
List<ControlParam> nextControlParams = nextDefaultControls
|
||||
.getControlParams();
|
||||
|
||||
result.addDataMapping(nextDataType, nextTemplate,
|
||||
nextControlParams);
|
||||
}
|
||||
|
||||
for (String nextDataType : otherDCCElement.datatypeDefCtrlMappings.keySet())
|
||||
{
|
||||
String nextTemplate = otherDCCElement.getTemplateFor(nextDataType);
|
||||
DefaultControl nextDefaultControls = otherDCCElement.datatypeDefCtrlMappings
|
||||
.get(nextDataType);
|
||||
List<ControlParam> nextControlParams = nextDefaultControls
|
||||
.getControlParams();
|
||||
|
||||
result.addDataMapping(nextDataType, nextTemplate, nextControlParams);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* package */void addDataMapping(String dataType, String template,
|
||||
List<ControlParam> parameters)
|
||||
{
|
||||
if (parameters == null)
|
||||
{
|
||||
parameters = Collections.emptyList();
|
||||
}
|
||||
DefaultControl newControl = new DefaultControl(dataType, template);
|
||||
for (ControlParam p : parameters)
|
||||
{
|
||||
newControl.addControlParam(p);
|
||||
}
|
||||
this.datatypeDefCtrlMappings.put(dataType, newControl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
return datatypeDefCtrlMappings.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object otherObj)
|
||||
{
|
||||
if (otherObj == null || !otherObj.getClass().equals(this.getClass()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
DefaultControlsConfigElement otherDCCE = (DefaultControlsConfigElement) otherObj;
|
||||
return this.datatypeDefCtrlMappings
|
||||
.equals(otherDCCE.datatypeDefCtrlMappings);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns an unmodifiable Set of the names of the default-control items.
|
||||
* @return Set of names.
|
||||
*/
|
||||
public Set<String> getNames()
|
||||
{
|
||||
Set<String> result = new HashSet<String>(datatypeDefCtrlMappings.size());
|
||||
for (String dataType : datatypeDefCtrlMappings.keySet())
|
||||
{
|
||||
result.add(dataType);
|
||||
}
|
||||
return Collections.unmodifiableSet(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a String representing the path of the template associated
|
||||
* with the given dataType.
|
||||
*
|
||||
* @param dataType the dataType for which a template is required.
|
||||
* @return the path of the associated template. <code>null</code> if the specified
|
||||
* dataType is <code>null</code> or if there is no registered template.
|
||||
*/
|
||||
public String getTemplateFor(String dataType)
|
||||
{
|
||||
DefaultControl ctrl = datatypeDefCtrlMappings.get(dataType);
|
||||
if (ctrl == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ctrl.getTemplate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns an unmodifiable List of <code>ControlParam</code> objects
|
||||
* associated with the specified dataType.
|
||||
*
|
||||
* @param dataType the dataType for which control-params are required.
|
||||
* @return an unmodifiable List of the associated <code>ControlParam</code> objects.
|
||||
*
|
||||
* @see org.alfresco.web.config.DefaultControlsConfigElement.ControlParam
|
||||
*/
|
||||
public List<ControlParam> getControlParamsFor(String dataType)
|
||||
{
|
||||
return Collections.unmodifiableList(datatypeDefCtrlMappings.get(
|
||||
dataType).getControlParams());
|
||||
}
|
||||
|
||||
/**
|
||||
* This class represents a single default-control configuration item within a
|
||||
* group of <default-controls>.
|
||||
*
|
||||
* @author Neil McErlean.
|
||||
*/
|
||||
public static class DefaultControl
|
||||
{
|
||||
private final String name;
|
||||
private final String template;
|
||||
private final List<ControlParam> controlParams = new ArrayList<ControlParam>();
|
||||
|
||||
/**
|
||||
* Constructs a DefaultControl object with the specified name and template.
|
||||
*
|
||||
* @param name the name of the type.
|
||||
* @param template the template associated with that name.
|
||||
*/
|
||||
public DefaultControl(String name, String template)
|
||||
{
|
||||
this.name = name;
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
void addControlParam(ControlParam param)
|
||||
{
|
||||
controlParams.add(param);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the name of the type of this DefaultControl.
|
||||
* @return the name of the type.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the template path of this DefaultControl.
|
||||
* @return the template path.
|
||||
*/
|
||||
public String getTemplate()
|
||||
{
|
||||
return template;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns an unmodifiable List of <code>ControlParam</code>
|
||||
* objects that are associated with this DefaultControl.
|
||||
* @return an unmodifiable List of ControlParam references.
|
||||
*/
|
||||
public List<ControlParam> getControlParams()
|
||||
{
|
||||
return Collections.unmodifiableList(controlParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
return name.hashCode() + 7 * template.hashCode() + 13
|
||||
* controlParams.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object otherObj)
|
||||
{
|
||||
if (otherObj == this)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (otherObj == null
|
||||
|| !otherObj.getClass().equals(this.getClass()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
DefaultControl otherDC = (DefaultControl) otherObj;
|
||||
return otherDC.name.equals(this.name)
|
||||
&& otherDC.template.equals(this.template)
|
||||
&& otherDC.controlParams.equals(this.controlParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append(name).append(":").append(template);
|
||||
result.append(controlParams);
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class represents a single control-param configuration item.
|
||||
*
|
||||
* @author Neil McErlean.
|
||||
*/
|
||||
public static class ControlParam
|
||||
{
|
||||
private final String name;
|
||||
private final String value;
|
||||
|
||||
/**
|
||||
* Constructs a ControlParam object with the specified name and value.
|
||||
*
|
||||
* @param name the name of the param.
|
||||
* @param value the value associated with that name.
|
||||
*/
|
||||
public ControlParam(String name, String value)
|
||||
{
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of this ControlParam.
|
||||
* @return the param name.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of this ControlParam.
|
||||
* @return the value.
|
||||
*/
|
||||
public String getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append(name).append(":").append(value);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
return name.hashCode() + 7 * value.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object otherObj)
|
||||
{
|
||||
if (otherObj == this)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (otherObj == null
|
||||
|| !otherObj.getClass().equals(this.getClass()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ControlParam otherCP = (ControlParam) otherObj;
|
||||
return otherCP.name.equals(this.name)
|
||||
&& otherCP.value.equals(this.value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2008 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 received 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.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.config.ConfigElement;
|
||||
import org.alfresco.config.ConfigException;
|
||||
import org.alfresco.config.xml.elementreader.ConfigElementReader;
|
||||
import org.alfresco.web.config.DefaultControlsConfigElement.ControlParam;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* This class is a custom element reader to parse the config file for
|
||||
* <default-controls> elements.
|
||||
*
|
||||
* @author Neil McErlean.
|
||||
*/
|
||||
public class DefaultControlsElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ELEMENT_DEFAULT_CONTROLS = "default-controls";
|
||||
public static final String ELEMENT_CONTROL_PARAM = "control-param";
|
||||
public static final String ATTR_NAME = "name";
|
||||
public static final String ATTR_TEMPLATE = "template";
|
||||
|
||||
/**
|
||||
* @see org.alfresco.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
DefaultControlsConfigElement result = null;
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
String name = element.getName();
|
||||
if (!name.equals(ELEMENT_DEFAULT_CONTROLS))
|
||||
{
|
||||
throw new ConfigException(this.getClass().getName()
|
||||
+ " can only parse " + ELEMENT_DEFAULT_CONTROLS
|
||||
+ " elements, the element passed was '" + name + "'");
|
||||
}
|
||||
|
||||
result = new DefaultControlsConfigElement();
|
||||
|
||||
Iterator<Element> xmlNodes = element.elementIterator();
|
||||
while (xmlNodes.hasNext())
|
||||
{
|
||||
Element nextNode = xmlNodes.next();
|
||||
String typeName = nextNode.attributeValue(ATTR_NAME);
|
||||
String templatePath = nextNode.attributeValue(ATTR_TEMPLATE);
|
||||
|
||||
List<Element> controlParamNode = nextNode.elements(ELEMENT_CONTROL_PARAM);
|
||||
ControlParam param = null;
|
||||
// If the optional control-param tags are present
|
||||
List<ControlParam> params = new ArrayList<ControlParam>();
|
||||
|
||||
for (Element nextControlParam : controlParamNode)
|
||||
{
|
||||
String paramName = nextControlParam.attributeValue(ATTR_NAME);
|
||||
String elementValue = nextControlParam.getTextTrim();
|
||||
// This impl assumes a String value within the control-param tags.
|
||||
// Cannot handle a value as XML attribute.
|
||||
param = new ControlParam(paramName, elementValue);
|
||||
params.add(param);
|
||||
}
|
||||
|
||||
result.addDataMapping(typeName, templatePath, params);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -1,775 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2008 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 received 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.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.alfresco.config.ConfigElement;
|
||||
import org.alfresco.config.ConfigException;
|
||||
import org.alfresco.config.element.ConfigElementAdapter;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Custom config element that represents form values for the client.
|
||||
*
|
||||
* @author Neil McErlean.
|
||||
*/
|
||||
public class FormConfigElement extends ConfigElementAdapter
|
||||
{
|
||||
private static final long serialVersionUID = -7008510360503886308L;
|
||||
private static Log logger = LogFactory.getLog(FormConfigElement.class);
|
||||
|
||||
public enum Mode
|
||||
{
|
||||
VIEW, EDIT, CREATE;
|
||||
public static Mode fromString(String modeString)
|
||||
{
|
||||
if (modeString.equalsIgnoreCase("create")) {
|
||||
return Mode.CREATE;
|
||||
}
|
||||
else if (modeString.equalsIgnoreCase("edit"))
|
||||
{
|
||||
return Mode.EDIT;
|
||||
}
|
||||
else if (modeString.equalsIgnoreCase("view"))
|
||||
{
|
||||
return Mode.VIEW;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final String FORM_ID = "form";
|
||||
private String submissionURL;
|
||||
private List<StringPair> modelOverrides = new ArrayList<StringPair>();
|
||||
|
||||
// We need to maintain the order of templates - per mode.
|
||||
private List<String> createTemplates = new ArrayList<String>();
|
||||
private List<String> editTemplates = new ArrayList<String>();
|
||||
private List<String> viewTemplates = new ArrayList<String>();
|
||||
|
||||
/**
|
||||
* Map of the required roles for create-form templates.
|
||||
* Key = the template String. Value = the requires-role String.
|
||||
*/
|
||||
private Map<String, String> rolesForCreateTemplates = new HashMap<String, String>();
|
||||
private Map<String, String> rolesForEditTemplates = new HashMap<String, String>();
|
||||
private Map<String, String> rolesForViewTemplates = new HashMap<String, String>();
|
||||
|
||||
private List<FieldVisibilityRule> visibilityRules = new ArrayList<FieldVisibilityRule>();
|
||||
|
||||
private Map<String, FormSet> sets = new HashMap<String, FormSet>();
|
||||
private Map<String, FormField> fields = new HashMap<String, FormField>();
|
||||
|
||||
public FormConfigElement()
|
||||
{
|
||||
super(FORM_ID);
|
||||
}
|
||||
|
||||
public FormConfigElement(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.config.ConfigElement#getChildren()
|
||||
*/
|
||||
public List<ConfigElement> getChildren()
|
||||
{
|
||||
throw new ConfigException(
|
||||
"Reading the default-controls config via the generic interfaces is not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.config.ConfigElement#combine(org.alfresco.config.ConfigElement)
|
||||
*/
|
||||
public ConfigElement combine(ConfigElement otherConfigElement)
|
||||
{
|
||||
FormConfigElement otherFormElem = (FormConfigElement)otherConfigElement;
|
||||
FormConfigElement result = new FormConfigElement();
|
||||
|
||||
combineSubmissionURL(otherFormElem, result);
|
||||
|
||||
combineTemplates(otherFormElem, result);
|
||||
|
||||
combineFieldVisibilities(otherFormElem, result);
|
||||
|
||||
combineSets(otherFormElem, result);
|
||||
|
||||
combineFields(otherFormElem, result);
|
||||
|
||||
//TODO field-controls
|
||||
|
||||
//TODO constraint-for-field
|
||||
|
||||
combineModelOverrides(otherFormElem, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void combineFields(FormConfigElement otherFormElem,
|
||||
FormConfigElement result)
|
||||
{
|
||||
for (String nextFieldId : fields.keySet())
|
||||
{
|
||||
FormField nextField = fields.get(nextFieldId);
|
||||
Map<String, String> nextAttributes = nextField.getAttributes();
|
||||
|
||||
List<String> attributeNames = new ArrayList<String>(nextAttributes.size());
|
||||
List<String> attributeValues = new ArrayList<String>(nextAttributes.size());
|
||||
for (String nextAttrName : nextAttributes.keySet())
|
||||
{
|
||||
attributeNames.add(nextAttrName);
|
||||
attributeValues.add(nextAttributes.get(nextAttrName));
|
||||
}
|
||||
result.addField(nextFieldId, attributeNames, attributeValues);
|
||||
}
|
||||
for (String nextFieldId : otherFormElem.fields.keySet())
|
||||
{
|
||||
FormField nextField = otherFormElem.fields.get(nextFieldId);
|
||||
Map<String, String> nextAttributes = nextField.getAttributes();
|
||||
|
||||
List<String> attributeNames = new ArrayList<String>(nextAttributes.size());
|
||||
List<String> attributeValues = new ArrayList<String>(nextAttributes.size());
|
||||
for (String nextAttrName : nextAttributes.keySet())
|
||||
{
|
||||
attributeNames.add(nextAttrName);
|
||||
attributeValues.add(nextAttributes.get(nextAttrName));
|
||||
}
|
||||
result.addField(nextFieldId, attributeNames, attributeValues);
|
||||
}
|
||||
}
|
||||
|
||||
private void combineModelOverrides(FormConfigElement otherFormElem,
|
||||
FormConfigElement result)
|
||||
{
|
||||
for (StringPair override : modelOverrides)
|
||||
{
|
||||
result.addModelOverrides(override.getName(), override.getValue());
|
||||
}
|
||||
for (StringPair override : otherFormElem.modelOverrides)
|
||||
{
|
||||
result.addModelOverrides(override.getName(), override.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private void combineSets(FormConfigElement otherFormElem,
|
||||
FormConfigElement result)
|
||||
{
|
||||
for (String nextOldSet : sets.keySet())
|
||||
{
|
||||
FormSet nextOldSetData = sets.get(nextOldSet);
|
||||
String setId = nextOldSetData.getSetId();
|
||||
String parentId = nextOldSetData.getParentId();
|
||||
String appearance = nextOldSetData.getAppearance();
|
||||
result.addSet(setId, parentId, appearance);
|
||||
}
|
||||
for (String nextNewSet : otherFormElem.sets.keySet())
|
||||
{
|
||||
FormSet nextNewSetData = otherFormElem.sets.get(nextNewSet);
|
||||
String setId = nextNewSetData.getSetId();
|
||||
String parentId = nextNewSetData.getParentId();
|
||||
String appearance = nextNewSetData.getAppearance();
|
||||
result.addSet(setId, parentId, appearance);
|
||||
}
|
||||
}
|
||||
|
||||
private void combineFieldVisibilities(FormConfigElement otherFormElem,
|
||||
FormConfigElement result)
|
||||
{
|
||||
List<FieldVisibilityRule> combinedInstructions = new ArrayList<FieldVisibilityRule>();
|
||||
combinedInstructions.addAll(this.visibilityRules);
|
||||
|
||||
//If there are already instructions pertaining to a particular
|
||||
// field id, we can just leave them in place as the new should override the old.
|
||||
//TODO Test this is true.
|
||||
combinedInstructions.addAll(otherFormElem.visibilityRules);
|
||||
for (FieldVisibilityRule fvi : combinedInstructions)
|
||||
{
|
||||
result.addFieldVisibility(fvi.isShow() ? "show" : "hide"
|
||||
, fvi.getFieldId(), fvi.getModes());
|
||||
}
|
||||
}
|
||||
|
||||
private void combineTemplates(FormConfigElement otherFormElem,
|
||||
FormConfigElement result)
|
||||
{
|
||||
for (String s : this.createTemplates)
|
||||
{
|
||||
String reqsRole = this.rolesForCreateTemplates.get(s);
|
||||
result.addFormTemplate("create-form", s, reqsRole);
|
||||
}
|
||||
for (String s : otherFormElem.createTemplates)
|
||||
{
|
||||
String reqsRole = otherFormElem.rolesForCreateTemplates.get(s);
|
||||
result.addFormTemplate("create-form", s, reqsRole);
|
||||
}
|
||||
|
||||
for (String s : this.editTemplates)
|
||||
{
|
||||
String reqsRole = this.rolesForEditTemplates.get(s);
|
||||
result.addFormTemplate("edit-form", s, reqsRole);
|
||||
}
|
||||
for (String s : otherFormElem.editTemplates)
|
||||
{
|
||||
String reqsRole = otherFormElem.rolesForEditTemplates.get(s);
|
||||
result.addFormTemplate("edit-form", s, reqsRole);
|
||||
}
|
||||
|
||||
for (String s : this.viewTemplates)
|
||||
{
|
||||
String reqsRole = this.rolesForViewTemplates.get(s);
|
||||
result.addFormTemplate("view-form", s, reqsRole);
|
||||
}
|
||||
for (String s : otherFormElem.viewTemplates)
|
||||
{
|
||||
String reqsRole = otherFormElem.rolesForViewTemplates.get(s);
|
||||
result.addFormTemplate("view-form", s, reqsRole);
|
||||
}
|
||||
}
|
||||
|
||||
private void combineSubmissionURL(FormConfigElement otherFormElem,
|
||||
FormConfigElement result)
|
||||
{
|
||||
String otherSubmissionURL = otherFormElem.getSubmissionURL();
|
||||
result.setSubmissionURL(otherSubmissionURL == null ? this.submissionURL : otherSubmissionURL);
|
||||
}
|
||||
|
||||
public String getSubmissionURL()
|
||||
{
|
||||
return this.submissionURL;
|
||||
}
|
||||
|
||||
public Map<String, FormSet> getSets()
|
||||
{
|
||||
return Collections.unmodifiableMap(this.sets);
|
||||
}
|
||||
|
||||
public Set<String> getSetIDs()
|
||||
{
|
||||
return Collections.unmodifiableSet(this.sets.keySet());
|
||||
}
|
||||
|
||||
public List<FieldVisibilityRule> getFieldVisibilityRules()
|
||||
{
|
||||
return Collections.unmodifiableList(this.visibilityRules);
|
||||
}
|
||||
|
||||
//TODO This is all fields. need getVisFields(Role)
|
||||
public Map<String, FormField> getFields()
|
||||
{
|
||||
return Collections.unmodifiableMap(this.fields);
|
||||
}
|
||||
|
||||
public Map<String, FormField> getVisibleCreateFields()
|
||||
{
|
||||
return getFieldsVisibleInMode(Mode.CREATE);
|
||||
}
|
||||
public Map<String, FormField> getVisibleEditFields()
|
||||
{
|
||||
return getFieldsVisibleInMode(Mode.EDIT);
|
||||
}
|
||||
public Map<String, FormField> getVisibleViewFields()
|
||||
{
|
||||
return getFieldsVisibleInMode(Mode.VIEW);
|
||||
}
|
||||
|
||||
public Map<String, String> getCreateTemplates()
|
||||
{
|
||||
return Collections.unmodifiableMap(this.rolesForCreateTemplates);
|
||||
}
|
||||
|
||||
public Map<String, String> getEditTemplates()
|
||||
{
|
||||
return Collections.unmodifiableMap(this.rolesForEditTemplates);
|
||||
}
|
||||
|
||||
public Map<String, String> getViewTemplates()
|
||||
{
|
||||
return Collections.unmodifiableMap(this.rolesForViewTemplates);
|
||||
}
|
||||
|
||||
public List<StringPair> getModelOverrideProperties()
|
||||
{
|
||||
return Collections.unmodifiableList(modelOverrides);
|
||||
}
|
||||
|
||||
/* package */void setSubmissionURL(String newURL)
|
||||
{
|
||||
this.submissionURL = newURL;
|
||||
}
|
||||
|
||||
/* package */void addFormTemplate(String nodeName, String template,
|
||||
String requiredRole)
|
||||
{
|
||||
if (requiredRole == null)
|
||||
{
|
||||
requiredRole = "";
|
||||
}
|
||||
|
||||
if (nodeName.equals("create-form"))
|
||||
{
|
||||
if (!createTemplates.contains(template))
|
||||
{
|
||||
createTemplates.add(template);
|
||||
}
|
||||
rolesForCreateTemplates.put(template, requiredRole);
|
||||
}
|
||||
else if (nodeName.equals("edit-form"))
|
||||
{
|
||||
if (!editTemplates.contains(template))
|
||||
{
|
||||
editTemplates.add(template);
|
||||
}
|
||||
rolesForEditTemplates.put(template, requiredRole);
|
||||
}
|
||||
else if (nodeName.equals("view-form"))
|
||||
{
|
||||
if (!viewTemplates.contains(template))
|
||||
{
|
||||
viewTemplates.add(template);
|
||||
}
|
||||
rolesForViewTemplates.put(template, requiredRole);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("Unrecognised mode: " + nodeName);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* package */void addFieldVisibility(String showOrHide, String fieldId,
|
||||
String mode)
|
||||
{
|
||||
FieldVisibilityRule instruc = new FieldVisibilityRule(showOrHide, fieldId, mode);
|
||||
this.visibilityRules.add(instruc);
|
||||
}
|
||||
|
||||
/* package */void addSet(String setId, String parentSetId, String appearance)
|
||||
{
|
||||
sets.put(setId, new FormSet(setId, parentSetId, appearance));
|
||||
}
|
||||
|
||||
/* package */void addField(String fieldId, List<String> attributeNames,
|
||||
List<String> attributeValues)
|
||||
{
|
||||
Map<String, String> attrs = new HashMap<String, String>();
|
||||
for (int i = 0; i < attributeNames.size(); i++)
|
||||
{
|
||||
attrs.put(attributeNames.get(i), attributeValues.get(i));
|
||||
}
|
||||
fields.put(fieldId, new FormField(attrs));
|
||||
}
|
||||
|
||||
/* package */void addControlForField(String fieldId, String template,
|
||||
List<String> controlParamNames, List<String> controlParamValues)
|
||||
{
|
||||
FormField field = fields.get(fieldId);
|
||||
field.setTemplate(template);
|
||||
for (int i = 0; i < controlParamNames.size(); i++)
|
||||
{
|
||||
field.addControlParam(new StringPair(controlParamNames.get(i),
|
||||
controlParamValues.get(i)));
|
||||
}
|
||||
}
|
||||
|
||||
/* package */void addConstraintForField(String fieldId, String type,
|
||||
String message, String messageId)
|
||||
{
|
||||
FormField field = fields.get(fieldId);
|
||||
field.setConstraintType(type);
|
||||
field.setConstraintMessage(message);
|
||||
field.setConstraintMessageId(messageId);
|
||||
}
|
||||
|
||||
/* package */void addModelOverrides(String name, String value)
|
||||
{
|
||||
StringPair modelOverride = new StringPair(name, value);
|
||||
//TODO Consider using a different collection type here.
|
||||
for (Iterator<StringPair> iter = modelOverrides.iterator(); iter.hasNext(); )
|
||||
{
|
||||
if (iter.next().getName().equals(name))
|
||||
{
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
modelOverrides.add(modelOverride);
|
||||
}
|
||||
|
||||
private String findFirstMatchingTemplate(List<String> templates,
|
||||
Map<String, String> templatesToRoles, List<String> currentRoles)
|
||||
{
|
||||
// If there is no current role, we can only return templates that require no role.
|
||||
if (currentRoles == null || currentRoles.isEmpty())
|
||||
{
|
||||
for (String template : templates)
|
||||
{
|
||||
String requiredRolesForThisTemplate = templatesToRoles.get(template);
|
||||
if (requiredRolesForThisTemplate.trim().length() == 0)
|
||||
{
|
||||
return template;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Here there is at least one current role.
|
||||
for (String template : templates)
|
||||
{
|
||||
String requiredRolesForThisTemplate = templatesToRoles.get(template);
|
||||
for (String role : currentRoles)
|
||||
{
|
||||
if (requiredRolesForThisTemplate.contains(role))
|
||||
{
|
||||
return template;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param m
|
||||
* @param roles a list of roles, can be an empty list or null.
|
||||
* @return <code>null</code> if there is no template available for the specified role(s).
|
||||
*/
|
||||
public String getFormTemplate(Mode m, List<String> roles)
|
||||
{
|
||||
switch (m)
|
||||
{
|
||||
case CREATE: return findFirstMatchingTemplate(createTemplates, rolesForCreateTemplates, roles);
|
||||
case EDIT: return findFirstMatchingTemplate(editTemplates, rolesForEditTemplates, roles);
|
||||
case VIEW: return findFirstMatchingTemplate(viewTemplates, rolesForViewTemplates, roles);
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks whether the specified field is visible in the specified mode.
|
||||
* The algorithm for determining visibility works as follows
|
||||
* <ul>
|
||||
* <li>If there is no field-visibility configuration (show or hide tags) then
|
||||
* all fields are visible in all modes.</li>
|
||||
* <li>If there are one or more hide tags then the specified fields will be hidden
|
||||
* in the specified modes. All other fields remain visible as before.</li>
|
||||
* <li>However, as soon as a single show tag appears in the config xml, this is
|
||||
* taken as a signal that all field visibility is to be manually configured.
|
||||
* At that point, all fields default to hidden and only those explicitly
|
||||
* configured to be shown (with a show tag) will actually be shown.</li>
|
||||
* <li>Show and hide rules will be applied in sequence with later rules
|
||||
* invalidating previous rules.</li>
|
||||
* <li>Show or hide rules which only apply for specified modes have an implicit
|
||||
* element. e.g. <show id="name" for-mode="view"/> would show the name field
|
||||
* in view mode and by implication, hide it in other modes.</li>
|
||||
* </ul>
|
||||
* @param fieldId
|
||||
* @param m
|
||||
* @return
|
||||
*/
|
||||
public boolean isFieldVisible(String fieldId, Mode m)
|
||||
{
|
||||
if (visibilityRules.isEmpty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean listContainsAtLeastOneShow = false;
|
||||
// true means show, false means hide, null means 'no answer'.
|
||||
Boolean latestInstructionToShow = null;
|
||||
for (FieldVisibilityRule instruc : visibilityRules)
|
||||
{
|
||||
if (instruc.isShow())
|
||||
{
|
||||
listContainsAtLeastOneShow = true;
|
||||
}
|
||||
if (instruc.getFieldId().equals(fieldId))
|
||||
{
|
||||
// This matters
|
||||
if (instruc.getListOfModes().contains(m))
|
||||
{
|
||||
latestInstructionToShow = instruc.isShow() ?
|
||||
Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
latestInstructionToShow = instruc.isShow() ?
|
||||
Boolean.FALSE : Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (latestInstructionToShow == null)
|
||||
{
|
||||
// We really on the 'default' behaviour
|
||||
return !listContainsAtLeastOneShow;
|
||||
}
|
||||
else
|
||||
{
|
||||
return latestInstructionToShow.booleanValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, FormField> getFieldsVisibleInMode(Mode mode)
|
||||
{
|
||||
Map<String, FormField> result = new HashMap<String, FormField>();
|
||||
for (String fieldId : this.fields.keySet())
|
||||
{
|
||||
if (this.isFieldVisible(fieldId, mode))
|
||||
{
|
||||
result.put(fieldId, fields.get(fieldId));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This inner class represents a <set> element within a <form>
|
||||
* element.
|
||||
*
|
||||
* @author Neil McErlean.
|
||||
*/
|
||||
public static class FormSet
|
||||
{
|
||||
private final String setId;
|
||||
private final String parentId;
|
||||
private final String appearance;
|
||||
public FormSet(String setId, String parentId, String appearance)
|
||||
{
|
||||
this.setId = setId;
|
||||
this.parentId = parentId;
|
||||
this.appearance = appearance;
|
||||
}
|
||||
public String getSetId()
|
||||
{
|
||||
return setId;
|
||||
}
|
||||
public String getParentId()
|
||||
{
|
||||
return parentId;
|
||||
}
|
||||
public String getAppearance()
|
||||
{
|
||||
return appearance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object otherObj)
|
||||
{
|
||||
if (otherObj == null
|
||||
|| !otherObj.getClass().equals(this.getClass()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
FormSet otherSet = (FormSet) otherObj;
|
||||
return this.setId.equals(otherSet.setId)
|
||||
&& this.parentId.equals(otherSet.parentId)
|
||||
&& this.appearance.equals(otherSet.appearance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return setId.hashCode()
|
||||
+ 7 * parentId.hashCode() + 13 * appearance.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public static class FormField
|
||||
{
|
||||
|
||||
//TODO I think I'll have to add explicit methods for all params e.g. getRequiredRoles():String
|
||||
// Maps of attributes are not enough as they leave too much work up to the client.
|
||||
|
||||
private final Map<String, String> attributes;
|
||||
private String template;
|
||||
private final List<StringPair> controlParams = new ArrayList<StringPair>();
|
||||
private String constraintType;
|
||||
private String constraintMessage;
|
||||
private String constraintMessageId;
|
||||
public FormField(Map<String, String> attributes)
|
||||
{
|
||||
this.attributes = attributes;
|
||||
}
|
||||
public void setTemplate(String template)
|
||||
{
|
||||
this.template = template;
|
||||
}
|
||||
public void setConstraintType(String constraintType)
|
||||
{
|
||||
this.constraintType = constraintType;
|
||||
}
|
||||
public void setConstraintMessage(String constraintMessage)
|
||||
{
|
||||
this.constraintMessage = constraintMessage;
|
||||
}
|
||||
public void setConstraintMessageId(String constraintMessageId)
|
||||
{
|
||||
this.constraintMessageId = constraintMessageId;
|
||||
}
|
||||
public void addControlParam(StringPair nameValue)
|
||||
{
|
||||
this.controlParams.add(nameValue);
|
||||
}
|
||||
public Map<String, String> getAttributes()
|
||||
{
|
||||
return Collections.unmodifiableMap(attributes);
|
||||
}
|
||||
public String getTemplate()
|
||||
{
|
||||
return template;
|
||||
}
|
||||
public List<StringPair> getControlParams()
|
||||
{
|
||||
return Collections.unmodifiableList(controlParams);
|
||||
}
|
||||
public String getConstraintType()
|
||||
{
|
||||
return constraintType;
|
||||
}
|
||||
public String getConstraintMessage()
|
||||
{
|
||||
return constraintMessage;
|
||||
}
|
||||
public String getConstraintMessageId()
|
||||
{
|
||||
return constraintMessageId;
|
||||
}
|
||||
}
|
||||
|
||||
public static class FieldVisibilityRule
|
||||
{
|
||||
private final boolean show;
|
||||
private final String fieldId;
|
||||
private final List<Mode> forModes;
|
||||
public FieldVisibilityRule(String showOrHide, String fieldId, String modesString)
|
||||
{
|
||||
if (showOrHide.equals("show"))
|
||||
{
|
||||
this.show = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.show = false;
|
||||
}
|
||||
this.fieldId = fieldId;
|
||||
this.forModes = new ArrayList<Mode>();
|
||||
if (modesString == null)
|
||||
{
|
||||
forModes.addAll(Arrays.asList(Mode.values()));
|
||||
}
|
||||
else
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer(modesString, ",");
|
||||
while (st.hasMoreTokens())
|
||||
{
|
||||
String nextToken = st.nextToken().trim();
|
||||
Mode nextMode = Mode.fromString(nextToken);
|
||||
forModes.add(nextMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isShow()
|
||||
{
|
||||
return show;
|
||||
}
|
||||
|
||||
public boolean isHide()
|
||||
{
|
||||
return !isShow();
|
||||
}
|
||||
|
||||
public String getFieldId()
|
||||
{
|
||||
return fieldId;
|
||||
}
|
||||
|
||||
public List<Mode> getListOfModes()
|
||||
{
|
||||
return Collections.unmodifiableList(forModes);
|
||||
}
|
||||
|
||||
public String getModes()
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Iterator<Mode> iter = forModes.iterator(); iter.hasNext(); )
|
||||
{
|
||||
result.append(iter.next());
|
||||
if (iter.hasNext())
|
||||
{
|
||||
result.append(", ");
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append(show ? "show" : "hide");
|
||||
result.append(" ").append(fieldId).append(" ").append(forModes);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object otherObj)
|
||||
{
|
||||
if (otherObj == null
|
||||
|| !otherObj.getClass().equals(this.getClass()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
FieldVisibilityRule otherFVI = (FieldVisibilityRule) otherObj;
|
||||
return this.show == otherFVI.show
|
||||
&& this.fieldId.equals(otherFVI.fieldId)
|
||||
&& this.forModes.equals(otherFVI.forModes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return show ? 1 : 0
|
||||
+ 7 * fieldId.hashCode() + 13 * forModes.hashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,209 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2008 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 received 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.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.config.ConfigElement;
|
||||
import org.alfresco.config.ConfigException;
|
||||
import org.alfresco.config.xml.elementreader.ConfigElementReader;
|
||||
import org.dom4j.Attribute;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* This class is a custom element reader to parse the config file for
|
||||
* <form> elements.
|
||||
*
|
||||
* @author Neil McErlean.
|
||||
*/
|
||||
public class FormElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ATTR_APPEARANCE = "appearance";
|
||||
public static final String ATTR_FOR_MODE = "for-mode";
|
||||
public static final String ATTR_MESSAGE = "message";
|
||||
public static final String ATTR_MESSAGE_ID = "message-id";
|
||||
public static final String ATTR_NAME = "name";
|
||||
public static final String ATTR_NAME_ID = "id";
|
||||
public static final String ATTR_PARENT = "parent";
|
||||
public static final String ATTR_REQUIRES_ROLE = "requires-role";
|
||||
public static final String ATTR_SUBMISSION_URL = "submission-url";
|
||||
public static final String ATTR_TEMPLATE = "template";
|
||||
public static final String ATTR_TYPE = "type";
|
||||
public static final String ELEMENT_FORM = "form";
|
||||
public static final String ELEMENT_HIDE = "hide";
|
||||
public static final String ELEMENT_SHOW = "show";
|
||||
|
||||
/**
|
||||
* @see org.alfresco.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
public ConfigElement parse(Element formElement)
|
||||
{
|
||||
FormConfigElement result = null;
|
||||
if (formElement == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
String name = formElement.getName();
|
||||
if (!name.equals(ELEMENT_FORM))
|
||||
{
|
||||
throw new ConfigException(this.getClass().getName()
|
||||
+ " can only parse " + ELEMENT_FORM
|
||||
+ " elements, the element passed was '" + name + "'");
|
||||
}
|
||||
|
||||
result = new FormConfigElement();
|
||||
|
||||
parseSubmissionURL(formElement, result);
|
||||
|
||||
// Using xpath expressions to select nodes under <form> and their attributes.
|
||||
parseForms(formElement, result);
|
||||
|
||||
parseFieldVisibilities(formElement, result);
|
||||
|
||||
parseSets(formElement, result);
|
||||
|
||||
parseFields(formElement, result);
|
||||
|
||||
parseModelOverrides(formElement, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void parseModelOverrides(Element formElement, FormConfigElement result)
|
||||
{
|
||||
for (Object propObj : formElement.selectNodes("./model-override/property")) {
|
||||
Element propertyElem = (Element)propObj;
|
||||
String propName = propertyElem.attributeValue(ATTR_NAME);
|
||||
String propValue = propertyElem.getTextTrim();
|
||||
result.addModelOverrides(propName, propValue);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void parseFields(Element formElement, FormConfigElement result)
|
||||
{
|
||||
for (Object fieldObj : formElement.selectNodes("./appearance/field")) {
|
||||
Element fieldElem = (Element)fieldObj;
|
||||
List<Attribute> fieldAttributes = fieldElem.selectNodes("./@*");
|
||||
|
||||
List<String> fieldAttributeNames = new ArrayList<String>();
|
||||
List<String> fieldAttributeValues = new ArrayList<String>();
|
||||
|
||||
// With special handling for the mandatory "id" attribute.
|
||||
String fieldIdValue = null;
|
||||
for (Attribute nextAttr : fieldAttributes) {
|
||||
String nextAttributeName = nextAttr.getName();
|
||||
String nextAttributeValue = nextAttr.getValue();
|
||||
|
||||
if (nextAttributeName.equals(ATTR_NAME_ID))
|
||||
{
|
||||
fieldIdValue = nextAttributeValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
fieldAttributeNames.add(nextAttributeName);
|
||||
fieldAttributeValues.add(nextAttributeValue);
|
||||
}
|
||||
}
|
||||
if (fieldIdValue == null)
|
||||
{
|
||||
throw new ConfigException("<field> node missing mandatory id attribute.");
|
||||
}
|
||||
result.addField(fieldIdValue, fieldAttributeNames, fieldAttributeValues);
|
||||
|
||||
List<Element> controlObjs = fieldElem.selectNodes("./control");
|
||||
if (!controlObjs.isEmpty())
|
||||
{
|
||||
Element controlElem = controlObjs.get(0);
|
||||
|
||||
String templateValue = controlElem.attributeValue(ATTR_TEMPLATE);
|
||||
List<String> controlParamNames = new ArrayList<String>();
|
||||
List<String> controlParamValues = new ArrayList<String>();
|
||||
for (Object paramObj : controlElem
|
||||
.selectNodes("./control-param"))
|
||||
{
|
||||
Element paramElem = (Element) paramObj;
|
||||
controlParamNames.add(paramElem.attributeValue(ATTR_NAME));
|
||||
controlParamValues.add(paramElem.getTextTrim());
|
||||
}
|
||||
result.addControlForField(fieldIdValue, templateValue, controlParamNames, controlParamValues);
|
||||
}
|
||||
|
||||
for (Object constraintMessageObj : fieldElem.selectNodes("./constraint-message")) {
|
||||
Element constraintMessage = (Element)constraintMessageObj;
|
||||
String type = constraintMessage.attributeValue(ATTR_TYPE);
|
||||
String message = constraintMessage.attributeValue(ATTR_MESSAGE);
|
||||
String messageId = constraintMessage.attributeValue(ATTR_MESSAGE_ID);
|
||||
result.addConstraintForField(fieldIdValue, type, message, messageId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void parseSets(Element formElement, FormConfigElement result)
|
||||
{
|
||||
for (Object setObj : formElement.selectNodes("./appearance/set")) {
|
||||
Element setElem = (Element)setObj;
|
||||
String setId = setElem.attributeValue(ATTR_NAME_ID);
|
||||
String parentSetId = setElem.attributeValue(ATTR_PARENT);
|
||||
String appearance = setElem.attributeValue(ATTR_APPEARANCE);
|
||||
|
||||
result.addSet(setId, parentSetId, appearance);
|
||||
}
|
||||
}
|
||||
|
||||
private void parseFieldVisibilities(Element formElement,
|
||||
FormConfigElement result)
|
||||
{
|
||||
for (Object obj : formElement.selectNodes("./field-visibility/show|./field-visibility/hide")) {
|
||||
Element showOrHideElem = (Element)obj;
|
||||
String nodeName = showOrHideElem.getName();
|
||||
String fieldId = showOrHideElem.attributeValue(ATTR_NAME_ID);
|
||||
String mode = showOrHideElem.attributeValue(ATTR_FOR_MODE);
|
||||
|
||||
result.addFieldVisibility(nodeName, fieldId, mode);
|
||||
}
|
||||
}
|
||||
|
||||
private void parseForms(Element formElement, FormConfigElement result)
|
||||
{
|
||||
for (Object obj : formElement.selectNodes("./edit-form|./view-form|./create-form")) {
|
||||
Element editOrViewOrCreateFormElem = (Element)obj;
|
||||
String nodeName = editOrViewOrCreateFormElem.getName();
|
||||
String template = editOrViewOrCreateFormElem.attributeValue(ATTR_TEMPLATE);
|
||||
String requiresRole = editOrViewOrCreateFormElem.attributeValue(ATTR_REQUIRES_ROLE);
|
||||
|
||||
result.addFormTemplate(nodeName, template, requiresRole);
|
||||
}
|
||||
}
|
||||
|
||||
private void parseSubmissionURL(Element formElement,
|
||||
FormConfigElement result)
|
||||
{
|
||||
String submissionURL = formElement.attributeValue(ATTR_SUBMISSION_URL);
|
||||
result.setSubmissionURL(submissionURL);
|
||||
}
|
||||
}
|
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2008 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 received 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.config;
|
||||
|
||||
/**
|
||||
* This immutable class represents a pair of Strings, such as a Name-Value pair. A null
|
||||
* value is allowed, but a null name is not.
|
||||
*
|
||||
* @author Neil McErlean.
|
||||
*/
|
||||
public class StringPair implements Comparable<StringPair>
|
||||
{
|
||||
private final String name;
|
||||
private final String value;
|
||||
|
||||
public StringPair(String name, String value)
|
||||
{
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getValue()
|
||||
{
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public int compareTo(StringPair otherStringPair)
|
||||
{
|
||||
if (otherStringPair == null)
|
||||
{
|
||||
throw new NullPointerException("Cannot compareTo null.");
|
||||
}
|
||||
if (this.equals(otherStringPair))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return this.toString().compareTo(otherStringPair.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object otherObj)
|
||||
{
|
||||
if (otherObj == null || !otherObj.getClass().equals(this.getClass()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
StringPair otherStringPair = (StringPair)otherObj;
|
||||
|
||||
// These String.valueOf calls will protect us from NPEs in the case of
|
||||
// null values.
|
||||
return this.name.equals(otherStringPair.name)
|
||||
&& String.valueOf(this.value).equals(String.valueOf(otherStringPair.value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int valueHashCode = 0;
|
||||
if (value != null)
|
||||
{
|
||||
valueHashCode = value.hashCode();
|
||||
}
|
||||
return name.hashCode() + 7 * valueHashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append(name).append("=").append(value);
|
||||
return result.toString();
|
||||
}
|
||||
}
|
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2008 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 received 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.config;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class StringPairTest extends TestCase
|
||||
{
|
||||
private final StringPair pairA = new StringPair("name", "Fred");
|
||||
private final StringPair pairAduplicate = new StringPair("name", "Fred");
|
||||
private final StringPair pairB = new StringPair("name", "Barney");
|
||||
|
||||
public StringPairTest(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void testNullValuedPair()
|
||||
{
|
||||
StringPair nullValue = new StringPair("NullValue", null);
|
||||
|
||||
// These calls are to generate potential NPEs.
|
||||
int ignored = nullValue.hashCode();
|
||||
boolean dontCare = nullValue.equals(pairA);
|
||||
dontCare = pairA.equals(nullValue);
|
||||
ignored = nullValue.compareTo(pairA);
|
||||
ignored = pairA.compareTo(nullValue);
|
||||
}
|
||||
|
||||
public void testHashCode()
|
||||
{
|
||||
assertEquals("Equal objects must have equal hashCodes.", pairA.hashCode(), pairAduplicate.hashCode());
|
||||
}
|
||||
|
||||
public void testEquals()
|
||||
{
|
||||
assertEquals("Equal objects appear unequal.", pairA, pairAduplicate);
|
||||
assertTrue("Unequal objects appear equal.", !pairA.equals(pairB));
|
||||
}
|
||||
|
||||
public void testCompareTo()
|
||||
{
|
||||
assertEquals("Equal objects have compareTo == 0.", 0, pairA.compareTo(pairAduplicate));
|
||||
assertEquals("Equal objects have compareTo == 0.", 0, pairAduplicate.compareTo(pairA));
|
||||
|
||||
assertTrue("Unequal objects should have compareTo != 0.", pairA.compareTo(pairB) > 0);
|
||||
assertTrue("Unequal objects should have compareTo != 0.", pairB.compareTo(pairA) < 0);
|
||||
}
|
||||
|
||||
public void testCompareToNull()
|
||||
{
|
||||
try
|
||||
{
|
||||
pairA.compareTo(null);
|
||||
}
|
||||
catch (NullPointerException expected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
fail("Expected NPE not thrown.");
|
||||
}
|
||||
}
|
@@ -26,11 +26,8 @@ package org.alfresco.web.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.config.Config;
|
||||
import org.alfresco.config.ConfigElement;
|
||||
@@ -40,11 +37,7 @@ import org.alfresco.util.BaseTest;
|
||||
import org.alfresco.web.config.ActionsConfigElement.ActionDefinition;
|
||||
import org.alfresco.web.config.ActionsConfigElement.ActionGroup;
|
||||
import org.alfresco.web.config.AdvancedSearchConfigElement.CustomProperty;
|
||||
import org.alfresco.web.config.DefaultControlsConfigElement.ControlParam;
|
||||
import org.alfresco.web.config.DialogsConfigElement.DialogConfig;
|
||||
import org.alfresco.web.config.FormConfigElement.FormField;
|
||||
import org.alfresco.web.config.FormConfigElement.FormSet;
|
||||
import org.alfresco.web.config.FormConfigElement.Mode;
|
||||
import org.alfresco.web.config.PropertySheetConfigElement.ItemConfig;
|
||||
import org.alfresco.web.config.WizardsConfigElement.ConditionalPageConfig;
|
||||
import org.alfresco.web.config.WizardsConfigElement.PageConfig;
|
||||
|
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 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.web.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.config.Config;
|
||||
import org.alfresco.config.ConfigElement;
|
||||
import org.alfresco.config.xml.XMLConfigService;
|
||||
import org.alfresco.util.BaseTest;
|
||||
import org.alfresco.web.config.DefaultControlsConfigElement.ControlParam;
|
||||
|
||||
/**
|
||||
* JUnit tests to exercise the forms-related capabilities in to the web client
|
||||
* config service. These only include those override-related tests that require
|
||||
* multiple config xml files.
|
||||
*
|
||||
* @author Neil McErlean
|
||||
*/
|
||||
public class WebClientFormsOverridingTest extends BaseTest
|
||||
{
|
||||
private XMLConfigService configService;
|
||||
private Config globalConfig;
|
||||
private FormConfigElement formConfigElement;
|
||||
private static final String FORMS_CONFIG = "test-config-forms.xml";
|
||||
private static final String FORMS_OVERRIDE_CONFIG = "test-config-forms-override.xml";
|
||||
|
||||
/**
|
||||
* @see junit.framework.TestCase#setUp()
|
||||
*/
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
configService = initXMLConfigService(FORMS_CONFIG,
|
||||
FORMS_OVERRIDE_CONFIG);
|
||||
assertNotNull("configService was null.", configService);
|
||||
globalConfig = configService.getGlobalConfig();
|
||||
assertNotNull("Global config was null.", globalConfig);
|
||||
|
||||
Config contentConfig = configService.getConfig("content");
|
||||
assertNotNull("contentConfig was null.", contentConfig);
|
||||
|
||||
ConfigElement confElement = contentConfig.getConfigElement("form");
|
||||
assertNotNull("confElement was null.", confElement);
|
||||
assertTrue("confElement should be instanceof FormConfigElement.",
|
||||
confElement instanceof FormConfigElement);
|
||||
formConfigElement = (FormConfigElement) confElement;
|
||||
}
|
||||
|
||||
public void testDefaultControlsOverride()
|
||||
{
|
||||
ConfigElement globalDefaultControls = globalConfig
|
||||
.getConfigElement("default-controls");
|
||||
assertNotNull("global default-controls element should not be null",
|
||||
globalDefaultControls);
|
||||
assertTrue(
|
||||
"config element should be an instance of DefaultControlsConfigElement",
|
||||
(globalDefaultControls instanceof DefaultControlsConfigElement));
|
||||
DefaultControlsConfigElement dcCE = (DefaultControlsConfigElement) globalDefaultControls;
|
||||
|
||||
assertTrue("New template is missing.", dcCE.getNames().contains("xyz"));
|
||||
assertEquals("Expected template incorrect.", "org/alfresco/xyz.ftl",
|
||||
dcCE.getTemplateFor("xyz"));
|
||||
|
||||
ControlParam expectedNewControlParam = new ControlParam("c", "Never.");
|
||||
assertTrue("New control-param missing.", dcCE
|
||||
.getControlParamsFor("abc").contains(expectedNewControlParam));
|
||||
}
|
||||
|
||||
public void testConstraintHandlersOverride()
|
||||
{
|
||||
ConfigElement globalConstraintHandlers = globalConfig
|
||||
.getConfigElement("constraint-handlers");
|
||||
assertNotNull("global constraint-handlers element should not be null",
|
||||
globalConstraintHandlers);
|
||||
assertTrue(
|
||||
"config element should be an instance of ConstraintHandlersConfigElement",
|
||||
(globalConstraintHandlers instanceof ConstraintHandlersConfigElement));
|
||||
ConstraintHandlersConfigElement chCE = (ConstraintHandlersConfigElement) globalConstraintHandlers;
|
||||
|
||||
assertTrue("New type is missing.", chCE.getConstraintTypes().contains(
|
||||
"RANGE"));
|
||||
assertEquals("Expected handler incorrect.",
|
||||
"Alfresco.forms.validation.rangeMatch", chCE
|
||||
.getValidationHandlerFor("RANGE"));
|
||||
|
||||
assertEquals("Modified message is wrong.", "Overridden Message", chCE
|
||||
.getMessageFor("NUMERIC"));
|
||||
}
|
||||
|
||||
public void testFormSubmissionUrlAndModelOverridePropsOverride()
|
||||
{
|
||||
assertEquals("Submission URL was incorrect.", "overridden/submission/url",
|
||||
formConfigElement.getSubmissionURL());
|
||||
|
||||
List<StringPair> expectedModelOverrideProperties = new ArrayList<StringPair>();
|
||||
expectedModelOverrideProperties.add(new StringPair(
|
||||
"fields.title.mandatory", "false"));
|
||||
assertEquals("Expected property missing.",
|
||||
expectedModelOverrideProperties, formConfigElement
|
||||
.getModelOverrideProperties());
|
||||
}
|
||||
|
||||
}
|
@@ -1,474 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2008 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 received 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.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.config.Config;
|
||||
import org.alfresco.config.ConfigElement;
|
||||
import org.alfresco.config.ConfigException;
|
||||
import org.alfresco.config.xml.XMLConfigService;
|
||||
import org.alfresco.util.BaseTest;
|
||||
import org.alfresco.web.config.DefaultControlsConfigElement.ControlParam;
|
||||
import org.alfresco.web.config.FormConfigElement.FormField;
|
||||
import org.alfresco.web.config.FormConfigElement.FormSet;
|
||||
import org.alfresco.web.config.FormConfigElement.Mode;
|
||||
|
||||
/**
|
||||
* JUnit tests to exercise the forms-related capabilities in to the web client
|
||||
* config service. These tests only include those that require a single config
|
||||
* xml file. Override-related tests, which use multiple config xml files, are
|
||||
* located in peer classes in this package.
|
||||
*
|
||||
* @author Neil McErlean
|
||||
*/
|
||||
public class WebClientFormsTest extends BaseTest
|
||||
{
|
||||
private static final String TEST_CONFIG_XML = "test-config-forms.xml";
|
||||
private XMLConfigService configService;
|
||||
private Config globalConfig;
|
||||
private ConfigElement globalDefaultControls;
|
||||
private ConfigElement globalConstraintHandlers;
|
||||
private FormConfigElement formConfigElement;
|
||||
private DefaultControlsConfigElement defltCtrlsConfElement;
|
||||
|
||||
/**
|
||||
* @see junit.framework.TestCase#setUp()
|
||||
*/
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
configService = initXMLConfigService(TEST_CONFIG_XML);
|
||||
assertNotNull("configService was null.", configService);
|
||||
|
||||
Config contentConfig = configService.getConfig("content");
|
||||
assertNotNull("contentConfig was null.", contentConfig);
|
||||
|
||||
ConfigElement confElement = contentConfig.getConfigElement("form");
|
||||
assertNotNull("confElement was null.", confElement);
|
||||
assertTrue("confElement should be instanceof FormConfigElement.",
|
||||
confElement instanceof FormConfigElement);
|
||||
formConfigElement = (FormConfigElement) confElement;
|
||||
|
||||
globalConfig = configService.getGlobalConfig();
|
||||
|
||||
globalDefaultControls = globalConfig
|
||||
.getConfigElement("default-controls");
|
||||
assertNotNull("global default-controls element should not be null",
|
||||
globalDefaultControls);
|
||||
assertTrue(
|
||||
"config element should be an instance of DefaultControlsConfigElement",
|
||||
(globalDefaultControls instanceof DefaultControlsConfigElement));
|
||||
defltCtrlsConfElement = (DefaultControlsConfigElement) globalDefaultControls;
|
||||
|
||||
globalConstraintHandlers = globalConfig
|
||||
.getConfigElement("constraint-handlers");
|
||||
assertNotNull("global constraint-handlers element should not be null",
|
||||
globalConstraintHandlers);
|
||||
assertTrue(
|
||||
"config element should be an instance of ConstraintHandlersConfigElement",
|
||||
(globalConstraintHandlers instanceof ConstraintHandlersConfigElement));
|
||||
}
|
||||
|
||||
public void testDefaultControlsMappingNameToTemplate()
|
||||
{
|
||||
// Test that the default-control types are read from the config file
|
||||
Map<String, String> expectedDataMappings = new HashMap<String, String>();
|
||||
expectedDataMappings.put("d:text",
|
||||
"org/alfresco/forms/controls/textfield.ftl");
|
||||
expectedDataMappings.put("d:boolean",
|
||||
"org/alfresco/forms/controls/checkbox.ftl");
|
||||
expectedDataMappings.put("association",
|
||||
"org/alfresco/forms/controls/association-picker.ftl");
|
||||
expectedDataMappings.put("abc", "org/alfresco/abc.ftl");
|
||||
|
||||
Set<String> actualNames = defltCtrlsConfElement.getNames();
|
||||
assertEquals("Incorrect name count, expected "
|
||||
+ expectedDataMappings.size(), expectedDataMappings.size(),
|
||||
actualNames.size());
|
||||
|
||||
// Ugly hack to get around JUnit 3.8.1 not having
|
||||
// assertEquals(Collection, Collection)
|
||||
for (String nextName : expectedDataMappings.keySet())
|
||||
{
|
||||
assertTrue("actualNames was missing " + nextName, actualNames
|
||||
.contains(nextName));
|
||||
}
|
||||
for (String nextName : actualNames)
|
||||
{
|
||||
assertTrue("expectedDataMappings was missing " + nextName,
|
||||
expectedDataMappings.keySet().contains(nextName));
|
||||
}
|
||||
|
||||
// Test that the datatypes map to the expected template.
|
||||
for (String nextKey : expectedDataMappings.keySet())
|
||||
{
|
||||
String nextExpectedValue = expectedDataMappings.get(nextKey);
|
||||
String nextActualValue = defltCtrlsConfElement.getTemplateFor(nextKey);
|
||||
assertTrue("Incorrect template for " + nextKey + ": "
|
||||
+ nextActualValue, nextExpectedValue
|
||||
.equals(nextActualValue));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testReadControlParamsFromConfigXml()
|
||||
{
|
||||
Map<String, List<ControlParam>> expectedControlParams = new HashMap<String, List<ControlParam>>();
|
||||
|
||||
List<ControlParam> textParams = new ArrayList<ControlParam>();
|
||||
textParams.add(new ControlParam("size", "50"));
|
||||
|
||||
List<ControlParam> abcParams = new ArrayList<ControlParam>();
|
||||
abcParams.add(new ControlParam("a", "1"));
|
||||
abcParams.add(new ControlParam("b", "Hello"));
|
||||
abcParams.add(new ControlParam("c", "For ever and ever."));
|
||||
abcParams.add(new ControlParam("d", ""));
|
||||
|
||||
expectedControlParams.put("d:text", textParams);
|
||||
expectedControlParams.put("d:boolean", Collections.EMPTY_LIST);
|
||||
expectedControlParams.put("association", Collections.EMPTY_LIST);
|
||||
expectedControlParams.put("abc", abcParams);
|
||||
|
||||
for (String name : expectedControlParams.keySet())
|
||||
{
|
||||
List<ControlParam> actualControlParams = defltCtrlsConfElement
|
||||
.getControlParamsFor(name);
|
||||
assertEquals("Incorrect params for " + name, expectedControlParams
|
||||
.get(name), actualControlParams);
|
||||
}
|
||||
}
|
||||
|
||||
public void testDefaultControlsConfigElementShouldHaveNoChildren()
|
||||
{
|
||||
try
|
||||
{
|
||||
defltCtrlsConfElement.getChildren();
|
||||
fail("getChildren() did not throw an exception");
|
||||
} catch (ConfigException ce)
|
||||
{
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the combination of a DefaultControlsConfigElement with another that
|
||||
* contains additional data.
|
||||
*/
|
||||
public void testCombineDefaultControlsWithAddedParam()
|
||||
{
|
||||
DefaultControlsConfigElement basicElement = new DefaultControlsConfigElement();
|
||||
basicElement.addDataMapping("text", "path/textbox.ftl", null);
|
||||
|
||||
// This element is the same as the above, but adds a control-param.
|
||||
DefaultControlsConfigElement parameterisedElement = new DefaultControlsConfigElement();
|
||||
List<ControlParam> testParams = new ArrayList<ControlParam>();
|
||||
testParams.add(new ControlParam("A", "1"));
|
||||
parameterisedElement.addDataMapping("text", "path/textbox.ftl",
|
||||
testParams);
|
||||
|
||||
ConfigElement combinedElem = basicElement.combine(parameterisedElement);
|
||||
assertEquals("Combined elem incorrect.", parameterisedElement,
|
||||
combinedElem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the combination of a DefaultControlsConfigElement with another that
|
||||
* contains modified data.
|
||||
*/
|
||||
public void testCombineDefaultControlsWithModifiedParam()
|
||||
{
|
||||
DefaultControlsConfigElement initialElement = new DefaultControlsConfigElement();
|
||||
List<ControlParam> testParams = new ArrayList<ControlParam>();
|
||||
testParams.add(new ControlParam("A", "1"));
|
||||
initialElement.addDataMapping("text", "path/textbox.ftl", testParams);
|
||||
|
||||
// This element is the same as the above, but modifies the
|
||||
// control-param.
|
||||
DefaultControlsConfigElement modifiedElement = new DefaultControlsConfigElement();
|
||||
List<ControlParam> modifiedTestParams = new ArrayList<ControlParam>();
|
||||
modifiedTestParams.add(new ControlParam("A", "5"));
|
||||
modifiedElement.addDataMapping("text", "path/textbox.ftl",
|
||||
modifiedTestParams);
|
||||
|
||||
ConfigElement combinedElem = initialElement.combine(modifiedElement);
|
||||
assertEquals("Combined elem incorrect.", modifiedElement, combinedElem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the combination of a DefaultControlsConfigElement with another that
|
||||
* contains deleted data. TODO Do we actually need to support this type of
|
||||
* customisation?
|
||||
*/
|
||||
public void testCombineDefaultControlsWithDeletedParam()
|
||||
{
|
||||
DefaultControlsConfigElement initialElement = new DefaultControlsConfigElement();
|
||||
List<ControlParam> testParams = new ArrayList<ControlParam>();
|
||||
testParams.add(new ControlParam("A", "1"));
|
||||
initialElement.addDataMapping("text", "path/textbox.ftl", testParams);
|
||||
|
||||
// This element is the same as the above, but deletes the
|
||||
// control-param.
|
||||
DefaultControlsConfigElement modifiedElement = new DefaultControlsConfigElement();
|
||||
modifiedElement.addDataMapping("text", "path/textbox.ftl", null);
|
||||
|
||||
ConfigElement combinedElem = initialElement.combine(modifiedElement);
|
||||
assertEquals("Combined elem incorrect.", modifiedElement, combinedElem);
|
||||
}
|
||||
|
||||
public void testReadConstraintHandlersFromConfigXml()
|
||||
{
|
||||
// Test that the constraint-handlers' constraints are read from the
|
||||
// config file
|
||||
Map<String, String> expectedValidationHandlers = new HashMap<String, String>();
|
||||
expectedValidationHandlers.put("REGEX",
|
||||
"Alfresco.forms.validation.regexMatch");
|
||||
expectedValidationHandlers.put("NUMERIC",
|
||||
"Alfresco.forms.validation.numericMatch");
|
||||
|
||||
ConstraintHandlersConfigElement chConfigElement = (ConstraintHandlersConfigElement) globalConstraintHandlers;
|
||||
List<String> actualTypes = chConfigElement.getConstraintTypes();
|
||||
assertEquals("Incorrect type count.",
|
||||
expectedValidationHandlers.size(), actualTypes.size());
|
||||
|
||||
// Ugly hack to get around JUnit 3.8.1 not having
|
||||
// assertEquals(Collection, Collection)
|
||||
for (String nextType : expectedValidationHandlers.keySet())
|
||||
{
|
||||
assertTrue("actualTypes was missing " + nextType, actualTypes
|
||||
.contains(nextType));
|
||||
}
|
||||
for (String nextType : actualTypes)
|
||||
{
|
||||
assertTrue("expectedValidationHandlers missing " + nextType,
|
||||
expectedValidationHandlers.keySet().contains(nextType));
|
||||
}
|
||||
|
||||
// Test that the types map to the expected validation handler.
|
||||
for (String nextKey : expectedValidationHandlers.keySet())
|
||||
{
|
||||
String nextExpectedValue = expectedValidationHandlers.get(nextKey);
|
||||
String nextActualValue = chConfigElement
|
||||
.getValidationHandlerFor(nextKey);
|
||||
assertTrue("Incorrect handler for " + nextKey + ": "
|
||||
+ nextActualValue, nextExpectedValue
|
||||
.equals(nextActualValue));
|
||||
}
|
||||
|
||||
// Test that the constraint-handlers' messages are read from the config
|
||||
// file
|
||||
Map<String, String> expectedMessages = new HashMap<String, String>();
|
||||
expectedMessages.put("REGEX", null);
|
||||
expectedMessages.put("NUMERIC", "Test Message");
|
||||
|
||||
// Test that the types map to the expected message.
|
||||
for (String nextKey : expectedValidationHandlers.keySet())
|
||||
{
|
||||
String nextExpectedValue = expectedMessages.get(nextKey);
|
||||
String nextActualValue = chConfigElement.getMessageFor(nextKey);
|
||||
assertEquals("Incorrect message for " + nextKey + ".",
|
||||
nextExpectedValue, nextActualValue);
|
||||
}
|
||||
|
||||
// Test that the constraint-handlers' message-ids are read from the
|
||||
// config file
|
||||
Map<String, String> expectedMessageIDs = new HashMap<String, String>();
|
||||
expectedMessageIDs.put("REGEX", null);
|
||||
expectedMessageIDs.put("NUMERIC", "regex_error");
|
||||
|
||||
// Test that the types map to the expected message-id.
|
||||
for (String nextKey : expectedValidationHandlers.keySet())
|
||||
{
|
||||
String nextExpectedValue = expectedMessageIDs.get(nextKey);
|
||||
String nextActualValue = chConfigElement.getMessageIdFor(nextKey);
|
||||
assertEquals("Incorrect message-id for " + nextKey + ".",
|
||||
nextExpectedValue, nextActualValue);
|
||||
}
|
||||
}
|
||||
|
||||
public void testConstraintHandlerElementShouldHaveNoChildren()
|
||||
{
|
||||
try
|
||||
{
|
||||
ConstraintHandlersConfigElement chConfigElement = (ConstraintHandlersConfigElement) globalConstraintHandlers;
|
||||
chConfigElement.getChildren();
|
||||
fail("getChildren() did not throw an exception");
|
||||
} catch (ConfigException ce)
|
||||
{
|
||||
// expected
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testFormSubmissionUrlAndModelOverrideProps()
|
||||
{
|
||||
assertEquals("Submission URL was incorrect.", "submission/url",
|
||||
formConfigElement.getSubmissionURL());
|
||||
|
||||
List<StringPair> expectedModelOverrideProperties = new ArrayList<StringPair>();
|
||||
expectedModelOverrideProperties.add(new StringPair(
|
||||
"fields.title.mandatory", "true"));
|
||||
assertEquals("Expected property missing.",
|
||||
expectedModelOverrideProperties, formConfigElement
|
||||
.getModelOverrideProperties());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testGetFormTemplatesForModesAndRoles()
|
||||
{
|
||||
// Get the form templates. Testing the mode and role combinations.
|
||||
// For this config xml, there are no templates available to a user
|
||||
// without a role.
|
||||
assertNull("Incorrect template.", formConfigElement.getFormTemplate(
|
||||
Mode.CREATE, null));
|
||||
assertNull("Incorrect template.", formConfigElement.getFormTemplate(
|
||||
Mode.EDIT, null));
|
||||
assertNull("Incorrect template.", formConfigElement.getFormTemplate(
|
||||
Mode.VIEW, null));
|
||||
assertNull("Incorrect template.", formConfigElement.getFormTemplate(
|
||||
Mode.CREATE, Collections.EMPTY_LIST));
|
||||
assertNull("Incorrect template.", formConfigElement.getFormTemplate(
|
||||
Mode.EDIT, Collections.EMPTY_LIST));
|
||||
assertNull("Incorrect template.", formConfigElement.getFormTemplate(
|
||||
Mode.VIEW, Collections.EMPTY_LIST));
|
||||
|
||||
List<String> roles = new ArrayList<String>();
|
||||
roles.add("Consumer");
|
||||
roles.add("Manager");
|
||||
assertEquals("Incorrect template.", "/path/create/template",
|
||||
formConfigElement.getFormTemplate(Mode.CREATE, roles));
|
||||
assertEquals("Incorrect template.", "/path/edit/template/manager",
|
||||
formConfigElement.getFormTemplate(Mode.EDIT, roles));
|
||||
assertEquals("Incorrect template.", "/path/view/template",
|
||||
formConfigElement.getFormTemplate(Mode.VIEW, roles));
|
||||
}
|
||||
|
||||
public void testGetFormFieldVisibilitiesForModes()
|
||||
{
|
||||
assertTrue("Field should be visible.", formConfigElement
|
||||
.isFieldVisible("name", Mode.CREATE));
|
||||
assertTrue("Field should be visible.", formConfigElement
|
||||
.isFieldVisible("title", Mode.CREATE));
|
||||
assertTrue("Field should be visible.", formConfigElement
|
||||
.isFieldVisible("quota", Mode.CREATE));
|
||||
assertFalse("Field should be invisible.", formConfigElement
|
||||
.isFieldVisible("rubbish", Mode.CREATE));
|
||||
|
||||
assertTrue("Field should be visible.", formConfigElement
|
||||
.isFieldVisible("name", Mode.EDIT));
|
||||
assertFalse("Field should be invisible.", formConfigElement
|
||||
.isFieldVisible("title", Mode.EDIT));
|
||||
assertFalse("Field should be invisible.", formConfigElement
|
||||
.isFieldVisible("quota", Mode.EDIT));
|
||||
assertFalse("Field should be invisible.", formConfigElement
|
||||
.isFieldVisible("rubbish", Mode.EDIT));
|
||||
|
||||
assertTrue("Field should be visible.", formConfigElement
|
||||
.isFieldVisible("name", Mode.VIEW));
|
||||
assertTrue("Field should be visible.", formConfigElement
|
||||
.isFieldVisible("title", Mode.VIEW));
|
||||
assertTrue("Field should be visible.", formConfigElement
|
||||
.isFieldVisible("quota", Mode.VIEW));
|
||||
assertFalse("Field should be invisible.", formConfigElement
|
||||
.isFieldVisible("rubbish", Mode.VIEW));
|
||||
}
|
||||
|
||||
public void testGetSetsFromForm()
|
||||
{
|
||||
Set<String> expectedSetIds = new HashSet<String>();
|
||||
expectedSetIds.add("details");
|
||||
expectedSetIds.add("user");
|
||||
assertEquals("Set IDs were wrong.", expectedSetIds, formConfigElement.getSets().keySet());
|
||||
|
||||
Map<String, FormSet> sets = formConfigElement.getSets();
|
||||
assertEquals("Set parent was wrong.", "details", sets.get("user")
|
||||
.getParentId());
|
||||
assertEquals("Set parent was wrong.", null, sets.get("details")
|
||||
.getParentId());
|
||||
|
||||
assertEquals("Set parent was wrong.", "fieldset", sets.get("details")
|
||||
.getAppearance());
|
||||
assertEquals("Set parent was wrong.", "panel", sets.get("user")
|
||||
.getAppearance());
|
||||
}
|
||||
|
||||
public void testAccessAllFieldRelatedData()
|
||||
{
|
||||
// Field checks
|
||||
Map<String, FormField> fields = formConfigElement.getFields();
|
||||
assertEquals("Wrong number of Fields.", 4, fields.size());
|
||||
|
||||
FormField usernameField = fields.get("username");
|
||||
assertNotNull("usernameField was null.", usernameField);
|
||||
assertTrue("Missing attribute.", usernameField.getAttributes()
|
||||
.containsKey("set"));
|
||||
assertEquals("Incorrect attribute.", "user", usernameField
|
||||
.getAttributes().get("set"));
|
||||
assertNull("username field's template should be null.", usernameField
|
||||
.getTemplate());
|
||||
|
||||
FormField nameField = fields.get("name");
|
||||
String nameTemplate = nameField.getTemplate();
|
||||
assertNotNull("name field had null template", nameTemplate);
|
||||
assertEquals("name field had incorrect template.",
|
||||
"alfresco/extension/formcontrols/my-name.ftl", nameTemplate);
|
||||
|
||||
List<StringPair> controlParams = nameField.getControlParams();
|
||||
assertNotNull("name field should have control params.", controlParams);
|
||||
assertEquals("name field has incorrect number of control params.", 1,
|
||||
controlParams.size());
|
||||
|
||||
assertEquals("Control param has wrong name.", "foo", controlParams.get(
|
||||
0).getName());
|
||||
assertEquals("Control param has wrong value.", "bar", controlParams
|
||||
.get(0).getValue());
|
||||
|
||||
assertEquals("name field had incorrect type.", "REGEX", nameField
|
||||
.getConstraintType());
|
||||
assertEquals("name field had incorrect message.",
|
||||
"The name can not contain the character '{0}'", nameField
|
||||
.getConstraintMessage());
|
||||
assertEquals("name field had incorrect message-id.",
|
||||
"field_error_name", nameField.getConstraintMessageId());
|
||||
}
|
||||
|
||||
public void testFormConfigElementShouldHaveNoChildren()
|
||||
{
|
||||
try
|
||||
{
|
||||
formConfigElement.getChildren();
|
||||
fail("getChildren() did not throw an exception.");
|
||||
} catch (ConfigException expectedException)
|
||||
{
|
||||
// intentionally empty
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,62 +0,0 @@
|
||||
<alfresco-config>
|
||||
<config>
|
||||
<default-controls>
|
||||
<type name="d:text" template="org/alfresco/forms/controls/textfield.ftl">
|
||||
<control-param name="size">50</control-param>
|
||||
</type>
|
||||
<type name="d:boolean" template="org/alfresco/forms/controls/checkbox.ftl" />
|
||||
<type name="association" template="org/alfresco/forms/controls/association-picker.ftl" />
|
||||
<type name="abc" template="org/alfresco/abc.ftl">
|
||||
<control-param name="a">1</control-param>
|
||||
<control-param name="b">Hello</control-param>
|
||||
<control-param name="c">Never.</control-param>
|
||||
<control-param name="d"></control-param>
|
||||
</type>
|
||||
<type name="xyz" template="org/alfresco/xyz.ftl">
|
||||
</type>
|
||||
</default-controls>
|
||||
<constraint-handlers>
|
||||
<constraint type="REGEX" validation-handler="Alfresco.forms.validation.regexMatch" />
|
||||
<constraint type="NUMERIC" validation-handler="Alfresco.forms.validation.numericMatch"
|
||||
message="Overridden Message" message-id="regex_error" />
|
||||
<constraint type="RANGE" validation-handler="Alfresco.forms.validation.rangeMatch" />
|
||||
</constraint-handlers>
|
||||
</config>
|
||||
|
||||
<!-- The evaluator would normally be node-type, but that makes testing difficult -->
|
||||
<config evaluator="string-compare" condition="content">
|
||||
<!-- For this example, I'm going to include all optional attributes -->
|
||||
<form submission-url="overridden/submission/url">
|
||||
<view-form template="/path/view/template" requires-role="Consumer" />
|
||||
<edit-form template="/path/edit/template/manager" requires-role="Manager" />
|
||||
<edit-form template="/path/edit/template/contributor" requires-role="Contributor" />
|
||||
<create-form template="/path/create/template" requires-role="Manager" />
|
||||
<field-visibility>
|
||||
<!-- This comment is here to test the FormReader -->
|
||||
<show id="name" />
|
||||
<show id="title" for-mode="view, create" />
|
||||
<hide id="quota" for-mode="edit" />
|
||||
</field-visibility>
|
||||
<appearance>
|
||||
<set id="details" appearance="fieldset" />
|
||||
<set id="user" parent="details" appearance="panel" />
|
||||
|
||||
<field id="name" label="Name" label-id="field_label_name" disabled="true" set="details"
|
||||
help-text="This is the name of the node" help-text-id="field_help_name" >
|
||||
<control template="alfresco/extension/formcontrols/my-name.ftl">
|
||||
<control-param name="foo">bar</control-param>
|
||||
</control>
|
||||
<constraint-message type="REGEX" message="The name can not contain the character '{0}'"
|
||||
message-id="field_error_name" />
|
||||
</field>
|
||||
<field id="title" label="My Title" set="details" />
|
||||
<field id="username" set="user" />
|
||||
<field id="quota" set="user" requires-role="Coordinator" />
|
||||
</appearance>
|
||||
<model-override>
|
||||
<property name="fields.title.mandatory">false</property>
|
||||
</model-override>
|
||||
</form>
|
||||
</config>
|
||||
|
||||
</alfresco-config>
|
@@ -1,74 +0,0 @@
|
||||
<alfresco-config>
|
||||
<plug-ins>
|
||||
<element-readers>
|
||||
<element-reader element-name="property-sheet" class="org.alfresco.web.config.PropertySheetElementReader"/>
|
||||
<element-reader element-name="client" class="org.alfresco.web.config.ClientElementReader"/>
|
||||
<element-reader element-name="navigation" class="org.alfresco.web.config.NavigationElementReader" />
|
||||
<element-reader element-name="languages" class="org.alfresco.web.config.LanguagesElementReader" />
|
||||
<element-reader element-name="advanced-search" class="org.alfresco.web.config.AdvancedSearchElementReader" />
|
||||
<element-reader element-name="views" class="org.alfresco.web.config.ViewsElementReader" />
|
||||
<element-reader element-name="actions" class="org.alfresco.web.config.ActionsElementReader" />
|
||||
<element-reader element-name="default-controls" class="org.alfresco.web.config.DefaultControlsElementReader"/>
|
||||
<element-reader element-name="constraint-handlers" class="org.alfresco.web.config.ConstraintHandlersElementReader"/>
|
||||
<element-reader element-name="form" class="org.alfresco.web.config.FormElementReader"/>
|
||||
</element-readers>
|
||||
</plug-ins>
|
||||
|
||||
<config>
|
||||
<default-controls>
|
||||
<type name="d:text" template="org/alfresco/forms/controls/textfield.ftl">
|
||||
<control-param name="size">50</control-param>
|
||||
</type>
|
||||
<type name="d:boolean" template="org/alfresco/forms/controls/checkbox.ftl" />
|
||||
<type name="association" template="org/alfresco/forms/controls/association-picker.ftl" />
|
||||
<type name="abc" template="org/alfresco/abc.ftl">
|
||||
<control-param name="a">1</control-param>
|
||||
<control-param name="b">Hello</control-param>
|
||||
<control-param name="c">For ever and ever.</control-param>
|
||||
<control-param name="d"></control-param>
|
||||
</type>
|
||||
</default-controls>
|
||||
<constraint-handlers>
|
||||
<constraint type="REGEX" validation-handler="Alfresco.forms.validation.regexMatch" />
|
||||
<constraint type="NUMERIC" validation-handler="Alfresco.forms.validation.numericMatch"
|
||||
message="Test Message" message-id="regex_error" />
|
||||
</constraint-handlers>
|
||||
</config>
|
||||
|
||||
<!-- The evaluator would normally be node-type, but that makes testing difficult -->
|
||||
<config evaluator="string-compare" condition="content">
|
||||
<!-- For this example, I'm going to include all optional attributes -->
|
||||
<form submission-url="submission/url">
|
||||
<view-form template="/path/view/template" requires-role="Consumer" />
|
||||
<edit-form template="/path/edit/template/manager" requires-role="Manager" />
|
||||
<edit-form template="/path/edit/template/contributor" requires-role="Contributor" />
|
||||
<create-form template="/path/create/template" requires-role="Manager" />
|
||||
<field-visibility>
|
||||
<!-- This comment is here to test the FormReader -->
|
||||
<show id="name" />
|
||||
<show id="title" for-mode="view, create" />
|
||||
<hide id="quota" for-mode="edit" />
|
||||
</field-visibility>
|
||||
<appearance>
|
||||
<set id="details" appearance="fieldset" />
|
||||
<set id="user" parent="details" appearance="panel" />
|
||||
|
||||
<field id="name" label="Name" label-id="field_label_name" disabled="true" set="details"
|
||||
help-text="This is the name of the node" help-text-id="field_help_name" >
|
||||
<control template="alfresco/extension/formcontrols/my-name.ftl">
|
||||
<control-param name="foo">bar</control-param>
|
||||
</control>
|
||||
<constraint-message type="REGEX" message="The name can not contain the character '{0}'"
|
||||
message-id="field_error_name" />
|
||||
</field>
|
||||
<field id="title" label="My Title" set="details" />
|
||||
<field id="username" set="user" />
|
||||
<field id="quota" set="user" requires-role="Coordinator" />
|
||||
</appearance>
|
||||
<model-override>
|
||||
<property name="fields.title.mandatory">true</property>
|
||||
</model-override>
|
||||
</form>
|
||||
</config>
|
||||
|
||||
</alfresco-config>
|
Reference in New Issue
Block a user