Search in sources :

Example 1 with ConfigService

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

the class BaseActionWizard method getTestableAspects.

/**
 * Returns a list of aspects that can be tested i.e. hasAspect
 *
 * @return List of SelectItem objects representing the aspects that can be tested for
 */
public List<SelectItem> getTestableAspects() {
    if ((this.testableAspects == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        // get the list of common aspects
        this.testableAspects = new ArrayList<SelectItem>();
        this.testableAspects.addAll(getCommonAspects());
        // get those aspects configured to appear only in the remove aspect action
        ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
        Config wizardCfg = svc.getConfig("Action Wizards");
        if (wizardCfg != null) {
            ConfigElement aspectsCfg = wizardCfg.getConfigElement("aspects-test");
            if (aspectsCfg != null) {
                List<SelectItem> aspects = readAspectsConfig(FacesContext.getCurrentInstance(), aspectsCfg);
                this.testableAspects.addAll(aspects);
            } else {
                logger.warn("Could not find 'aspects-test' configuration element");
            }
        } else {
            logger.warn("Could not find 'Action Wizards' configuration section");
        }
        // make sure the list is sorted by the label
        QuickSort sorter = new QuickSort(this.testableAspects, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
        sorter.sort();
    }
    return this.testableAspects;
}
Also used : 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)

Example 2 with ConfigService

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

the class BaseActionWizard method initialiseActionHandlers.

/**
 * Initialises the action handlers from the current configuration.
 */
protected void initialiseActionHandlers() {
    if ((this.actionHandlers == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
        Config wizardCfg = svc.getConfig("Action Wizards");
        if (wizardCfg != null) {
            ConfigElement actionHandlerCfg = wizardCfg.getConfigElement("action-handlers");
            if (actionHandlerCfg != null) {
                this.actionHandlers = new HashMap<String, IHandler>(20);
                // instantiate each handler and store in the map
                for (ConfigElement child : actionHandlerCfg.getChildren()) {
                    String actionName = child.getAttribute("name");
                    String handlerClass = child.getAttribute("class");
                    if (actionName != null && actionName.length() > 0 && handlerClass != null && handlerClass.length() > 0) {
                        try {
                            @SuppressWarnings("unchecked") Class klass = Class.forName(handlerClass);
                            IHandler handler = (IHandler) klass.newInstance();
                            this.actionHandlers.put(actionName, handler);
                        } catch (Exception e) {
                            throw new AlfrescoRuntimeException("Failed to setup action handler for '" + actionName + "'", e);
                        }
                    }
                }
            } else {
                logger.warn("Could not find 'action-handlers' configuration element");
            }
        } else {
            logger.warn("Could not find 'Action Wizards' configuration section");
        }
    }
}
Also used : ConfigService(org.springframework.extensions.config.ConfigService) ConfigElement(org.springframework.extensions.config.ConfigElement) Config(org.springframework.extensions.config.Config) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 3 with ConfigService

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

the class ScriptCommandProcessor method validateArguments.

/**
 * @see org.alfresco.web.app.servlet.command.CommandProcessor#validateArguments(javax.servlet.ServletContext, java.lang.String, java.util.Map, java.lang.String[])
 */
public boolean validateArguments(ServletContext sc, String command, Map<String, String> args, String[] urlElements) {
    boolean allowed = false;
    String scriptPath = args.get(ARG_SCRIPT_PATH);
    if (scriptPath != null) {
        // resolve path to a node
        this.scriptRef = BaseServlet.resolveNamePath(sc, scriptPath).NodeRef;
        // same for the document context path if specified
        String docPath = args.get(ARG_CONTEXT_PATH);
        if (docPath != null) {
            this.docRef = BaseServlet.resolveNamePath(sc, docPath).NodeRef;
        }
    } else {
        if (urlElements.length < 3) {
            throw new IllegalArgumentException("Not enough URL arguments passed to command servlet.");
        }
        // get NodeRef to the node script to execute
        StoreRef storeRef = new StoreRef(urlElements[0], urlElements[1]);
        this.scriptRef = new NodeRef(storeRef, urlElements[2]);
        if (urlElements.length >= 6) {
            storeRef = new StoreRef(urlElements[3], urlElements[4]);
            this.docRef = new NodeRef(storeRef, urlElements[5]);
        }
    }
    // check we can READ access the nodes specified
    PermissionService ps = Repository.getServiceRegistry(sc).getPermissionService();
    allowed = (ps.hasPermission(this.scriptRef, PermissionService.READ) == AccessStatus.ALLOWED);
    if (this.docRef != null) {
        allowed &= (ps.hasPermission(this.docRef, PermissionService.READ) == AccessStatus.ALLOWED);
    }
    // check to see if user is allowed to execute arbituary javascript
    // by default only an admin authority can perform this action
    ConfigService configService = Application.getConfigService(sc);
    ClientConfigElement configElement = (ClientConfigElement) configService.getGlobalConfig().getConfigElement("client");
    boolean allowScriptExecute = configElement.getAllowUserScriptExecute();
    AuthorityService authService = Repository.getServiceRegistry(sc).getAuthorityService();
    allowed &= (allowScriptExecute || authService.isAdminAuthority(AuthenticationUtil.getFullyAuthenticatedUser()));
    return allowed;
}
Also used : PermissionService(org.alfresco.service.cmr.security.PermissionService) StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ConfigService(org.springframework.extensions.config.ConfigService) AuthorityService(org.alfresco.service.cmr.security.AuthorityService) ClientConfigElement(org.alfresco.web.config.ClientConfigElement)

Example 4 with ConfigService

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

the class UIPropertySheet method encodeBegin.

/**
 * @see javax.faces.component.UIComponent#encodeBegin(javax.faces.context.FacesContext)
 */
@SuppressWarnings("unchecked")
public void encodeBegin(FacesContext context) throws IOException {
    int howManyChildren = getChildren().size();
    Boolean externalConfig = (Boolean) getAttributes().get("externalConfig");
    // generate a variable name to use if necessary
    if (this.variable == null) {
        this.variable = DEFAULT_VAR_NAME;
    }
    // force retrieval of node info
    Node node = getNode();
    if (howManyChildren == 0) {
        if (externalConfig != null && externalConfig.booleanValue()) {
            // configure the component using the config service
            if (logger.isDebugEnabled())
                logger.debug("Configuring property sheet using ConfigService");
            // get the properties to display
            ConfigService configSvc = Application.getConfigService(FacesContext.getCurrentInstance());
            Config configProps = null;
            if (getConfigArea() == null) {
                configProps = configSvc.getConfig(node);
            } else {
                // only look within the given area
                configProps = configSvc.getConfig(node, new ConfigLookupContext(getConfigArea()));
            }
            PropertySheetConfigElement itemsToDisplay = (PropertySheetConfigElement) configProps.getConfigElement("property-sheet");
            if (itemsToDisplay != null) {
                Collection<ItemConfig> itemsToRender = null;
                if (this.getMode().equalsIgnoreCase(EDIT_MODE)) {
                    itemsToRender = itemsToDisplay.getEditableItemsToShow().values();
                    if (logger.isDebugEnabled())
                        logger.debug("Items to render: " + itemsToDisplay.getEditableItemNamesToShow());
                } else {
                    itemsToRender = itemsToDisplay.getItemsToShow().values();
                    if (logger.isDebugEnabled())
                        logger.debug("Items to render: " + itemsToDisplay.getItemNamesToShow());
                }
                createComponentsFromConfig(context, itemsToRender);
            } else {
                if (logger.isDebugEnabled())
                    logger.debug("There are no items to render!");
            }
        } else {
            // show all the properties for the current node
            if (logger.isDebugEnabled())
                logger.debug("Configuring property sheet using node's current state");
            createComponentsFromNode(context, node);
        }
    }
    // put the node in the session if it is not there already
    Map sessionMap = getFacesContext().getExternalContext().getSessionMap();
    sessionMap.put(this.variable, node);
    if (logger.isDebugEnabled())
        logger.debug("Put node into session with key '" + this.variable + "': " + node);
    super.encodeBegin(context);
}
Also used : ItemConfig(org.alfresco.web.config.PropertySheetConfigElement.ItemConfig) ConfigLookupContext(org.springframework.extensions.config.ConfigLookupContext) ConfigService(org.springframework.extensions.config.ConfigService) PropertySheetConfigElement(org.alfresco.web.config.PropertySheetConfigElement) PropertyConfig(org.alfresco.web.config.PropertySheetConfigElement.PropertyConfig) SeparatorConfig(org.alfresco.web.config.PropertySheetConfigElement.SeparatorConfig) AssociationConfig(org.alfresco.web.config.PropertySheetConfigElement.AssociationConfig) ChildAssociationConfig(org.alfresco.web.config.PropertySheetConfigElement.ChildAssociationConfig) ItemConfig(org.alfresco.web.config.PropertySheetConfigElement.ItemConfig) Config(org.springframework.extensions.config.Config) Node(org.alfresco.web.bean.repository.Node) Map(java.util.Map)

Example 5 with ConfigService

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

the class UIOpenSearch method getRegisteredEngines.

/**
 * Returns a list of OpenSearchEngine objects representing the
 * registered OpenSearch engines.
 *
 * @param context Faces context
 * @return List of registered engines
 */
private List<OpenSearchEngine> getRegisteredEngines(FacesContext context) {
    List<OpenSearchEngine> engines = null;
    // get the web api config service object from spring
    ConfigService cfgSvc = (ConfigService) FacesContextUtils.getRequiredWebApplicationContext(context).getBean("webscripts.config");
    SearchProxy searchProxy = (SearchProxy) FacesContextUtils.getRequiredWebApplicationContext(context).getBean("webscript.org.alfresco.repository.search.searchproxy.get");
    if (cfgSvc != null) {
        // get the OpenSearch configuration
        Config cfg = cfgSvc.getConfig("OpenSearch");
        OpenSearchConfigElement osConfig = (OpenSearchConfigElement) cfg.getConfigElement(OpenSearchConfigElement.CONFIG_ELEMENT_ID);
        if (osConfig != null) {
            // generate the the list of engines with a unique for each
            int id = 1;
            engines = new ArrayList<OpenSearchEngine>();
            Set<EngineConfig> enginesCfg = osConfig.getEngines();
            for (EngineConfig engineCfg : enginesCfg) {
                // resolve engine label
                String label = engineCfg.getLabel();
                String labelId = engineCfg.getLabelId();
                if (labelId != null && labelId.length() > 0) {
                    label = Application.getMessage(context, labelId);
                }
                // locate search engine template url of most appropriate response type
                String url = searchProxy.createUrl(engineCfg, MimetypeMap.MIMETYPE_ATOM);
                if (url == null) {
                    url = searchProxy.createUrl(engineCfg, MimetypeMap.MIMETYPE_RSS);
                }
                if (url != null) {
                    if (url.startsWith("/")) {
                        url = context.getExternalContext().getRequestContextPath() + "/wcservice" + url;
                    }
                    // add the engine
                    OpenSearchEngine engine = new OpenSearchEngine(id, label, url);
                    engines.add(engine);
                    // increase the id counter
                    id++;
                }
            }
        }
    }
    return engines;
}
Also used : ConfigService(org.springframework.extensions.config.ConfigService) EngineConfig(org.alfresco.repo.web.scripts.config.OpenSearchConfigElement.EngineConfig) Config(org.springframework.extensions.config.Config) SearchProxy(org.alfresco.repo.web.scripts.bean.SearchProxy) EngineConfig(org.alfresco.repo.web.scripts.config.OpenSearchConfigElement.EngineConfig) OpenSearchConfigElement(org.alfresco.repo.web.scripts.config.OpenSearchConfigElement)

Aggregations

ConfigService (org.springframework.extensions.config.ConfigService)35 Config (org.springframework.extensions.config.Config)28 ConfigElement (org.springframework.extensions.config.ConfigElement)18 SelectItem (javax.faces.model.SelectItem)10 QuickSort (org.alfresco.web.data.QuickSort)9 FacesContext (javax.faces.context.FacesContext)7 DialogConfig (org.alfresco.web.config.DialogsConfigElement.DialogConfig)5 WizardConfig (org.alfresco.web.config.WizardsConfigElement.WizardConfig)5 ClientConfigElement (org.alfresco.web.config.ClientConfigElement)4 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)3 QName (org.alfresco.service.namespace.QName)3 IOException (java.io.IOException)2 Map (java.util.Map)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 PropertySheetConfigElement (org.alfresco.web.config.PropertySheetConfigElement)2 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 UIComponent (javax.faces.component.UIComponent)1 ResponseWriter (javax.faces.context.ResponseWriter)1 PropertyNotFoundException (javax.faces.el.PropertyNotFoundException)1