Search in sources :

Example 1 with ActionGroup

use of org.alfresco.web.config.ActionsConfigElement.ActionGroup in project acs-community-packaging by Alfresco.

the class ActionsElementReader method parse.

/**
 * @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;
}
Also used : ActionGroup(org.alfresco.web.config.ActionsConfigElement.ActionGroup) ConfigElement(org.springframework.extensions.config.ConfigElement) Element(org.dom4j.Element) ConfigException(org.springframework.extensions.config.ConfigException) ActionDefinition(org.alfresco.web.config.ActionsConfigElement.ActionDefinition)

Example 2 with ActionGroup

use of org.alfresco.web.config.ActionsConfigElement.ActionGroup in project acs-community-packaging by Alfresco.

the class UIActions method encodeBegin.

/**
 * @see javax.faces.component.UIComponentBase#encodeBegin(javax.faces.context.FacesContext)
 */
@SuppressWarnings("unchecked")
public void encodeBegin(FacesContext context) throws IOException {
    if (isRendered() == false) {
        return;
    }
    if (logger.isDebugEnabled())
        logger.debug("encodeBegin() for <r:actions/> Id: " + getId() + " groupId: " + getValue());
    // put the context object into the requestMap so it is accessable
    // by any child component value binding expressions
    Object actionContext = getContext();
    Map requestMap = getFacesContext().getExternalContext().getRequestMap();
    requestMap.put(ACTION_CONTEXT, actionContext);
    String contextId;
    if (actionContext instanceof Node) {
        contextId = ((Node) actionContext).getType().toString();
        if (this.groups.contains(contextId)) {
            if (logger.isDebugEnabled())
                logger.debug("---already built component tree for actions contextId: " + contextId);
            return;
        }
    } else {
        contextId = CONTEXTID_DEFAULT;
        if (this.groups.contains(contextId)) {
            if (logger.isDebugEnabled())
                logger.debug("---already built component tree for default actions.");
            return;
        }
    }
    // this will need removing from the child component set to ensure that it does not grow endlessly
    for (Iterator i = getChildren().iterator(); i.hasNext(); ) /**/
    {
        UIComponent child = (UIComponent) i.next();
        if (contextId.equals(child.getAttributes().get("contextId"))) {
            if (logger.isDebugEnabled())
                logger.debug("***removing old child component set for contextId: " + contextId);
            i.remove();
            break;
        }
    }
    String groupId = getValue();
    if (groupId != null && groupId.length() != 0) {
        Config config;
        if (actionContext instanceof Node) {
            config = Application.getConfigService(context).getConfig(actionContext);
        } else {
            config = Application.getConfigService(context).getGlobalConfig();
        }
        if (config != null) {
            // find the Actions specific config element
            ActionsConfigElement actionConfig = (ActionsConfigElement) config.getConfigElement(ActionsConfigElement.CONFIG_ELEMENT_ID);
            if (actionConfig != null) {
                // and lookup our ActionGroup by Id
                ActionGroup actionGroup = actionConfig.getActionGroup(groupId);
                if (actionGroup != null) {
                    // render the action group component tree
                    if (logger.isDebugEnabled())
                        logger.debug("-constructing ActionGroup: " + groupId + " for ContextId: " + contextId);
                    buildActionGroup(context, actionConfig, actionGroup, contextId);
                } else {
                    logger.warn("Unable to find specified Action Group config ID: " + groupId);
                }
            }
        }
    }
}
Also used : ActionsConfigElement(org.alfresco.web.config.ActionsConfigElement) ActionGroup(org.alfresco.web.config.ActionsConfigElement.ActionGroup) Config(org.springframework.extensions.config.Config) Node(org.alfresco.web.bean.repository.Node) Iterator(java.util.Iterator) UIComponent(javax.faces.component.UIComponent) Map(java.util.Map)

Aggregations

ActionGroup (org.alfresco.web.config.ActionsConfigElement.ActionGroup)2 Iterator (java.util.Iterator)1 Map (java.util.Map)1 UIComponent (javax.faces.component.UIComponent)1 Node (org.alfresco.web.bean.repository.Node)1 ActionsConfigElement (org.alfresco.web.config.ActionsConfigElement)1 ActionDefinition (org.alfresco.web.config.ActionsConfigElement.ActionDefinition)1 Element (org.dom4j.Element)1 Config (org.springframework.extensions.config.Config)1 ConfigElement (org.springframework.extensions.config.ConfigElement)1 ConfigException (org.springframework.extensions.config.ConfigException)1