Package net.sourceforge.stripes.config

Examples of net.sourceforge.stripes.config.Configuration


     * @param isForPage true if the URL is to be embedded in a page (e.g. in an anchor of img tag),
     *            false if for some other purpose.
     */
    public UrlBuilder(Locale locale, Class<? extends ActionBean> beanType, boolean isForPage) {
        this(locale, isForPage);
        Configuration configuration = StripesFilter.getConfiguration();
        if (configuration != null) {
            this.baseUrl = configuration.getActionResolver().getUrlBinding(beanType);
        }
        else {
            throw new StripesRuntimeException("Unable to lookup URL binding for ActionBean class "
                    + "because there is no Configuration object available.");
        }
View Full Code Here


     * @param value the object to be formatted
     * @return a formatter, if one can be found; null otherwise
     */
    @SuppressWarnings("unchecked")
  protected Formatter getFormatter(Object value) {
        Configuration configuration = StripesFilter.getConfiguration();
        if (configuration == null)
            return null;

        FormatterFactory factory = configuration.getFormatterFactory();
        if (factory == null)
            return null;

        return factory.getFormatter(value.getClass(), locale, null, null);
    }
View Full Code Here

     * @return a map of ActionBean property names to their validation metadata
     * @see ValidationMetadataProvider#getValidationMetadata(Class)
     */
    protected Map<String, ValidationMetadata> getValidationMetadata() {
        Map<String, ValidationMetadata> validations = null;
        Configuration configuration = StripesFilter.getConfiguration();
        if (configuration != null) {
            Class<? extends ActionBean> beanType = null;
            try {
                beanType = configuration.getActionResolver().getActionBeanType(this.baseUrl);
            }
            catch (UrlBindingConflictException e) {
                // This can be safely ignored
            }

            if (beanType != null) {
                validations = configuration.getValidationMetadataProvider().getValidationMetadata(
                        beanType);
            }
        }

        if (validations == null)
View Full Code Here

    /**
     * Returns the Configuration that is being used to process the current request.
     */
    public static Configuration getConfiguration() {
        Configuration configuration = StripesFilter.configurationStash.get();

        // If the configuration wasn't available in thread local, check to see if we only
        // know about one configuration in total, and if so use that one
        if (configuration == null) {
            synchronized (StripesFilter.configurations) {
View Full Code Here

        // Check to see if the action bean already exists
        ActionBean actionBean = (ActionBean) getPageContext().findAttribute(binding);
        boolean beanNotPresent = actionBean == null;

        try {
            final Configuration config = StripesFilter.getConfiguration();
            final ActionResolver resolver = StripesFilter.getConfiguration().getActionResolver();
            final HttpServletRequest request = (HttpServletRequest) getPageContext().getRequest();
            final HttpServletResponse response = (HttpServletResponse) getPageContext().getResponse();
            Resolution resolution = null;
            ExecutionContext ctx = new ExecutionContext();

            // Lookup the ActionBean if we don't already have it
            if (beanNotPresent) {
                ActionBeanContext tempContext =
                        config.getActionBeanContextFactory().getContextInstance(request, response);
                tempContext.setServletContext(getPageContext().getServletContext());
                ctx.setLifecycleStage(LifecycleStage.ActionBeanResolution);
                ctx.setActionBeanContext(tempContext);

                // Run action bean resolution
                ctx.setInterceptors(config.getInterceptors(LifecycleStage.ActionBeanResolution));
                resolution = ctx.wrap( new Interceptor() {
                    public Resolution intercept(ExecutionContext ec) throws Exception {
                        ActionBean bean = resolver.getActionBean(ec.getActionBeanContext(), binding);
                        ec.setActionBean(bean);
                        return null;
                    }
                });
            }
            else {
                ctx.setActionBean(actionBean);
                ctx.setActionBeanContext(actionBean.getContext());
            }

            // Then, if and only if an event was specified, run handler resolution
            if (resolution == null && event != null && (beanNotPresent || this.alwaysExecuteEvent)) {
                ctx.setLifecycleStage(LifecycleStage.HandlerResolution);
                ctx.setInterceptors(config.getInterceptors(LifecycleStage.HandlerResolution));
                resolution = ctx.wrap( new Interceptor() {
                    public Resolution intercept(ExecutionContext ec) throws Exception {
                        ec.setHandler(resolver.getHandler(ec.getActionBean().getClass(), event));
                        ec.getActionBeanContext().setEventName(event);
                        return null;
                    }
                });
            }

            // Make the PageContext available during the validation stage so that we
            // can execute EL based expression validation
            try {
                DispatcherHelper.setPageContext(getPageContext());

                // Bind applicable request parameters to the ActionBean
                if (resolution == null && (beanNotPresent || this.validate == true)) {
                    resolution = DispatcherHelper.doBindingAndValidation(ctx, this.validate);
                }

                // Run custom validations if we're validating
                if (resolution == null && this.validate == true) {
                    String temp =  config.getBootstrapPropertyResolver().getProperty(
                                        DispatcherServlet.RUN_CUSTOM_VALIDATION_WHEN_ERRORS);
                    boolean validateWhenErrors = temp != null && Boolean.valueOf(temp);

                    resolution = DispatcherHelper.doCustomValidation(ctx, validateWhenErrors);
                }
View Full Code Here

     * @param ctx the ExecutionContext being used to process the current request
     * @return a Resolution if any interceptor determines that the request processing should
     *         be aborted in favor of another Resolution, null otherwise.
     */
    public static Resolution resolveActionBean(final ExecutionContext ctx) throws Exception {
        final Configuration config = StripesFilter.getConfiguration();
        ctx.setLifecycleStage(LifecycleStage.ActionBeanResolution);
        ctx.setInterceptors(config.getInterceptors(LifecycleStage.ActionBeanResolution));
        return  ctx.wrap( new Interceptor() {
            public Resolution intercept(ExecutionContext ctx) throws Exception {
                // Look up the ActionBean and set it on the context
                ActionBeanContext context = ctx.getActionBeanContext();
                ActionBean bean = StripesFilter.getConfiguration().getActionResolver().getActionBean(context);
View Full Code Here

     * @param ctx the ExecutionContext being used to process the current request
     * @return a Resolution if any interceptor determines that the request processing should
     *         be aborted in favor of another Resolution, null otherwise.
     */
    public static Resolution resolveHandler(final ExecutionContext ctx) throws Exception {
        final Configuration config = StripesFilter.getConfiguration();
        ctx.setLifecycleStage(LifecycleStage.HandlerResolution);
        ctx.setInterceptors(config.getInterceptors(LifecycleStage.HandlerResolution));

        return ctx.wrap( new Interceptor() {
            public Resolution intercept(ExecutionContext ctx) throws Exception {
                ActionBean bean = ctx.getActionBean();
                ActionBeanContext context = ctx.getActionBeanContext();
                ActionResolver resolver = config.getActionResolver();

                // Then lookup the event name and handler method etc.
                String eventName = resolver.getEventName(bean.getClass(), context);
                context.setEventName(eventName);

View Full Code Here

                                                    final boolean validate) throws Exception {
        // Bind the value to the bean - this includes performing field level validation
        final Method handler = ctx.getHandler();
        final boolean doBind = handler == null || handler.getAnnotation(DontBind.class) == null;
        final boolean doValidate = doBind && validate && (handler == null || handler.getAnnotation(DontValidate.class) == null);
        final Configuration config = StripesFilter.getConfiguration();

        ctx.setLifecycleStage(LifecycleStage.BindingAndValidation);
        ctx.setInterceptors(config.getInterceptors(LifecycleStage.BindingAndValidation));

        return ctx.wrap(new Interceptor() {
            public Resolution intercept(ExecutionContext ctx) throws Exception {
                if (doBind) {
                    ActionBeanPropertyBinder binder = config.getActionBeanPropertyBinder();
                    binder.bind(ctx.getActionBean(), ctx.getActionBeanContext(), doValidate);
                    fillInValidationErrors(ctx);
                }
                return null;
            }
View Full Code Here

        final ValidationErrors errors = ctx.getActionBeanContext().getValidationErrors();
        final ActionBean bean = ctx.getActionBean();
        final Method handler = ctx.getHandler();
        final boolean doBind = handler != null && handler.getAnnotation(DontBind.class) == null;
        final boolean doValidate = doBind && handler.getAnnotation(DontValidate.class) == null;
        Configuration config = StripesFilter.getConfiguration();

        // Run the bean's methods annotated with @ValidateMethod if the following conditions are met:
        //   l. This event is not marked to bypass binding
        //   2. This event is not marked to bypass validation (doValidate == true)
        //   3. We have no errors so far OR alwaysInvokeValidate is true
        if (doValidate) {

            ctx.setLifecycleStage(LifecycleStage.CustomValidation);
            ctx.setInterceptors(config.getInterceptors(LifecycleStage.CustomValidation));

            return ctx.wrap( new Interceptor() {
        public Resolution intercept(ExecutionContext context) throws Exception {
                    // Run any of the annotated validation methods
                    Method[] validations = findCustomValidationMethods(bean.getClass());
View Full Code Here

     *        type conversion should occur
     * @return a Resolution if the error handling code determines that some kind of resolution
     *         should be processed in favor of continuing on to handler invocation
     */
    public static Resolution invokeEventHandler(ExecutionContext ctx) throws Exception {
        final Configuration config = StripesFilter.getConfiguration();
        final Method handler = ctx.getHandler();
        final ActionBean bean = ctx.getActionBean();

        // Finally execute the handler method!
        ctx.setLifecycleStage(LifecycleStage.EventHandling);
        ctx.setInterceptors(config.getInterceptors(LifecycleStage.EventHandling));

        return ctx.wrap( new Interceptor() {
            public Resolution intercept(ExecutionContext ctx) throws Exception {
                Object returnValue = handler.invoke(bean);
                fillInValidationErrors(ctx);
View Full Code Here

TOP

Related Classes of net.sourceforge.stripes.config.Configuration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.