Package org.apache.commons.validator

Examples of org.apache.commons.validator.ValidatorResources


     */
    public static void main(String[] args)
        throws ValidatorException, IOException, SAXException {
           
        InputStream in = null;
        ValidatorResources resources = null;
       
        try {
       
            // Create a new instance of a ValidatorResource, then get a stream
            // 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.
            in = ValidateExample.class.getResourceAsStream("validator-example.xml");
            resources = new ValidatorResources(in);
           
        } finally {
            // Make sure we close the input stream.
            if (in != null) {
                in.close();
View Full Code Here


            for (int streamIndex = 0;streamIndex < streamSize;streamIndex++) {
                InputStream is = (InputStream) streamList.get(streamIndex);
                streamArray[streamIndex] = is;
            }

            this.resources = new ValidatorResources(streamArray);
        } catch (SAXException sex) {
            log.error("Skipping all validation",sex);
            throw new ServletException(sex);
        } finally {
            Iterator streamIterator = streamList.iterator();
View Full Code Here

     */
    public int doStartTag() throws JspException {
        StringBuffer results = new StringBuffer();

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

        Locale locale = RequestUtils.retrieveUserLocale(this.pageContext, null);

        Form form = resources.get(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.getDependencies().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

     */
    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

        ServletContext application,
        HttpServletRequest request,
        ActionMessages errors,
        int page) {

        ValidatorResources resources =
            Resources.getValidatorResources(application, request);

        Locale locale = RequestUtils.getUserLocale(request, null);

        Validator validator = new Validator(resources, key);
View Full Code Here

        setFormName(formName);

        StringBuffer results = new StringBuffer();

        ModuleConfig config = RequestUtils.getModuleConfig(request, app);
        ValidatorResources resources =
            (ValidatorResources)app.getAttribute(ValidatorPlugIn.VALIDATOR_KEY +
                                                 config.getPrefix());

        Locale locale = StrutsUtils.getLocale(request, session);

        Form form = resources.get(locale, formName);
        if (form != null)
        {
            if(this.dynamicJavascript)
            {
                results.append(getDynamicJavascript(resources, locale, form));
View Full Code Here

     */
    public static void main(String[] args)
        throws ValidatorException, IOException, SAXException {
           
        InputStream in = null;
        ValidatorResources resources = null;
       
        try {
       
            // Create a new instance of a ValidatorResource, then get a stream
            // 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.
            in = ValidateExample.class.getResourceAsStream("validator-example.xml");
            resources = new ValidatorResources(in);
           
        } finally {
            // Make sure we close the input stream.
            if (in != null) {
                in.close();
View Full Code Here

        ServletContext application,
        HttpServletRequest request,
        ActionErrors errors,
        int page) {
   
        ValidatorResources resources =
            Resources.getValidatorResources(application, request);
           
        Locale locale = Resources.getLocale(request);
   
        Validator validator = new Validator(resources, key);
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.