Package org.apache.commons.validator

Examples of org.apache.commons.validator.ValidatorResources


                URL url = (URL) urlList.get(urlIndex);

                urlArray[urlIndex] = url.toExternalForm();
            }

            this.resources = new ValidatorResources(urlArray);
        } catch (SAXException sex) {
            log.error("Skipping all validation", sex);
            throw new ServletException(sex);
        }
    }
View Full Code Here


          (HttpServletRequest)pageContext.getRequest();
        ServletContext servletContext = pageContext.getServletContext();
        ModuleConfig config =
          ModuleUtils.getInstance().getModuleConfig(request, servletContext);

        ValidatorResources resources =
            (ValidatorResources) pageContext.getAttribute(
                ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix(),
                PageContext.APPLICATION_SCOPE);

        Locale locale = TagUtils.getInstance().getUserLocale(pageContext, null);

        Form form = resources.getForm(locale, formName);
        if (form != null) {
            if ("true".equalsIgnoreCase(dynamicJavascript)) {
                MessageResources messages =
                    (MessageResources) pageContext.getAttribute(
                        bundle + config.getPrefix(),
                        PageContext.APPLICATION_SCOPE);

                List lActions = new ArrayList();
                List lActionMethods = new ArrayList();

                // Get List of actions for this Form
                for (Iterator i = form.getFields().iterator(); i.hasNext();) {
                    Field field = (Field) i.next();

                    for (Iterator x = field.getDependencyList().iterator();
                        x.hasNext();) {
                        Object o = x.next();

                        if (o != null && !lActionMethods.contains(o)) {
                            lActionMethods.add(o);
                        }
                    }

                }

                // Create list of ValidatorActions based on lActionMethods
                for (Iterator i = lActionMethods.iterator(); i.hasNext();) {
                    String depends = (String) i.next();
                    ValidatorAction va = resources.getValidatorAction(depends);

                    // throw nicer NPE for easier debugging
                    if (va == null) {
                        throw new NullPointerException(
                            "Depends string \""
View Full Code Here

    private void initResources(ServletContext servletContext) {
        if (pathnames != null) {
            ActionContext ctx = ActionContext.getContext();
            try {
               
                ValidatorResources resources = this.loadResources(servletContext);
   
               
                String prefix = ctx.getActionInvocation().getProxy().getNamespace();
               
               
View Full Code Here

        }

        StringTokenizer st = new StringTokenizer(pathnames, RESOURCE_DELIM);

        List urlList = new ArrayList();
        ValidatorResources resources = null;
        try {
            while (st.hasMoreTokens()) {
                String validatorRules = st.nextToken().trim();

                if (LOG.isInfoEnabled()) {
                    LOG.info("Loading validation rules file from '"
                        + validatorRules + "'");
                }

                URL input =
                    ctx.getResource(validatorRules);

                // If the config isn't in the servlet context, try the class
                // loader which allows the config files to be stored in a jar
                if (input == null) {
                    input = getClass().getResource(validatorRules);
                }

                if (input != null) {
                    urlList.add(input);
                } else {
                    throw new ServletException(
                        "Skipping validation rules file from '"
                        + validatorRules + "'.  No url could be located.");
                }
            }

            int urlSize = urlList.size();
            String[] urlArray = new String[urlSize];

            for (int urlIndex = 0; urlIndex < urlSize; urlIndex++) {
                URL url = (URL) urlList.get(urlIndex);

                urlArray[urlIndex] = url.toExternalForm();
            }

            resources =  new ValidatorResources(urlArray);
        } catch (SAXException sex) {
            LOG.error("Skipping all validation", sex);
            throw new StrutsException("Skipping all validation because the validation files cannot be loaded", sex);
        }
        return resources;
View Full Code Here

        throws JspException {
        StringBuffer results = new StringBuffer();

        ModuleConfig config =
            TagUtils.getInstance().getModuleConfig(pageContext);
        ValidatorResources resources =
            (ValidatorResources) pageContext.getAttribute(
              ValidatorPlugIn.VALIDATOR_KEY
                + config.getPrefix(), PageContext.APPLICATION_SCOPE);

        if (resources == null) {
            throw new JspException(
                "ValidatorResources not found in application scope under key \""
                + ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix() + "\"");
        }

        Locale locale =
            TagUtils.getInstance().getUserLocale(this.pageContext, null);

        Form form = null;
        if ("true".equalsIgnoreCase(dynamicJavascript)) {
            form = resources.getForm(locale, formName);
            if (form == null) {
                throw new JspException("No form found under '" + formName
                    + "' in locale '" + locale
                    + "'.  A form must be defined in the "
                    + "Commons Validator configuration when "
View Full Code Here

            // handle on the XML file with the actions in it, and initialize the
            // resources from it.  This would normally be done by a servlet
            // run during JSP initialization or some other application-startup
            // routine.

            ValidatorResources resources = new ValidatorResources();
            in = ValidateExample.class.getResourceAsStream("validator-example.xml");
            ValidatorResourcesInitializer.initialize(resources, in);

            // Create a test bean to validate against.
            ValidateBean bean = new ValidateBean();
View Full Code Here

     */
    protected String renderJavascript() throws JspException {
        StringBuffer results = new StringBuffer();

        ModuleConfig config = TagUtils.getInstance().getModuleConfig(pageContext);
        ValidatorResources resources =
            (ValidatorResources) pageContext.getAttribute(
                ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix(),
                PageContext.APPLICATION_SCOPE);

        if (resources == null) {
            throw new JspException(
                "ValidatorResources not found in application scope under key \""
                + ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix() + "\"");
        }       

        Locale locale = TagUtils.getInstance().getUserLocale(this.pageContext, null);

        Form form = resources.getForm(locale, formName);

        if ("true".equalsIgnoreCase(dynamicJavascript) && form == null)
        {
            throw new JspException("No form found under '"
                                   + formName
View Full Code Here

    private void initResources(ServletContext servletContext) {
        if (pathnames != null) {
            ActionContext ctx = ActionContext.getContext();
            try {
               
                ValidatorResources resources = this.loadResources(servletContext);
   
               
                String prefix = ctx.getActionInvocation().getProxy().getNamespace();
               
               
View Full Code Here

        }

        StringTokenizer st = new StringTokenizer(pathnames, RESOURCE_DELIM);

        List urlList = new ArrayList();
        ValidatorResources resources = null;
        try {
            while (st.hasMoreTokens()) {
                String validatorRules = st.nextToken().trim();

                if (log.isInfoEnabled()) {
                    log.info("Loading validation rules file from '"
                        + validatorRules + "'");
                }

                URL input =
                    ctx.getResource(validatorRules);

                // If the config isn't in the servlet context, try the class
                // loader which allows the config files to be stored in a jar
                if (input == null) {
                    input = getClass().getResource(validatorRules);
                }

                if (input != null) {
                    urlList.add(input);
                } else {
                    throw new ServletException(
                        "Skipping validation rules file from '"
                        + validatorRules + "'.  No url could be located.");
                }
            }

            int urlSize = urlList.size();
            String[] urlArray = new String[urlSize];

            for (int urlIndex = 0; urlIndex < urlSize; urlIndex++) {
                URL url = (URL) urlList.get(urlIndex);

                urlArray[urlIndex] = url.toExternalForm();
            }

            resources =  new ValidatorResources(urlArray);
        } catch (SAXException sex) {
            log.error("Skipping all validation", sex);
            throw new StrutsException("Skipping all validation because the validation files cannot be loaded", sex);
        }
        return resources;
View Full Code Here

     */
    protected String renderJavascript() throws JspException {
        StringBuffer results = new StringBuffer();

        ModuleConfig config = TagUtils.getInstance().getModuleConfig(pageContext);
        ValidatorResources resources =
            (ValidatorResources) pageContext.getAttribute(
                ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix(),
                PageContext.APPLICATION_SCOPE);

        if (resources == null) {
            throw new JspException(
                "ValidatorResources not found in application scope under key \""
                + ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix() + "\"");
        }       

        Locale locale = TagUtils.getInstance().getUserLocale(this.pageContext, null);

        Form form = resources.getForm(locale, formName);

        if ("true".equalsIgnoreCase(dynamicJavascript) && form == null)
        {
            throw new JspException("No form found under '"
                                   + formName
View Full Code Here

TOP

Related Classes of org.apache.commons.validator.ValidatorResources

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.