Search in sources :

Example 6 with ConfigService

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

the class CreateRuleWizard method initialiseConditionHandlers.

/**
 * Initialises the condition handlers from the current configuration.
 */
protected void initialiseConditionHandlers() {
    if ((this.conditionHandlers == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
        Config wizardCfg = svc.getConfig("Action Wizards");
        if (wizardCfg != null) {
            ConfigElement conditionHandlerCfg = wizardCfg.getConfigElement("condition-handlers");
            if (conditionHandlerCfg != null) {
                this.conditionHandlers = new HashMap<String, IHandler>(20);
                // instantiate each handler and store in the map
                for (ConfigElement child : conditionHandlerCfg.getChildren()) {
                    String conditionName = child.getAttribute("name");
                    String handlerClass = child.getAttribute("class");
                    if (conditionName != null && conditionName.length() > 0 && handlerClass != null && handlerClass.length() > 0) {
                        try {
                            @SuppressWarnings("unchecked") Class klass = Class.forName(handlerClass);
                            IHandler handler = (IHandler) klass.newInstance();
                            this.conditionHandlers.put(conditionName, handler);
                        } catch (Exception e) {
                            throw new AlfrescoRuntimeException("Failed to setup condition handler for '" + conditionName + "'", e);
                        }
                    }
                }
            } else {
                logger.warn("Could not find 'condition-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) IHandler(org.alfresco.web.bean.actions.IHandler) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 7 with ConfigService

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

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

the class DocumentPropertiesDialog method getOtherPropertiesPresent.

/**
 * Determines whether this document has any other properties other than the
 * default set to display to the user.
 *
 * @return true of there are properties to show, false otherwise
 */
public boolean getOtherPropertiesPresent() {
    if ((this.hasOtherProperties == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        // we need to use the config service to see whether there are any
        // editable properties configured for this document.
        ConfigService configSvc = Application.getConfigService(FacesContext.getCurrentInstance());
        Config configProps = configSvc.getConfig(this.editableNode);
        PropertySheetConfigElement propsToDisplay = (PropertySheetConfigElement) configProps.getConfigElement("property-sheet");
        if (propsToDisplay != null && propsToDisplay.getEditableItemNamesToShow().size() > 0) {
            this.hasOtherProperties = Boolean.TRUE;
        } else {
            this.hasOtherProperties = Boolean.FALSE;
        }
    }
    return this.hasOtherProperties.booleanValue();
}
Also used : ConfigService(org.springframework.extensions.config.ConfigService) PropertySheetConfigElement(org.alfresco.web.config.PropertySheetConfigElement) Config(org.springframework.extensions.config.Config)

Example 9 with ConfigService

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

the class DashboardManager method getDashboardConfig.

/**
 * @return The externally configured WebClient config element for the Dashboards
 */
public static DashboardsConfigElement getDashboardConfig() {
    ConfigService service = Application.getConfigService(FacesContext.getCurrentInstance());
    DashboardsConfigElement config = (DashboardsConfigElement) service.getConfig("Dashboards").getConfigElement(DashboardsConfigElement.CONFIG_ELEMENT_ID);
    return config;
}
Also used : ConfigService(org.springframework.extensions.config.ConfigService) DashboardsConfigElement(org.alfresco.web.config.DashboardsConfigElement)

Example 10 with ConfigService

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

the class AlfrescoFacesPortlet method facesRender.

/**
 * @see org.apache.myfaces.portlet.MyFacesGenericPortlet#facesRender(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
 */
protected void facesRender(RenderRequest request, RenderResponse response) throws PortletException, IOException {
    Application.setInPortalServer(true);
    try {
        // Set the current locale
        I18NUtil.setLocale(getLanguage(request.getPortletSession()));
        if (request.getParameter(ERROR_OCCURRED) != null) {
            String errorPage = getErrorPage();
            if (logger.isDebugEnabled())
                logger.debug("An error has occurred, redirecting to error page: " + errorPage);
            response.setContentType("text/html");
            PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher(errorPage);
            dispatcher.include(request, response);
        } else {
            WebApplicationContext ctx = (WebApplicationContext) getPortletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
            AuthenticationService auth = (AuthenticationService) ctx.getBean("AuthenticationService");
            // if we have no User object in the session then an HTTP Session timeout must have occured
            // use the viewId to check that we are not already on the login page
            PortletSession session = request.getPortletSession();
            String viewId = request.getParameter(VIEW_ID);
            // keep track of last view id so we can use it as return page from multi-part requests
            request.getPortletSession().setAttribute(SESSION_LAST_VIEW_ID, viewId);
            SessionUser sessionUser = (SessionUser) request.getPortletSession().getAttribute(AuthenticationHelper.AUTHENTICATION_USER, PortletSession.APPLICATION_SCOPE);
            User user = sessionUser instanceof User ? (User) sessionUser : null;
            if (user == null && (viewId == null || viewId.equals(getLoginPage()) == false)) {
                if (portalGuestAuthenticate(ctx, session, auth) != null) {
                    if (logger.isDebugEnabled())
                        logger.debug("Guest access successful.");
                    // perform the forward to the page processed by the Faces servlet
                    response.setContentType("text/html");
                    request.getPortletSession().setAttribute(PortletUtil.PORTLET_REQUEST_FLAG, "true");
                    // get the start location as configured by the web-client config
                    ConfigService configService = (ConfigService) ctx.getBean("webClientConfigService");
                    ClientConfigElement configElement = (ClientConfigElement) configService.getGlobalConfig().getConfigElement("client");
                    if (NavigationBean.LOCATION_MYALFRESCO.equals(configElement.getInitialLocation())) {
                        nonFacesRequest(request, response, "/jsp/dashboards/container.jsp");
                    } else {
                        nonFacesRequest(request, response, FacesHelper.BROWSE_VIEW_ID);
                    }
                } else {
                    if (logger.isDebugEnabled())
                        logger.debug("No valid User login, requesting login page. ViewId: " + viewId);
                    // set last used username as special session value used by the LoginBean
                    session.setAttribute(AuthenticationHelper.SESSION_USERNAME, request.getPreferences().getValue(PREF_ALF_USERNAME, null));
                    // login page is the default portal page
                    response.setContentType("text/html");
                    request.getPortletSession().setAttribute(PortletUtil.PORTLET_REQUEST_FLAG, "true");
                    nonFacesRequest(request, response);
                }
            } else {
                if (session.getAttribute(AuthenticationHelper.SESSION_INVALIDATED) != null) {
                    // remove the username preference value as explicit logout was requested by the user
                    if (request.getPreferences().isReadOnly(PREF_ALF_USERNAME) == false) {
                        request.getPreferences().reset(PREF_ALF_USERNAME);
                    }
                    session.removeAttribute(AuthenticationHelper.SESSION_INVALIDATED);
                }
                try {
                    if (user != null) {
                        if (logger.isDebugEnabled())
                            logger.debug("Validating ticket: " + user.getTicket());
                        // setup the authentication context
                        auth.validate(user.getTicket());
                    }
                    // do the normal JSF processing
                    super.facesRender(request, response);
                } catch (AuthenticationException authErr) {
                    // ticket is no longer valid!
                    if (logger.isDebugEnabled())
                        logger.debug("Invalid ticket, requesting login page.");
                    // remove User object as it's now useless
                    session.removeAttribute(AuthenticationHelper.AUTHENTICATION_USER, PortletSession.APPLICATION_SCOPE);
                    // login page is the default portal page
                    response.setContentType("text/html");
                    request.getPortletSession().setAttribute(PortletUtil.PORTLET_REQUEST_FLAG, "true");
                    nonFacesRequest(request, response);
                } catch (Throwable e) {
                    if (getErrorPage() != null) {
                        handleError(request, response, e);
                    } else {
                        logger.warn("No error page configured, re-throwing exception");
                        if (e instanceof PortletException) {
                            throw (PortletException) e;
                        } else if (e instanceof IOException) {
                            throw (IOException) e;
                        } else {
                            throw new PortletException(e);
                        }
                    }
                }
            }
        }
    } finally {
        Application.setInPortalServer(false);
    }
}
Also used : User(org.alfresco.web.bean.repository.User) SessionUser(org.alfresco.repo.SessionUser) AuthenticationException(org.alfresco.repo.security.authentication.AuthenticationException) PortletException(javax.portlet.PortletException) IOException(java.io.IOException) ClientConfigElement(org.alfresco.web.config.ClientConfigElement) WebApplicationContext(org.springframework.web.context.WebApplicationContext) PortletRequestDispatcher(javax.portlet.PortletRequestDispatcher) SessionUser(org.alfresco.repo.SessionUser) ConfigService(org.springframework.extensions.config.ConfigService) PortletSession(javax.portlet.PortletSession) AuthenticationService(org.alfresco.service.cmr.security.AuthenticationService)

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