mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged 5.1.N (5.1.2) to 5.2.N (5.2.1)
125605 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2) 125498 slanglois: MNT-16155 Update source headers - remove svn:eol-style property on Java and JSP source files git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@125783 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,319 +1,319 @@
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.element.ConfigElementAdapter;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.web.action.ActionEvaluator;
|
||||
import org.alfresco.web.bean.repository.Repository;
|
||||
|
||||
/**
|
||||
* Action config element.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class ActionsConfigElement extends ConfigElementAdapter
|
||||
{
|
||||
public static final String CONFIG_ELEMENT_ID = "actions";
|
||||
|
||||
private Map<String, ActionDefinition> actionDefs = new HashMap<String, ActionDefinition>(32, 1.0f);
|
||||
private Map<String, ActionGroup> actionGroups = new HashMap<String, ActionGroup>(16, 1.0f);
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public ActionsConfigElement()
|
||||
{
|
||||
super(CONFIG_ELEMENT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name String
|
||||
*/
|
||||
public ActionsConfigElement(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#getChildren()
|
||||
*/
|
||||
public List<ConfigElement> getChildren()
|
||||
{
|
||||
throw new ConfigException("Reading the Actions config via the generic interfaces is not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#combine(org.springframework.extensions.config.ConfigElement)
|
||||
*/
|
||||
public ConfigElement combine(ConfigElement configElement)
|
||||
{
|
||||
ActionsConfigElement newElement = (ActionsConfigElement)configElement;
|
||||
ActionsConfigElement combinedElement = new ActionsConfigElement();
|
||||
|
||||
// add the existing action definitions
|
||||
combinedElement.actionDefs.putAll(this.actionDefs);
|
||||
|
||||
// overwrite any existing action definitions i.e. don't combine
|
||||
combinedElement.actionDefs.putAll(newElement.actionDefs);
|
||||
|
||||
// add the existing action groups
|
||||
Map<String, ActionGroup> combinedActionGroups = new HashMap<String, ActionGroup>(this.actionGroups.size());
|
||||
try
|
||||
{
|
||||
for (ActionGroup group : this.actionGroups.values())
|
||||
{
|
||||
combinedActionGroups.put(group.getId(), (ActionGroup)group.clone());
|
||||
}
|
||||
}
|
||||
catch (CloneNotSupportedException e)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("clone() required on ActionGroup class.", e);
|
||||
}
|
||||
combinedElement.actionGroups = combinedActionGroups;
|
||||
|
||||
// any new action groups with the same name must be combined
|
||||
for (ActionGroup newGroup : newElement.actionGroups.values())
|
||||
{
|
||||
if (combinedElement.actionGroups.containsKey(newGroup.getId()))
|
||||
{
|
||||
// there is already a group with this id, combine it with the new one
|
||||
ActionGroup combinedGroup = combinedElement.actionGroups.get(newGroup.getId());
|
||||
if (newGroup.ShowLink != combinedGroup.ShowLink)
|
||||
{
|
||||
combinedGroup.ShowLink = newGroup.ShowLink;
|
||||
}
|
||||
if (newGroup.Style != null)
|
||||
{
|
||||
combinedGroup.Style = newGroup.Style;
|
||||
}
|
||||
if (newGroup.StyleClass != null)
|
||||
{
|
||||
combinedGroup.StyleClass = newGroup.StyleClass;
|
||||
}
|
||||
|
||||
// add all the actions from the new group to the combined one
|
||||
for (String actionRef : newGroup.getAllActions())
|
||||
{
|
||||
combinedGroup.addAction(actionRef);
|
||||
}
|
||||
|
||||
// add all the hidden actions from the new group to the combined one
|
||||
for (String actionRef : newGroup.getHiddenActions())
|
||||
{
|
||||
combinedGroup.hideAction(actionRef);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// it's a new group so just add it
|
||||
combinedElement.actionGroups.put(newGroup.getId(), newGroup);
|
||||
}
|
||||
}
|
||||
|
||||
return combinedElement;
|
||||
}
|
||||
|
||||
/*package*/ void addActionDefinition(ActionDefinition actionDef)
|
||||
{
|
||||
actionDefs.put(actionDef.getId(), actionDef);
|
||||
}
|
||||
|
||||
public ActionDefinition getActionDefinition(String id)
|
||||
{
|
||||
return actionDefs.get(id);
|
||||
}
|
||||
|
||||
/*package*/ void addActionGroup(ActionGroup group)
|
||||
{
|
||||
actionGroups.put(group.getId(), group);
|
||||
}
|
||||
|
||||
public ActionGroup getActionGroup(String id)
|
||||
{
|
||||
return actionGroups.get(id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Simple class representing the definition of a UI action.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public static class ActionDefinition
|
||||
{
|
||||
public ActionDefinition(String id)
|
||||
{
|
||||
if (id == null || id.length() == 0)
|
||||
{
|
||||
throw new IllegalArgumentException("ActionDefinition ID is mandatory.");
|
||||
}
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void addAllowPermission(String permission)
|
||||
{
|
||||
if (permissionAllow == null)
|
||||
{
|
||||
permissionAllow = new ArrayList<String>(2);
|
||||
}
|
||||
permissionAllow.add(permission);
|
||||
}
|
||||
|
||||
public void addDenyPermission(String permission)
|
||||
{
|
||||
if (permissionDeny == null)
|
||||
{
|
||||
permissionDeny = new ArrayList<String>(1);
|
||||
}
|
||||
permissionDeny.add(permission);
|
||||
}
|
||||
|
||||
public List<String> getAllowPermissions()
|
||||
{
|
||||
return permissionAllow;
|
||||
}
|
||||
|
||||
public List<String> getDenyPermissions()
|
||||
{
|
||||
return permissionDeny;
|
||||
}
|
||||
|
||||
public void addParam(String name, String value)
|
||||
{
|
||||
if (params == null)
|
||||
{
|
||||
params = new HashMap<String, String>(1, 1.0f);
|
||||
}
|
||||
params.put(name, value);
|
||||
}
|
||||
|
||||
public Map<String, String> getParams()
|
||||
{
|
||||
return params;
|
||||
}
|
||||
|
||||
String id;
|
||||
private List<String> permissionAllow = null;
|
||||
private List<String> permissionDeny = null;
|
||||
private Map<String, String> params = null;
|
||||
|
||||
public ActionEvaluator Evaluator = null;
|
||||
public String Label;
|
||||
public String LabelMsg;
|
||||
public String Tooltip;
|
||||
public String TooltipMsg;
|
||||
public boolean ShowLink = true;
|
||||
public String Style;
|
||||
public String StyleClass;
|
||||
public String Image;
|
||||
public String ActionListener;
|
||||
public String Action;
|
||||
public String Href;
|
||||
public String Target;
|
||||
public String Script;
|
||||
public String Onclick;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Simple class representing a group of UI actions.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public static class ActionGroup implements Iterable<String>, Cloneable
|
||||
{
|
||||
public ActionGroup(String id)
|
||||
{
|
||||
if (id == null || id.length() == 0)
|
||||
{
|
||||
throw new IllegalArgumentException("ActionGroup ID is mandatory.");
|
||||
}
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException
|
||||
{
|
||||
ActionGroup clone = new ActionGroup(id);
|
||||
clone.actions = (Set<String>)((LinkedHashSet)actions).clone();
|
||||
clone.hiddenActions = (Set<String>)((HashSet)hiddenActions).clone();
|
||||
clone.ShowLink = ShowLink;
|
||||
clone.Style = Style;
|
||||
clone.StyleClass = StyleClass;
|
||||
return clone;
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator over the visible ActionDefinition IDs referenced by this group
|
||||
*/
|
||||
public Iterator<String> iterator()
|
||||
{
|
||||
// create a list of the visible actions and return it's iterator
|
||||
ArrayList<String> visibleActions = new ArrayList<String>(this.actions.size());
|
||||
for (String actionId : this.actions)
|
||||
{
|
||||
if (this.hiddenActions.contains(actionId) == false)
|
||||
{
|
||||
visibleActions.add(actionId);
|
||||
}
|
||||
}
|
||||
|
||||
visibleActions.trimToSize();
|
||||
|
||||
return visibleActions.iterator();
|
||||
}
|
||||
|
||||
/*package*/ void addAction(String actionId)
|
||||
{
|
||||
actions.add(actionId);
|
||||
}
|
||||
|
||||
/*package*/ void hideAction(String actionId)
|
||||
{
|
||||
this.hiddenActions.add(actionId);
|
||||
}
|
||||
|
||||
/*package*/ Set<String> getAllActions()
|
||||
{
|
||||
return this.actions;
|
||||
}
|
||||
|
||||
/*package*/ Set<String> getHiddenActions()
|
||||
{
|
||||
return this.hiddenActions;
|
||||
}
|
||||
|
||||
private String id;
|
||||
|
||||
/** the action definitions, we use a Linked HashSet to ensure we do not have more
|
||||
than one action with the same Id and that the insertion order is preserved */
|
||||
private Set<String> actions = new LinkedHashSet<String>(16, 1.0f);
|
||||
|
||||
/** the actions that have been hidden */
|
||||
private Set<String> hiddenActions = new HashSet<String>(4, 1.0f);
|
||||
|
||||
public boolean ShowLink;
|
||||
public String Style;
|
||||
public String StyleClass;
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.element.ConfigElementAdapter;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.web.action.ActionEvaluator;
|
||||
import org.alfresco.web.bean.repository.Repository;
|
||||
|
||||
/**
|
||||
* Action config element.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class ActionsConfigElement extends ConfigElementAdapter
|
||||
{
|
||||
public static final String CONFIG_ELEMENT_ID = "actions";
|
||||
|
||||
private Map<String, ActionDefinition> actionDefs = new HashMap<String, ActionDefinition>(32, 1.0f);
|
||||
private Map<String, ActionGroup> actionGroups = new HashMap<String, ActionGroup>(16, 1.0f);
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public ActionsConfigElement()
|
||||
{
|
||||
super(CONFIG_ELEMENT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name String
|
||||
*/
|
||||
public ActionsConfigElement(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#getChildren()
|
||||
*/
|
||||
public List<ConfigElement> getChildren()
|
||||
{
|
||||
throw new ConfigException("Reading the Actions config via the generic interfaces is not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#combine(org.springframework.extensions.config.ConfigElement)
|
||||
*/
|
||||
public ConfigElement combine(ConfigElement configElement)
|
||||
{
|
||||
ActionsConfigElement newElement = (ActionsConfigElement)configElement;
|
||||
ActionsConfigElement combinedElement = new ActionsConfigElement();
|
||||
|
||||
// add the existing action definitions
|
||||
combinedElement.actionDefs.putAll(this.actionDefs);
|
||||
|
||||
// overwrite any existing action definitions i.e. don't combine
|
||||
combinedElement.actionDefs.putAll(newElement.actionDefs);
|
||||
|
||||
// add the existing action groups
|
||||
Map<String, ActionGroup> combinedActionGroups = new HashMap<String, ActionGroup>(this.actionGroups.size());
|
||||
try
|
||||
{
|
||||
for (ActionGroup group : this.actionGroups.values())
|
||||
{
|
||||
combinedActionGroups.put(group.getId(), (ActionGroup)group.clone());
|
||||
}
|
||||
}
|
||||
catch (CloneNotSupportedException e)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("clone() required on ActionGroup class.", e);
|
||||
}
|
||||
combinedElement.actionGroups = combinedActionGroups;
|
||||
|
||||
// any new action groups with the same name must be combined
|
||||
for (ActionGroup newGroup : newElement.actionGroups.values())
|
||||
{
|
||||
if (combinedElement.actionGroups.containsKey(newGroup.getId()))
|
||||
{
|
||||
// there is already a group with this id, combine it with the new one
|
||||
ActionGroup combinedGroup = combinedElement.actionGroups.get(newGroup.getId());
|
||||
if (newGroup.ShowLink != combinedGroup.ShowLink)
|
||||
{
|
||||
combinedGroup.ShowLink = newGroup.ShowLink;
|
||||
}
|
||||
if (newGroup.Style != null)
|
||||
{
|
||||
combinedGroup.Style = newGroup.Style;
|
||||
}
|
||||
if (newGroup.StyleClass != null)
|
||||
{
|
||||
combinedGroup.StyleClass = newGroup.StyleClass;
|
||||
}
|
||||
|
||||
// add all the actions from the new group to the combined one
|
||||
for (String actionRef : newGroup.getAllActions())
|
||||
{
|
||||
combinedGroup.addAction(actionRef);
|
||||
}
|
||||
|
||||
// add all the hidden actions from the new group to the combined one
|
||||
for (String actionRef : newGroup.getHiddenActions())
|
||||
{
|
||||
combinedGroup.hideAction(actionRef);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// it's a new group so just add it
|
||||
combinedElement.actionGroups.put(newGroup.getId(), newGroup);
|
||||
}
|
||||
}
|
||||
|
||||
return combinedElement;
|
||||
}
|
||||
|
||||
/*package*/ void addActionDefinition(ActionDefinition actionDef)
|
||||
{
|
||||
actionDefs.put(actionDef.getId(), actionDef);
|
||||
}
|
||||
|
||||
public ActionDefinition getActionDefinition(String id)
|
||||
{
|
||||
return actionDefs.get(id);
|
||||
}
|
||||
|
||||
/*package*/ void addActionGroup(ActionGroup group)
|
||||
{
|
||||
actionGroups.put(group.getId(), group);
|
||||
}
|
||||
|
||||
public ActionGroup getActionGroup(String id)
|
||||
{
|
||||
return actionGroups.get(id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Simple class representing the definition of a UI action.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public static class ActionDefinition
|
||||
{
|
||||
public ActionDefinition(String id)
|
||||
{
|
||||
if (id == null || id.length() == 0)
|
||||
{
|
||||
throw new IllegalArgumentException("ActionDefinition ID is mandatory.");
|
||||
}
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void addAllowPermission(String permission)
|
||||
{
|
||||
if (permissionAllow == null)
|
||||
{
|
||||
permissionAllow = new ArrayList<String>(2);
|
||||
}
|
||||
permissionAllow.add(permission);
|
||||
}
|
||||
|
||||
public void addDenyPermission(String permission)
|
||||
{
|
||||
if (permissionDeny == null)
|
||||
{
|
||||
permissionDeny = new ArrayList<String>(1);
|
||||
}
|
||||
permissionDeny.add(permission);
|
||||
}
|
||||
|
||||
public List<String> getAllowPermissions()
|
||||
{
|
||||
return permissionAllow;
|
||||
}
|
||||
|
||||
public List<String> getDenyPermissions()
|
||||
{
|
||||
return permissionDeny;
|
||||
}
|
||||
|
||||
public void addParam(String name, String value)
|
||||
{
|
||||
if (params == null)
|
||||
{
|
||||
params = new HashMap<String, String>(1, 1.0f);
|
||||
}
|
||||
params.put(name, value);
|
||||
}
|
||||
|
||||
public Map<String, String> getParams()
|
||||
{
|
||||
return params;
|
||||
}
|
||||
|
||||
String id;
|
||||
private List<String> permissionAllow = null;
|
||||
private List<String> permissionDeny = null;
|
||||
private Map<String, String> params = null;
|
||||
|
||||
public ActionEvaluator Evaluator = null;
|
||||
public String Label;
|
||||
public String LabelMsg;
|
||||
public String Tooltip;
|
||||
public String TooltipMsg;
|
||||
public boolean ShowLink = true;
|
||||
public String Style;
|
||||
public String StyleClass;
|
||||
public String Image;
|
||||
public String ActionListener;
|
||||
public String Action;
|
||||
public String Href;
|
||||
public String Target;
|
||||
public String Script;
|
||||
public String Onclick;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Simple class representing a group of UI actions.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public static class ActionGroup implements Iterable<String>, Cloneable
|
||||
{
|
||||
public ActionGroup(String id)
|
||||
{
|
||||
if (id == null || id.length() == 0)
|
||||
{
|
||||
throw new IllegalArgumentException("ActionGroup ID is mandatory.");
|
||||
}
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException
|
||||
{
|
||||
ActionGroup clone = new ActionGroup(id);
|
||||
clone.actions = (Set<String>)((LinkedHashSet)actions).clone();
|
||||
clone.hiddenActions = (Set<String>)((HashSet)hiddenActions).clone();
|
||||
clone.ShowLink = ShowLink;
|
||||
clone.Style = Style;
|
||||
clone.StyleClass = StyleClass;
|
||||
return clone;
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator over the visible ActionDefinition IDs referenced by this group
|
||||
*/
|
||||
public Iterator<String> iterator()
|
||||
{
|
||||
// create a list of the visible actions and return it's iterator
|
||||
ArrayList<String> visibleActions = new ArrayList<String>(this.actions.size());
|
||||
for (String actionId : this.actions)
|
||||
{
|
||||
if (this.hiddenActions.contains(actionId) == false)
|
||||
{
|
||||
visibleActions.add(actionId);
|
||||
}
|
||||
}
|
||||
|
||||
visibleActions.trimToSize();
|
||||
|
||||
return visibleActions.iterator();
|
||||
}
|
||||
|
||||
/*package*/ void addAction(String actionId)
|
||||
{
|
||||
actions.add(actionId);
|
||||
}
|
||||
|
||||
/*package*/ void hideAction(String actionId)
|
||||
{
|
||||
this.hiddenActions.add(actionId);
|
||||
}
|
||||
|
||||
/*package*/ Set<String> getAllActions()
|
||||
{
|
||||
return this.actions;
|
||||
}
|
||||
|
||||
/*package*/ Set<String> getHiddenActions()
|
||||
{
|
||||
return this.hiddenActions;
|
||||
}
|
||||
|
||||
private String id;
|
||||
|
||||
/** the action definitions, we use a Linked HashSet to ensure we do not have more
|
||||
than one action with the same Id and that the insertion order is preserved */
|
||||
private Set<String> actions = new LinkedHashSet<String>(16, 1.0f);
|
||||
|
||||
/** the actions that have been hidden */
|
||||
private Set<String> hiddenActions = new HashSet<String>(4, 1.0f);
|
||||
|
||||
public boolean ShowLink;
|
||||
public String Style;
|
||||
public String StyleClass;
|
||||
}
|
||||
}
|
||||
|
@@ -1,254 +1,254 @@
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.xml.elementreader.ConfigElementReader;
|
||||
import org.alfresco.web.action.ActionEvaluator;
|
||||
import org.alfresco.web.config.ActionsConfigElement.ActionDefinition;
|
||||
import org.alfresco.web.config.ActionsConfigElement.ActionGroup;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* Config Element Reader for the "Action" config blocks.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class ActionsElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ELEMENT_ACTION = "action";
|
||||
public static final String ELEMENT_ACTIONGROUP = "action-group";
|
||||
public static final String ELEMENT_PERMISSIONS = "permissions";
|
||||
public static final String ELEMENT_PERMISSION = "permission";
|
||||
public static final String ELEMENT_EVALUATOR = "evaluator";
|
||||
public static final String ELEMENT_LABEL = "label";
|
||||
public static final String ELEMENT_LABELMSG = "label-id";
|
||||
public static final String ELEMENT_TOOLTIP = "tooltip";
|
||||
public static final String ELEMENT_TOOLTIPMSG = "tooltip-id";
|
||||
public static final String ELEMENT_SHOWLINK = "show-link";
|
||||
public static final String ELEMENT_STYLE = "style";
|
||||
public static final String ELEMENT_STYLECLASS = "style-class";
|
||||
public static final String ELEMENT_IMAGE = "image";
|
||||
public static final String ELEMENT_ACTIONLISTENER = "action-listener";
|
||||
public static final String ELEMENT_ONCLICK = "onclick";
|
||||
public static final String ELEMENT_HREF = "href";
|
||||
public static final String ELEMENT_TARGET = "target";
|
||||
public static final String ELEMENT_SCRIPT = "script";
|
||||
public static final String ELEMENT_PARAMS = "params";
|
||||
public static final String ELEMENT_PARAM = "param";
|
||||
public static final String ATTRIBUTE_ID = "id";
|
||||
public static final String ATTRIBUTE_IDREF = "idref";
|
||||
public static final String ATTRIBUTE_NAME = "name";
|
||||
public static final String ATTRIBUTE_ALLOW = "allow";
|
||||
public static final String ATTRIBUTE_HIDE = "hide";
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
ActionsConfigElement configElement = new ActionsConfigElement();
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
if (ActionsConfigElement.CONFIG_ELEMENT_ID.equals(element.getName()) == false)
|
||||
{
|
||||
throw new ConfigException("ActionsElementReader can only parse config elements of type 'Actions'");
|
||||
}
|
||||
|
||||
Iterator<Element> actionItr = element.elementIterator(ELEMENT_ACTION);
|
||||
while (actionItr.hasNext())
|
||||
{
|
||||
// work on each 'action' element in turn
|
||||
Element actionElement = actionItr.next();
|
||||
|
||||
// parse the action definition for the element
|
||||
ActionDefinition actionDef = parseActionDefinition(actionElement);
|
||||
|
||||
// add our finished action def to the map of all actions
|
||||
configElement.addActionDefinition(actionDef);
|
||||
}
|
||||
|
||||
Iterator<Element> actionGroupItr = element.elementIterator(ELEMENT_ACTIONGROUP);
|
||||
while (actionGroupItr.hasNext())
|
||||
{
|
||||
// work on each 'action-group' element in turn
|
||||
Element groupElement = actionGroupItr.next();
|
||||
String groupId = groupElement.attributeValue(ATTRIBUTE_ID);
|
||||
if (groupId == null || groupId.length() == 0)
|
||||
{
|
||||
throw new ConfigException("'action-group' config element specified without mandatory 'id' attribute.");
|
||||
}
|
||||
|
||||
// build a structure to represent the action group
|
||||
ActionGroup actionGroup = new ActionGroup(groupId);
|
||||
|
||||
// loop round each action ref and add them to the list for this action group
|
||||
Iterator<Element> actionRefItr = groupElement.elementIterator(ELEMENT_ACTION);
|
||||
while (actionRefItr.hasNext())
|
||||
{
|
||||
Element actionRefElement = actionRefItr.next();
|
||||
|
||||
// look for an action referred to be Id - this is the common use-case
|
||||
String idRef = actionRefElement.attributeValue(ATTRIBUTE_IDREF);
|
||||
if (idRef == null || idRef.length() == 0)
|
||||
{
|
||||
// look for an action defined directly rather than referenced by Id
|
||||
String id = actionRefElement.attributeValue(ATTRIBUTE_ID);
|
||||
if (id != null && id.length() != 0)
|
||||
{
|
||||
ActionDefinition def = parseActionDefinition(actionRefElement);
|
||||
// override action definition ID based on the group name to avoid conflicts
|
||||
def.id = actionGroup.getId() + '_' + def.getId();
|
||||
configElement.addActionDefinition(def);
|
||||
actionGroup.addAction(def.getId());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// look for the hide attribute
|
||||
String hide = actionRefElement.attributeValue(ATTRIBUTE_HIDE);
|
||||
if (hide != null && Boolean.parseBoolean(hide))
|
||||
{
|
||||
actionGroup.hideAction(idRef);
|
||||
}
|
||||
else
|
||||
{
|
||||
// add the action definition ID to the group
|
||||
actionGroup.addAction(idRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get simple string properties for the action group
|
||||
actionGroup.Style = groupElement.elementTextTrim(ELEMENT_STYLE);
|
||||
actionGroup.StyleClass = groupElement.elementTextTrim(ELEMENT_STYLECLASS);
|
||||
if (groupElement.element(ELEMENT_SHOWLINK) != null)
|
||||
{
|
||||
actionGroup.ShowLink = Boolean.parseBoolean(groupElement.element(ELEMENT_SHOWLINK).getTextTrim());
|
||||
}
|
||||
|
||||
// add the action group to the map of all action groups
|
||||
configElement.addActionGroup(actionGroup);
|
||||
}
|
||||
}
|
||||
|
||||
return configElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an ActionDefinition from the specific config element.
|
||||
*
|
||||
* @param actionElement The config element containing the action def
|
||||
*
|
||||
* @return The populated ActionDefinition
|
||||
*/
|
||||
public ActionDefinition parseActionDefinition(Element actionElement)
|
||||
{
|
||||
String actionId = actionElement.attributeValue(ATTRIBUTE_ID);
|
||||
if (actionId == null || actionId.length() == 0)
|
||||
{
|
||||
throw new ConfigException("'action' config element specified without mandatory 'id' attribute.");
|
||||
}
|
||||
|
||||
// build a structure to represent the action definition
|
||||
ActionDefinition actionDef = new ActionDefinition(actionId);
|
||||
|
||||
// look for the permissions element - it can contain many permission
|
||||
Element permissionsElement = actionElement.element(ELEMENT_PERMISSIONS);
|
||||
if (permissionsElement != null)
|
||||
{
|
||||
// read and process each permission element
|
||||
Iterator<Element> permissionItr = permissionsElement.elementIterator(ELEMENT_PERMISSION);
|
||||
while (permissionItr.hasNext())
|
||||
{
|
||||
Element permissionElement = permissionItr.next();
|
||||
boolean allow = true;
|
||||
if (permissionElement.attributeValue(ATTRIBUTE_ALLOW) != null)
|
||||
{
|
||||
allow = Boolean.parseBoolean(permissionElement.attributeValue(ATTRIBUTE_ALLOW));
|
||||
}
|
||||
String permissionValue = permissionElement.getTextTrim();
|
||||
if (allow)
|
||||
{
|
||||
actionDef.addAllowPermission(permissionValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
actionDef.addDenyPermission(permissionValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// find and construct the specified evaluator class
|
||||
Element evaluatorElement = actionElement.element(ELEMENT_EVALUATOR);
|
||||
if (evaluatorElement != null)
|
||||
{
|
||||
Object evaluator;
|
||||
String className = evaluatorElement.getTextTrim();
|
||||
try
|
||||
{
|
||||
Class clazz = Class.forName(className);
|
||||
evaluator = clazz.newInstance();
|
||||
}
|
||||
catch (Throwable err)
|
||||
{
|
||||
throw new ConfigException("Unable to construct action '" +
|
||||
actionId + "' evaluator classname: " +className);
|
||||
}
|
||||
if (evaluator instanceof ActionEvaluator == false)
|
||||
{
|
||||
throw new ConfigException("Action '" + actionId + "' evaluator class '" +
|
||||
className + "' does not implement ActionEvaluator interface.");
|
||||
}
|
||||
actionDef.Evaluator = (ActionEvaluator)evaluator;
|
||||
}
|
||||
|
||||
// find any parameter values that the action requires
|
||||
Element paramsElement = actionElement.element(ELEMENT_PARAMS);
|
||||
if (paramsElement != null)
|
||||
{
|
||||
Iterator<Element> paramsItr = paramsElement.elementIterator(ELEMENT_PARAM);
|
||||
while (paramsItr.hasNext())
|
||||
{
|
||||
Element paramElement = paramsItr.next();
|
||||
String name = paramElement.attributeValue(ATTRIBUTE_NAME);
|
||||
if (name == null || name.length() == 0)
|
||||
{
|
||||
throw new ConfigException("Action '" + actionId +
|
||||
"' param does not have mandatory 'name' attribute.");
|
||||
}
|
||||
String value = paramElement.getTextTrim();
|
||||
if (value == null || value.length() == 0)
|
||||
{
|
||||
throw new ConfigException("Action '" + actionId + "' param '" + name + "'" +
|
||||
"' does not have a value.");
|
||||
}
|
||||
actionDef.addParam(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
// get simple string properties for the action
|
||||
actionDef.Label = actionElement.elementTextTrim(ELEMENT_LABEL);
|
||||
actionDef.LabelMsg = actionElement.elementTextTrim(ELEMENT_LABELMSG);
|
||||
actionDef.Tooltip = actionElement.elementTextTrim(ELEMENT_TOOLTIP);
|
||||
actionDef.TooltipMsg = actionElement.elementTextTrim(ELEMENT_TOOLTIPMSG);
|
||||
actionDef.Href = actionElement.elementTextTrim(ELEMENT_HREF);
|
||||
actionDef.Target = actionElement.elementTextTrim(ELEMENT_TARGET);
|
||||
actionDef.Script = actionElement.elementTextTrim(ELEMENT_SCRIPT);
|
||||
actionDef.Action = actionElement.elementTextTrim(ELEMENT_ACTION);
|
||||
actionDef.ActionListener = actionElement.elementTextTrim(ELEMENT_ACTIONLISTENER);
|
||||
actionDef.Onclick = actionElement.elementTextTrim(ELEMENT_ONCLICK);
|
||||
actionDef.Image = actionElement.elementTextTrim(ELEMENT_IMAGE);
|
||||
actionDef.Style = actionElement.elementTextTrim(ELEMENT_STYLE);
|
||||
actionDef.StyleClass = actionElement.elementTextTrim(ELEMENT_STYLECLASS);
|
||||
if (actionElement.element(ELEMENT_SHOWLINK) != null)
|
||||
{
|
||||
actionDef.ShowLink = Boolean.parseBoolean(actionElement.element(ELEMENT_SHOWLINK).getTextTrim());
|
||||
}
|
||||
|
||||
return actionDef;
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.xml.elementreader.ConfigElementReader;
|
||||
import org.alfresco.web.action.ActionEvaluator;
|
||||
import org.alfresco.web.config.ActionsConfigElement.ActionDefinition;
|
||||
import org.alfresco.web.config.ActionsConfigElement.ActionGroup;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* Config Element Reader for the "Action" config blocks.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class ActionsElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ELEMENT_ACTION = "action";
|
||||
public static final String ELEMENT_ACTIONGROUP = "action-group";
|
||||
public static final String ELEMENT_PERMISSIONS = "permissions";
|
||||
public static final String ELEMENT_PERMISSION = "permission";
|
||||
public static final String ELEMENT_EVALUATOR = "evaluator";
|
||||
public static final String ELEMENT_LABEL = "label";
|
||||
public static final String ELEMENT_LABELMSG = "label-id";
|
||||
public static final String ELEMENT_TOOLTIP = "tooltip";
|
||||
public static final String ELEMENT_TOOLTIPMSG = "tooltip-id";
|
||||
public static final String ELEMENT_SHOWLINK = "show-link";
|
||||
public static final String ELEMENT_STYLE = "style";
|
||||
public static final String ELEMENT_STYLECLASS = "style-class";
|
||||
public static final String ELEMENT_IMAGE = "image";
|
||||
public static final String ELEMENT_ACTIONLISTENER = "action-listener";
|
||||
public static final String ELEMENT_ONCLICK = "onclick";
|
||||
public static final String ELEMENT_HREF = "href";
|
||||
public static final String ELEMENT_TARGET = "target";
|
||||
public static final String ELEMENT_SCRIPT = "script";
|
||||
public static final String ELEMENT_PARAMS = "params";
|
||||
public static final String ELEMENT_PARAM = "param";
|
||||
public static final String ATTRIBUTE_ID = "id";
|
||||
public static final String ATTRIBUTE_IDREF = "idref";
|
||||
public static final String ATTRIBUTE_NAME = "name";
|
||||
public static final String ATTRIBUTE_ALLOW = "allow";
|
||||
public static final String ATTRIBUTE_HIDE = "hide";
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
ActionsConfigElement configElement = new ActionsConfigElement();
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
if (ActionsConfigElement.CONFIG_ELEMENT_ID.equals(element.getName()) == false)
|
||||
{
|
||||
throw new ConfigException("ActionsElementReader can only parse config elements of type 'Actions'");
|
||||
}
|
||||
|
||||
Iterator<Element> actionItr = element.elementIterator(ELEMENT_ACTION);
|
||||
while (actionItr.hasNext())
|
||||
{
|
||||
// work on each 'action' element in turn
|
||||
Element actionElement = actionItr.next();
|
||||
|
||||
// parse the action definition for the element
|
||||
ActionDefinition actionDef = parseActionDefinition(actionElement);
|
||||
|
||||
// add our finished action def to the map of all actions
|
||||
configElement.addActionDefinition(actionDef);
|
||||
}
|
||||
|
||||
Iterator<Element> actionGroupItr = element.elementIterator(ELEMENT_ACTIONGROUP);
|
||||
while (actionGroupItr.hasNext())
|
||||
{
|
||||
// work on each 'action-group' element in turn
|
||||
Element groupElement = actionGroupItr.next();
|
||||
String groupId = groupElement.attributeValue(ATTRIBUTE_ID);
|
||||
if (groupId == null || groupId.length() == 0)
|
||||
{
|
||||
throw new ConfigException("'action-group' config element specified without mandatory 'id' attribute.");
|
||||
}
|
||||
|
||||
// build a structure to represent the action group
|
||||
ActionGroup actionGroup = new ActionGroup(groupId);
|
||||
|
||||
// loop round each action ref and add them to the list for this action group
|
||||
Iterator<Element> actionRefItr = groupElement.elementIterator(ELEMENT_ACTION);
|
||||
while (actionRefItr.hasNext())
|
||||
{
|
||||
Element actionRefElement = actionRefItr.next();
|
||||
|
||||
// look for an action referred to be Id - this is the common use-case
|
||||
String idRef = actionRefElement.attributeValue(ATTRIBUTE_IDREF);
|
||||
if (idRef == null || idRef.length() == 0)
|
||||
{
|
||||
// look for an action defined directly rather than referenced by Id
|
||||
String id = actionRefElement.attributeValue(ATTRIBUTE_ID);
|
||||
if (id != null && id.length() != 0)
|
||||
{
|
||||
ActionDefinition def = parseActionDefinition(actionRefElement);
|
||||
// override action definition ID based on the group name to avoid conflicts
|
||||
def.id = actionGroup.getId() + '_' + def.getId();
|
||||
configElement.addActionDefinition(def);
|
||||
actionGroup.addAction(def.getId());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// look for the hide attribute
|
||||
String hide = actionRefElement.attributeValue(ATTRIBUTE_HIDE);
|
||||
if (hide != null && Boolean.parseBoolean(hide))
|
||||
{
|
||||
actionGroup.hideAction(idRef);
|
||||
}
|
||||
else
|
||||
{
|
||||
// add the action definition ID to the group
|
||||
actionGroup.addAction(idRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get simple string properties for the action group
|
||||
actionGroup.Style = groupElement.elementTextTrim(ELEMENT_STYLE);
|
||||
actionGroup.StyleClass = groupElement.elementTextTrim(ELEMENT_STYLECLASS);
|
||||
if (groupElement.element(ELEMENT_SHOWLINK) != null)
|
||||
{
|
||||
actionGroup.ShowLink = Boolean.parseBoolean(groupElement.element(ELEMENT_SHOWLINK).getTextTrim());
|
||||
}
|
||||
|
||||
// add the action group to the map of all action groups
|
||||
configElement.addActionGroup(actionGroup);
|
||||
}
|
||||
}
|
||||
|
||||
return configElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an ActionDefinition from the specific config element.
|
||||
*
|
||||
* @param actionElement The config element containing the action def
|
||||
*
|
||||
* @return The populated ActionDefinition
|
||||
*/
|
||||
public ActionDefinition parseActionDefinition(Element actionElement)
|
||||
{
|
||||
String actionId = actionElement.attributeValue(ATTRIBUTE_ID);
|
||||
if (actionId == null || actionId.length() == 0)
|
||||
{
|
||||
throw new ConfigException("'action' config element specified without mandatory 'id' attribute.");
|
||||
}
|
||||
|
||||
// build a structure to represent the action definition
|
||||
ActionDefinition actionDef = new ActionDefinition(actionId);
|
||||
|
||||
// look for the permissions element - it can contain many permission
|
||||
Element permissionsElement = actionElement.element(ELEMENT_PERMISSIONS);
|
||||
if (permissionsElement != null)
|
||||
{
|
||||
// read and process each permission element
|
||||
Iterator<Element> permissionItr = permissionsElement.elementIterator(ELEMENT_PERMISSION);
|
||||
while (permissionItr.hasNext())
|
||||
{
|
||||
Element permissionElement = permissionItr.next();
|
||||
boolean allow = true;
|
||||
if (permissionElement.attributeValue(ATTRIBUTE_ALLOW) != null)
|
||||
{
|
||||
allow = Boolean.parseBoolean(permissionElement.attributeValue(ATTRIBUTE_ALLOW));
|
||||
}
|
||||
String permissionValue = permissionElement.getTextTrim();
|
||||
if (allow)
|
||||
{
|
||||
actionDef.addAllowPermission(permissionValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
actionDef.addDenyPermission(permissionValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// find and construct the specified evaluator class
|
||||
Element evaluatorElement = actionElement.element(ELEMENT_EVALUATOR);
|
||||
if (evaluatorElement != null)
|
||||
{
|
||||
Object evaluator;
|
||||
String className = evaluatorElement.getTextTrim();
|
||||
try
|
||||
{
|
||||
Class clazz = Class.forName(className);
|
||||
evaluator = clazz.newInstance();
|
||||
}
|
||||
catch (Throwable err)
|
||||
{
|
||||
throw new ConfigException("Unable to construct action '" +
|
||||
actionId + "' evaluator classname: " +className);
|
||||
}
|
||||
if (evaluator instanceof ActionEvaluator == false)
|
||||
{
|
||||
throw new ConfigException("Action '" + actionId + "' evaluator class '" +
|
||||
className + "' does not implement ActionEvaluator interface.");
|
||||
}
|
||||
actionDef.Evaluator = (ActionEvaluator)evaluator;
|
||||
}
|
||||
|
||||
// find any parameter values that the action requires
|
||||
Element paramsElement = actionElement.element(ELEMENT_PARAMS);
|
||||
if (paramsElement != null)
|
||||
{
|
||||
Iterator<Element> paramsItr = paramsElement.elementIterator(ELEMENT_PARAM);
|
||||
while (paramsItr.hasNext())
|
||||
{
|
||||
Element paramElement = paramsItr.next();
|
||||
String name = paramElement.attributeValue(ATTRIBUTE_NAME);
|
||||
if (name == null || name.length() == 0)
|
||||
{
|
||||
throw new ConfigException("Action '" + actionId +
|
||||
"' param does not have mandatory 'name' attribute.");
|
||||
}
|
||||
String value = paramElement.getTextTrim();
|
||||
if (value == null || value.length() == 0)
|
||||
{
|
||||
throw new ConfigException("Action '" + actionId + "' param '" + name + "'" +
|
||||
"' does not have a value.");
|
||||
}
|
||||
actionDef.addParam(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
// get simple string properties for the action
|
||||
actionDef.Label = actionElement.elementTextTrim(ELEMENT_LABEL);
|
||||
actionDef.LabelMsg = actionElement.elementTextTrim(ELEMENT_LABELMSG);
|
||||
actionDef.Tooltip = actionElement.elementTextTrim(ELEMENT_TOOLTIP);
|
||||
actionDef.TooltipMsg = actionElement.elementTextTrim(ELEMENT_TOOLTIPMSG);
|
||||
actionDef.Href = actionElement.elementTextTrim(ELEMENT_HREF);
|
||||
actionDef.Target = actionElement.elementTextTrim(ELEMENT_TARGET);
|
||||
actionDef.Script = actionElement.elementTextTrim(ELEMENT_SCRIPT);
|
||||
actionDef.Action = actionElement.elementTextTrim(ELEMENT_ACTION);
|
||||
actionDef.ActionListener = actionElement.elementTextTrim(ELEMENT_ACTIONLISTENER);
|
||||
actionDef.Onclick = actionElement.elementTextTrim(ELEMENT_ONCLICK);
|
||||
actionDef.Image = actionElement.elementTextTrim(ELEMENT_IMAGE);
|
||||
actionDef.Style = actionElement.elementTextTrim(ELEMENT_STYLE);
|
||||
actionDef.StyleClass = actionElement.elementTextTrim(ELEMENT_STYLECLASS);
|
||||
if (actionElement.element(ELEMENT_SHOWLINK) != null)
|
||||
{
|
||||
actionDef.ShowLink = Boolean.parseBoolean(actionElement.element(ELEMENT_SHOWLINK).getTextTrim());
|
||||
}
|
||||
|
||||
return actionDef;
|
||||
}
|
||||
}
|
||||
|
@@ -1,230 +1,230 @@
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.element.ConfigElementAdapter;
|
||||
|
||||
/**
|
||||
* Custom config element that represents config values for advanced search
|
||||
*
|
||||
* @author Gavin Cornwell
|
||||
*/
|
||||
public class AdvancedSearchConfigElement extends ConfigElementAdapter implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -6427054671579839728L;
|
||||
|
||||
public static final String CONFIG_ELEMENT_ID = "advanced-search";
|
||||
|
||||
private List<String> contentTypes = null;
|
||||
private List<String> folderTypes = null;
|
||||
private List<CustomProperty> customProps = null;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
public AdvancedSearchConfigElement()
|
||||
{
|
||||
super(CONFIG_ELEMENT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param name Name of the element this config element represents
|
||||
*/
|
||||
public AdvancedSearchConfigElement(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#getChildren()
|
||||
*/
|
||||
@Override
|
||||
public List<ConfigElement> getChildren()
|
||||
{
|
||||
throw new ConfigException("Reading the advanced search config via the generic interfaces is not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#combine(org.springframework.extensions.config.ConfigElement)
|
||||
*/
|
||||
public ConfigElement combine(ConfigElement configElement)
|
||||
{
|
||||
AdvancedSearchConfigElement newElement = (AdvancedSearchConfigElement)configElement;
|
||||
AdvancedSearchConfigElement combinedElement = new AdvancedSearchConfigElement();
|
||||
|
||||
// just copy the list of types and properties from this instance to the new one
|
||||
if (this.contentTypes != null)
|
||||
{
|
||||
for (String type : this.contentTypes)
|
||||
{
|
||||
combinedElement.addContentType(type);
|
||||
}
|
||||
}
|
||||
if (this.folderTypes != null)
|
||||
{
|
||||
for (String type : this.folderTypes)
|
||||
{
|
||||
combinedElement.addFolderType(type);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.customProps != null)
|
||||
{
|
||||
for (CustomProperty property : this.customProps)
|
||||
{
|
||||
combinedElement.addCustomProperty(property);
|
||||
}
|
||||
}
|
||||
|
||||
// now add those types and custom properties from the element to be combined
|
||||
if (newElement.getContentTypes() != null)
|
||||
{
|
||||
for (String type : newElement.getContentTypes())
|
||||
{
|
||||
combinedElement.addContentType(type);
|
||||
}
|
||||
}
|
||||
|
||||
if (newElement.getFolderTypes() != null)
|
||||
{
|
||||
for (String type : newElement.getFolderTypes())
|
||||
{
|
||||
combinedElement.addFolderType(type);
|
||||
}
|
||||
}
|
||||
|
||||
if (newElement.getCustomProperties() != null)
|
||||
{
|
||||
for (CustomProperty property : newElement.getCustomProperties())
|
||||
{
|
||||
combinedElement.addCustomProperty(property);
|
||||
}
|
||||
}
|
||||
|
||||
return combinedElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the contentTypes.
|
||||
*/
|
||||
public List<String> getContentTypes()
|
||||
{
|
||||
return this.contentTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param contentTypes The contentTypes to set.
|
||||
*/
|
||||
/*package*/ void setContentTypes(List<String> contentTypes)
|
||||
{
|
||||
this.contentTypes = contentTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param contentType Adds the given content type to the list
|
||||
*/
|
||||
/*package*/ void addContentType(String contentType)
|
||||
{
|
||||
if (this.contentTypes == null)
|
||||
{
|
||||
this.contentTypes = new ArrayList<String>(3);
|
||||
}
|
||||
|
||||
if (this.contentTypes.contains(contentType) == false)
|
||||
{
|
||||
this.contentTypes.add(contentType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the folderTypes.
|
||||
*/
|
||||
public List<String> getFolderTypes()
|
||||
{
|
||||
return this.folderTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param folderTypes The folderTypes to set.
|
||||
*/
|
||||
/*package*/ void setFolderTypes(List<String> folderTypes)
|
||||
{
|
||||
this.folderTypes = folderTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param folderType Adds the given folder type to the list
|
||||
*/
|
||||
/*package*/ void addFolderType(String folderType)
|
||||
{
|
||||
if (this.folderTypes == null)
|
||||
{
|
||||
this.folderTypes = new ArrayList<String>(3);
|
||||
}
|
||||
|
||||
if (this.folderTypes.contains(folderType) == false)
|
||||
{
|
||||
this.folderTypes.add(folderType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the customProps.
|
||||
*/
|
||||
public List<CustomProperty> getCustomProperties()
|
||||
{
|
||||
return this.customProps;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param customProps The customProps to set.
|
||||
*/
|
||||
/*package*/ void setCustomProperties(List<CustomProperty> customProps)
|
||||
{
|
||||
this.customProps = customProps;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param property Adds the given custom property to the list
|
||||
*/
|
||||
/*package*/ void addCustomProperty(CustomProperty property)
|
||||
{
|
||||
if (this.customProps == null)
|
||||
{
|
||||
this.customProps = new ArrayList<CustomProperty>(3);
|
||||
}
|
||||
|
||||
// TODO: Determine if the CustomProperty being added is already
|
||||
// in the list
|
||||
|
||||
this.customProps.add(property);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple wrapper class for custom advanced search property
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public static class CustomProperty implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1457092137913897740L;
|
||||
|
||||
CustomProperty(String type, String aspect, String property, String labelId)
|
||||
{
|
||||
Type = type;
|
||||
Aspect = aspect;
|
||||
Property = property;
|
||||
LabelId = labelId;
|
||||
}
|
||||
|
||||
public String Type;
|
||||
public String Aspect;
|
||||
public String Property;
|
||||
public String LabelId;
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.element.ConfigElementAdapter;
|
||||
|
||||
/**
|
||||
* Custom config element that represents config values for advanced search
|
||||
*
|
||||
* @author Gavin Cornwell
|
||||
*/
|
||||
public class AdvancedSearchConfigElement extends ConfigElementAdapter implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -6427054671579839728L;
|
||||
|
||||
public static final String CONFIG_ELEMENT_ID = "advanced-search";
|
||||
|
||||
private List<String> contentTypes = null;
|
||||
private List<String> folderTypes = null;
|
||||
private List<CustomProperty> customProps = null;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
public AdvancedSearchConfigElement()
|
||||
{
|
||||
super(CONFIG_ELEMENT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param name Name of the element this config element represents
|
||||
*/
|
||||
public AdvancedSearchConfigElement(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#getChildren()
|
||||
*/
|
||||
@Override
|
||||
public List<ConfigElement> getChildren()
|
||||
{
|
||||
throw new ConfigException("Reading the advanced search config via the generic interfaces is not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#combine(org.springframework.extensions.config.ConfigElement)
|
||||
*/
|
||||
public ConfigElement combine(ConfigElement configElement)
|
||||
{
|
||||
AdvancedSearchConfigElement newElement = (AdvancedSearchConfigElement)configElement;
|
||||
AdvancedSearchConfigElement combinedElement = new AdvancedSearchConfigElement();
|
||||
|
||||
// just copy the list of types and properties from this instance to the new one
|
||||
if (this.contentTypes != null)
|
||||
{
|
||||
for (String type : this.contentTypes)
|
||||
{
|
||||
combinedElement.addContentType(type);
|
||||
}
|
||||
}
|
||||
if (this.folderTypes != null)
|
||||
{
|
||||
for (String type : this.folderTypes)
|
||||
{
|
||||
combinedElement.addFolderType(type);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.customProps != null)
|
||||
{
|
||||
for (CustomProperty property : this.customProps)
|
||||
{
|
||||
combinedElement.addCustomProperty(property);
|
||||
}
|
||||
}
|
||||
|
||||
// now add those types and custom properties from the element to be combined
|
||||
if (newElement.getContentTypes() != null)
|
||||
{
|
||||
for (String type : newElement.getContentTypes())
|
||||
{
|
||||
combinedElement.addContentType(type);
|
||||
}
|
||||
}
|
||||
|
||||
if (newElement.getFolderTypes() != null)
|
||||
{
|
||||
for (String type : newElement.getFolderTypes())
|
||||
{
|
||||
combinedElement.addFolderType(type);
|
||||
}
|
||||
}
|
||||
|
||||
if (newElement.getCustomProperties() != null)
|
||||
{
|
||||
for (CustomProperty property : newElement.getCustomProperties())
|
||||
{
|
||||
combinedElement.addCustomProperty(property);
|
||||
}
|
||||
}
|
||||
|
||||
return combinedElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the contentTypes.
|
||||
*/
|
||||
public List<String> getContentTypes()
|
||||
{
|
||||
return this.contentTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param contentTypes The contentTypes to set.
|
||||
*/
|
||||
/*package*/ void setContentTypes(List<String> contentTypes)
|
||||
{
|
||||
this.contentTypes = contentTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param contentType Adds the given content type to the list
|
||||
*/
|
||||
/*package*/ void addContentType(String contentType)
|
||||
{
|
||||
if (this.contentTypes == null)
|
||||
{
|
||||
this.contentTypes = new ArrayList<String>(3);
|
||||
}
|
||||
|
||||
if (this.contentTypes.contains(contentType) == false)
|
||||
{
|
||||
this.contentTypes.add(contentType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the folderTypes.
|
||||
*/
|
||||
public List<String> getFolderTypes()
|
||||
{
|
||||
return this.folderTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param folderTypes The folderTypes to set.
|
||||
*/
|
||||
/*package*/ void setFolderTypes(List<String> folderTypes)
|
||||
{
|
||||
this.folderTypes = folderTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param folderType Adds the given folder type to the list
|
||||
*/
|
||||
/*package*/ void addFolderType(String folderType)
|
||||
{
|
||||
if (this.folderTypes == null)
|
||||
{
|
||||
this.folderTypes = new ArrayList<String>(3);
|
||||
}
|
||||
|
||||
if (this.folderTypes.contains(folderType) == false)
|
||||
{
|
||||
this.folderTypes.add(folderType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the customProps.
|
||||
*/
|
||||
public List<CustomProperty> getCustomProperties()
|
||||
{
|
||||
return this.customProps;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param customProps The customProps to set.
|
||||
*/
|
||||
/*package*/ void setCustomProperties(List<CustomProperty> customProps)
|
||||
{
|
||||
this.customProps = customProps;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param property Adds the given custom property to the list
|
||||
*/
|
||||
/*package*/ void addCustomProperty(CustomProperty property)
|
||||
{
|
||||
if (this.customProps == null)
|
||||
{
|
||||
this.customProps = new ArrayList<CustomProperty>(3);
|
||||
}
|
||||
|
||||
// TODO: Determine if the CustomProperty being added is already
|
||||
// in the list
|
||||
|
||||
this.customProps.add(property);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple wrapper class for custom advanced search property
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public static class CustomProperty implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1457092137913897740L;
|
||||
|
||||
CustomProperty(String type, String aspect, String property, String labelId)
|
||||
{
|
||||
Type = type;
|
||||
Aspect = aspect;
|
||||
Property = property;
|
||||
LabelId = labelId;
|
||||
}
|
||||
|
||||
public String Type;
|
||||
public String Aspect;
|
||||
public String Property;
|
||||
public String LabelId;
|
||||
}
|
||||
}
|
||||
|
@@ -1,108 +1,108 @@
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.xml.elementreader.ConfigElementReader;
|
||||
import org.alfresco.web.config.AdvancedSearchConfigElement.CustomProperty;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* Custom element reader to parse config for advanced search
|
||||
*
|
||||
* @author Gavin Cornwell
|
||||
*/
|
||||
public class AdvancedSearchElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ELEMENT_CONTENTTYPES = "content-types";
|
||||
public static final String ELEMENT_FOLDERTYPES = "folder-types";
|
||||
public static final String ELEMENT_TYPE = "type";
|
||||
public static final String ELEMENT_CUSTOMPROPS = "custom-properties";
|
||||
public static final String ELEMENT_METADATA = "meta-data";
|
||||
public static final String ATTRIBUTE_NAME = "name";
|
||||
public static final String ATTRIBUTE_TYPE = "type";
|
||||
public static final String ATTRIBUTE_PROPERTY = "property";
|
||||
public static final String ATTRIBUTE_ASPECT = "aspect";
|
||||
public static final String ATTRIBUTE_DISPLAYLABEL = "display-label-id";
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
AdvancedSearchConfigElement configElement = null;
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
String name = element.getName();
|
||||
if (name.equals(AdvancedSearchConfigElement.CONFIG_ELEMENT_ID) == false)
|
||||
{
|
||||
throw new ConfigException("AdvancedSearchElementReader can only parse " +
|
||||
AdvancedSearchConfigElement.CONFIG_ELEMENT_ID + " elements, the element passed was '" +
|
||||
name + "'");
|
||||
}
|
||||
|
||||
configElement = new AdvancedSearchConfigElement();
|
||||
|
||||
// get the list of content types
|
||||
Element contentTypes = element.element(ELEMENT_CONTENTTYPES);
|
||||
if (contentTypes != null)
|
||||
{
|
||||
Iterator<Element> typesItr = contentTypes.elementIterator(ELEMENT_TYPE);
|
||||
List<String> types = new ArrayList<String>(5);
|
||||
while (typesItr.hasNext())
|
||||
{
|
||||
Element contentType = typesItr.next();
|
||||
String type = contentType.attributeValue(ATTRIBUTE_NAME);
|
||||
if (type != null)
|
||||
{
|
||||
types.add(type);
|
||||
}
|
||||
}
|
||||
configElement.setContentTypes(types);
|
||||
}
|
||||
|
||||
// get the list of folder types
|
||||
Element folderTypes = element.element(ELEMENT_FOLDERTYPES);
|
||||
if (folderTypes != null)
|
||||
{
|
||||
Iterator<Element> typesItr = folderTypes.elementIterator(ELEMENT_TYPE);
|
||||
List<String> types = new ArrayList<String>(5);
|
||||
while (typesItr.hasNext())
|
||||
{
|
||||
Element folderType = typesItr.next();
|
||||
String type = folderType.attributeValue(ATTRIBUTE_NAME);
|
||||
if (type != null)
|
||||
{
|
||||
types.add(type);
|
||||
}
|
||||
}
|
||||
configElement.setFolderTypes(types);
|
||||
}
|
||||
|
||||
// get the list of custom properties to display
|
||||
Element customProps = element.element(ELEMENT_CUSTOMPROPS);
|
||||
if (customProps != null)
|
||||
{
|
||||
Iterator<Element> propsItr = customProps.elementIterator(ELEMENT_METADATA);
|
||||
List<CustomProperty> props = new ArrayList<CustomProperty>(5);
|
||||
while (propsItr.hasNext())
|
||||
{
|
||||
Element propElement = propsItr.next();
|
||||
String type = propElement.attributeValue(ATTRIBUTE_TYPE);
|
||||
String aspect = propElement.attributeValue(ATTRIBUTE_ASPECT);
|
||||
String prop = propElement.attributeValue(ATTRIBUTE_PROPERTY);
|
||||
String labelId = propElement.attributeValue(ATTRIBUTE_DISPLAYLABEL);
|
||||
props.add(new AdvancedSearchConfigElement.CustomProperty(type, aspect, prop, labelId));
|
||||
}
|
||||
configElement.setCustomProperties(props);
|
||||
}
|
||||
}
|
||||
|
||||
return configElement;
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.xml.elementreader.ConfigElementReader;
|
||||
import org.alfresco.web.config.AdvancedSearchConfigElement.CustomProperty;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* Custom element reader to parse config for advanced search
|
||||
*
|
||||
* @author Gavin Cornwell
|
||||
*/
|
||||
public class AdvancedSearchElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ELEMENT_CONTENTTYPES = "content-types";
|
||||
public static final String ELEMENT_FOLDERTYPES = "folder-types";
|
||||
public static final String ELEMENT_TYPE = "type";
|
||||
public static final String ELEMENT_CUSTOMPROPS = "custom-properties";
|
||||
public static final String ELEMENT_METADATA = "meta-data";
|
||||
public static final String ATTRIBUTE_NAME = "name";
|
||||
public static final String ATTRIBUTE_TYPE = "type";
|
||||
public static final String ATTRIBUTE_PROPERTY = "property";
|
||||
public static final String ATTRIBUTE_ASPECT = "aspect";
|
||||
public static final String ATTRIBUTE_DISPLAYLABEL = "display-label-id";
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
AdvancedSearchConfigElement configElement = null;
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
String name = element.getName();
|
||||
if (name.equals(AdvancedSearchConfigElement.CONFIG_ELEMENT_ID) == false)
|
||||
{
|
||||
throw new ConfigException("AdvancedSearchElementReader can only parse " +
|
||||
AdvancedSearchConfigElement.CONFIG_ELEMENT_ID + " elements, the element passed was '" +
|
||||
name + "'");
|
||||
}
|
||||
|
||||
configElement = new AdvancedSearchConfigElement();
|
||||
|
||||
// get the list of content types
|
||||
Element contentTypes = element.element(ELEMENT_CONTENTTYPES);
|
||||
if (contentTypes != null)
|
||||
{
|
||||
Iterator<Element> typesItr = contentTypes.elementIterator(ELEMENT_TYPE);
|
||||
List<String> types = new ArrayList<String>(5);
|
||||
while (typesItr.hasNext())
|
||||
{
|
||||
Element contentType = typesItr.next();
|
||||
String type = contentType.attributeValue(ATTRIBUTE_NAME);
|
||||
if (type != null)
|
||||
{
|
||||
types.add(type);
|
||||
}
|
||||
}
|
||||
configElement.setContentTypes(types);
|
||||
}
|
||||
|
||||
// get the list of folder types
|
||||
Element folderTypes = element.element(ELEMENT_FOLDERTYPES);
|
||||
if (folderTypes != null)
|
||||
{
|
||||
Iterator<Element> typesItr = folderTypes.elementIterator(ELEMENT_TYPE);
|
||||
List<String> types = new ArrayList<String>(5);
|
||||
while (typesItr.hasNext())
|
||||
{
|
||||
Element folderType = typesItr.next();
|
||||
String type = folderType.attributeValue(ATTRIBUTE_NAME);
|
||||
if (type != null)
|
||||
{
|
||||
types.add(type);
|
||||
}
|
||||
}
|
||||
configElement.setFolderTypes(types);
|
||||
}
|
||||
|
||||
// get the list of custom properties to display
|
||||
Element customProps = element.element(ELEMENT_CUSTOMPROPS);
|
||||
if (customProps != null)
|
||||
{
|
||||
Iterator<Element> propsItr = customProps.elementIterator(ELEMENT_METADATA);
|
||||
List<CustomProperty> props = new ArrayList<CustomProperty>(5);
|
||||
while (propsItr.hasNext())
|
||||
{
|
||||
Element propElement = propsItr.next();
|
||||
String type = propElement.attributeValue(ATTRIBUTE_TYPE);
|
||||
String aspect = propElement.attributeValue(ATTRIBUTE_ASPECT);
|
||||
String prop = propElement.attributeValue(ATTRIBUTE_PROPERTY);
|
||||
String labelId = propElement.attributeValue(ATTRIBUTE_DISPLAYLABEL);
|
||||
props.add(new AdvancedSearchConfigElement.CustomProperty(type, aspect, prop, labelId));
|
||||
}
|
||||
configElement.setCustomProperties(props);
|
||||
}
|
||||
}
|
||||
|
||||
return configElement;
|
||||
}
|
||||
}
|
||||
|
@@ -1,89 +1,89 @@
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.element.ConfigElementAdapter;
|
||||
|
||||
/**
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class CommandServletConfigElement extends ConfigElementAdapter
|
||||
{
|
||||
public static final String CONFIG_ELEMENT_ID = "command-servlet";
|
||||
|
||||
private Map<String, Class> commandProcessors = new HashMap<String, Class>(4, 1.0f);
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public CommandServletConfigElement()
|
||||
{
|
||||
super("command-servlet");
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param name Name of the element this config element represents
|
||||
*/
|
||||
public CommandServletConfigElement(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#getChildren()
|
||||
*/
|
||||
public List<ConfigElement> getChildren()
|
||||
{
|
||||
throw new ConfigException("Reading the Command Servlet config via the generic interfaces is not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#combine(org.springframework.extensions.config.ConfigElement)
|
||||
*/
|
||||
public ConfigElement combine(ConfigElement configElement)
|
||||
{
|
||||
CommandServletConfigElement newElement = (CommandServletConfigElement)configElement;
|
||||
CommandServletConfigElement combinedElement = new CommandServletConfigElement();
|
||||
|
||||
for (String name : commandProcessors.keySet())
|
||||
{
|
||||
combinedElement.addCommandProcessor(name, commandProcessors.get(name));
|
||||
}
|
||||
for (String name : newElement.commandProcessors.keySet())
|
||||
{
|
||||
combinedElement.addCommandProcessor(name, newElement.commandProcessors.get(name));
|
||||
}
|
||||
|
||||
return combinedElement;
|
||||
}
|
||||
|
||||
/*package*/ void addCommandProcessor(String name, String className)
|
||||
{
|
||||
try
|
||||
{
|
||||
Class clazz = Class.forName(className);
|
||||
commandProcessors.put(name, clazz);
|
||||
}
|
||||
catch (Throwable err)
|
||||
{
|
||||
throw new ConfigException("Unable to load command proccessor class: " +
|
||||
className + " due to " + err.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void addCommandProcessor(String name, Class clazz)
|
||||
{
|
||||
commandProcessors.put(name, clazz);
|
||||
}
|
||||
|
||||
public Class getCommandProcessor(String name)
|
||||
{
|
||||
return commandProcessors.get(name);
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.element.ConfigElementAdapter;
|
||||
|
||||
/**
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class CommandServletConfigElement extends ConfigElementAdapter
|
||||
{
|
||||
public static final String CONFIG_ELEMENT_ID = "command-servlet";
|
||||
|
||||
private Map<String, Class> commandProcessors = new HashMap<String, Class>(4, 1.0f);
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public CommandServletConfigElement()
|
||||
{
|
||||
super("command-servlet");
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param name Name of the element this config element represents
|
||||
*/
|
||||
public CommandServletConfigElement(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#getChildren()
|
||||
*/
|
||||
public List<ConfigElement> getChildren()
|
||||
{
|
||||
throw new ConfigException("Reading the Command Servlet config via the generic interfaces is not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#combine(org.springframework.extensions.config.ConfigElement)
|
||||
*/
|
||||
public ConfigElement combine(ConfigElement configElement)
|
||||
{
|
||||
CommandServletConfigElement newElement = (CommandServletConfigElement)configElement;
|
||||
CommandServletConfigElement combinedElement = new CommandServletConfigElement();
|
||||
|
||||
for (String name : commandProcessors.keySet())
|
||||
{
|
||||
combinedElement.addCommandProcessor(name, commandProcessors.get(name));
|
||||
}
|
||||
for (String name : newElement.commandProcessors.keySet())
|
||||
{
|
||||
combinedElement.addCommandProcessor(name, newElement.commandProcessors.get(name));
|
||||
}
|
||||
|
||||
return combinedElement;
|
||||
}
|
||||
|
||||
/*package*/ void addCommandProcessor(String name, String className)
|
||||
{
|
||||
try
|
||||
{
|
||||
Class clazz = Class.forName(className);
|
||||
commandProcessors.put(name, clazz);
|
||||
}
|
||||
catch (Throwable err)
|
||||
{
|
||||
throw new ConfigException("Unable to load command proccessor class: " +
|
||||
className + " due to " + err.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void addCommandProcessor(String name, Class clazz)
|
||||
{
|
||||
commandProcessors.put(name, clazz);
|
||||
}
|
||||
|
||||
public Class getCommandProcessor(String name)
|
||||
{
|
||||
return commandProcessors.get(name);
|
||||
}
|
||||
}
|
||||
|
@@ -1,57 +1,57 @@
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.xml.elementreader.ConfigElementReader;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class CommandServletElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ELEMENT_COMMANDPROCESSOR = "command-processor";
|
||||
public static final String ATTRIBUTE_NAME = "name";
|
||||
public static final String ATTRIBUTE_CLASS = "class";
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
CommandServletConfigElement configElement = new CommandServletConfigElement();
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
if (CommandServletConfigElement.CONFIG_ELEMENT_ID.equals(element.getName()) == false)
|
||||
{
|
||||
throw new ConfigException("CommandServletElementReader can only parse config elements of type 'command-servlet'");
|
||||
}
|
||||
|
||||
Iterator<Element> itr = element.elementIterator(ELEMENT_COMMANDPROCESSOR);
|
||||
while (itr.hasNext())
|
||||
{
|
||||
Element procElement = itr.next();
|
||||
|
||||
String name = procElement.attributeValue(ATTRIBUTE_NAME);
|
||||
String className = procElement.attributeValue(ATTRIBUTE_CLASS);
|
||||
|
||||
if (name == null || name.length() == 0)
|
||||
{
|
||||
throw new ConfigException("'name' attribute is mandatory for command processor config element.");
|
||||
}
|
||||
if (className == null || className.length() == 0)
|
||||
{
|
||||
throw new ConfigException("'class' attribute is mandatory for command processor config element.");
|
||||
}
|
||||
|
||||
configElement.addCommandProcessor(name, className);
|
||||
}
|
||||
}
|
||||
|
||||
return configElement;
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.xml.elementreader.ConfigElementReader;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class CommandServletElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ELEMENT_COMMANDPROCESSOR = "command-processor";
|
||||
public static final String ATTRIBUTE_NAME = "name";
|
||||
public static final String ATTRIBUTE_CLASS = "class";
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
CommandServletConfigElement configElement = new CommandServletConfigElement();
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
if (CommandServletConfigElement.CONFIG_ELEMENT_ID.equals(element.getName()) == false)
|
||||
{
|
||||
throw new ConfigException("CommandServletElementReader can only parse config elements of type 'command-servlet'");
|
||||
}
|
||||
|
||||
Iterator<Element> itr = element.elementIterator(ELEMENT_COMMANDPROCESSOR);
|
||||
while (itr.hasNext())
|
||||
{
|
||||
Element procElement = itr.next();
|
||||
|
||||
String name = procElement.attributeValue(ATTRIBUTE_NAME);
|
||||
String className = procElement.attributeValue(ATTRIBUTE_CLASS);
|
||||
|
||||
if (name == null || name.length() == 0)
|
||||
{
|
||||
throw new ConfigException("'name' attribute is mandatory for command processor config element.");
|
||||
}
|
||||
if (className == null || className.length() == 0)
|
||||
{
|
||||
throw new ConfigException("'class' attribute is mandatory for command processor config element.");
|
||||
}
|
||||
|
||||
configElement.addCommandProcessor(name, className);
|
||||
}
|
||||
}
|
||||
|
||||
return configElement;
|
||||
}
|
||||
}
|
||||
|
@@ -1,186 +1,186 @@
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.element.ConfigElementAdapter;
|
||||
|
||||
/**
|
||||
* Dashboard config element.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class DashboardsConfigElement extends ConfigElementAdapter
|
||||
{
|
||||
public static final String CONFIG_ELEMENT_ID = "dashboards";
|
||||
|
||||
private Map<String, LayoutDefinition> layoutDefs = new LinkedHashMap<String, LayoutDefinition>(4, 1.0f);
|
||||
private Map<String, DashletDefinition> dashletDefs = new LinkedHashMap<String, DashletDefinition>(8, 1.0f);
|
||||
private List<String> defaultDashlets = null;
|
||||
private boolean allowGuestConfig = false;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public DashboardsConfigElement()
|
||||
{
|
||||
super(CONFIG_ELEMENT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name String
|
||||
*/
|
||||
public DashboardsConfigElement(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#getChildren()
|
||||
*/
|
||||
public List<ConfigElement> getChildren()
|
||||
{
|
||||
throw new ConfigException("Reading the Dashboards config via the generic interfaces is not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#combine(org.springframework.extensions.config.ConfigElement)
|
||||
*/
|
||||
public ConfigElement combine(ConfigElement configElement)
|
||||
{
|
||||
DashboardsConfigElement newElement = (DashboardsConfigElement)configElement;
|
||||
DashboardsConfigElement combinedElement = new DashboardsConfigElement();
|
||||
|
||||
// put all into combined from this and then from new to override any already present
|
||||
combinedElement.dashletDefs.putAll(this.dashletDefs);
|
||||
combinedElement.dashletDefs.putAll(newElement.dashletDefs);
|
||||
|
||||
combinedElement.layoutDefs.putAll(this.layoutDefs);
|
||||
combinedElement.layoutDefs.putAll(newElement.layoutDefs);
|
||||
|
||||
if (newElement.allowGuestConfig != combinedElement.allowGuestConfig)
|
||||
{
|
||||
combinedElement.allowGuestConfig = newElement.allowGuestConfig;
|
||||
}
|
||||
|
||||
// the default-dashlets list is completely replaced if config is overriden
|
||||
if (newElement.defaultDashlets != null)
|
||||
{
|
||||
combinedElement.defaultDashlets =
|
||||
(List<String>)((ArrayList<String>)newElement.defaultDashlets).clone();
|
||||
}
|
||||
else if (this.defaultDashlets != null)
|
||||
{
|
||||
combinedElement.defaultDashlets =
|
||||
(List<String>)((ArrayList<String>)this.defaultDashlets).clone();
|
||||
}
|
||||
|
||||
return combinedElement;
|
||||
}
|
||||
|
||||
/*package*/ void setAllowGuestConfig(boolean allow)
|
||||
{
|
||||
this.allowGuestConfig = allow;
|
||||
}
|
||||
|
||||
public boolean getAllowGuestConfig()
|
||||
{
|
||||
return this.allowGuestConfig;
|
||||
}
|
||||
|
||||
/*package*/ void addLayoutDefinition(LayoutDefinition def)
|
||||
{
|
||||
this.layoutDefs.put(def.Id, def);
|
||||
}
|
||||
|
||||
public LayoutDefinition getLayoutDefinition(String id)
|
||||
{
|
||||
return this.layoutDefs.get(id);
|
||||
}
|
||||
|
||||
/*package*/ void addDashletDefinition(DashletDefinition def)
|
||||
{
|
||||
this.dashletDefs.put(def.Id, def);
|
||||
}
|
||||
|
||||
public DashletDefinition getDashletDefinition(String id)
|
||||
{
|
||||
return this.dashletDefs.get(id);
|
||||
}
|
||||
|
||||
public Collection<LayoutDefinition> getLayouts()
|
||||
{
|
||||
return this.layoutDefs.values();
|
||||
}
|
||||
|
||||
public Collection<DashletDefinition> getDashlets()
|
||||
{
|
||||
return this.dashletDefs.values();
|
||||
}
|
||||
|
||||
/*package*/ void addDefaultDashlet(String id)
|
||||
{
|
||||
if (this.defaultDashlets == null)
|
||||
{
|
||||
this.defaultDashlets = new ArrayList<String>(2);
|
||||
}
|
||||
this.defaultDashlets.add(id);
|
||||
}
|
||||
|
||||
public Collection<String> getDefaultDashlets()
|
||||
{
|
||||
return this.defaultDashlets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Structure class for the definition of a dashboard page layout
|
||||
*/
|
||||
public static class LayoutDefinition implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -3014156293576142077L;
|
||||
|
||||
LayoutDefinition(String id)
|
||||
{
|
||||
this.Id = id;
|
||||
}
|
||||
|
||||
public String Id;
|
||||
public String Image;
|
||||
public int Columns;
|
||||
public int ColumnLength;
|
||||
public String Label;
|
||||
public String LabelId;
|
||||
public String Description;
|
||||
public String DescriptionId;
|
||||
public String JSPPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Structure class for the definition of a dashboard dashlet component
|
||||
*/
|
||||
public static class DashletDefinition implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -5755903997700459631L;
|
||||
|
||||
DashletDefinition(String id)
|
||||
{
|
||||
this.Id = id;
|
||||
}
|
||||
|
||||
public String Id;
|
||||
public boolean AllowNarrow = true;
|
||||
public String Label;
|
||||
public String LabelId;
|
||||
public String Description;
|
||||
public String DescriptionId;
|
||||
public String JSPPage;
|
||||
public String ConfigJSPPage;
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.element.ConfigElementAdapter;
|
||||
|
||||
/**
|
||||
* Dashboard config element.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class DashboardsConfigElement extends ConfigElementAdapter
|
||||
{
|
||||
public static final String CONFIG_ELEMENT_ID = "dashboards";
|
||||
|
||||
private Map<String, LayoutDefinition> layoutDefs = new LinkedHashMap<String, LayoutDefinition>(4, 1.0f);
|
||||
private Map<String, DashletDefinition> dashletDefs = new LinkedHashMap<String, DashletDefinition>(8, 1.0f);
|
||||
private List<String> defaultDashlets = null;
|
||||
private boolean allowGuestConfig = false;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public DashboardsConfigElement()
|
||||
{
|
||||
super(CONFIG_ELEMENT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name String
|
||||
*/
|
||||
public DashboardsConfigElement(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#getChildren()
|
||||
*/
|
||||
public List<ConfigElement> getChildren()
|
||||
{
|
||||
throw new ConfigException("Reading the Dashboards config via the generic interfaces is not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#combine(org.springframework.extensions.config.ConfigElement)
|
||||
*/
|
||||
public ConfigElement combine(ConfigElement configElement)
|
||||
{
|
||||
DashboardsConfigElement newElement = (DashboardsConfigElement)configElement;
|
||||
DashboardsConfigElement combinedElement = new DashboardsConfigElement();
|
||||
|
||||
// put all into combined from this and then from new to override any already present
|
||||
combinedElement.dashletDefs.putAll(this.dashletDefs);
|
||||
combinedElement.dashletDefs.putAll(newElement.dashletDefs);
|
||||
|
||||
combinedElement.layoutDefs.putAll(this.layoutDefs);
|
||||
combinedElement.layoutDefs.putAll(newElement.layoutDefs);
|
||||
|
||||
if (newElement.allowGuestConfig != combinedElement.allowGuestConfig)
|
||||
{
|
||||
combinedElement.allowGuestConfig = newElement.allowGuestConfig;
|
||||
}
|
||||
|
||||
// the default-dashlets list is completely replaced if config is overriden
|
||||
if (newElement.defaultDashlets != null)
|
||||
{
|
||||
combinedElement.defaultDashlets =
|
||||
(List<String>)((ArrayList<String>)newElement.defaultDashlets).clone();
|
||||
}
|
||||
else if (this.defaultDashlets != null)
|
||||
{
|
||||
combinedElement.defaultDashlets =
|
||||
(List<String>)((ArrayList<String>)this.defaultDashlets).clone();
|
||||
}
|
||||
|
||||
return combinedElement;
|
||||
}
|
||||
|
||||
/*package*/ void setAllowGuestConfig(boolean allow)
|
||||
{
|
||||
this.allowGuestConfig = allow;
|
||||
}
|
||||
|
||||
public boolean getAllowGuestConfig()
|
||||
{
|
||||
return this.allowGuestConfig;
|
||||
}
|
||||
|
||||
/*package*/ void addLayoutDefinition(LayoutDefinition def)
|
||||
{
|
||||
this.layoutDefs.put(def.Id, def);
|
||||
}
|
||||
|
||||
public LayoutDefinition getLayoutDefinition(String id)
|
||||
{
|
||||
return this.layoutDefs.get(id);
|
||||
}
|
||||
|
||||
/*package*/ void addDashletDefinition(DashletDefinition def)
|
||||
{
|
||||
this.dashletDefs.put(def.Id, def);
|
||||
}
|
||||
|
||||
public DashletDefinition getDashletDefinition(String id)
|
||||
{
|
||||
return this.dashletDefs.get(id);
|
||||
}
|
||||
|
||||
public Collection<LayoutDefinition> getLayouts()
|
||||
{
|
||||
return this.layoutDefs.values();
|
||||
}
|
||||
|
||||
public Collection<DashletDefinition> getDashlets()
|
||||
{
|
||||
return this.dashletDefs.values();
|
||||
}
|
||||
|
||||
/*package*/ void addDefaultDashlet(String id)
|
||||
{
|
||||
if (this.defaultDashlets == null)
|
||||
{
|
||||
this.defaultDashlets = new ArrayList<String>(2);
|
||||
}
|
||||
this.defaultDashlets.add(id);
|
||||
}
|
||||
|
||||
public Collection<String> getDefaultDashlets()
|
||||
{
|
||||
return this.defaultDashlets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Structure class for the definition of a dashboard page layout
|
||||
*/
|
||||
public static class LayoutDefinition implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -3014156293576142077L;
|
||||
|
||||
LayoutDefinition(String id)
|
||||
{
|
||||
this.Id = id;
|
||||
}
|
||||
|
||||
public String Id;
|
||||
public String Image;
|
||||
public int Columns;
|
||||
public int ColumnLength;
|
||||
public String Label;
|
||||
public String LabelId;
|
||||
public String Description;
|
||||
public String DescriptionId;
|
||||
public String JSPPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Structure class for the definition of a dashboard dashlet component
|
||||
*/
|
||||
public static class DashletDefinition implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -5755903997700459631L;
|
||||
|
||||
DashletDefinition(String id)
|
||||
{
|
||||
this.Id = id;
|
||||
}
|
||||
|
||||
public String Id;
|
||||
public boolean AllowNarrow = true;
|
||||
public String Label;
|
||||
public String LabelId;
|
||||
public String Description;
|
||||
public String DescriptionId;
|
||||
public String JSPPage;
|
||||
public String ConfigJSPPage;
|
||||
}
|
||||
}
|
||||
|
@@ -1,211 +1,211 @@
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.xml.elementreader.ConfigElementReader;
|
||||
import org.alfresco.web.config.DashboardsConfigElement.DashletDefinition;
|
||||
import org.alfresco.web.config.DashboardsConfigElement.LayoutDefinition;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* Reader for the 'dashboards' config element and child elements.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class DashboardsElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ELEMENT_DASHBOARDS = "dashboards";
|
||||
public static final String ELEMENT_LAYOUTS = "layouts";
|
||||
public static final String ELEMENT_LAYOUT = "layout";
|
||||
public static final String ELEMENT_DASHLETS = "dashlets";
|
||||
public static final String ELEMENT_DASHLET = "dashlet";
|
||||
public static final String ELEMENT_GUESTCONFIG = "allow-guest-config";
|
||||
public static final String ELEMENT_DEFAULTDASHLETS = "default-dashlets";
|
||||
public static final String ATTR_ID = "id";
|
||||
public static final String ATTR_COLUMNS = "columns";
|
||||
public static final String ATTR_COLUMNLENGTH = "column-length";
|
||||
public static final String ATTR_IMAGE = "image";
|
||||
public static final String ATTR_LABEL = "label";
|
||||
public static final String ATTR_DESCRIPTION = "description";
|
||||
public static final String ATTR_LABELID = "label-id";
|
||||
public static final String ATTR_DESCRIPTIONID = "description-id";
|
||||
public static final String ATTR_JSP = "jsp";
|
||||
public static final String ATTR_CONFIGJSP = "config-jsp";
|
||||
public static final String ATTR_ALLOWNARROW = "allow-narrow";
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
DashboardsConfigElement configElement = new DashboardsConfigElement();
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
if (DashboardsConfigElement.CONFIG_ELEMENT_ID.equals(element.getName()) == false)
|
||||
{
|
||||
throw new ConfigException("DashboardsElementReader can only process elements of type 'dashboards'");
|
||||
}
|
||||
|
||||
Element layoutsElement = element.element(ELEMENT_LAYOUTS);
|
||||
if (layoutsElement != null)
|
||||
{
|
||||
Iterator<Element> layoutsItr = layoutsElement.elementIterator(ELEMENT_LAYOUT);
|
||||
while (layoutsItr.hasNext())
|
||||
{
|
||||
LayoutDefinition layoutDef = parseLayoutDefinition(layoutsItr.next());
|
||||
configElement.addLayoutDefinition(layoutDef);
|
||||
}
|
||||
}
|
||||
|
||||
Element dashletsElement = element.element(ELEMENT_DASHLETS);
|
||||
if (dashletsElement != null)
|
||||
{
|
||||
Iterator<Element> dashletsItr = dashletsElement.elementIterator(ELEMENT_DASHLET);
|
||||
while (dashletsItr.hasNext())
|
||||
{
|
||||
DashletDefinition dashletDef = parseDashletDefinition(dashletsItr.next());
|
||||
configElement.addDashletDefinition(dashletDef);
|
||||
}
|
||||
}
|
||||
|
||||
Element defaultDashletsElement = element.element(ELEMENT_DEFAULTDASHLETS);
|
||||
if (defaultDashletsElement != null)
|
||||
{
|
||||
Iterator<Element> dashletsItr = defaultDashletsElement.elementIterator(ELEMENT_DASHLET);
|
||||
while (dashletsItr.hasNext())
|
||||
{
|
||||
String id = getMandatoryDashletAttributeValue(dashletsItr.next(), ATTR_ID);
|
||||
configElement.addDefaultDashlet(id);
|
||||
}
|
||||
}
|
||||
|
||||
Element guestConfigElement = element.element(ELEMENT_GUESTCONFIG);
|
||||
if (guestConfigElement != null)
|
||||
{
|
||||
boolean allow = Boolean.parseBoolean(guestConfigElement.getTextTrim());
|
||||
configElement.setAllowGuestConfig(allow);
|
||||
}
|
||||
}
|
||||
|
||||
return configElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a single Layout definition from config.
|
||||
*
|
||||
* @param config Element
|
||||
*
|
||||
* @return LayoutDefinition for the specified config element.
|
||||
*/
|
||||
private static LayoutDefinition parseLayoutDefinition(Element config)
|
||||
{
|
||||
String id = getMandatoryLayoutAttributeValue(config, ATTR_ID);
|
||||
|
||||
LayoutDefinition def = new LayoutDefinition(id);
|
||||
|
||||
String columns = getMandatoryLayoutAttributeValue(config, ATTR_COLUMNS);
|
||||
def.Columns = Integer.parseInt(columns);
|
||||
String columnLength = getMandatoryLayoutAttributeValue(config, ATTR_COLUMNLENGTH);
|
||||
def.ColumnLength = Integer.parseInt(columnLength);
|
||||
def.Image = getMandatoryLayoutAttributeValue(config, ATTR_IMAGE);
|
||||
def.JSPPage = getMandatoryLayoutAttributeValue(config, ATTR_JSP);
|
||||
String label = config.attributeValue(ATTR_LABEL);
|
||||
String labelId = config.attributeValue(ATTR_LABELID);
|
||||
if ((label == null || label.length() == 0) && (labelId == null || labelId.length() == 0))
|
||||
{
|
||||
throw new ConfigException("Either 'label' or 'label-id' attribute must be specified for Dashboard 'layout' configuration element.");
|
||||
}
|
||||
def.Label = label;
|
||||
def.LabelId = labelId;
|
||||
String description = config.attributeValue(ATTR_DESCRIPTION);
|
||||
String descriptionId = config.attributeValue(ATTR_DESCRIPTIONID);
|
||||
if ((description == null || description.length() == 0) && (descriptionId == null || descriptionId.length() == 0))
|
||||
{
|
||||
throw new ConfigException("Either 'description' or 'description-id' attribute must be specified for Dashboard 'layout' configuration element.");
|
||||
}
|
||||
def.Description = description;
|
||||
def.DescriptionId = descriptionId;
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a mandatory layout attribute layout. Throw an exception if the value is not found.
|
||||
*
|
||||
* @param config Element
|
||||
* @param attr String
|
||||
*
|
||||
* @return String value
|
||||
*/
|
||||
private static String getMandatoryLayoutAttributeValue(Element config, String attr)
|
||||
{
|
||||
String value = config.attributeValue(attr);
|
||||
if (value == null || value.length() == 0)
|
||||
{
|
||||
throw new ConfigException("Missing mandatory '" + attr + "' attribute for Dashboard 'layout' configuration element.");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a single Dashlet definition from config.
|
||||
*
|
||||
* @param config Element
|
||||
*
|
||||
* @return DashletDefinition for the specified config element.
|
||||
*/
|
||||
private static DashletDefinition parseDashletDefinition(Element config)
|
||||
{
|
||||
String id = getMandatoryDashletAttributeValue(config, ATTR_ID);
|
||||
|
||||
DashletDefinition def = new DashletDefinition(id);
|
||||
|
||||
String allowNarrow = config.attributeValue(ATTR_ALLOWNARROW);
|
||||
if (allowNarrow != null && allowNarrow.length() != 0)
|
||||
{
|
||||
def.AllowNarrow = Boolean.parseBoolean(allowNarrow);
|
||||
}
|
||||
def.JSPPage = getMandatoryDashletAttributeValue(config, ATTR_JSP);
|
||||
def.ConfigJSPPage = config.attributeValue(ATTR_CONFIGJSP);
|
||||
String label = config.attributeValue(ATTR_LABEL);
|
||||
String labelId = config.attributeValue(ATTR_LABELID);
|
||||
if ((label == null || label.length() == 0) && (labelId == null || labelId.length() == 0))
|
||||
{
|
||||
throw new ConfigException("Either 'label' or 'label-id' attribute must be specified for Dashboard 'dashlet' configuration element.");
|
||||
}
|
||||
def.Label = label;
|
||||
def.LabelId = labelId;
|
||||
String description = config.attributeValue(ATTR_DESCRIPTION);
|
||||
String descriptionId = config.attributeValue(ATTR_DESCRIPTIONID);
|
||||
if ((description == null || description.length() == 0) && (descriptionId == null || descriptionId.length() == 0))
|
||||
{
|
||||
throw new ConfigException("Either 'description' or 'description-id' attribute must be specified for Dashboard 'dashlet' configuration element.");
|
||||
}
|
||||
def.Description = description;
|
||||
def.DescriptionId = descriptionId;
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a mandatory dashlet attribute layout. Throw an exception if the value is not found.
|
||||
*
|
||||
* @param config Element
|
||||
* @param attr String
|
||||
*
|
||||
* @return String value
|
||||
*/
|
||||
private static String getMandatoryDashletAttributeValue(Element config, String attr)
|
||||
{
|
||||
String value = config.attributeValue(attr);
|
||||
if (value == null || value.length() == 0)
|
||||
{
|
||||
throw new ConfigException("Missing mandatory '" + attr + "' attribute for Dashboard 'dashlet' configuration element.");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.xml.elementreader.ConfigElementReader;
|
||||
import org.alfresco.web.config.DashboardsConfigElement.DashletDefinition;
|
||||
import org.alfresco.web.config.DashboardsConfigElement.LayoutDefinition;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* Reader for the 'dashboards' config element and child elements.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class DashboardsElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ELEMENT_DASHBOARDS = "dashboards";
|
||||
public static final String ELEMENT_LAYOUTS = "layouts";
|
||||
public static final String ELEMENT_LAYOUT = "layout";
|
||||
public static final String ELEMENT_DASHLETS = "dashlets";
|
||||
public static final String ELEMENT_DASHLET = "dashlet";
|
||||
public static final String ELEMENT_GUESTCONFIG = "allow-guest-config";
|
||||
public static final String ELEMENT_DEFAULTDASHLETS = "default-dashlets";
|
||||
public static final String ATTR_ID = "id";
|
||||
public static final String ATTR_COLUMNS = "columns";
|
||||
public static final String ATTR_COLUMNLENGTH = "column-length";
|
||||
public static final String ATTR_IMAGE = "image";
|
||||
public static final String ATTR_LABEL = "label";
|
||||
public static final String ATTR_DESCRIPTION = "description";
|
||||
public static final String ATTR_LABELID = "label-id";
|
||||
public static final String ATTR_DESCRIPTIONID = "description-id";
|
||||
public static final String ATTR_JSP = "jsp";
|
||||
public static final String ATTR_CONFIGJSP = "config-jsp";
|
||||
public static final String ATTR_ALLOWNARROW = "allow-narrow";
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
DashboardsConfigElement configElement = new DashboardsConfigElement();
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
if (DashboardsConfigElement.CONFIG_ELEMENT_ID.equals(element.getName()) == false)
|
||||
{
|
||||
throw new ConfigException("DashboardsElementReader can only process elements of type 'dashboards'");
|
||||
}
|
||||
|
||||
Element layoutsElement = element.element(ELEMENT_LAYOUTS);
|
||||
if (layoutsElement != null)
|
||||
{
|
||||
Iterator<Element> layoutsItr = layoutsElement.elementIterator(ELEMENT_LAYOUT);
|
||||
while (layoutsItr.hasNext())
|
||||
{
|
||||
LayoutDefinition layoutDef = parseLayoutDefinition(layoutsItr.next());
|
||||
configElement.addLayoutDefinition(layoutDef);
|
||||
}
|
||||
}
|
||||
|
||||
Element dashletsElement = element.element(ELEMENT_DASHLETS);
|
||||
if (dashletsElement != null)
|
||||
{
|
||||
Iterator<Element> dashletsItr = dashletsElement.elementIterator(ELEMENT_DASHLET);
|
||||
while (dashletsItr.hasNext())
|
||||
{
|
||||
DashletDefinition dashletDef = parseDashletDefinition(dashletsItr.next());
|
||||
configElement.addDashletDefinition(dashletDef);
|
||||
}
|
||||
}
|
||||
|
||||
Element defaultDashletsElement = element.element(ELEMENT_DEFAULTDASHLETS);
|
||||
if (defaultDashletsElement != null)
|
||||
{
|
||||
Iterator<Element> dashletsItr = defaultDashletsElement.elementIterator(ELEMENT_DASHLET);
|
||||
while (dashletsItr.hasNext())
|
||||
{
|
||||
String id = getMandatoryDashletAttributeValue(dashletsItr.next(), ATTR_ID);
|
||||
configElement.addDefaultDashlet(id);
|
||||
}
|
||||
}
|
||||
|
||||
Element guestConfigElement = element.element(ELEMENT_GUESTCONFIG);
|
||||
if (guestConfigElement != null)
|
||||
{
|
||||
boolean allow = Boolean.parseBoolean(guestConfigElement.getTextTrim());
|
||||
configElement.setAllowGuestConfig(allow);
|
||||
}
|
||||
}
|
||||
|
||||
return configElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a single Layout definition from config.
|
||||
*
|
||||
* @param config Element
|
||||
*
|
||||
* @return LayoutDefinition for the specified config element.
|
||||
*/
|
||||
private static LayoutDefinition parseLayoutDefinition(Element config)
|
||||
{
|
||||
String id = getMandatoryLayoutAttributeValue(config, ATTR_ID);
|
||||
|
||||
LayoutDefinition def = new LayoutDefinition(id);
|
||||
|
||||
String columns = getMandatoryLayoutAttributeValue(config, ATTR_COLUMNS);
|
||||
def.Columns = Integer.parseInt(columns);
|
||||
String columnLength = getMandatoryLayoutAttributeValue(config, ATTR_COLUMNLENGTH);
|
||||
def.ColumnLength = Integer.parseInt(columnLength);
|
||||
def.Image = getMandatoryLayoutAttributeValue(config, ATTR_IMAGE);
|
||||
def.JSPPage = getMandatoryLayoutAttributeValue(config, ATTR_JSP);
|
||||
String label = config.attributeValue(ATTR_LABEL);
|
||||
String labelId = config.attributeValue(ATTR_LABELID);
|
||||
if ((label == null || label.length() == 0) && (labelId == null || labelId.length() == 0))
|
||||
{
|
||||
throw new ConfigException("Either 'label' or 'label-id' attribute must be specified for Dashboard 'layout' configuration element.");
|
||||
}
|
||||
def.Label = label;
|
||||
def.LabelId = labelId;
|
||||
String description = config.attributeValue(ATTR_DESCRIPTION);
|
||||
String descriptionId = config.attributeValue(ATTR_DESCRIPTIONID);
|
||||
if ((description == null || description.length() == 0) && (descriptionId == null || descriptionId.length() == 0))
|
||||
{
|
||||
throw new ConfigException("Either 'description' or 'description-id' attribute must be specified for Dashboard 'layout' configuration element.");
|
||||
}
|
||||
def.Description = description;
|
||||
def.DescriptionId = descriptionId;
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a mandatory layout attribute layout. Throw an exception if the value is not found.
|
||||
*
|
||||
* @param config Element
|
||||
* @param attr String
|
||||
*
|
||||
* @return String value
|
||||
*/
|
||||
private static String getMandatoryLayoutAttributeValue(Element config, String attr)
|
||||
{
|
||||
String value = config.attributeValue(attr);
|
||||
if (value == null || value.length() == 0)
|
||||
{
|
||||
throw new ConfigException("Missing mandatory '" + attr + "' attribute for Dashboard 'layout' configuration element.");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a single Dashlet definition from config.
|
||||
*
|
||||
* @param config Element
|
||||
*
|
||||
* @return DashletDefinition for the specified config element.
|
||||
*/
|
||||
private static DashletDefinition parseDashletDefinition(Element config)
|
||||
{
|
||||
String id = getMandatoryDashletAttributeValue(config, ATTR_ID);
|
||||
|
||||
DashletDefinition def = new DashletDefinition(id);
|
||||
|
||||
String allowNarrow = config.attributeValue(ATTR_ALLOWNARROW);
|
||||
if (allowNarrow != null && allowNarrow.length() != 0)
|
||||
{
|
||||
def.AllowNarrow = Boolean.parseBoolean(allowNarrow);
|
||||
}
|
||||
def.JSPPage = getMandatoryDashletAttributeValue(config, ATTR_JSP);
|
||||
def.ConfigJSPPage = config.attributeValue(ATTR_CONFIGJSP);
|
||||
String label = config.attributeValue(ATTR_LABEL);
|
||||
String labelId = config.attributeValue(ATTR_LABELID);
|
||||
if ((label == null || label.length() == 0) && (labelId == null || labelId.length() == 0))
|
||||
{
|
||||
throw new ConfigException("Either 'label' or 'label-id' attribute must be specified for Dashboard 'dashlet' configuration element.");
|
||||
}
|
||||
def.Label = label;
|
||||
def.LabelId = labelId;
|
||||
String description = config.attributeValue(ATTR_DESCRIPTION);
|
||||
String descriptionId = config.attributeValue(ATTR_DESCRIPTIONID);
|
||||
if ((description == null || description.length() == 0) && (descriptionId == null || descriptionId.length() == 0))
|
||||
{
|
||||
throw new ConfigException("Either 'description' or 'description-id' attribute must be specified for Dashboard 'dashlet' configuration element.");
|
||||
}
|
||||
def.Description = description;
|
||||
def.DescriptionId = descriptionId;
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a mandatory dashlet attribute layout. Throw an exception if the value is not found.
|
||||
*
|
||||
* @param config Element
|
||||
* @param attr String
|
||||
*
|
||||
* @return String value
|
||||
*/
|
||||
private static String getMandatoryDashletAttributeValue(Element config, String attr)
|
||||
{
|
||||
String value = config.attributeValue(attr);
|
||||
if (value == null || value.length() == 0)
|
||||
{
|
||||
throw new ConfigException("Missing mandatory '" + attr + "' attribute for Dashboard 'dashlet' configuration element.");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,186 +1,186 @@
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.xml.elementreader.ConfigElementReader;
|
||||
import org.alfresco.web.config.DialogsConfigElement.DialogButtonConfig;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* Custom element reader to parse config for dialogs
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class DialogsElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ELEMENT_DIALOGS = "dialogs";
|
||||
public static final String ELEMENT_DIALOG = "dialog";
|
||||
public static final String ELEMENT_BUTTONS = "buttons";
|
||||
public static final String ELEMENT_BUTTON = "button";
|
||||
public static final String ATTR_NAME = "name";
|
||||
public static final String ATTR_PAGE = "page";
|
||||
public static final String ATTR_MANAGED_BEAN = "managed-bean";
|
||||
public static final String ATTR_ICON = "icon";
|
||||
public static final String ATTR_TITLE = "title";
|
||||
public static final String ATTR_TITLE_ID = "title-id";
|
||||
public static final String ATTR_SUBTITLE = "subtitle";
|
||||
public static final String ATTR_SUBTITLE_ID = "subtitle-id";
|
||||
public static final String ATTR_DESCRIPTION = "description";
|
||||
public static final String ATTR_DESCRIPTION_ID = "description-id";
|
||||
public static final String ATTR_ERROR_MSG_ID = "error-message-id";
|
||||
public static final String ATTR_SHOW_OK_BUTTON = "show-ok-button";
|
||||
|
||||
// action related attributes
|
||||
public static final String ATTR_ACTIONS_CONFIG_ID = "actions-config-id";
|
||||
public static final String ATTR_ACTIONS_AS_MENU = "actions-as-menu";
|
||||
public static final String ATTR_ACTIONS_MENU_LABEL = "actions-menu-label";
|
||||
public static final String ATTR_ACTIONS_MENU_LABEL_ID = "actions-menu-label-id";
|
||||
public static final String ATTR_MORE_ACTIONS_CONFIG_ID = "more-actions-config-id";
|
||||
public static final String ATTR_MORE_ACTIONS_MENU_LABEL = "more-actions-menu-label";
|
||||
public static final String ATTR_MORE_ACTIONS_MENU_LABEL_ID = "more-actions-menu-label-id";
|
||||
|
||||
// button related attributes
|
||||
public static final String ATTR_ID = "id";
|
||||
public static final String ATTR_LABEL = "label";
|
||||
public static final String ATTR_LABEL_ID = "label-id";
|
||||
public static final String ATTR_ACTION = "action";
|
||||
public static final String ATTR_DISABLED = "disabled";
|
||||
public static final String ATTR_ONCLICK = "onclick";
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
DialogsConfigElement configElement = null;
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
String elementName = element.getName();
|
||||
if (elementName.equals(ELEMENT_DIALOGS) == false)
|
||||
{
|
||||
throw new ConfigException("DialogsElementReader can only parse " +
|
||||
ELEMENT_DIALOGS + "elements, the element passed was '" +
|
||||
elementName + "'");
|
||||
}
|
||||
|
||||
configElement = new DialogsConfigElement();
|
||||
|
||||
// go through the dialogs
|
||||
Iterator<Element> items = element.elementIterator(ELEMENT_DIALOG);
|
||||
while (items.hasNext())
|
||||
{
|
||||
Element item = items.next();
|
||||
|
||||
String name = item.attributeValue(ATTR_NAME);
|
||||
String page = item.attributeValue(ATTR_PAGE);
|
||||
String bean = item.attributeValue(ATTR_MANAGED_BEAN);
|
||||
String icon = item.attributeValue(ATTR_ICON);
|
||||
String title = item.attributeValue(ATTR_TITLE);
|
||||
String titleId = item.attributeValue(ATTR_TITLE_ID);
|
||||
String subTitle = item.attributeValue(ATTR_SUBTITLE);
|
||||
String subTitleId = item.attributeValue(ATTR_SUBTITLE_ID);
|
||||
String description = item.attributeValue(ATTR_DESCRIPTION);
|
||||
String descriptionId = item.attributeValue(ATTR_DESCRIPTION_ID);
|
||||
String errorMsgId = item.attributeValue(ATTR_ERROR_MSG_ID);
|
||||
String showOK = item.attributeValue(ATTR_SHOW_OK_BUTTON);
|
||||
|
||||
boolean isOKButtonVisible = true;
|
||||
if (showOK != null)
|
||||
{
|
||||
isOKButtonVisible = Boolean.parseBoolean(showOK);
|
||||
}
|
||||
|
||||
// action related config
|
||||
String actionsConfigId = item.attributeValue(ATTR_ACTIONS_CONFIG_ID);
|
||||
boolean useMenuForActions = false;
|
||||
String asMenu = item.attributeValue(ATTR_ACTIONS_AS_MENU);
|
||||
if (asMenu != null)
|
||||
{
|
||||
useMenuForActions = Boolean.parseBoolean(asMenu);
|
||||
}
|
||||
String actionsMenuLabel = item.attributeValue(ATTR_ACTIONS_MENU_LABEL);
|
||||
String actionsMenuLabelId = item.attributeValue(ATTR_ACTIONS_MENU_LABEL_ID);
|
||||
String moreActionsConfigId = item.attributeValue(ATTR_MORE_ACTIONS_CONFIG_ID);
|
||||
String moreActionsMenuLabel = item.attributeValue(ATTR_MORE_ACTIONS_MENU_LABEL);
|
||||
String moreActionsMenuLabelId = item.attributeValue(ATTR_MORE_ACTIONS_MENU_LABEL_ID);
|
||||
|
||||
// parse any buttons that may be present
|
||||
List<DialogButtonConfig> buttons = parseButtons(item);
|
||||
|
||||
// setup the attrbiutes object
|
||||
DialogsConfigElement.DialogAttributes attrs =
|
||||
new DialogsConfigElement.DialogAttributes(name, page, bean);
|
||||
attrs.setIcon(icon);
|
||||
attrs.setTitle(title);
|
||||
attrs.setTitleId(titleId);
|
||||
attrs.setSubTitle(subTitle);
|
||||
attrs.setSubTitleId(subTitleId);
|
||||
attrs.setDescription(description);
|
||||
attrs.setDescriptionId(descriptionId);
|
||||
attrs.setErrorMessageId(errorMsgId);
|
||||
attrs.setOKButtonVisible(isOKButtonVisible);
|
||||
attrs.setButtons(buttons);
|
||||
attrs.setActionsConfigId(actionsConfigId);
|
||||
attrs.setActionsAsMenu(useMenuForActions);
|
||||
attrs.setActionsMenuLabel(actionsMenuLabel);
|
||||
attrs.setActionsMenuLabelId(actionsMenuLabelId);
|
||||
attrs.setMoreActionsConfigId(moreActionsConfigId);
|
||||
attrs.setMoreActionsMenuLabel(moreActionsMenuLabel);
|
||||
attrs.setMoreActionsMenuLabelId(moreActionsMenuLabelId);
|
||||
|
||||
// create and add the dialog config object
|
||||
DialogsConfigElement.DialogConfig cfg = new DialogsConfigElement.DialogConfig(attrs);
|
||||
configElement.addDialog(cfg);
|
||||
}
|
||||
}
|
||||
|
||||
return configElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the configuration for additional buttons.
|
||||
*
|
||||
* @param dialog The dialog XML element
|
||||
* @return List of configured buttons
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected List<DialogButtonConfig> parseButtons(Element dialog)
|
||||
{
|
||||
List<DialogButtonConfig> buttons = null;
|
||||
|
||||
// iterate over any configured buttons
|
||||
Element buttonsConfig = dialog.element(ELEMENT_BUTTONS);
|
||||
if (buttonsConfig != null)
|
||||
{
|
||||
buttons = new ArrayList<DialogButtonConfig>(4);
|
||||
|
||||
Iterator<Element> children = buttonsConfig.elementIterator(ELEMENT_BUTTON);
|
||||
while (children.hasNext())
|
||||
{
|
||||
Element button = children.next();
|
||||
|
||||
String id = button.attributeValue(ATTR_ID);
|
||||
String label = button.attributeValue(ATTR_LABEL);
|
||||
String labelId = button.attributeValue(ATTR_LABEL_ID);
|
||||
String action = button.attributeValue(ATTR_ACTION);
|
||||
String disabled = button.attributeValue(ATTR_DISABLED);
|
||||
String onclick = button.attributeValue(ATTR_ONCLICK);
|
||||
|
||||
// create the button config object
|
||||
DialogButtonConfig btnCfg = new DialogButtonConfig(id, label,
|
||||
labelId, action, disabled, onclick);
|
||||
|
||||
// add the button to the list
|
||||
buttons.add(btnCfg);
|
||||
}
|
||||
}
|
||||
|
||||
return buttons;
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.xml.elementreader.ConfigElementReader;
|
||||
import org.alfresco.web.config.DialogsConfigElement.DialogButtonConfig;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* Custom element reader to parse config for dialogs
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class DialogsElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ELEMENT_DIALOGS = "dialogs";
|
||||
public static final String ELEMENT_DIALOG = "dialog";
|
||||
public static final String ELEMENT_BUTTONS = "buttons";
|
||||
public static final String ELEMENT_BUTTON = "button";
|
||||
public static final String ATTR_NAME = "name";
|
||||
public static final String ATTR_PAGE = "page";
|
||||
public static final String ATTR_MANAGED_BEAN = "managed-bean";
|
||||
public static final String ATTR_ICON = "icon";
|
||||
public static final String ATTR_TITLE = "title";
|
||||
public static final String ATTR_TITLE_ID = "title-id";
|
||||
public static final String ATTR_SUBTITLE = "subtitle";
|
||||
public static final String ATTR_SUBTITLE_ID = "subtitle-id";
|
||||
public static final String ATTR_DESCRIPTION = "description";
|
||||
public static final String ATTR_DESCRIPTION_ID = "description-id";
|
||||
public static final String ATTR_ERROR_MSG_ID = "error-message-id";
|
||||
public static final String ATTR_SHOW_OK_BUTTON = "show-ok-button";
|
||||
|
||||
// action related attributes
|
||||
public static final String ATTR_ACTIONS_CONFIG_ID = "actions-config-id";
|
||||
public static final String ATTR_ACTIONS_AS_MENU = "actions-as-menu";
|
||||
public static final String ATTR_ACTIONS_MENU_LABEL = "actions-menu-label";
|
||||
public static final String ATTR_ACTIONS_MENU_LABEL_ID = "actions-menu-label-id";
|
||||
public static final String ATTR_MORE_ACTIONS_CONFIG_ID = "more-actions-config-id";
|
||||
public static final String ATTR_MORE_ACTIONS_MENU_LABEL = "more-actions-menu-label";
|
||||
public static final String ATTR_MORE_ACTIONS_MENU_LABEL_ID = "more-actions-menu-label-id";
|
||||
|
||||
// button related attributes
|
||||
public static final String ATTR_ID = "id";
|
||||
public static final String ATTR_LABEL = "label";
|
||||
public static final String ATTR_LABEL_ID = "label-id";
|
||||
public static final String ATTR_ACTION = "action";
|
||||
public static final String ATTR_DISABLED = "disabled";
|
||||
public static final String ATTR_ONCLICK = "onclick";
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
DialogsConfigElement configElement = null;
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
String elementName = element.getName();
|
||||
if (elementName.equals(ELEMENT_DIALOGS) == false)
|
||||
{
|
||||
throw new ConfigException("DialogsElementReader can only parse " +
|
||||
ELEMENT_DIALOGS + "elements, the element passed was '" +
|
||||
elementName + "'");
|
||||
}
|
||||
|
||||
configElement = new DialogsConfigElement();
|
||||
|
||||
// go through the dialogs
|
||||
Iterator<Element> items = element.elementIterator(ELEMENT_DIALOG);
|
||||
while (items.hasNext())
|
||||
{
|
||||
Element item = items.next();
|
||||
|
||||
String name = item.attributeValue(ATTR_NAME);
|
||||
String page = item.attributeValue(ATTR_PAGE);
|
||||
String bean = item.attributeValue(ATTR_MANAGED_BEAN);
|
||||
String icon = item.attributeValue(ATTR_ICON);
|
||||
String title = item.attributeValue(ATTR_TITLE);
|
||||
String titleId = item.attributeValue(ATTR_TITLE_ID);
|
||||
String subTitle = item.attributeValue(ATTR_SUBTITLE);
|
||||
String subTitleId = item.attributeValue(ATTR_SUBTITLE_ID);
|
||||
String description = item.attributeValue(ATTR_DESCRIPTION);
|
||||
String descriptionId = item.attributeValue(ATTR_DESCRIPTION_ID);
|
||||
String errorMsgId = item.attributeValue(ATTR_ERROR_MSG_ID);
|
||||
String showOK = item.attributeValue(ATTR_SHOW_OK_BUTTON);
|
||||
|
||||
boolean isOKButtonVisible = true;
|
||||
if (showOK != null)
|
||||
{
|
||||
isOKButtonVisible = Boolean.parseBoolean(showOK);
|
||||
}
|
||||
|
||||
// action related config
|
||||
String actionsConfigId = item.attributeValue(ATTR_ACTIONS_CONFIG_ID);
|
||||
boolean useMenuForActions = false;
|
||||
String asMenu = item.attributeValue(ATTR_ACTIONS_AS_MENU);
|
||||
if (asMenu != null)
|
||||
{
|
||||
useMenuForActions = Boolean.parseBoolean(asMenu);
|
||||
}
|
||||
String actionsMenuLabel = item.attributeValue(ATTR_ACTIONS_MENU_LABEL);
|
||||
String actionsMenuLabelId = item.attributeValue(ATTR_ACTIONS_MENU_LABEL_ID);
|
||||
String moreActionsConfigId = item.attributeValue(ATTR_MORE_ACTIONS_CONFIG_ID);
|
||||
String moreActionsMenuLabel = item.attributeValue(ATTR_MORE_ACTIONS_MENU_LABEL);
|
||||
String moreActionsMenuLabelId = item.attributeValue(ATTR_MORE_ACTIONS_MENU_LABEL_ID);
|
||||
|
||||
// parse any buttons that may be present
|
||||
List<DialogButtonConfig> buttons = parseButtons(item);
|
||||
|
||||
// setup the attrbiutes object
|
||||
DialogsConfigElement.DialogAttributes attrs =
|
||||
new DialogsConfigElement.DialogAttributes(name, page, bean);
|
||||
attrs.setIcon(icon);
|
||||
attrs.setTitle(title);
|
||||
attrs.setTitleId(titleId);
|
||||
attrs.setSubTitle(subTitle);
|
||||
attrs.setSubTitleId(subTitleId);
|
||||
attrs.setDescription(description);
|
||||
attrs.setDescriptionId(descriptionId);
|
||||
attrs.setErrorMessageId(errorMsgId);
|
||||
attrs.setOKButtonVisible(isOKButtonVisible);
|
||||
attrs.setButtons(buttons);
|
||||
attrs.setActionsConfigId(actionsConfigId);
|
||||
attrs.setActionsAsMenu(useMenuForActions);
|
||||
attrs.setActionsMenuLabel(actionsMenuLabel);
|
||||
attrs.setActionsMenuLabelId(actionsMenuLabelId);
|
||||
attrs.setMoreActionsConfigId(moreActionsConfigId);
|
||||
attrs.setMoreActionsMenuLabel(moreActionsMenuLabel);
|
||||
attrs.setMoreActionsMenuLabelId(moreActionsMenuLabelId);
|
||||
|
||||
// create and add the dialog config object
|
||||
DialogsConfigElement.DialogConfig cfg = new DialogsConfigElement.DialogConfig(attrs);
|
||||
configElement.addDialog(cfg);
|
||||
}
|
||||
}
|
||||
|
||||
return configElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the configuration for additional buttons.
|
||||
*
|
||||
* @param dialog The dialog XML element
|
||||
* @return List of configured buttons
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected List<DialogButtonConfig> parseButtons(Element dialog)
|
||||
{
|
||||
List<DialogButtonConfig> buttons = null;
|
||||
|
||||
// iterate over any configured buttons
|
||||
Element buttonsConfig = dialog.element(ELEMENT_BUTTONS);
|
||||
if (buttonsConfig != null)
|
||||
{
|
||||
buttons = new ArrayList<DialogButtonConfig>(4);
|
||||
|
||||
Iterator<Element> children = buttonsConfig.elementIterator(ELEMENT_BUTTON);
|
||||
while (children.hasNext())
|
||||
{
|
||||
Element button = children.next();
|
||||
|
||||
String id = button.attributeValue(ATTR_ID);
|
||||
String label = button.attributeValue(ATTR_LABEL);
|
||||
String labelId = button.attributeValue(ATTR_LABEL_ID);
|
||||
String action = button.attributeValue(ATTR_ACTION);
|
||||
String disabled = button.attributeValue(ATTR_DISABLED);
|
||||
String onclick = button.attributeValue(ATTR_ONCLICK);
|
||||
|
||||
// create the button config object
|
||||
DialogButtonConfig btnCfg = new DialogButtonConfig(id, label,
|
||||
labelId, action, disabled, onclick);
|
||||
|
||||
// add the button to the list
|
||||
buttons.add(btnCfg);
|
||||
}
|
||||
}
|
||||
|
||||
return buttons;
|
||||
}
|
||||
}
|
||||
|
@@ -1,109 +1,109 @@
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.element.ConfigElementAdapter;
|
||||
|
||||
/**
|
||||
* Custom config element that represents config values for languages
|
||||
*
|
||||
* @author Gavin Cornwell
|
||||
*/
|
||||
public class LanguagesConfigElement extends ConfigElementAdapter
|
||||
{
|
||||
public static final String CONFIG_ELEMENT_ID = "languages";
|
||||
|
||||
private Map<String, String> localeMap = new HashMap<String, String>();
|
||||
private List<String> languages = new ArrayList<String>(8);
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
public LanguagesConfigElement()
|
||||
{
|
||||
super(CONFIG_ELEMENT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param name Name of the element this config element represents
|
||||
*/
|
||||
public LanguagesConfigElement(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#getChildren()
|
||||
*/
|
||||
@Override
|
||||
public List<ConfigElement> getChildren()
|
||||
{
|
||||
throw new ConfigException("Reading the languages config via the generic interfaces is not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#combine(org.springframework.extensions.config.ConfigElement)
|
||||
*/
|
||||
public ConfigElement combine(ConfigElement configElement)
|
||||
{
|
||||
LanguagesConfigElement newElement = (LanguagesConfigElement)configElement;
|
||||
LanguagesConfigElement combinedElement = new LanguagesConfigElement();
|
||||
|
||||
// add the languages from this config element
|
||||
for (String locale : this.languages)
|
||||
{
|
||||
combinedElement.addLanguage(locale, this.localeMap.get(locale));
|
||||
}
|
||||
|
||||
// now add the languages from the one to be combined (but
|
||||
// only if they are not already in the list)
|
||||
List<String> languages = newElement.getLanguages();
|
||||
for (String locale : languages)
|
||||
{
|
||||
if (combinedElement.getLabelForLanguage(locale) == null)
|
||||
{
|
||||
String label = newElement.getLabelForLanguage(locale);
|
||||
combinedElement.addLanguage(locale, label);
|
||||
}
|
||||
}
|
||||
|
||||
return combinedElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a language locale and display label to the list.
|
||||
*
|
||||
* @param locale Locale code
|
||||
* @param label Display label
|
||||
*/
|
||||
/*package*/ void addLanguage(String locale, String label)
|
||||
{
|
||||
this.localeMap.put(locale, label);
|
||||
this.languages.add(locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return List of supported language locale strings in config file order
|
||||
*/
|
||||
public List<String> getLanguages()
|
||||
{
|
||||
return this.languages;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param locale The locale string to lookup language label for
|
||||
*
|
||||
* @return the language label for specified locale string, or null if not found
|
||||
*/
|
||||
public String getLabelForLanguage(String locale)
|
||||
{
|
||||
return this.localeMap.get(locale);
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.element.ConfigElementAdapter;
|
||||
|
||||
/**
|
||||
* Custom config element that represents config values for languages
|
||||
*
|
||||
* @author Gavin Cornwell
|
||||
*/
|
||||
public class LanguagesConfigElement extends ConfigElementAdapter
|
||||
{
|
||||
public static final String CONFIG_ELEMENT_ID = "languages";
|
||||
|
||||
private Map<String, String> localeMap = new HashMap<String, String>();
|
||||
private List<String> languages = new ArrayList<String>(8);
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
public LanguagesConfigElement()
|
||||
{
|
||||
super(CONFIG_ELEMENT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param name Name of the element this config element represents
|
||||
*/
|
||||
public LanguagesConfigElement(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#getChildren()
|
||||
*/
|
||||
@Override
|
||||
public List<ConfigElement> getChildren()
|
||||
{
|
||||
throw new ConfigException("Reading the languages config via the generic interfaces is not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#combine(org.springframework.extensions.config.ConfigElement)
|
||||
*/
|
||||
public ConfigElement combine(ConfigElement configElement)
|
||||
{
|
||||
LanguagesConfigElement newElement = (LanguagesConfigElement)configElement;
|
||||
LanguagesConfigElement combinedElement = new LanguagesConfigElement();
|
||||
|
||||
// add the languages from this config element
|
||||
for (String locale : this.languages)
|
||||
{
|
||||
combinedElement.addLanguage(locale, this.localeMap.get(locale));
|
||||
}
|
||||
|
||||
// now add the languages from the one to be combined (but
|
||||
// only if they are not already in the list)
|
||||
List<String> languages = newElement.getLanguages();
|
||||
for (String locale : languages)
|
||||
{
|
||||
if (combinedElement.getLabelForLanguage(locale) == null)
|
||||
{
|
||||
String label = newElement.getLabelForLanguage(locale);
|
||||
combinedElement.addLanguage(locale, label);
|
||||
}
|
||||
}
|
||||
|
||||
return combinedElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a language locale and display label to the list.
|
||||
*
|
||||
* @param locale Locale code
|
||||
* @param label Display label
|
||||
*/
|
||||
/*package*/ void addLanguage(String locale, String label)
|
||||
{
|
||||
this.localeMap.put(locale, label);
|
||||
this.languages.add(locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return List of supported language locale strings in config file order
|
||||
*/
|
||||
public List<String> getLanguages()
|
||||
{
|
||||
return this.languages;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param locale The locale string to lookup language label for
|
||||
*
|
||||
* @return the language label for specified locale string, or null if not found
|
||||
*/
|
||||
public String getLabelForLanguage(String locale)
|
||||
{
|
||||
return this.localeMap.get(locale);
|
||||
}
|
||||
}
|
||||
|
@@ -1,58 +1,58 @@
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.xml.elementreader.ConfigElementReader;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* Custom element reader to parse config for languages
|
||||
*
|
||||
* @author Gavin Cornwell
|
||||
*/
|
||||
public class LanguagesElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ELEMENT_LANGUAGE = "language";
|
||||
public static final String ATTRIBUTE_LOCALE = "locale";
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
LanguagesConfigElement configElement = null;
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
String name = element.getName();
|
||||
if (name.equals(LanguagesConfigElement.CONFIG_ELEMENT_ID) == false)
|
||||
{
|
||||
throw new ConfigException("LanguagesElementReader can only parse " +
|
||||
LanguagesConfigElement.CONFIG_ELEMENT_ID + " elements, the element passed was '" +
|
||||
name + "'");
|
||||
}
|
||||
|
||||
configElement = new LanguagesConfigElement();
|
||||
|
||||
Iterator<Element> langsItr = element.elementIterator(ELEMENT_LANGUAGE);
|
||||
while (langsItr.hasNext())
|
||||
{
|
||||
Element language = langsItr.next();
|
||||
String localeCode = language.attributeValue(ATTRIBUTE_LOCALE);
|
||||
String label = language.getTextTrim();
|
||||
|
||||
if (localeCode != null && localeCode.length() != 0 &&
|
||||
label != null && label.length() != 0)
|
||||
{
|
||||
// store the language code against the display label
|
||||
configElement.addLanguage(localeCode, label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return configElement;
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.xml.elementreader.ConfigElementReader;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* Custom element reader to parse config for languages
|
||||
*
|
||||
* @author Gavin Cornwell
|
||||
*/
|
||||
public class LanguagesElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ELEMENT_LANGUAGE = "language";
|
||||
public static final String ATTRIBUTE_LOCALE = "locale";
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
LanguagesConfigElement configElement = null;
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
String name = element.getName();
|
||||
if (name.equals(LanguagesConfigElement.CONFIG_ELEMENT_ID) == false)
|
||||
{
|
||||
throw new ConfigException("LanguagesElementReader can only parse " +
|
||||
LanguagesConfigElement.CONFIG_ELEMENT_ID + " elements, the element passed was '" +
|
||||
name + "'");
|
||||
}
|
||||
|
||||
configElement = new LanguagesConfigElement();
|
||||
|
||||
Iterator<Element> langsItr = element.elementIterator(ELEMENT_LANGUAGE);
|
||||
while (langsItr.hasNext())
|
||||
{
|
||||
Element language = langsItr.next();
|
||||
String localeCode = language.attributeValue(ATTRIBUTE_LOCALE);
|
||||
String label = language.getTextTrim();
|
||||
|
||||
if (localeCode != null && localeCode.length() != 0 &&
|
||||
label != null && label.length() != 0)
|
||||
{
|
||||
// store the language code against the display label
|
||||
configElement.addLanguage(localeCode, label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return configElement;
|
||||
}
|
||||
}
|
||||
|
@@ -1,230 +1,230 @@
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.element.ConfigElementAdapter;
|
||||
import org.springframework.extensions.config.element.GenericConfigElement;
|
||||
|
||||
/**
|
||||
* Custom config element that represents the config data for navigation
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class NavigationConfigElement extends ConfigElementAdapter
|
||||
{
|
||||
private HashMap<String, NavigationResult> viewIds = new HashMap<String, NavigationResult>();
|
||||
private HashMap<String, NavigationResult> outcomes = new HashMap<String, NavigationResult>();
|
||||
|
||||
private boolean kidsPopulated = false;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public NavigationConfigElement()
|
||||
{
|
||||
super("navigation");
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param name Name of the element this config element represents
|
||||
*/
|
||||
public NavigationConfigElement(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ConfigElement#getChildren()
|
||||
*/
|
||||
public List<ConfigElement> getChildren()
|
||||
{
|
||||
// lazily build the list of generic config elements representing
|
||||
// the navigation overrides as the caller may not even call this method
|
||||
|
||||
List<ConfigElement> kids = null;
|
||||
|
||||
if (this.viewIds.size() > 0 || this.outcomes.size() > 0)
|
||||
{
|
||||
if (this.kidsPopulated == false)
|
||||
{
|
||||
// create generic config elements for the from-view-id items
|
||||
for (String fromViewId : this.viewIds.keySet())
|
||||
{
|
||||
GenericConfigElement ce = new GenericConfigElement(NavigationElementReader.ELEMENT_OVERRIDE);
|
||||
ce.addAttribute(NavigationElementReader.ATTR_FROM_VIEWID, fromViewId);
|
||||
|
||||
NavigationResult navRes = this.viewIds.get(fromViewId);
|
||||
String result = navRes.getResult();
|
||||
if (navRes.isOutcome())
|
||||
{
|
||||
ce.addAttribute(NavigationElementReader.ATTR_TO_OUTCOME, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
ce.addAttribute(NavigationElementReader.ATTR_TO_VIEWID, result);
|
||||
}
|
||||
|
||||
// add the element
|
||||
this.children.add(ce);
|
||||
}
|
||||
|
||||
// create generic config elements for the from-outcome items
|
||||
for (String fromOutcome : this.outcomes.keySet())
|
||||
{
|
||||
GenericConfigElement ce = new GenericConfigElement(NavigationElementReader.ELEMENT_OVERRIDE);
|
||||
ce.addAttribute(NavigationElementReader.ATTR_FROM_OUTCOME, fromOutcome);
|
||||
|
||||
NavigationResult navRes = this.outcomes.get(fromOutcome);
|
||||
String result = navRes.getResult();
|
||||
if (navRes.isOutcome())
|
||||
{
|
||||
ce.addAttribute(NavigationElementReader.ATTR_TO_OUTCOME, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
ce.addAttribute(NavigationElementReader.ATTR_TO_VIEWID, result);
|
||||
}
|
||||
|
||||
// add the element
|
||||
this.children.add(ce);
|
||||
}
|
||||
|
||||
this.kidsPopulated = true;
|
||||
}
|
||||
|
||||
kids = super.getChildren();
|
||||
}
|
||||
|
||||
return kids;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ConfigElement#combine(org.springframework.extensions.config.ConfigElement)
|
||||
*/
|
||||
public ConfigElement combine(ConfigElement configElement)
|
||||
{
|
||||
NavigationConfigElement newElement = (NavigationConfigElement)configElement;
|
||||
NavigationConfigElement combinedElement = new NavigationConfigElement();
|
||||
|
||||
// add all the existing from view id overrides
|
||||
for (String fromViewId : this.viewIds.keySet())
|
||||
{
|
||||
combinedElement.addOverride(fromViewId, null, this.viewIds.get(fromViewId));
|
||||
}
|
||||
|
||||
// add all the existing from outcome overrides
|
||||
for (String fromOutcome : this.outcomes.keySet())
|
||||
{
|
||||
combinedElement.addOverride(null, fromOutcome, this.outcomes.get(fromOutcome));
|
||||
}
|
||||
|
||||
// add all the from view id overrides from the given element
|
||||
HashMap<String, NavigationResult> viewIds = newElement.getViewIds();
|
||||
for (String fromViewId : viewIds.keySet())
|
||||
{
|
||||
combinedElement.addOverride(fromViewId, null, viewIds.get(fromViewId));
|
||||
}
|
||||
|
||||
// add all the from outcome overrides from the given element
|
||||
HashMap<String, NavigationResult> outcomes = newElement.getOutcomes();
|
||||
for (String fromOutcome : outcomes.keySet())
|
||||
{
|
||||
combinedElement.addOverride(null, fromOutcome, outcomes.get(fromOutcome));
|
||||
}
|
||||
|
||||
return combinedElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of view ids that have overrides defined
|
||||
*
|
||||
* @return Map of view ids and navigation results
|
||||
*/
|
||||
public HashMap<String, NavigationResult> getViewIds()
|
||||
{
|
||||
return this.viewIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of outcomes that have overrides defined
|
||||
*
|
||||
* @return Map of outcomes and navigation results
|
||||
*/
|
||||
public HashMap<String, NavigationResult> getOutcomes()
|
||||
{
|
||||
return this.outcomes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an override configuration item
|
||||
*
|
||||
* @param fromViewId The from-view-id value from the config
|
||||
* @param fromOutcome The from-outcome value from the config
|
||||
* @param toViewId The to-view-id value from the config
|
||||
* @param toOutcome The to-outcome value from the config
|
||||
*/
|
||||
public void addOverride(String fromViewId, String fromOutcome,
|
||||
String toViewId, String toOutcome)
|
||||
{
|
||||
// NOTE: the constructor will check the validity of the to* parameters
|
||||
NavigationResult result = new NavigationResult(toViewId, toOutcome);
|
||||
addOverride(fromViewId, fromOutcome, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an override configuration item
|
||||
*
|
||||
* @param fromViewId The from-view-id value from the config
|
||||
* @param fromOutcome The from-outcome value from the config
|
||||
* @param result The navigation result object to add
|
||||
*/
|
||||
public void addOverride(String fromViewId, String fromOutcome,
|
||||
NavigationResult result)
|
||||
{
|
||||
if (fromViewId != null && fromOutcome != null)
|
||||
{
|
||||
throw new IllegalStateException("You can not have both a from-view-id and from-outcome");
|
||||
}
|
||||
|
||||
if (fromViewId != null)
|
||||
{
|
||||
this.viewIds.put(fromViewId, result);
|
||||
}
|
||||
else if (fromOutcome != null)
|
||||
{
|
||||
this.outcomes.put(fromOutcome, result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the best match navigation override configured for the given
|
||||
* current view id and/or outcome.
|
||||
*
|
||||
* If an outcome is passed it takes precedence, the view id will not be
|
||||
* used.
|
||||
*
|
||||
* @param fromViewId The current view id
|
||||
* @param fromOutcome The current outcome
|
||||
* @return The navigation result
|
||||
*/
|
||||
public NavigationResult getOverride(String fromViewId, String fromOutcome)
|
||||
{
|
||||
NavigationResult result = null;
|
||||
|
||||
// look for a match for the outcome if one was provided
|
||||
if (fromOutcome != null)
|
||||
{
|
||||
result = this.outcomes.get(fromOutcome);
|
||||
}
|
||||
else if (fromViewId != null)
|
||||
{
|
||||
result = this.viewIds.get(fromViewId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.element.ConfigElementAdapter;
|
||||
import org.springframework.extensions.config.element.GenericConfigElement;
|
||||
|
||||
/**
|
||||
* Custom config element that represents the config data for navigation
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class NavigationConfigElement extends ConfigElementAdapter
|
||||
{
|
||||
private HashMap<String, NavigationResult> viewIds = new HashMap<String, NavigationResult>();
|
||||
private HashMap<String, NavigationResult> outcomes = new HashMap<String, NavigationResult>();
|
||||
|
||||
private boolean kidsPopulated = false;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public NavigationConfigElement()
|
||||
{
|
||||
super("navigation");
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param name Name of the element this config element represents
|
||||
*/
|
||||
public NavigationConfigElement(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ConfigElement#getChildren()
|
||||
*/
|
||||
public List<ConfigElement> getChildren()
|
||||
{
|
||||
// lazily build the list of generic config elements representing
|
||||
// the navigation overrides as the caller may not even call this method
|
||||
|
||||
List<ConfigElement> kids = null;
|
||||
|
||||
if (this.viewIds.size() > 0 || this.outcomes.size() > 0)
|
||||
{
|
||||
if (this.kidsPopulated == false)
|
||||
{
|
||||
// create generic config elements for the from-view-id items
|
||||
for (String fromViewId : this.viewIds.keySet())
|
||||
{
|
||||
GenericConfigElement ce = new GenericConfigElement(NavigationElementReader.ELEMENT_OVERRIDE);
|
||||
ce.addAttribute(NavigationElementReader.ATTR_FROM_VIEWID, fromViewId);
|
||||
|
||||
NavigationResult navRes = this.viewIds.get(fromViewId);
|
||||
String result = navRes.getResult();
|
||||
if (navRes.isOutcome())
|
||||
{
|
||||
ce.addAttribute(NavigationElementReader.ATTR_TO_OUTCOME, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
ce.addAttribute(NavigationElementReader.ATTR_TO_VIEWID, result);
|
||||
}
|
||||
|
||||
// add the element
|
||||
this.children.add(ce);
|
||||
}
|
||||
|
||||
// create generic config elements for the from-outcome items
|
||||
for (String fromOutcome : this.outcomes.keySet())
|
||||
{
|
||||
GenericConfigElement ce = new GenericConfigElement(NavigationElementReader.ELEMENT_OVERRIDE);
|
||||
ce.addAttribute(NavigationElementReader.ATTR_FROM_OUTCOME, fromOutcome);
|
||||
|
||||
NavigationResult navRes = this.outcomes.get(fromOutcome);
|
||||
String result = navRes.getResult();
|
||||
if (navRes.isOutcome())
|
||||
{
|
||||
ce.addAttribute(NavigationElementReader.ATTR_TO_OUTCOME, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
ce.addAttribute(NavigationElementReader.ATTR_TO_VIEWID, result);
|
||||
}
|
||||
|
||||
// add the element
|
||||
this.children.add(ce);
|
||||
}
|
||||
|
||||
this.kidsPopulated = true;
|
||||
}
|
||||
|
||||
kids = super.getChildren();
|
||||
}
|
||||
|
||||
return kids;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ConfigElement#combine(org.springframework.extensions.config.ConfigElement)
|
||||
*/
|
||||
public ConfigElement combine(ConfigElement configElement)
|
||||
{
|
||||
NavigationConfigElement newElement = (NavigationConfigElement)configElement;
|
||||
NavigationConfigElement combinedElement = new NavigationConfigElement();
|
||||
|
||||
// add all the existing from view id overrides
|
||||
for (String fromViewId : this.viewIds.keySet())
|
||||
{
|
||||
combinedElement.addOverride(fromViewId, null, this.viewIds.get(fromViewId));
|
||||
}
|
||||
|
||||
// add all the existing from outcome overrides
|
||||
for (String fromOutcome : this.outcomes.keySet())
|
||||
{
|
||||
combinedElement.addOverride(null, fromOutcome, this.outcomes.get(fromOutcome));
|
||||
}
|
||||
|
||||
// add all the from view id overrides from the given element
|
||||
HashMap<String, NavigationResult> viewIds = newElement.getViewIds();
|
||||
for (String fromViewId : viewIds.keySet())
|
||||
{
|
||||
combinedElement.addOverride(fromViewId, null, viewIds.get(fromViewId));
|
||||
}
|
||||
|
||||
// add all the from outcome overrides from the given element
|
||||
HashMap<String, NavigationResult> outcomes = newElement.getOutcomes();
|
||||
for (String fromOutcome : outcomes.keySet())
|
||||
{
|
||||
combinedElement.addOverride(null, fromOutcome, outcomes.get(fromOutcome));
|
||||
}
|
||||
|
||||
return combinedElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of view ids that have overrides defined
|
||||
*
|
||||
* @return Map of view ids and navigation results
|
||||
*/
|
||||
public HashMap<String, NavigationResult> getViewIds()
|
||||
{
|
||||
return this.viewIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of outcomes that have overrides defined
|
||||
*
|
||||
* @return Map of outcomes and navigation results
|
||||
*/
|
||||
public HashMap<String, NavigationResult> getOutcomes()
|
||||
{
|
||||
return this.outcomes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an override configuration item
|
||||
*
|
||||
* @param fromViewId The from-view-id value from the config
|
||||
* @param fromOutcome The from-outcome value from the config
|
||||
* @param toViewId The to-view-id value from the config
|
||||
* @param toOutcome The to-outcome value from the config
|
||||
*/
|
||||
public void addOverride(String fromViewId, String fromOutcome,
|
||||
String toViewId, String toOutcome)
|
||||
{
|
||||
// NOTE: the constructor will check the validity of the to* parameters
|
||||
NavigationResult result = new NavigationResult(toViewId, toOutcome);
|
||||
addOverride(fromViewId, fromOutcome, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an override configuration item
|
||||
*
|
||||
* @param fromViewId The from-view-id value from the config
|
||||
* @param fromOutcome The from-outcome value from the config
|
||||
* @param result The navigation result object to add
|
||||
*/
|
||||
public void addOverride(String fromViewId, String fromOutcome,
|
||||
NavigationResult result)
|
||||
{
|
||||
if (fromViewId != null && fromOutcome != null)
|
||||
{
|
||||
throw new IllegalStateException("You can not have both a from-view-id and from-outcome");
|
||||
}
|
||||
|
||||
if (fromViewId != null)
|
||||
{
|
||||
this.viewIds.put(fromViewId, result);
|
||||
}
|
||||
else if (fromOutcome != null)
|
||||
{
|
||||
this.outcomes.put(fromOutcome, result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the best match navigation override configured for the given
|
||||
* current view id and/or outcome.
|
||||
*
|
||||
* If an outcome is passed it takes precedence, the view id will not be
|
||||
* used.
|
||||
*
|
||||
* @param fromViewId The current view id
|
||||
* @param fromOutcome The current outcome
|
||||
* @return The navigation result
|
||||
*/
|
||||
public NavigationResult getOverride(String fromViewId, String fromOutcome)
|
||||
{
|
||||
NavigationResult result = null;
|
||||
|
||||
// look for a match for the outcome if one was provided
|
||||
if (fromOutcome != null)
|
||||
{
|
||||
result = this.outcomes.get(fromOutcome);
|
||||
}
|
||||
else if (fromViewId != null)
|
||||
{
|
||||
result = this.viewIds.get(fromViewId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@@ -1,64 +1,64 @@
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.xml.elementreader.ConfigElementReader;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* Custom element reader to parse config for navigation overrides
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class NavigationElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ELEMENT_NAVIGATION = "navigation";
|
||||
public static final String ELEMENT_OVERRIDE = "override";
|
||||
public static final String ATTR_FROM_VIEWID = "from-view-id";
|
||||
public static final String ATTR_FROM_OUTCOME = "from-outcome";
|
||||
public static final String ATTR_TO_VIEWID = "to-view-id";
|
||||
public static final String ATTR_TO_OUTCOME = "to-outcome";
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
NavigationConfigElement configElement = null;
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
String name = element.getName();
|
||||
if (ELEMENT_NAVIGATION.equals(name) == false)
|
||||
{
|
||||
throw new ConfigException("NavigationElementReader can only parse " +
|
||||
ELEMENT_NAVIGATION + "elements, " + "the element passed was '" +
|
||||
name + "'");
|
||||
}
|
||||
|
||||
configElement = new NavigationConfigElement();
|
||||
|
||||
// go through the items to show
|
||||
Iterator<Element> items = element.elementIterator();
|
||||
while (items.hasNext())
|
||||
{
|
||||
Element item = items.next();
|
||||
|
||||
// only process the override elements
|
||||
if (ELEMENT_OVERRIDE.equals(item.getName()))
|
||||
{
|
||||
String fromViewId = item.attributeValue(ATTR_FROM_VIEWID);
|
||||
String fromOutcome = item.attributeValue(ATTR_FROM_OUTCOME);
|
||||
String toViewId = item.attributeValue(ATTR_TO_VIEWID);
|
||||
String toOutcome = item.attributeValue(ATTR_TO_OUTCOME);
|
||||
|
||||
configElement.addOverride(fromViewId, fromOutcome, toViewId, toOutcome);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return configElement;
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.xml.elementreader.ConfigElementReader;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* Custom element reader to parse config for navigation overrides
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class NavigationElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ELEMENT_NAVIGATION = "navigation";
|
||||
public static final String ELEMENT_OVERRIDE = "override";
|
||||
public static final String ATTR_FROM_VIEWID = "from-view-id";
|
||||
public static final String ATTR_FROM_OUTCOME = "from-outcome";
|
||||
public static final String ATTR_TO_VIEWID = "to-view-id";
|
||||
public static final String ATTR_TO_OUTCOME = "to-outcome";
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
NavigationConfigElement configElement = null;
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
String name = element.getName();
|
||||
if (ELEMENT_NAVIGATION.equals(name) == false)
|
||||
{
|
||||
throw new ConfigException("NavigationElementReader can only parse " +
|
||||
ELEMENT_NAVIGATION + "elements, " + "the element passed was '" +
|
||||
name + "'");
|
||||
}
|
||||
|
||||
configElement = new NavigationConfigElement();
|
||||
|
||||
// go through the items to show
|
||||
Iterator<Element> items = element.elementIterator();
|
||||
while (items.hasNext())
|
||||
{
|
||||
Element item = items.next();
|
||||
|
||||
// only process the override elements
|
||||
if (ELEMENT_OVERRIDE.equals(item.getName()))
|
||||
{
|
||||
String fromViewId = item.attributeValue(ATTR_FROM_VIEWID);
|
||||
String fromOutcome = item.attributeValue(ATTR_FROM_OUTCOME);
|
||||
String toViewId = item.attributeValue(ATTR_TO_VIEWID);
|
||||
String toOutcome = item.attributeValue(ATTR_TO_OUTCOME);
|
||||
|
||||
configElement.addOverride(fromViewId, fromOutcome, toViewId, toOutcome);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return configElement;
|
||||
}
|
||||
}
|
||||
|
@@ -1,71 +1,71 @@
|
||||
package org.alfresco.web.config;
|
||||
|
||||
/**
|
||||
* Represents the result of a navigation config result.
|
||||
*
|
||||
* This object holds the string result which can either represent an outcome
|
||||
* or a view id.
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class NavigationResult
|
||||
{
|
||||
private String result;
|
||||
private boolean isOutcome = true;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
* @param viewId The to-view-id value
|
||||
* @param outcome The to-outcome value
|
||||
*/
|
||||
public NavigationResult(String viewId, String outcome)
|
||||
{
|
||||
if (viewId != null && outcome != null)
|
||||
{
|
||||
throw new IllegalStateException("You can not have both a to-view-id and to-outcome");
|
||||
}
|
||||
|
||||
if (outcome != null)
|
||||
{
|
||||
this.result = outcome;
|
||||
}
|
||||
else if (viewId != null)
|
||||
{
|
||||
this.result = viewId;
|
||||
this.isOutcome = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result
|
||||
*
|
||||
* @return The result
|
||||
*/
|
||||
public String getResult()
|
||||
{
|
||||
return this.result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the result is an outcome
|
||||
*
|
||||
* @return true if the result represents an outcome,
|
||||
* false if it represents a view id
|
||||
*/
|
||||
public boolean isOutcome()
|
||||
{
|
||||
return this.isOutcome;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder(super.toString());
|
||||
buffer.append(" (result=").append(this.result);
|
||||
buffer.append(" isOutcome=").append(this.isOutcome).append(")");
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.config;
|
||||
|
||||
/**
|
||||
* Represents the result of a navigation config result.
|
||||
*
|
||||
* This object holds the string result which can either represent an outcome
|
||||
* or a view id.
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class NavigationResult
|
||||
{
|
||||
private String result;
|
||||
private boolean isOutcome = true;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
* @param viewId The to-view-id value
|
||||
* @param outcome The to-outcome value
|
||||
*/
|
||||
public NavigationResult(String viewId, String outcome)
|
||||
{
|
||||
if (viewId != null && outcome != null)
|
||||
{
|
||||
throw new IllegalStateException("You can not have both a to-view-id and to-outcome");
|
||||
}
|
||||
|
||||
if (outcome != null)
|
||||
{
|
||||
this.result = outcome;
|
||||
}
|
||||
else if (viewId != null)
|
||||
{
|
||||
this.result = viewId;
|
||||
this.isOutcome = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result
|
||||
*
|
||||
* @return The result
|
||||
*/
|
||||
public String getResult()
|
||||
{
|
||||
return this.result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the result is an outcome
|
||||
*
|
||||
* @return true if the result represents an outcome,
|
||||
* false if it represents a view id
|
||||
*/
|
||||
public boolean isOutcome()
|
||||
{
|
||||
return this.isOutcome;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder(super.toString());
|
||||
buffer.append(" (result=").append(this.result);
|
||||
buffer.append(" isOutcome=").append(this.isOutcome).append(")");
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
@@ -1,353 +1,353 @@
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.element.ConfigElementAdapter;
|
||||
|
||||
/**
|
||||
* Custom config element that represents config values for views in the client
|
||||
*
|
||||
* @author Gavin Cornwell
|
||||
*/
|
||||
public class ViewsConfigElement extends ConfigElementAdapter implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -503735723795178986L;
|
||||
|
||||
public static final String CONFIG_ELEMENT_ID = "views";
|
||||
|
||||
public static final String VIEW_DETAILS = "details";
|
||||
public static final String VIEW_ICONS = "icons";
|
||||
public static final String VIEW_LIST = "list";
|
||||
public static final String VIEW_BUBBLE = "bubble";
|
||||
public static final String SORT_ASCENDING = "ascending";
|
||||
public static final String SORT_DESCENDING = "descending";
|
||||
|
||||
private static final String SEPARATOR = ":";
|
||||
|
||||
// defaults
|
||||
private int defaultPageSize = 10;
|
||||
private String defaultView = "details";
|
||||
private String defaultSortColumn = "name";
|
||||
|
||||
// list to store all the configured views
|
||||
private List<String> views = new ArrayList<String>(4);
|
||||
|
||||
// map to store all the default views
|
||||
private Map<String, String> defaultViews = new HashMap<String, String>(4);
|
||||
|
||||
// map to store all default page sizes for configured client views
|
||||
private Map<String, Integer> pageSizes = new HashMap<String, Integer>(10);
|
||||
|
||||
// map to store default sort columns for configured views
|
||||
private Map<String, String> sortColumns = new HashMap<String, String>(4);
|
||||
|
||||
// list of pages that have been configured to have ascending sorts
|
||||
private Map<String, String> sortDirections = new HashMap<String, String>(1);
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
public ViewsConfigElement()
|
||||
{
|
||||
super(CONFIG_ELEMENT_ID);
|
||||
|
||||
// add the default page sizes to the map
|
||||
this.pageSizes.put(VIEW_DETAILS, defaultPageSize);
|
||||
this.pageSizes.put(VIEW_LIST, defaultPageSize);
|
||||
this.pageSizes.put(VIEW_ICONS, 9);
|
||||
this.pageSizes.put(VIEW_BUBBLE, 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param name Name of the element this config element represents
|
||||
*/
|
||||
public ViewsConfigElement(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#getChildren()
|
||||
*/
|
||||
@Override
|
||||
public List<ConfigElement> getChildren()
|
||||
{
|
||||
throw new ConfigException("Reading the views config via the generic interfaces is not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#combine(org.springframework.extensions.config.ConfigElement)
|
||||
*/
|
||||
public ConfigElement combine(ConfigElement configElement)
|
||||
{
|
||||
ViewsConfigElement newElement = (ViewsConfigElement)configElement;
|
||||
ViewsConfigElement combinedElement = new ViewsConfigElement();
|
||||
|
||||
// copy all the config from this element into the new one
|
||||
for (String viewImpl : this.views)
|
||||
{
|
||||
combinedElement.addView(viewImpl);
|
||||
}
|
||||
|
||||
for (String page : this.defaultViews.keySet())
|
||||
{
|
||||
combinedElement.addDefaultView(page, this.defaultViews.get(page));
|
||||
}
|
||||
|
||||
for (String pageView : this.pageSizes.keySet())
|
||||
{
|
||||
if (pageView.indexOf(SEPARATOR) != -1)
|
||||
{
|
||||
String page = pageView.substring(0, pageView.indexOf(SEPARATOR));
|
||||
String view = pageView.substring(pageView.indexOf(SEPARATOR)+1);
|
||||
combinedElement.addDefaultPageSize(page, view, this.pageSizes.get(pageView).intValue());
|
||||
}
|
||||
}
|
||||
|
||||
for (String page : this.sortColumns.keySet())
|
||||
{
|
||||
combinedElement.addDefaultSortColumn(page, this.sortColumns.get(page));
|
||||
}
|
||||
|
||||
for (String page : this.sortDirections.keySet())
|
||||
{
|
||||
combinedElement.addSortDirection(page, this.sortDirections.get(page));
|
||||
}
|
||||
|
||||
// copy all the config from the element to be combined into the new one
|
||||
for (String viewImpl : newElement.getViews())
|
||||
{
|
||||
combinedElement.addView(viewImpl);
|
||||
}
|
||||
|
||||
Map<String, String> newDefaultViews = newElement.getDefaultViews();
|
||||
for (String page : newDefaultViews.keySet())
|
||||
{
|
||||
combinedElement.addDefaultView(page, newDefaultViews.get(page));
|
||||
}
|
||||
|
||||
Map<String, Integer> newPageSizes = newElement.getDefaultPageSizes();
|
||||
for (String pageView : newPageSizes.keySet())
|
||||
{
|
||||
if (pageView.indexOf(SEPARATOR) != -1)
|
||||
{
|
||||
String page = pageView.substring(0, pageView.indexOf(SEPARATOR));
|
||||
String view = pageView.substring(pageView.indexOf(SEPARATOR)+1);
|
||||
combinedElement.addDefaultPageSize(page, view, newPageSizes.get(pageView).intValue());
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, String> newSortColumns = newElement.getDefaultSortColumns();
|
||||
for (String page : newSortColumns.keySet())
|
||||
{
|
||||
combinedElement.addDefaultSortColumn(page, newSortColumns.get(page));
|
||||
}
|
||||
|
||||
Map<String, String> existingSortDirs = newElement.getSortDirections();
|
||||
for (String page : existingSortDirs.keySet())
|
||||
{
|
||||
combinedElement.addSortDirection(page, existingSortDirs.get(page));
|
||||
}
|
||||
|
||||
return combinedElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a configured view
|
||||
*
|
||||
* @param renderer The implementation class of the view (the renderer)
|
||||
*/
|
||||
/*package*/ void addView(String renderer)
|
||||
{
|
||||
this.views.add(renderer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of configured views for the client
|
||||
*
|
||||
* @return List of the implementation classes for the configured views
|
||||
*/
|
||||
public List<String> getViews()
|
||||
{
|
||||
return this.views;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a default view setting
|
||||
*
|
||||
* @param page The page to set the default view for
|
||||
* @param view The view name that will be the default
|
||||
*/
|
||||
/*package*/ void addDefaultView(String page, String view)
|
||||
{
|
||||
this.defaultViews.put(page, view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default view for the given page
|
||||
*
|
||||
* @param page The page to get the default view for
|
||||
* @return The defualt view, if there isn't a configured default for the
|
||||
* given page 'details' will be returned
|
||||
*/
|
||||
public String getDefaultView(String page)
|
||||
{
|
||||
String view = this.defaultViews.get(page);
|
||||
|
||||
if (view == null)
|
||||
{
|
||||
view = this.defaultView;
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of default views for each page
|
||||
*
|
||||
* @return Map of default views
|
||||
*/
|
||||
/*package*/ Map<String, String> getDefaultViews()
|
||||
{
|
||||
return this.defaultViews;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a configured page size to the internal store
|
||||
*
|
||||
* @param page The name of the page i.e. browse, forums etc.
|
||||
* @param view The name of the view the size is for i.e. details, icons etc.
|
||||
* @param size The size of the page
|
||||
*/
|
||||
/*package*/ void addDefaultPageSize(String page, String view, int size)
|
||||
{
|
||||
this.pageSizes.put(page + SEPARATOR + view, new Integer(size));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the page size for the given page and view combination
|
||||
*
|
||||
* @param page The name of the page i.e. browse, forums etc.
|
||||
* @param view The name of the view the size is for i.e. details, icons etc.
|
||||
* @return The size of the requested page, if the combination doesn't exist
|
||||
* the default for the view will be used, if the view doesn't exist either
|
||||
* 10 will be returned.
|
||||
*/
|
||||
public int getDefaultPageSize(String page, String view)
|
||||
{
|
||||
Integer pageSize = this.pageSizes.get(page + SEPARATOR + view);
|
||||
|
||||
// try just the view if the combination isn't present
|
||||
if (pageSize == null)
|
||||
{
|
||||
pageSize = this.pageSizes.get(view);
|
||||
|
||||
// if the view is not present either default to 10
|
||||
if (pageSize == null)
|
||||
{
|
||||
pageSize = new Integer(10);
|
||||
}
|
||||
}
|
||||
|
||||
return pageSize.intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of page sizes
|
||||
*
|
||||
* @return Map of page sizes
|
||||
*/
|
||||
/*package*/ Map<String, Integer> getDefaultPageSizes()
|
||||
{
|
||||
return this.pageSizes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a default sorting column for the given page
|
||||
*
|
||||
* @param page The name of the page i.e. browse, forums etc.
|
||||
* @param column The name of the column to initially sort by
|
||||
*/
|
||||
/*package*/ void addDefaultSortColumn(String page, String column)
|
||||
{
|
||||
this.sortColumns.put(page, column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default sort column for the given page
|
||||
*
|
||||
* @param page The name of the page i.e. browse, forums etc.
|
||||
* @return The name of the column to sort by, name is returned if
|
||||
* the page is not found
|
||||
*/
|
||||
public String getDefaultSortColumn(String page)
|
||||
{
|
||||
String column = this.sortColumns.get(page);
|
||||
|
||||
if (column == null)
|
||||
{
|
||||
column = this.defaultSortColumn;
|
||||
}
|
||||
|
||||
return column;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of the sorted columns for each page
|
||||
*
|
||||
* @return Map of sort columns
|
||||
*/
|
||||
/*package*/ Map<String, String> getDefaultSortColumns()
|
||||
{
|
||||
return this.sortColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given page as using the given sort direction
|
||||
*
|
||||
* @param page The name of the page i.e. browse, forums etc.
|
||||
* @param dir The sort direction
|
||||
*/
|
||||
/*package*/ void addSortDirection(String page, String dir)
|
||||
{
|
||||
this.sortDirections.put(page, dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the given page has been
|
||||
* configured to use descending sorting by default
|
||||
*
|
||||
* @param page The name of the page i.e. browse, forums etc.
|
||||
* @return true if the page should use descending sorts
|
||||
*/
|
||||
public boolean hasDescendingSort(String page)
|
||||
{
|
||||
boolean usesDescendingSort = false;
|
||||
|
||||
String sortDir = this.sortDirections.get(page);
|
||||
if (sortDir != null && sortDir.equalsIgnoreCase(SORT_DESCENDING))
|
||||
{
|
||||
usesDescendingSort = true;
|
||||
}
|
||||
|
||||
return usesDescendingSort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of the sort directions
|
||||
*
|
||||
* @return Map of sort directions
|
||||
*/
|
||||
/*package*/ Map<String, String> getSortDirections()
|
||||
{
|
||||
return this.sortDirections;
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.element.ConfigElementAdapter;
|
||||
|
||||
/**
|
||||
* Custom config element that represents config values for views in the client
|
||||
*
|
||||
* @author Gavin Cornwell
|
||||
*/
|
||||
public class ViewsConfigElement extends ConfigElementAdapter implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -503735723795178986L;
|
||||
|
||||
public static final String CONFIG_ELEMENT_ID = "views";
|
||||
|
||||
public static final String VIEW_DETAILS = "details";
|
||||
public static final String VIEW_ICONS = "icons";
|
||||
public static final String VIEW_LIST = "list";
|
||||
public static final String VIEW_BUBBLE = "bubble";
|
||||
public static final String SORT_ASCENDING = "ascending";
|
||||
public static final String SORT_DESCENDING = "descending";
|
||||
|
||||
private static final String SEPARATOR = ":";
|
||||
|
||||
// defaults
|
||||
private int defaultPageSize = 10;
|
||||
private String defaultView = "details";
|
||||
private String defaultSortColumn = "name";
|
||||
|
||||
// list to store all the configured views
|
||||
private List<String> views = new ArrayList<String>(4);
|
||||
|
||||
// map to store all the default views
|
||||
private Map<String, String> defaultViews = new HashMap<String, String>(4);
|
||||
|
||||
// map to store all default page sizes for configured client views
|
||||
private Map<String, Integer> pageSizes = new HashMap<String, Integer>(10);
|
||||
|
||||
// map to store default sort columns for configured views
|
||||
private Map<String, String> sortColumns = new HashMap<String, String>(4);
|
||||
|
||||
// list of pages that have been configured to have ascending sorts
|
||||
private Map<String, String> sortDirections = new HashMap<String, String>(1);
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
public ViewsConfigElement()
|
||||
{
|
||||
super(CONFIG_ELEMENT_ID);
|
||||
|
||||
// add the default page sizes to the map
|
||||
this.pageSizes.put(VIEW_DETAILS, defaultPageSize);
|
||||
this.pageSizes.put(VIEW_LIST, defaultPageSize);
|
||||
this.pageSizes.put(VIEW_ICONS, 9);
|
||||
this.pageSizes.put(VIEW_BUBBLE, 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param name Name of the element this config element represents
|
||||
*/
|
||||
public ViewsConfigElement(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#getChildren()
|
||||
*/
|
||||
@Override
|
||||
public List<ConfigElement> getChildren()
|
||||
{
|
||||
throw new ConfigException("Reading the views config via the generic interfaces is not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.element.ConfigElementAdapter#combine(org.springframework.extensions.config.ConfigElement)
|
||||
*/
|
||||
public ConfigElement combine(ConfigElement configElement)
|
||||
{
|
||||
ViewsConfigElement newElement = (ViewsConfigElement)configElement;
|
||||
ViewsConfigElement combinedElement = new ViewsConfigElement();
|
||||
|
||||
// copy all the config from this element into the new one
|
||||
for (String viewImpl : this.views)
|
||||
{
|
||||
combinedElement.addView(viewImpl);
|
||||
}
|
||||
|
||||
for (String page : this.defaultViews.keySet())
|
||||
{
|
||||
combinedElement.addDefaultView(page, this.defaultViews.get(page));
|
||||
}
|
||||
|
||||
for (String pageView : this.pageSizes.keySet())
|
||||
{
|
||||
if (pageView.indexOf(SEPARATOR) != -1)
|
||||
{
|
||||
String page = pageView.substring(0, pageView.indexOf(SEPARATOR));
|
||||
String view = pageView.substring(pageView.indexOf(SEPARATOR)+1);
|
||||
combinedElement.addDefaultPageSize(page, view, this.pageSizes.get(pageView).intValue());
|
||||
}
|
||||
}
|
||||
|
||||
for (String page : this.sortColumns.keySet())
|
||||
{
|
||||
combinedElement.addDefaultSortColumn(page, this.sortColumns.get(page));
|
||||
}
|
||||
|
||||
for (String page : this.sortDirections.keySet())
|
||||
{
|
||||
combinedElement.addSortDirection(page, this.sortDirections.get(page));
|
||||
}
|
||||
|
||||
// copy all the config from the element to be combined into the new one
|
||||
for (String viewImpl : newElement.getViews())
|
||||
{
|
||||
combinedElement.addView(viewImpl);
|
||||
}
|
||||
|
||||
Map<String, String> newDefaultViews = newElement.getDefaultViews();
|
||||
for (String page : newDefaultViews.keySet())
|
||||
{
|
||||
combinedElement.addDefaultView(page, newDefaultViews.get(page));
|
||||
}
|
||||
|
||||
Map<String, Integer> newPageSizes = newElement.getDefaultPageSizes();
|
||||
for (String pageView : newPageSizes.keySet())
|
||||
{
|
||||
if (pageView.indexOf(SEPARATOR) != -1)
|
||||
{
|
||||
String page = pageView.substring(0, pageView.indexOf(SEPARATOR));
|
||||
String view = pageView.substring(pageView.indexOf(SEPARATOR)+1);
|
||||
combinedElement.addDefaultPageSize(page, view, newPageSizes.get(pageView).intValue());
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, String> newSortColumns = newElement.getDefaultSortColumns();
|
||||
for (String page : newSortColumns.keySet())
|
||||
{
|
||||
combinedElement.addDefaultSortColumn(page, newSortColumns.get(page));
|
||||
}
|
||||
|
||||
Map<String, String> existingSortDirs = newElement.getSortDirections();
|
||||
for (String page : existingSortDirs.keySet())
|
||||
{
|
||||
combinedElement.addSortDirection(page, existingSortDirs.get(page));
|
||||
}
|
||||
|
||||
return combinedElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a configured view
|
||||
*
|
||||
* @param renderer The implementation class of the view (the renderer)
|
||||
*/
|
||||
/*package*/ void addView(String renderer)
|
||||
{
|
||||
this.views.add(renderer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of configured views for the client
|
||||
*
|
||||
* @return List of the implementation classes for the configured views
|
||||
*/
|
||||
public List<String> getViews()
|
||||
{
|
||||
return this.views;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a default view setting
|
||||
*
|
||||
* @param page The page to set the default view for
|
||||
* @param view The view name that will be the default
|
||||
*/
|
||||
/*package*/ void addDefaultView(String page, String view)
|
||||
{
|
||||
this.defaultViews.put(page, view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default view for the given page
|
||||
*
|
||||
* @param page The page to get the default view for
|
||||
* @return The defualt view, if there isn't a configured default for the
|
||||
* given page 'details' will be returned
|
||||
*/
|
||||
public String getDefaultView(String page)
|
||||
{
|
||||
String view = this.defaultViews.get(page);
|
||||
|
||||
if (view == null)
|
||||
{
|
||||
view = this.defaultView;
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of default views for each page
|
||||
*
|
||||
* @return Map of default views
|
||||
*/
|
||||
/*package*/ Map<String, String> getDefaultViews()
|
||||
{
|
||||
return this.defaultViews;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a configured page size to the internal store
|
||||
*
|
||||
* @param page The name of the page i.e. browse, forums etc.
|
||||
* @param view The name of the view the size is for i.e. details, icons etc.
|
||||
* @param size The size of the page
|
||||
*/
|
||||
/*package*/ void addDefaultPageSize(String page, String view, int size)
|
||||
{
|
||||
this.pageSizes.put(page + SEPARATOR + view, new Integer(size));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the page size for the given page and view combination
|
||||
*
|
||||
* @param page The name of the page i.e. browse, forums etc.
|
||||
* @param view The name of the view the size is for i.e. details, icons etc.
|
||||
* @return The size of the requested page, if the combination doesn't exist
|
||||
* the default for the view will be used, if the view doesn't exist either
|
||||
* 10 will be returned.
|
||||
*/
|
||||
public int getDefaultPageSize(String page, String view)
|
||||
{
|
||||
Integer pageSize = this.pageSizes.get(page + SEPARATOR + view);
|
||||
|
||||
// try just the view if the combination isn't present
|
||||
if (pageSize == null)
|
||||
{
|
||||
pageSize = this.pageSizes.get(view);
|
||||
|
||||
// if the view is not present either default to 10
|
||||
if (pageSize == null)
|
||||
{
|
||||
pageSize = new Integer(10);
|
||||
}
|
||||
}
|
||||
|
||||
return pageSize.intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of page sizes
|
||||
*
|
||||
* @return Map of page sizes
|
||||
*/
|
||||
/*package*/ Map<String, Integer> getDefaultPageSizes()
|
||||
{
|
||||
return this.pageSizes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a default sorting column for the given page
|
||||
*
|
||||
* @param page The name of the page i.e. browse, forums etc.
|
||||
* @param column The name of the column to initially sort by
|
||||
*/
|
||||
/*package*/ void addDefaultSortColumn(String page, String column)
|
||||
{
|
||||
this.sortColumns.put(page, column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default sort column for the given page
|
||||
*
|
||||
* @param page The name of the page i.e. browse, forums etc.
|
||||
* @return The name of the column to sort by, name is returned if
|
||||
* the page is not found
|
||||
*/
|
||||
public String getDefaultSortColumn(String page)
|
||||
{
|
||||
String column = this.sortColumns.get(page);
|
||||
|
||||
if (column == null)
|
||||
{
|
||||
column = this.defaultSortColumn;
|
||||
}
|
||||
|
||||
return column;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of the sorted columns for each page
|
||||
*
|
||||
* @return Map of sort columns
|
||||
*/
|
||||
/*package*/ Map<String, String> getDefaultSortColumns()
|
||||
{
|
||||
return this.sortColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given page as using the given sort direction
|
||||
*
|
||||
* @param page The name of the page i.e. browse, forums etc.
|
||||
* @param dir The sort direction
|
||||
*/
|
||||
/*package*/ void addSortDirection(String page, String dir)
|
||||
{
|
||||
this.sortDirections.put(page, dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the given page has been
|
||||
* configured to use descending sorting by default
|
||||
*
|
||||
* @param page The name of the page i.e. browse, forums etc.
|
||||
* @return true if the page should use descending sorts
|
||||
*/
|
||||
public boolean hasDescendingSort(String page)
|
||||
{
|
||||
boolean usesDescendingSort = false;
|
||||
|
||||
String sortDir = this.sortDirections.get(page);
|
||||
if (sortDir != null && sortDir.equalsIgnoreCase(SORT_DESCENDING))
|
||||
{
|
||||
usesDescendingSort = true;
|
||||
}
|
||||
|
||||
return usesDescendingSort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of the sort directions
|
||||
*
|
||||
* @return Map of sort directions
|
||||
*/
|
||||
/*package*/ Map<String, String> getSortDirections()
|
||||
{
|
||||
return this.sortDirections;
|
||||
}
|
||||
}
|
||||
|
@@ -1,134 +1,134 @@
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.xml.elementreader.ConfigElementReader;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* Custom element reader to parse config for client views
|
||||
*
|
||||
* @author Gavin Cornwell
|
||||
*/
|
||||
public class ViewsElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ELEMENT_VIEW = "view";
|
||||
public static final String ELEMENT_VIEWIMPL = "view-impl";
|
||||
public static final String ELEMENT_VIEWDEFAULTS = "view-defaults";
|
||||
public static final String ELEMENT_PAGESIZE = "page-size";
|
||||
public static final String ELEMENT_SORTCOLUMN = "sort-column";
|
||||
public static final String ELEMENT_SORTDIRECTION = "sort-direction";
|
||||
|
||||
private static Log logger = LogFactory.getLog(ViewsElementReader.class);
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
ViewsConfigElement configElement = null;
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
String name = element.getName();
|
||||
if (name.equals(ViewsConfigElement.CONFIG_ELEMENT_ID) == false)
|
||||
{
|
||||
throw new ConfigException("ViewsElementReader can only parse " +
|
||||
ViewsConfigElement.CONFIG_ELEMENT_ID + " elements, the element passed was '" +
|
||||
name + "'");
|
||||
}
|
||||
|
||||
configElement = new ViewsConfigElement();
|
||||
|
||||
// get the configured views
|
||||
Iterator<Element> renderers = element.elementIterator(ELEMENT_VIEWIMPL);
|
||||
while (renderers.hasNext())
|
||||
{
|
||||
Element renderer = renderers.next();
|
||||
configElement.addView(renderer.getTextTrim());
|
||||
}
|
||||
|
||||
// get all the view related default settings
|
||||
Element viewDefaults = element.element(ELEMENT_VIEWDEFAULTS);
|
||||
if (viewDefaults != null)
|
||||
{
|
||||
Iterator<Element> pages = viewDefaults.elementIterator();
|
||||
while (pages.hasNext())
|
||||
{
|
||||
Element page = pages.next();
|
||||
String pageName = page.getName();
|
||||
|
||||
// get the default view mode for the page
|
||||
Element defaultView = page.element(ELEMENT_VIEW);
|
||||
if (defaultView != null)
|
||||
{
|
||||
String viewName = defaultView.getTextTrim();
|
||||
configElement.addDefaultView(pageName, viewName);
|
||||
}
|
||||
|
||||
// get the initial sort column
|
||||
Element sortColumn = page.element(ELEMENT_SORTCOLUMN);
|
||||
if (sortColumn != null)
|
||||
{
|
||||
String column = sortColumn.getTextTrim();
|
||||
configElement.addDefaultSortColumn(pageName, column);
|
||||
}
|
||||
|
||||
// get the sort direction option
|
||||
Element sortDir = page.element(ELEMENT_SORTDIRECTION);
|
||||
if (sortDir != null)
|
||||
{
|
||||
configElement.addSortDirection(pageName, sortDir.getTextTrim());
|
||||
}
|
||||
|
||||
// process the page-size element
|
||||
processPageSizeElement(page.element(ELEMENT_PAGESIZE),
|
||||
pageName, configElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return configElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a page-size element
|
||||
*
|
||||
* @param pageSizeElement The element to process
|
||||
* @param page The page the page-size element belongs to
|
||||
* @param configElement The config element being populated
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void processPageSizeElement(Element pageSizeElement, String page,
|
||||
ViewsConfigElement configElement)
|
||||
{
|
||||
if (pageSizeElement != null)
|
||||
{
|
||||
Iterator<Element> views = pageSizeElement.elementIterator();
|
||||
while (views.hasNext())
|
||||
{
|
||||
Element view = views.next();
|
||||
String viewName = view.getName();
|
||||
String pageSize = view.getTextTrim();
|
||||
try
|
||||
{
|
||||
configElement.addDefaultPageSize(page, viewName, Integer.parseInt(pageSize));
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("Failed to set page size for view '" + viewName +
|
||||
"' in page '" + page + "' as '" + pageSize +
|
||||
"' is an invalid number!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.xml.elementreader.ConfigElementReader;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* Custom element reader to parse config for client views
|
||||
*
|
||||
* @author Gavin Cornwell
|
||||
*/
|
||||
public class ViewsElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ELEMENT_VIEW = "view";
|
||||
public static final String ELEMENT_VIEWIMPL = "view-impl";
|
||||
public static final String ELEMENT_VIEWDEFAULTS = "view-defaults";
|
||||
public static final String ELEMENT_PAGESIZE = "page-size";
|
||||
public static final String ELEMENT_SORTCOLUMN = "sort-column";
|
||||
public static final String ELEMENT_SORTDIRECTION = "sort-direction";
|
||||
|
||||
private static Log logger = LogFactory.getLog(ViewsElementReader.class);
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
ViewsConfigElement configElement = null;
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
String name = element.getName();
|
||||
if (name.equals(ViewsConfigElement.CONFIG_ELEMENT_ID) == false)
|
||||
{
|
||||
throw new ConfigException("ViewsElementReader can only parse " +
|
||||
ViewsConfigElement.CONFIG_ELEMENT_ID + " elements, the element passed was '" +
|
||||
name + "'");
|
||||
}
|
||||
|
||||
configElement = new ViewsConfigElement();
|
||||
|
||||
// get the configured views
|
||||
Iterator<Element> renderers = element.elementIterator(ELEMENT_VIEWIMPL);
|
||||
while (renderers.hasNext())
|
||||
{
|
||||
Element renderer = renderers.next();
|
||||
configElement.addView(renderer.getTextTrim());
|
||||
}
|
||||
|
||||
// get all the view related default settings
|
||||
Element viewDefaults = element.element(ELEMENT_VIEWDEFAULTS);
|
||||
if (viewDefaults != null)
|
||||
{
|
||||
Iterator<Element> pages = viewDefaults.elementIterator();
|
||||
while (pages.hasNext())
|
||||
{
|
||||
Element page = pages.next();
|
||||
String pageName = page.getName();
|
||||
|
||||
// get the default view mode for the page
|
||||
Element defaultView = page.element(ELEMENT_VIEW);
|
||||
if (defaultView != null)
|
||||
{
|
||||
String viewName = defaultView.getTextTrim();
|
||||
configElement.addDefaultView(pageName, viewName);
|
||||
}
|
||||
|
||||
// get the initial sort column
|
||||
Element sortColumn = page.element(ELEMENT_SORTCOLUMN);
|
||||
if (sortColumn != null)
|
||||
{
|
||||
String column = sortColumn.getTextTrim();
|
||||
configElement.addDefaultSortColumn(pageName, column);
|
||||
}
|
||||
|
||||
// get the sort direction option
|
||||
Element sortDir = page.element(ELEMENT_SORTDIRECTION);
|
||||
if (sortDir != null)
|
||||
{
|
||||
configElement.addSortDirection(pageName, sortDir.getTextTrim());
|
||||
}
|
||||
|
||||
// process the page-size element
|
||||
processPageSizeElement(page.element(ELEMENT_PAGESIZE),
|
||||
pageName, configElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return configElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a page-size element
|
||||
*
|
||||
* @param pageSizeElement The element to process
|
||||
* @param page The page the page-size element belongs to
|
||||
* @param configElement The config element being populated
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void processPageSizeElement(Element pageSizeElement, String page,
|
||||
ViewsConfigElement configElement)
|
||||
{
|
||||
if (pageSizeElement != null)
|
||||
{
|
||||
Iterator<Element> views = pageSizeElement.elementIterator();
|
||||
while (views.hasNext())
|
||||
{
|
||||
Element view = views.next();
|
||||
String viewName = view.getName();
|
||||
String pageSize = view.getTextTrim();
|
||||
try
|
||||
{
|
||||
configElement.addDefaultPageSize(page, viewName, Integer.parseInt(pageSize));
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("Failed to set page size for view '" + viewName +
|
||||
"' in page '" + page + "' as '" + pageSize +
|
||||
"' is an invalid number!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,458 +1,458 @@
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.element.ConfigElementAdapter;
|
||||
import org.springframework.extensions.surf.util.ParameterCheck;
|
||||
|
||||
/**
|
||||
* Custom config element that represents the config data for a property sheet
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class WizardsConfigElement extends ConfigElementAdapter
|
||||
{
|
||||
public static final String CONFIG_ELEMENT_ID = "wizards";
|
||||
|
||||
private Map<String, WizardConfig> wizards = new LinkedHashMap<String, WizardConfig>(8, 10f);
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public WizardsConfigElement()
|
||||
{
|
||||
super(CONFIG_ELEMENT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param name Name of the element this config element represents
|
||||
*/
|
||||
public WizardsConfigElement(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ConfigElement#getChildren()
|
||||
*/
|
||||
public List<ConfigElement> getChildren()
|
||||
{
|
||||
throw new ConfigException("Reading the wizards config via the generic interfaces is not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ConfigElement#combine(org.springframework.extensions.config.ConfigElement)
|
||||
*/
|
||||
public ConfigElement combine(ConfigElement configElement)
|
||||
{
|
||||
WizardsConfigElement combined = new WizardsConfigElement();
|
||||
|
||||
// add all the wizards from this element
|
||||
for (WizardConfig wizard : this.getWizards().values())
|
||||
{
|
||||
combined.addWizard(wizard);
|
||||
}
|
||||
|
||||
// add all the wizards from the given element
|
||||
for (WizardConfig wizard : ((WizardsConfigElement)configElement).getWizards().values())
|
||||
{
|
||||
combined.addWizard(wizard);
|
||||
}
|
||||
|
||||
return combined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the named wizard
|
||||
*
|
||||
* @param name The name of the wizard to retrieve
|
||||
* @return The WizardConfig object for the requested wizard or null if it doesn't exist
|
||||
*/
|
||||
public WizardConfig getWizard(String name)
|
||||
{
|
||||
return this.wizards.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns a map of the wizards
|
||||
*/
|
||||
public Map<String, WizardConfig> getWizards()
|
||||
{
|
||||
return this.wizards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a wizard
|
||||
*
|
||||
* @param wizardConfig A pre-configured wizard config object
|
||||
*/
|
||||
/*package*/ void addWizard(WizardConfig wizardConfig)
|
||||
{
|
||||
this.wizards.put(wizardConfig.getName(), wizardConfig);
|
||||
}
|
||||
|
||||
public abstract static class AbstractConfig implements Serializable
|
||||
{
|
||||
protected String title;
|
||||
protected String titleId;
|
||||
protected String description;
|
||||
protected String descriptionId;
|
||||
|
||||
|
||||
|
||||
protected AbstractConfig()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public AbstractConfig(String title, String titleId,
|
||||
String description, String descriptionId)
|
||||
{
|
||||
this.title = title;
|
||||
this.titleId = titleId;
|
||||
this.description = description;
|
||||
this.descriptionId = descriptionId;
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public String getDescriptionId()
|
||||
{
|
||||
return this.descriptionId;
|
||||
}
|
||||
|
||||
public String getTitle()
|
||||
{
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public String getTitleId()
|
||||
{
|
||||
return this.titleId;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the configuration of a single wizard i.e. the <wizard> element
|
||||
*/
|
||||
public static class WizardConfig extends AbstractConfig implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -3377339374041580932L;
|
||||
|
||||
protected String subTitle;
|
||||
protected String subTitleId;
|
||||
protected String name;
|
||||
protected String managedBean;
|
||||
protected String icon;
|
||||
protected String errorMsgId = "error_wizard";
|
||||
|
||||
protected Map<String, StepConfig> steps = new LinkedHashMap<String, StepConfig>(4);
|
||||
|
||||
protected WizardConfig()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public WizardConfig(String name, String bean, String icon,
|
||||
String title, String titleId,
|
||||
String subTitle, String subTitleId,
|
||||
String description, String descriptionId,
|
||||
String errorMsgId)
|
||||
{
|
||||
super(title, titleId, description, descriptionId);
|
||||
|
||||
// check we have a name
|
||||
ParameterCheck.mandatoryString("name", name);
|
||||
|
||||
this.subTitle = subTitle;
|
||||
this.subTitleId = subTitleId;
|
||||
this.name = name;
|
||||
this.managedBean = bean;
|
||||
this.icon = icon;
|
||||
|
||||
if (errorMsgId != null && errorMsgId.length() > 0)
|
||||
{
|
||||
this.errorMsgId = errorMsgId;
|
||||
}
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getManagedBean()
|
||||
{
|
||||
return this.managedBean;
|
||||
}
|
||||
|
||||
public String getSubTitle()
|
||||
{
|
||||
return this.subTitle;
|
||||
}
|
||||
|
||||
public String getSubTitleId()
|
||||
{
|
||||
return this.subTitleId;
|
||||
}
|
||||
|
||||
public String getIcon()
|
||||
{
|
||||
return this.icon;
|
||||
}
|
||||
|
||||
public String getErrorMessageId()
|
||||
{
|
||||
return this.errorMsgId;
|
||||
}
|
||||
|
||||
public int getNumberSteps()
|
||||
{
|
||||
return this.steps.size();
|
||||
}
|
||||
|
||||
public Map<String, StepConfig> getSteps()
|
||||
{
|
||||
return this.steps;
|
||||
}
|
||||
|
||||
public List<StepConfig> getStepsAsList()
|
||||
{
|
||||
List<StepConfig> stepList = new ArrayList<StepConfig>(this.steps.size());
|
||||
|
||||
for (StepConfig stepCfg : this.steps.values())
|
||||
{
|
||||
stepList.add(stepCfg);
|
||||
}
|
||||
|
||||
return stepList;
|
||||
}
|
||||
|
||||
public StepConfig getStepByName(String name)
|
||||
{
|
||||
return this.steps.get(name);
|
||||
}
|
||||
|
||||
/*package*/ void addStep(StepConfig step)
|
||||
{
|
||||
this.steps.put(step.getName(), step);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder(super.toString());
|
||||
buffer.append(" (name=").append(this.name);
|
||||
buffer.append(" managed-bean=").append(this.managedBean);
|
||||
buffer.append(" icon=").append(this.icon);
|
||||
buffer.append(" title=").append(this.title);
|
||||
buffer.append(" titleId=").append(this.titleId);
|
||||
buffer.append(" subTitle=").append(this.subTitle);
|
||||
buffer.append(" subTitleId=").append(this.subTitleId);
|
||||
buffer.append(" description=").append(this.description);
|
||||
buffer.append(" descriptionId=").append(this.descriptionId);
|
||||
buffer.append(" errorMsgId=").append(this.errorMsgId).append(")");
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the configuration of a page in a wizard i.e. the <page> element
|
||||
*/
|
||||
public static class PageConfig extends AbstractConfig implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 4154515148190230391L;
|
||||
|
||||
protected String path;
|
||||
protected String instruction;
|
||||
protected String instructionId;
|
||||
|
||||
public PageConfig(String path,
|
||||
String title, String titleId,
|
||||
String description, String descriptionId,
|
||||
String instruction, String instructionId)
|
||||
{
|
||||
super(title, titleId, description, descriptionId);
|
||||
|
||||
// check we have a path
|
||||
ParameterCheck.mandatoryString("path", path);
|
||||
|
||||
this.path = path;
|
||||
this.instruction = instruction;
|
||||
this.instructionId = instructionId;
|
||||
}
|
||||
|
||||
public String getPath()
|
||||
{
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public String getInstruction()
|
||||
{
|
||||
return this.instruction;
|
||||
}
|
||||
|
||||
public String getInstructionId()
|
||||
{
|
||||
return this.instructionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder(super.toString());
|
||||
buffer.append(" (path=").append(this.path);
|
||||
buffer.append(" title=").append(this.title);
|
||||
buffer.append(" titleId=").append(this.titleId);
|
||||
buffer.append(" description=").append(this.description);
|
||||
buffer.append(" descriptionId=").append(this.descriptionId);
|
||||
buffer.append(" instruction=").append(this.instruction);
|
||||
buffer.append(" instructionId=").append(this.instructionId).append(")");
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the configuration of a conditional page in a wizard
|
||||
* i.e. a <page> element that is placed within a <condition>
|
||||
* element.
|
||||
*/
|
||||
public static class ConditionalPageConfig extends PageConfig
|
||||
{
|
||||
private static final long serialVersionUID = -3398913681170199314L;
|
||||
|
||||
protected String condition;
|
||||
|
||||
public ConditionalPageConfig(String path, String condition,
|
||||
String title, String titleId,
|
||||
String description, String descriptionId,
|
||||
String instruction, String instructionId)
|
||||
{
|
||||
super(path, title, titleId, description, descriptionId, instruction, instructionId);
|
||||
|
||||
// check we have a path
|
||||
ParameterCheck.mandatoryString("condition", condition);
|
||||
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
public String getCondition()
|
||||
{
|
||||
return this.condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder(super.toString());
|
||||
buffer.append(" (path=").append(this.path);
|
||||
buffer.append(" condition=").append(this.condition);
|
||||
buffer.append(" title=").append(this.title);
|
||||
buffer.append(" titleId=").append(this.titleId);
|
||||
buffer.append(" description=").append(this.description);
|
||||
buffer.append(" descriptionId=").append(this.descriptionId);
|
||||
buffer.append(" instruction=").append(this.instruction);
|
||||
buffer.append(" instructionId=").append(this.instructionId).append(")");
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the configuration of a step in a wizard
|
||||
* i.e. the <step> element.
|
||||
*/
|
||||
public static class StepConfig extends AbstractConfig implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -3707570689181455754L;
|
||||
|
||||
protected String name;
|
||||
protected PageConfig defaultPage;
|
||||
protected List<ConditionalPageConfig> conditionalPages =
|
||||
new ArrayList<ConditionalPageConfig>(3);
|
||||
|
||||
public StepConfig(String name,
|
||||
String title, String titleId,
|
||||
String description, String descriptionId)
|
||||
{
|
||||
super(title, titleId, description, descriptionId);
|
||||
|
||||
// check we have a name
|
||||
ParameterCheck.mandatoryString("name", name);
|
||||
|
||||
// check we have a title
|
||||
if (this.title == null && this.titleId == null)
|
||||
{
|
||||
throw new IllegalArgumentException("A title or title-id attribute must be supplied for a step");
|
||||
}
|
||||
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public PageConfig getDefaultPage()
|
||||
{
|
||||
return this.defaultPage;
|
||||
}
|
||||
|
||||
public boolean hasConditionalPages()
|
||||
{
|
||||
return (this.conditionalPages.size() > 0);
|
||||
}
|
||||
|
||||
public List<ConditionalPageConfig> getConditionalPages()
|
||||
{
|
||||
return this.conditionalPages;
|
||||
}
|
||||
|
||||
/*package*/ void addConditionalPage(ConditionalPageConfig conditionalPage)
|
||||
{
|
||||
this.conditionalPages.add(conditionalPage);
|
||||
}
|
||||
|
||||
/*package*/ void setDefaultPage(PageConfig page)
|
||||
{
|
||||
this.defaultPage = page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder(super.toString());
|
||||
buffer.append(" (name=").append(this.name);
|
||||
buffer.append(" title=").append(this.title);
|
||||
buffer.append(" titleId=").append(this.titleId);
|
||||
buffer.append(" description=").append(this.description);
|
||||
buffer.append(" descriptionId=").append(this.descriptionId);
|
||||
buffer.append(" defaultPage=").append(this.defaultPage);
|
||||
buffer.append(" conditionalPages=").append(this.conditionalPages).append(")");
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.element.ConfigElementAdapter;
|
||||
import org.springframework.extensions.surf.util.ParameterCheck;
|
||||
|
||||
/**
|
||||
* Custom config element that represents the config data for a property sheet
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class WizardsConfigElement extends ConfigElementAdapter
|
||||
{
|
||||
public static final String CONFIG_ELEMENT_ID = "wizards";
|
||||
|
||||
private Map<String, WizardConfig> wizards = new LinkedHashMap<String, WizardConfig>(8, 10f);
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public WizardsConfigElement()
|
||||
{
|
||||
super(CONFIG_ELEMENT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param name Name of the element this config element represents
|
||||
*/
|
||||
public WizardsConfigElement(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ConfigElement#getChildren()
|
||||
*/
|
||||
public List<ConfigElement> getChildren()
|
||||
{
|
||||
throw new ConfigException("Reading the wizards config via the generic interfaces is not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ConfigElement#combine(org.springframework.extensions.config.ConfigElement)
|
||||
*/
|
||||
public ConfigElement combine(ConfigElement configElement)
|
||||
{
|
||||
WizardsConfigElement combined = new WizardsConfigElement();
|
||||
|
||||
// add all the wizards from this element
|
||||
for (WizardConfig wizard : this.getWizards().values())
|
||||
{
|
||||
combined.addWizard(wizard);
|
||||
}
|
||||
|
||||
// add all the wizards from the given element
|
||||
for (WizardConfig wizard : ((WizardsConfigElement)configElement).getWizards().values())
|
||||
{
|
||||
combined.addWizard(wizard);
|
||||
}
|
||||
|
||||
return combined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the named wizard
|
||||
*
|
||||
* @param name The name of the wizard to retrieve
|
||||
* @return The WizardConfig object for the requested wizard or null if it doesn't exist
|
||||
*/
|
||||
public WizardConfig getWizard(String name)
|
||||
{
|
||||
return this.wizards.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns a map of the wizards
|
||||
*/
|
||||
public Map<String, WizardConfig> getWizards()
|
||||
{
|
||||
return this.wizards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a wizard
|
||||
*
|
||||
* @param wizardConfig A pre-configured wizard config object
|
||||
*/
|
||||
/*package*/ void addWizard(WizardConfig wizardConfig)
|
||||
{
|
||||
this.wizards.put(wizardConfig.getName(), wizardConfig);
|
||||
}
|
||||
|
||||
public abstract static class AbstractConfig implements Serializable
|
||||
{
|
||||
protected String title;
|
||||
protected String titleId;
|
||||
protected String description;
|
||||
protected String descriptionId;
|
||||
|
||||
|
||||
|
||||
protected AbstractConfig()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public AbstractConfig(String title, String titleId,
|
||||
String description, String descriptionId)
|
||||
{
|
||||
this.title = title;
|
||||
this.titleId = titleId;
|
||||
this.description = description;
|
||||
this.descriptionId = descriptionId;
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public String getDescriptionId()
|
||||
{
|
||||
return this.descriptionId;
|
||||
}
|
||||
|
||||
public String getTitle()
|
||||
{
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public String getTitleId()
|
||||
{
|
||||
return this.titleId;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the configuration of a single wizard i.e. the <wizard> element
|
||||
*/
|
||||
public static class WizardConfig extends AbstractConfig implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -3377339374041580932L;
|
||||
|
||||
protected String subTitle;
|
||||
protected String subTitleId;
|
||||
protected String name;
|
||||
protected String managedBean;
|
||||
protected String icon;
|
||||
protected String errorMsgId = "error_wizard";
|
||||
|
||||
protected Map<String, StepConfig> steps = new LinkedHashMap<String, StepConfig>(4);
|
||||
|
||||
protected WizardConfig()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public WizardConfig(String name, String bean, String icon,
|
||||
String title, String titleId,
|
||||
String subTitle, String subTitleId,
|
||||
String description, String descriptionId,
|
||||
String errorMsgId)
|
||||
{
|
||||
super(title, titleId, description, descriptionId);
|
||||
|
||||
// check we have a name
|
||||
ParameterCheck.mandatoryString("name", name);
|
||||
|
||||
this.subTitle = subTitle;
|
||||
this.subTitleId = subTitleId;
|
||||
this.name = name;
|
||||
this.managedBean = bean;
|
||||
this.icon = icon;
|
||||
|
||||
if (errorMsgId != null && errorMsgId.length() > 0)
|
||||
{
|
||||
this.errorMsgId = errorMsgId;
|
||||
}
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getManagedBean()
|
||||
{
|
||||
return this.managedBean;
|
||||
}
|
||||
|
||||
public String getSubTitle()
|
||||
{
|
||||
return this.subTitle;
|
||||
}
|
||||
|
||||
public String getSubTitleId()
|
||||
{
|
||||
return this.subTitleId;
|
||||
}
|
||||
|
||||
public String getIcon()
|
||||
{
|
||||
return this.icon;
|
||||
}
|
||||
|
||||
public String getErrorMessageId()
|
||||
{
|
||||
return this.errorMsgId;
|
||||
}
|
||||
|
||||
public int getNumberSteps()
|
||||
{
|
||||
return this.steps.size();
|
||||
}
|
||||
|
||||
public Map<String, StepConfig> getSteps()
|
||||
{
|
||||
return this.steps;
|
||||
}
|
||||
|
||||
public List<StepConfig> getStepsAsList()
|
||||
{
|
||||
List<StepConfig> stepList = new ArrayList<StepConfig>(this.steps.size());
|
||||
|
||||
for (StepConfig stepCfg : this.steps.values())
|
||||
{
|
||||
stepList.add(stepCfg);
|
||||
}
|
||||
|
||||
return stepList;
|
||||
}
|
||||
|
||||
public StepConfig getStepByName(String name)
|
||||
{
|
||||
return this.steps.get(name);
|
||||
}
|
||||
|
||||
/*package*/ void addStep(StepConfig step)
|
||||
{
|
||||
this.steps.put(step.getName(), step);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder(super.toString());
|
||||
buffer.append(" (name=").append(this.name);
|
||||
buffer.append(" managed-bean=").append(this.managedBean);
|
||||
buffer.append(" icon=").append(this.icon);
|
||||
buffer.append(" title=").append(this.title);
|
||||
buffer.append(" titleId=").append(this.titleId);
|
||||
buffer.append(" subTitle=").append(this.subTitle);
|
||||
buffer.append(" subTitleId=").append(this.subTitleId);
|
||||
buffer.append(" description=").append(this.description);
|
||||
buffer.append(" descriptionId=").append(this.descriptionId);
|
||||
buffer.append(" errorMsgId=").append(this.errorMsgId).append(")");
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the configuration of a page in a wizard i.e. the <page> element
|
||||
*/
|
||||
public static class PageConfig extends AbstractConfig implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 4154515148190230391L;
|
||||
|
||||
protected String path;
|
||||
protected String instruction;
|
||||
protected String instructionId;
|
||||
|
||||
public PageConfig(String path,
|
||||
String title, String titleId,
|
||||
String description, String descriptionId,
|
||||
String instruction, String instructionId)
|
||||
{
|
||||
super(title, titleId, description, descriptionId);
|
||||
|
||||
// check we have a path
|
||||
ParameterCheck.mandatoryString("path", path);
|
||||
|
||||
this.path = path;
|
||||
this.instruction = instruction;
|
||||
this.instructionId = instructionId;
|
||||
}
|
||||
|
||||
public String getPath()
|
||||
{
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public String getInstruction()
|
||||
{
|
||||
return this.instruction;
|
||||
}
|
||||
|
||||
public String getInstructionId()
|
||||
{
|
||||
return this.instructionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder(super.toString());
|
||||
buffer.append(" (path=").append(this.path);
|
||||
buffer.append(" title=").append(this.title);
|
||||
buffer.append(" titleId=").append(this.titleId);
|
||||
buffer.append(" description=").append(this.description);
|
||||
buffer.append(" descriptionId=").append(this.descriptionId);
|
||||
buffer.append(" instruction=").append(this.instruction);
|
||||
buffer.append(" instructionId=").append(this.instructionId).append(")");
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the configuration of a conditional page in a wizard
|
||||
* i.e. a <page> element that is placed within a <condition>
|
||||
* element.
|
||||
*/
|
||||
public static class ConditionalPageConfig extends PageConfig
|
||||
{
|
||||
private static final long serialVersionUID = -3398913681170199314L;
|
||||
|
||||
protected String condition;
|
||||
|
||||
public ConditionalPageConfig(String path, String condition,
|
||||
String title, String titleId,
|
||||
String description, String descriptionId,
|
||||
String instruction, String instructionId)
|
||||
{
|
||||
super(path, title, titleId, description, descriptionId, instruction, instructionId);
|
||||
|
||||
// check we have a path
|
||||
ParameterCheck.mandatoryString("condition", condition);
|
||||
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
public String getCondition()
|
||||
{
|
||||
return this.condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder(super.toString());
|
||||
buffer.append(" (path=").append(this.path);
|
||||
buffer.append(" condition=").append(this.condition);
|
||||
buffer.append(" title=").append(this.title);
|
||||
buffer.append(" titleId=").append(this.titleId);
|
||||
buffer.append(" description=").append(this.description);
|
||||
buffer.append(" descriptionId=").append(this.descriptionId);
|
||||
buffer.append(" instruction=").append(this.instruction);
|
||||
buffer.append(" instructionId=").append(this.instructionId).append(")");
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the configuration of a step in a wizard
|
||||
* i.e. the <step> element.
|
||||
*/
|
||||
public static class StepConfig extends AbstractConfig implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -3707570689181455754L;
|
||||
|
||||
protected String name;
|
||||
protected PageConfig defaultPage;
|
||||
protected List<ConditionalPageConfig> conditionalPages =
|
||||
new ArrayList<ConditionalPageConfig>(3);
|
||||
|
||||
public StepConfig(String name,
|
||||
String title, String titleId,
|
||||
String description, String descriptionId)
|
||||
{
|
||||
super(title, titleId, description, descriptionId);
|
||||
|
||||
// check we have a name
|
||||
ParameterCheck.mandatoryString("name", name);
|
||||
|
||||
// check we have a title
|
||||
if (this.title == null && this.titleId == null)
|
||||
{
|
||||
throw new IllegalArgumentException("A title or title-id attribute must be supplied for a step");
|
||||
}
|
||||
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public PageConfig getDefaultPage()
|
||||
{
|
||||
return this.defaultPage;
|
||||
}
|
||||
|
||||
public boolean hasConditionalPages()
|
||||
{
|
||||
return (this.conditionalPages.size() > 0);
|
||||
}
|
||||
|
||||
public List<ConditionalPageConfig> getConditionalPages()
|
||||
{
|
||||
return this.conditionalPages;
|
||||
}
|
||||
|
||||
/*package*/ void addConditionalPage(ConditionalPageConfig conditionalPage)
|
||||
{
|
||||
this.conditionalPages.add(conditionalPage);
|
||||
}
|
||||
|
||||
/*package*/ void setDefaultPage(PageConfig page)
|
||||
{
|
||||
this.defaultPage = page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder(super.toString());
|
||||
buffer.append(" (name=").append(this.name);
|
||||
buffer.append(" title=").append(this.title);
|
||||
buffer.append(" titleId=").append(this.titleId);
|
||||
buffer.append(" description=").append(this.description);
|
||||
buffer.append(" descriptionId=").append(this.descriptionId);
|
||||
buffer.append(" defaultPage=").append(this.defaultPage);
|
||||
buffer.append(" conditionalPages=").append(this.conditionalPages).append(")");
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,159 +1,159 @@
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.xml.elementreader.ConfigElementReader;
|
||||
import org.alfresco.web.config.WizardsConfigElement.ConditionalPageConfig;
|
||||
import org.alfresco.web.config.WizardsConfigElement.PageConfig;
|
||||
import org.alfresco.web.config.WizardsConfigElement.StepConfig;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* Custom element reader to parse config for wizards
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class WizardsElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ELEMENT_WIZARDS = "wizards";
|
||||
public static final String ELEMENT_WIZARD = "wizard";
|
||||
public static final String ELEMENT_STEP = "step";
|
||||
public static final String ELEMENT_PAGE = "page";
|
||||
public static final String ELEMENT_CONDITION = "condition";
|
||||
|
||||
public static final String ATTR_NAME = "name";
|
||||
public static final String ATTR_MANAGED_BEAN = "managed-bean";
|
||||
public static final String ATTR_ICON = "icon";
|
||||
public static final String ATTR_TITLE = "title";
|
||||
public static final String ATTR_TITLE_ID = "title-id";
|
||||
public static final String ATTR_SUBTITLE = "subtitle";
|
||||
public static final String ATTR_SUBTITLE_ID = "subtitle-id";
|
||||
public static final String ATTR_DESCRIPTION = "description";
|
||||
public static final String ATTR_DESCRIPTION_ID = "description-id";
|
||||
public static final String ATTR_INSTRUCTION = "instruction";
|
||||
public static final String ATTR_INSTRUCTION_ID = "instruction-id";
|
||||
public static final String ATTR_ERROR_MSG_ID = "error-message-id";
|
||||
public static final String ATTR_IF = "if";
|
||||
public static final String ATTR_PATH = "path";
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
WizardsConfigElement configElement = null;
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
String elementName = element.getName();
|
||||
if (elementName.equals(ELEMENT_WIZARDS) == false)
|
||||
{
|
||||
throw new ConfigException("WizardsElementReader can only parse " +
|
||||
ELEMENT_WIZARDS + "elements, the element passed was '" +
|
||||
elementName + "'");
|
||||
}
|
||||
|
||||
configElement = new WizardsConfigElement();
|
||||
|
||||
// go through the items to show
|
||||
Iterator<Element> items = element.elementIterator(ELEMENT_WIZARD);
|
||||
while (items.hasNext())
|
||||
{
|
||||
Element wizard = items.next();
|
||||
|
||||
String name = wizard.attributeValue(ATTR_NAME);
|
||||
String bean = wizard.attributeValue(ATTR_MANAGED_BEAN);
|
||||
String icon = wizard.attributeValue(ATTR_ICON);
|
||||
String title = wizard.attributeValue(ATTR_TITLE);
|
||||
String titleId = wizard.attributeValue(ATTR_TITLE_ID);
|
||||
String subTitle = wizard.attributeValue(ATTR_SUBTITLE);
|
||||
String subTitleId = wizard.attributeValue(ATTR_SUBTITLE_ID);
|
||||
String description = wizard.attributeValue(ATTR_DESCRIPTION);
|
||||
String descriptionId = wizard.attributeValue(ATTR_DESCRIPTION_ID);
|
||||
String errorMsgId = wizard.attributeValue(ATTR_ERROR_MSG_ID);
|
||||
|
||||
// create the wizard config object
|
||||
WizardsConfigElement.WizardConfig wizardCfg = new WizardsConfigElement.WizardConfig(
|
||||
name, bean, icon, title, titleId, subTitle, subTitleId,
|
||||
description, descriptionId, errorMsgId);
|
||||
|
||||
Iterator<Element> steps = wizard.elementIterator(ELEMENT_STEP);
|
||||
while (steps.hasNext())
|
||||
{
|
||||
StepConfig stepCfg = parseStep(steps.next());
|
||||
wizardCfg.addStep(stepCfg);
|
||||
}
|
||||
|
||||
configElement.addWizard(wizardCfg);
|
||||
}
|
||||
}
|
||||
|
||||
return configElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the given element which represents a step in a wizard
|
||||
*
|
||||
* @param step The Element representing the step
|
||||
* @return A StepConfig object
|
||||
*/
|
||||
protected StepConfig parseStep(Element step)
|
||||
{
|
||||
// get the name of the step and create the config object
|
||||
String stepName = step.attributeValue(ATTR_NAME);
|
||||
String stepTitle = step.attributeValue(ATTR_TITLE);
|
||||
String stepTitleId = step.attributeValue(ATTR_TITLE_ID);
|
||||
String stepDescription = step.attributeValue(ATTR_DESCRIPTION);
|
||||
String stepDescriptionId = step.attributeValue(ATTR_DESCRIPTION_ID);
|
||||
StepConfig stepCfg = new StepConfig(stepName, stepTitle, stepTitleId,
|
||||
stepDescription, stepDescriptionId);
|
||||
|
||||
// find and parse the default page
|
||||
Element defaultPageElem = step.element(ELEMENT_PAGE);
|
||||
if (defaultPageElem != null)
|
||||
{
|
||||
String path = defaultPageElem.attributeValue(ATTR_PATH);
|
||||
String title = defaultPageElem.attributeValue(ATTR_TITLE);
|
||||
String titleId = defaultPageElem.attributeValue(ATTR_TITLE_ID);
|
||||
String description = defaultPageElem.attributeValue(ATTR_DESCRIPTION);
|
||||
String descriptionId = defaultPageElem.attributeValue(ATTR_DESCRIPTION_ID);
|
||||
String instruction = defaultPageElem.attributeValue(ATTR_INSTRUCTION);
|
||||
String instructionId = defaultPageElem.attributeValue(ATTR_INSTRUCTION_ID);
|
||||
|
||||
// create and set the page config on the step
|
||||
stepCfg.setDefaultPage(new PageConfig(path, title, titleId, description,
|
||||
descriptionId, instruction, instructionId));
|
||||
}
|
||||
|
||||
// find and parse any conditions that are present
|
||||
Iterator<Element> conditions = step.elementIterator(ELEMENT_CONDITION);
|
||||
while (conditions.hasNext())
|
||||
{
|
||||
Element conditionElem = conditions.next();
|
||||
|
||||
String ifAttr = conditionElem.attributeValue(ATTR_IF);
|
||||
Element conditionalPageElem = conditionElem.element(ELEMENT_PAGE);
|
||||
if (conditionalPageElem == null)
|
||||
{
|
||||
throw new ConfigException("A condition in step '" + stepCfg.getName() +
|
||||
"' does not have a containing <page> element");
|
||||
}
|
||||
|
||||
String path = conditionalPageElem.attributeValue(ATTR_PATH);
|
||||
String title = conditionalPageElem.attributeValue(ATTR_TITLE);
|
||||
String titleId = conditionalPageElem.attributeValue(ATTR_TITLE_ID);
|
||||
String description = conditionalPageElem.attributeValue(ATTR_DESCRIPTION);
|
||||
String descriptionId = conditionalPageElem.attributeValue(ATTR_DESCRIPTION_ID);
|
||||
String instruction = conditionalPageElem.attributeValue(ATTR_INSTRUCTION);
|
||||
String instructionId = conditionalPageElem.attributeValue(ATTR_INSTRUCTION_ID);
|
||||
|
||||
// create and add the page to the step
|
||||
stepCfg.addConditionalPage(new ConditionalPageConfig(path, ifAttr, title,
|
||||
titleId, description, descriptionId, instruction, instructionId));
|
||||
}
|
||||
|
||||
return stepCfg;
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.extensions.config.ConfigElement;
|
||||
import org.springframework.extensions.config.ConfigException;
|
||||
import org.springframework.extensions.config.xml.elementreader.ConfigElementReader;
|
||||
import org.alfresco.web.config.WizardsConfigElement.ConditionalPageConfig;
|
||||
import org.alfresco.web.config.WizardsConfigElement.PageConfig;
|
||||
import org.alfresco.web.config.WizardsConfigElement.StepConfig;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* Custom element reader to parse config for wizards
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class WizardsElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ELEMENT_WIZARDS = "wizards";
|
||||
public static final String ELEMENT_WIZARD = "wizard";
|
||||
public static final String ELEMENT_STEP = "step";
|
||||
public static final String ELEMENT_PAGE = "page";
|
||||
public static final String ELEMENT_CONDITION = "condition";
|
||||
|
||||
public static final String ATTR_NAME = "name";
|
||||
public static final String ATTR_MANAGED_BEAN = "managed-bean";
|
||||
public static final String ATTR_ICON = "icon";
|
||||
public static final String ATTR_TITLE = "title";
|
||||
public static final String ATTR_TITLE_ID = "title-id";
|
||||
public static final String ATTR_SUBTITLE = "subtitle";
|
||||
public static final String ATTR_SUBTITLE_ID = "subtitle-id";
|
||||
public static final String ATTR_DESCRIPTION = "description";
|
||||
public static final String ATTR_DESCRIPTION_ID = "description-id";
|
||||
public static final String ATTR_INSTRUCTION = "instruction";
|
||||
public static final String ATTR_INSTRUCTION_ID = "instruction-id";
|
||||
public static final String ATTR_ERROR_MSG_ID = "error-message-id";
|
||||
public static final String ATTR_IF = "if";
|
||||
public static final String ATTR_PATH = "path";
|
||||
|
||||
/**
|
||||
* @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
WizardsConfigElement configElement = null;
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
String elementName = element.getName();
|
||||
if (elementName.equals(ELEMENT_WIZARDS) == false)
|
||||
{
|
||||
throw new ConfigException("WizardsElementReader can only parse " +
|
||||
ELEMENT_WIZARDS + "elements, the element passed was '" +
|
||||
elementName + "'");
|
||||
}
|
||||
|
||||
configElement = new WizardsConfigElement();
|
||||
|
||||
// go through the items to show
|
||||
Iterator<Element> items = element.elementIterator(ELEMENT_WIZARD);
|
||||
while (items.hasNext())
|
||||
{
|
||||
Element wizard = items.next();
|
||||
|
||||
String name = wizard.attributeValue(ATTR_NAME);
|
||||
String bean = wizard.attributeValue(ATTR_MANAGED_BEAN);
|
||||
String icon = wizard.attributeValue(ATTR_ICON);
|
||||
String title = wizard.attributeValue(ATTR_TITLE);
|
||||
String titleId = wizard.attributeValue(ATTR_TITLE_ID);
|
||||
String subTitle = wizard.attributeValue(ATTR_SUBTITLE);
|
||||
String subTitleId = wizard.attributeValue(ATTR_SUBTITLE_ID);
|
||||
String description = wizard.attributeValue(ATTR_DESCRIPTION);
|
||||
String descriptionId = wizard.attributeValue(ATTR_DESCRIPTION_ID);
|
||||
String errorMsgId = wizard.attributeValue(ATTR_ERROR_MSG_ID);
|
||||
|
||||
// create the wizard config object
|
||||
WizardsConfigElement.WizardConfig wizardCfg = new WizardsConfigElement.WizardConfig(
|
||||
name, bean, icon, title, titleId, subTitle, subTitleId,
|
||||
description, descriptionId, errorMsgId);
|
||||
|
||||
Iterator<Element> steps = wizard.elementIterator(ELEMENT_STEP);
|
||||
while (steps.hasNext())
|
||||
{
|
||||
StepConfig stepCfg = parseStep(steps.next());
|
||||
wizardCfg.addStep(stepCfg);
|
||||
}
|
||||
|
||||
configElement.addWizard(wizardCfg);
|
||||
}
|
||||
}
|
||||
|
||||
return configElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the given element which represents a step in a wizard
|
||||
*
|
||||
* @param step The Element representing the step
|
||||
* @return A StepConfig object
|
||||
*/
|
||||
protected StepConfig parseStep(Element step)
|
||||
{
|
||||
// get the name of the step and create the config object
|
||||
String stepName = step.attributeValue(ATTR_NAME);
|
||||
String stepTitle = step.attributeValue(ATTR_TITLE);
|
||||
String stepTitleId = step.attributeValue(ATTR_TITLE_ID);
|
||||
String stepDescription = step.attributeValue(ATTR_DESCRIPTION);
|
||||
String stepDescriptionId = step.attributeValue(ATTR_DESCRIPTION_ID);
|
||||
StepConfig stepCfg = new StepConfig(stepName, stepTitle, stepTitleId,
|
||||
stepDescription, stepDescriptionId);
|
||||
|
||||
// find and parse the default page
|
||||
Element defaultPageElem = step.element(ELEMENT_PAGE);
|
||||
if (defaultPageElem != null)
|
||||
{
|
||||
String path = defaultPageElem.attributeValue(ATTR_PATH);
|
||||
String title = defaultPageElem.attributeValue(ATTR_TITLE);
|
||||
String titleId = defaultPageElem.attributeValue(ATTR_TITLE_ID);
|
||||
String description = defaultPageElem.attributeValue(ATTR_DESCRIPTION);
|
||||
String descriptionId = defaultPageElem.attributeValue(ATTR_DESCRIPTION_ID);
|
||||
String instruction = defaultPageElem.attributeValue(ATTR_INSTRUCTION);
|
||||
String instructionId = defaultPageElem.attributeValue(ATTR_INSTRUCTION_ID);
|
||||
|
||||
// create and set the page config on the step
|
||||
stepCfg.setDefaultPage(new PageConfig(path, title, titleId, description,
|
||||
descriptionId, instruction, instructionId));
|
||||
}
|
||||
|
||||
// find and parse any conditions that are present
|
||||
Iterator<Element> conditions = step.elementIterator(ELEMENT_CONDITION);
|
||||
while (conditions.hasNext())
|
||||
{
|
||||
Element conditionElem = conditions.next();
|
||||
|
||||
String ifAttr = conditionElem.attributeValue(ATTR_IF);
|
||||
Element conditionalPageElem = conditionElem.element(ELEMENT_PAGE);
|
||||
if (conditionalPageElem == null)
|
||||
{
|
||||
throw new ConfigException("A condition in step '" + stepCfg.getName() +
|
||||
"' does not have a containing <page> element");
|
||||
}
|
||||
|
||||
String path = conditionalPageElem.attributeValue(ATTR_PATH);
|
||||
String title = conditionalPageElem.attributeValue(ATTR_TITLE);
|
||||
String titleId = conditionalPageElem.attributeValue(ATTR_TITLE_ID);
|
||||
String description = conditionalPageElem.attributeValue(ATTR_DESCRIPTION);
|
||||
String descriptionId = conditionalPageElem.attributeValue(ATTR_DESCRIPTION_ID);
|
||||
String instruction = conditionalPageElem.attributeValue(ATTR_INSTRUCTION);
|
||||
String instructionId = conditionalPageElem.attributeValue(ATTR_INSTRUCTION_ID);
|
||||
|
||||
// create and add the page to the step
|
||||
stepCfg.addConditionalPage(new ConditionalPageConfig(path, ifAttr, title,
|
||||
titleId, description, descriptionId, instruction, instructionId));
|
||||
}
|
||||
|
||||
return stepCfg;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user