Search in sources :

Example 6 with ConfigElement

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

the class BaseContentWizard method getObjectTypesImpl.

private List<SelectItem> getObjectTypesImpl() {
    if ((this.objectTypes == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        FacesContext context = FacesContext.getCurrentInstance();
        // add the well known object type to start with
        this.objectTypes = new ArrayList<SelectItem>(5);
        ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
        Config wizardCfg = svc.getConfig("Content Wizards");
        if (wizardCfg != null) {
            ConfigElement defaultTypesCfg = wizardCfg.getConfigElement("default-content-type");
            String parentLabel = "";
            if (defaultTypesCfg != null) {
                // Get the default content-type to apply
                ConfigElement typeElement = defaultTypesCfg.getChildren().get(0);
                QName parentQName = Repository.resolveToQName(typeElement.getAttribute("name"));
                TypeDefinition parentType = null;
                if (parentQName != null) {
                    parentType = this.getDictionaryService().getType(parentQName);
                    if (parentType == null) {
                        // If no default content type is defined default to content
                        parentQName = ContentModel.TYPE_CONTENT;
                        parentType = this.getDictionaryService().getType(ContentModel.TYPE_CONTENT);
                        this.objectTypes.add(new SelectItem(ContentModel.TYPE_CONTENT.toString(), Application.getMessage(context, "content")));
                        logger.warn("Configured default content type not found in dictionary: " + parentQName);
                    } else {
                        // try and get the display label from config
                        parentLabel = Utils.getDisplayLabel(context, typeElement);
                        // if there wasn't a client based label try and get it from the dictionary
                        if (parentLabel == null) {
                            parentLabel = parentType.getTitle(this.getDictionaryService());
                        }
                        // finally, just use the localname
                        if (parentLabel == null) {
                            parentLabel = parentQName.getLocalName();
                        }
                    }
                }
                // Get all content types defined
                ConfigElement typesCfg = wizardCfg.getConfigElement("content-types");
                if (typesCfg != null) {
                    for (ConfigElement child : typesCfg.getChildren()) {
                        QName idQName = Repository.resolveToQName(child.getAttribute("name"));
                        if (idQName != null) {
                            TypeDefinition typeDef = this.getDictionaryService().getType(idQName);
                            if (typeDef != null) {
                                // for each type check if it is a subtype of the default content type
                                if (this.getDictionaryService().isSubClass(typeDef.getName(), parentType.getName())) {
                                    // try and 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) {
                                        label = typeDef.getTitle(this.getDictionaryService());
                                    }
                                    // finally, just use the localname
                                    if (label == null) {
                                        label = idQName.getLocalName();
                                    }
                                    this.objectTypes.add(new SelectItem(idQName.toString(), label));
                                } else {
                                    logger.warn("Failed to add '" + child.getAttribute("name") + "' to the list of content types - it is not a subtype of " + parentQName);
                                }
                            }
                        } else {
                            logger.warn("Failed to add '" + child.getAttribute("name") + "' to the list of content types as the type is not recognised");
                        }
                    }
                }
                // Case when no type is defined - we add the default content type to the list of available types
                if (this.objectTypes.isEmpty()) {
                    // add default content type to the list of available types
                    this.objectTypes.add(new SelectItem(parentQName.toString(), parentLabel));
                }
                // make sure the list is sorted by the label
                QuickSort sorter = new QuickSort(this.objectTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
                sorter.sort();
            } else {
                logger.warn("Could not find 'content-types' configuration element");
            }
        } else {
            logger.warn("Could not find 'Content Wizards' configuration section");
        }
    }
    return this.objectTypes;
}
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) SelectItem(javax.faces.model.SelectItem) Config(org.springframework.extensions.config.Config) QName(org.alfresco.service.namespace.QName) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition)

Example 7 with ConfigElement

use of org.springframework.extensions.config.ConfigElement 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 8 with ConfigElement

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

the class ClientElementReader method parse.

/**
 * @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
 */
@SuppressWarnings("unchecked")
public ConfigElement parse(Element element) {
    ClientConfigElement configElement = null;
    if (element != null) {
        String name = element.getName();
        if (name.equals(ClientConfigElement.CONFIG_ELEMENT_ID) == false) {
            throw new ConfigException("ClientElementReader can only parse " + ClientConfigElement.CONFIG_ELEMENT_ID + " elements, the element passed was '" + name + "'");
        }
        configElement = new ClientConfigElement();
        // get the recent space max items
        Element recentSpaces = element.element(ELEMENT_RECENTSPACESITEMS);
        if (recentSpaces != null) {
            configElement.setRecentSpacesItems(Integer.parseInt(recentSpaces.getTextTrim()));
        }
        // get the shelf component default visibility
        Element shelfVisible = element.element(ELEMENT_SHELFVISIBLE);
        if (shelfVisible != null) {
            configElement.setShelfVisible(Boolean.parseBoolean(shelfVisible.getTextTrim()));
        }
        // get the Help url
        Element helpUrl = element.element(ELEMENT_HELPURL);
        if (helpUrl != null) {
            configElement.setHelpUrl(helpUrl.getTextTrim());
        }
        // get the edit link type
        Element editLinkType = element.element(ELEMENT_EDITLINKTYPE);
        if (editLinkType != null) {
            configElement.setEditLinkType(editLinkType.getTextTrim());
        }
        // get the minimum number of characters for valid search string
        Element searchMin = element.element(ELEMENT_SEARCHMINIMUM);
        if (searchMin != null) {
            configElement.setSearchMinimum(Integer.parseInt(searchMin.getTextTrim()));
        }
        // get the search force AND terms setting
        Element searchForceAnd = element.element(ELEMENT_SEARCHANDTERMS);
        if (searchForceAnd != null) {
            configElement.setForceAndTerms(Boolean.parseBoolean(searchForceAnd.getTextTrim()));
        }
        // get the search max results size
        Element searchMaxResults = element.element(ELEMENT_SEARCHMAXRESULTS);
        if (searchMaxResults != null) {
            configElement.setSearchMaxResults(Integer.parseInt(searchMaxResults.getTextTrim()));
        }
        // get the search max results size
        Element isBulkFetchEnabled = element.element(ELEMENT_BULKFETCHENABLED);
        if (isBulkFetchEnabled != null) {
            configElement.setBulkFetchEnabled(Boolean.parseBoolean(isBulkFetchEnabled.getTextTrim()));
        }
        // get the selectors search max results size
        Element selectorsSearchMaxResults = element.element(ELEMENT_SELECTORSSEARCHMAXRESULTS);
        if (selectorsSearchMaxResults != null) {
            configElement.setSelectorsSearchMaxResults(Integer.parseInt(selectorsSearchMaxResults.getTextTrim()));
        }
        // get the invite users max results size
        Element inviteUsersMaxResults = element.element(ELEMENT_INVITESEARCHMAXRESULTS);
        if (inviteUsersMaxResults != null) {
            configElement.setInviteUsersMaxResults(Integer.parseInt(inviteUsersMaxResults.getTextTrim()));
        }
        // get the invite users max results size
        Element completedTasksMaxResults = element.element(ELEMENT_TASKSCOMPLETEDMAXRESULTS);
        if (completedTasksMaxResults != null) {
            configElement.setTasksCompletedMaxResults(Integer.parseInt(completedTasksMaxResults.getTextTrim()));
        }
        // get the default permission for newly created users Home Spaces
        Element permission = element.element(ELEMENT_HOMESPACEPERMISSION);
        if (permission != null) {
            configElement.setHomeSpacePermission(permission.getTextTrim());
        }
        // get the from address to use when sending emails from the client
        Element fromEmail = element.element(ELEMENT_FROMEMAILADDRESS);
        if (fromEmail != null) {
            configElement.setFromEmailAddress(fromEmail.getTextTrim());
        }
        // get the error page
        Element errorPage = element.element(ELEMENT_ERRORPAGE);
        if (errorPage != null) {
            configElement.setErrorPage(errorPage.getTextTrim());
        }
        // get the login page
        Element loginPage = element.element(ELEMENT_LOGINPAGE);
        if (loginPage != null) {
            configElement.setLoginPage(loginPage.getTextTrim());
        }
        // get the node summary popup enabled flag
        Element ajaxEnabled = element.element(ELEMENT_NODESUMMARY_ENABLED);
        if (ajaxEnabled != null) {
            configElement.setNodeSummaryEnabled(Boolean.parseBoolean(ajaxEnabled.getTextTrim()));
        }
        // get the initial location
        Element initialLocation = element.element(ELEMENT_INITIALLOCATION);
        if (initialLocation != null) {
            configElement.setInitialLocation(initialLocation.getTextTrim());
        }
        // get the default home space path
        Element defaultHomeSpacePath = element.element(ELEMENT_DEFAULTHOMESPACEPATH);
        if (defaultHomeSpacePath != null) {
            configElement.setDefaultHomeSpacePath(defaultHomeSpacePath.getTextTrim());
        }
        // get the default visibility of the clipboard status messages
        Element clipboardStatusVisible = element.element(ELEMENT_CLIPBOARDSTATUS);
        if (clipboardStatusVisible != null) {
            configElement.setClipboardStatusVisible(Boolean.parseBoolean(clipboardStatusVisible.getTextTrim()));
        }
        // get the default setting for the paste all action, should it clear the clipboard after?
        Element pasteAllAndClear = element.element(ELEMENT_PASTEALLANDCLEAR);
        if (pasteAllAndClear != null) {
            configElement.setPasteAllAndClearEnabled(Boolean.parseBoolean(pasteAllAndClear.getTextTrim()));
        }
        // get allow Guest to configure start location preferences
        Element guestConfigElement = element.element(ELEMENT_GUESTCONFIG);
        if (guestConfigElement != null) {
            boolean allow = Boolean.parseBoolean(guestConfigElement.getTextTrim());
            configElement.setAllowGuestConfig(allow);
        }
        // get the additional simple search attributes
        Element simpleSearchAdditionalAttributesElement = element.element(ELEMENT_SIMPLESEARCHADDITIONALATTRS);
        if (simpleSearchAdditionalAttributesElement != null) {
            List<Element> attrbElements = simpleSearchAdditionalAttributesElement.elements(ELEMENT_SIMPLESEARCHADDITIONALATTRSQNAME);
            if (attrbElements != null && attrbElements.size() != 0) {
                List<QName> simpleSearchAddtlAttrb = new ArrayList<QName>(4);
                for (Element elem : attrbElements) {
                    simpleSearchAddtlAttrb.add(QName.createQName(elem.getTextTrim()));
                }
                configElement.setSimpleSearchAdditionalAttributes(simpleSearchAddtlAttrb);
            }
        }
        // get the minimum length of usernames
        Element minUsername = element.element(ELEMENT_MINUSERNAMELENGTH);
        if (minUsername != null) {
            configElement.setMinUsernameLength(Integer.parseInt(minUsername.getTextTrim()));
        }
        // get the minimum length of passwords
        Element minPassword = element.element(ELEMENT_MINPASSWORDLENGTH);
        if (minPassword != null) {
            configElement.setMinPasswordLength(Integer.parseInt(minPassword.getTextTrim()));
        }
        // get the maximum length of passwords
        Element maxPassword = element.element(ELEMENT_MAXPASSWORDLENGTH);
        if (maxPassword != null) {
            configElement.setMaxPasswordLength(Integer.parseInt(maxPassword.getTextTrim()));
        }
        // get the minimum length of group names
        Element minGroupName = element.element(ELEMENT_MINGROUPNAMELENGTH);
        if (minGroupName != null) {
            configElement.setMinGroupNameLength(Integer.parseInt(minGroupName.getTextTrim()));
        }
        // get the breadcrumb mode
        Element breadcrumbMode = element.element(ELEMENT_BREADCRUMB_MODE);
        if (breadcrumbMode != null) {
            configElement.setBreadcrumbMode(breadcrumbMode.getTextTrim());
        }
        // Get the CIFS URL suffix
        Element cifsSuffix = element.element(ELEMENT_CIFSURLSUFFIX);
        if (cifsSuffix != null) {
            String suffix = cifsSuffix.getTextTrim();
            if (suffix.startsWith(".") == false) {
                suffix = "." + suffix;
            }
            configElement.setCifsURLSuffix(suffix);
        }
        // get the language selection mode
        Element langSelect = element.element(ELEMENT_LANGUAGESELECT);
        if (langSelect != null) {
            configElement.setLanguageSelect(Boolean.parseBoolean(langSelect.getTextTrim()));
        }
        // get the zero byte file upload mode
        Element zeroByteFiles = element.element(ELEMENT_ZEROBYTEFILEUPLOADS);
        if (zeroByteFiles != null) {
            configElement.setZeroByteFileUploads(Boolean.parseBoolean(zeroByteFiles.getTextTrim()));
        }
        // get allow user group admin mode
        Element userGroupAdmin = element.element(ELEMENT_USERGROUPADMIN);
        if (userGroupAdmin != null) {
            configElement.setUserGroupAdmin(Boolean.parseBoolean(userGroupAdmin.getTextTrim()));
        }
        // get allow user config mode
        Element userConfig = element.element(ELEMENT_ALLOWUSERCONFIG);
        if (userConfig != null) {
            configElement.setAllowUserConfig(Boolean.parseBoolean(userConfig.getTextTrim()));
        }
        // get the minimum number of characters for valid picker search string
        Element pickerSearchMin = element.element(ELEMENT_PICKERSEARCHMINIMUM);
        if (pickerSearchMin != null) {
            configElement.setPickerSearchMinimum(Integer.parseInt(pickerSearchMin.getTextTrim()));
        }
        // determine whether the JavaScript setContextPath method should
        // check the path of the current URL
        Element checkContextAgainstPath = element.element(ELEMENT_CHECKCONTEXTPATH);
        if (checkContextAgainstPath != null) {
            configElement.setCheckContextAgainstPath(Boolean.parseBoolean(checkContextAgainstPath.getTextTrim()));
        }
        // get allow any user to execute javascript via the command servlet
        Element allowUserScriptExecute = element.element(ELEMENT_ALLOWUSERSCRIPTEXECUTE);
        if (allowUserScriptExecute != null) {
            configElement.setAllowUserScriptExecute(Boolean.parseBoolean(allowUserScriptExecute.getTextTrim()));
        }
    }
    return configElement;
}
Also used : QName(org.alfresco.service.namespace.QName) ConfigElement(org.springframework.extensions.config.ConfigElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) ConfigException(org.springframework.extensions.config.ConfigException)

Example 9 with ConfigElement

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

the class PropertySheetElementReader method parse.

/**
 * @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
 */
@SuppressWarnings("unchecked")
public ConfigElement parse(Element element) {
    PropertySheetConfigElement configElement = null;
    if (element != null) {
        String name = element.getName();
        if (name.equals(ELEMENT_PROPERTY_SHEET) == false) {
            throw new ConfigException("PropertySheetElementReader can only parse " + ELEMENT_PROPERTY_SHEET + "elements, " + "the element passed was '" + name + "'");
        }
        configElement = new PropertySheetConfigElement();
        // go through the items to show
        Iterator<Element> items = element.elementIterator();
        while (items.hasNext()) {
            Element item = items.next();
            String propName = item.attributeValue(ATTR_NAME);
            String label = item.attributeValue(ATTR_DISPLAY_LABEL);
            String labelId = item.attributeValue(ATTR_DISPLAY_LABEL_ID);
            String readOnly = item.attributeValue(ATTR_READ_ONLY);
            String converter = item.attributeValue(ATTR_CONVERTER);
            String inEdit = item.attributeValue(ATTR_SHOW_IN_EDIT_MODE);
            String inView = item.attributeValue(ATTR_SHOW_IN_VIEW_MODE);
            String compGenerator = item.attributeValue(ATTR_COMPONENT_GENERATOR);
            if (ELEMENT_SHOW_PROPERTY.equals(item.getName())) {
                String ignoreIfMissing = item.attributeValue(ATTR_IGNORE_IF_MISSING);
                // add the property to show to the custom config element
                configElement.addProperty(propName, label, labelId, readOnly, converter, inView, inEdit, compGenerator, ignoreIfMissing);
            } else if (ELEMENT_SHOW_ASSOC.equals(item.getName())) {
                configElement.addAssociation(propName, label, labelId, readOnly, converter, inView, inEdit, compGenerator);
            } else if (ELEMENT_SHOW_CHILD_ASSOC.equals(item.getName())) {
                configElement.addChildAssociation(propName, label, labelId, readOnly, converter, inView, inEdit, compGenerator);
            } else if (ELEMENT_SEPARATOR.equals(item.getName())) {
                configElement.addSeparator(propName, label, labelId, inView, inEdit, compGenerator);
            }
        }
    }
    return configElement;
}
Also used : ConfigElement(org.springframework.extensions.config.ConfigElement) Element(org.dom4j.Element) ConfigException(org.springframework.extensions.config.ConfigException)

Example 10 with ConfigElement

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

the class ViewsElementReader method processPageSizeElement.

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

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