Search in sources :

Example 31 with ConfigElement

use of org.springframework.extensions.config.ConfigElement in project acs-community-packaging by Alfresco.

the class AdvancedSearchElementReader method parse.

/**
 * @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;
}
Also used : ConfigElement(org.springframework.extensions.config.ConfigElement) Element(org.dom4j.Element) CustomProperty(org.alfresco.web.config.AdvancedSearchConfigElement.CustomProperty) ArrayList(java.util.ArrayList) CustomProperty(org.alfresco.web.config.AdvancedSearchConfigElement.CustomProperty) ConfigException(org.springframework.extensions.config.ConfigException)

Example 32 with ConfigElement

use of org.springframework.extensions.config.ConfigElement in project acs-community-packaging by Alfresco.

the class CommandServletElementReader method parse.

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

Example 33 with ConfigElement

use of org.springframework.extensions.config.ConfigElement in project acs-community-packaging by Alfresco.

the class CreateRuleWizard method getModelTypes.

/**
 * Returns a list of the types available in the repository
 *
 * @return List of SelectItem objects
 */
public List<SelectItem> getModelTypes() {
    if ((this.modelTypes == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        FacesContext context = FacesContext.getCurrentInstance();
        ConfigService svc = Application.getConfigService(context);
        Config wizardCfg = svc.getConfig("Action Wizards");
        if (wizardCfg != null) {
            ConfigElement typesCfg = wizardCfg.getConfigElement("subtypes");
            if (typesCfg != null) {
                this.modelTypes = new ArrayList<SelectItem>();
                for (ConfigElement child : typesCfg.getChildren()) {
                    QName idQName = Repository.resolveToQName(child.getAttribute("name"));
                    // get the display label from config
                    String label = Utils.getDisplayLabel(context, child);
                    // if there wasn't a client based label try and get it from the dictionary
                    if (label == null) {
                        TypeDefinition typeDef = this.getDictionaryService().getType(idQName);
                        if (typeDef != null) {
                            label = typeDef.getTitle(this.getDictionaryService());
                        } else {
                            label = idQName.getLocalName();
                        }
                    }
                    this.modelTypes.add(new SelectItem(idQName.toString(), label));
                }
                // make sure the list is sorted by the label
                QuickSort sorter = new QuickSort(this.modelTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
                sorter.sort();
            } else {
                logger.warn("Could not find 'subtypes' configuration element");
            }
        } else {
            logger.warn("Could not find 'Action Wizards' configuration section");
        }
    }
    return this.modelTypes;
}
Also used : FacesContext(javax.faces.context.FacesContext) QuickSort(org.alfresco.web.data.QuickSort) ConfigService(org.springframework.extensions.config.ConfigService) ConfigElement(org.springframework.extensions.config.ConfigElement) Config(org.springframework.extensions.config.Config) SelectItem(javax.faces.model.SelectItem) QName(org.alfresco.service.namespace.QName) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition)

Example 34 with ConfigElement

use of org.springframework.extensions.config.ConfigElement in project acs-community-packaging by Alfresco.

the class ImagePickerRadioRenderer method encodeChildren.

/**
 * @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
 */
@SuppressWarnings("unchecked")
public void encodeChildren(FacesContext context, UIComponent component) throws IOException {
    if (component.isRendered() == false) {
        return;
    }
    UIImagePicker imagePicker = (UIImagePicker) component;
    Map attrs = imagePicker.getAttributes();
    Integer cols = (Integer) attrs.get("columns");
    if (cols != null && cols instanceof Integer) {
        this.columns = cols.intValue();
    }
    // retrieve the onclick handler, if there is one
    String onclick = (String) attrs.get("onclick");
    ResponseWriter out = context.getResponseWriter();
    // determine whether the options should be pulled from config or
    // from the child components
    String configSection = (String) attrs.get("configSection");
    if (configSection != null && configSection.length() > 0) {
        // render all the icons from the list that appear in the given
        // config section
        ConfigService cfgService = Application.getConfigService(context);
        Config cfg = cfgService.getConfig(configSection);
        if (cfg != null) {
            ConfigElement iconsCfg = cfg.getConfigElement("icons");
            if (iconsCfg != null) {
                for (ConfigElement icon : iconsCfg.getChildren()) {
                    String iconName = icon.getAttribute("name");
                    String iconPath = icon.getAttribute("path");
                    if (iconName != null && iconPath != null) {
                        UIListItem item = new UIListItem();
                        item.setValue(iconName);
                        item.setImage(iconPath);
                        renderItem(context, out, imagePicker, item, onclick);
                    }
                }
            }
        }
    } else {
        try {
            // get the child components
            for (Iterator i = imagePicker.getChildren().iterator(); i.hasNext(); ) /**/
            {
                UIComponent child = (UIComponent) i.next();
                if (child instanceof UIListItems) {
                    // get the value of the list items component and iterate
                    // through it's collection
                    Object listItems = ((UIListItems) child).getValue();
                    if (listItems instanceof Collection) {
                        Iterator iter = ((Collection) listItems).iterator();
                        while (iter.hasNext()) {
                            UIListItem item = (UIListItem) iter.next();
                            if (item.isRendered()) {
                                renderItem(context, out, imagePicker, item, onclick);
                            }
                        }
                    }
                } else if (child instanceof UIListItem && child.isRendered() == true) {
                    // found a valid UIListItem child to render
                    UIListItem item = (UIListItem) child;
                    renderItem(context, out, imagePicker, item, onclick);
                }
            }
        } catch (PropertyNotFoundException pnfe) {
            // method specified in the value binding expression
            if (logger.isWarnEnabled())
                logger.warn("Failed to retrieve icons: " + pnfe.toString());
            out.write(Application.getMessage(context, "no_icons_found"));
        }
    }
    // if we are in the middle of a row, close it
    if (open) {
        out.write("</tr>\n");
    }
}
Also used : PropertyNotFoundException(javax.faces.el.PropertyNotFoundException) ConfigElement(org.springframework.extensions.config.ConfigElement) Config(org.springframework.extensions.config.Config) UIComponent(javax.faces.component.UIComponent) UIListItems(org.alfresco.web.ui.common.component.UIListItems) UIImagePicker(org.alfresco.web.ui.common.component.UIImagePicker) ConfigService(org.springframework.extensions.config.ConfigService) ResponseWriter(javax.faces.context.ResponseWriter) UIListItem(org.alfresco.web.ui.common.component.UIListItem) Iterator(java.util.Iterator) Collection(java.util.Collection) Map(java.util.Map)

Example 35 with ConfigElement

use of org.springframework.extensions.config.ConfigElement in project acs-community-packaging by Alfresco.

the class DashboardsElementReader method parse.

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

Aggregations

ConfigElement (org.springframework.extensions.config.ConfigElement)38 Config (org.springframework.extensions.config.Config)21 ConfigService (org.springframework.extensions.config.ConfigService)18 Element (org.dom4j.Element)14 ConfigException (org.springframework.extensions.config.ConfigException)13 SelectItem (javax.faces.model.SelectItem)11 FacesContext (javax.faces.context.FacesContext)10 QuickSort (org.alfresco.web.data.QuickSort)9 QName (org.alfresco.service.namespace.QName)7 ArrayList (java.util.ArrayList)4 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)4 UIListItem (org.alfresco.web.ui.common.component.UIListItem)3 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 UIComponent (javax.faces.component.UIComponent)1