Package org.apache.commons.validator

Examples of org.apache.commons.validator.ValidatorResources


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

        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

     */
    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 = null;
        try {
            locale =
                (Locale) pageContext.getAttribute(Globals.LOCALE_KEY, PageContext.SESSION_SCOPE);
        } catch (IllegalStateException e) { // Invalidated session
            locale = null;
        }

        if (locale == null) {
            locale = defaultLocale;
        }

        Form form = null;
        form = resources.get(locale, formName);
        if (form != null) {
            if ("true".equals(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);

        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

        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

            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

    // Test retrieving resources
    public void testResources() {

        ValidatorAction action = null;

        ValidatorResources resources = validator.resources(facesContext);
        assertNotNull(resources);

        action = resources.getValidatorAction("integer");
        assertNotNull(action);

        action = resources.getValidatorAction("intRange");
        assertNotNull(action);

        action = resources.getValidatorAction("???undefined");
        assertNull(action);

    }
View Full Code Here

    // Test whether the precalculated validator actions includes the data
    // that it should
    public void testActions() {

        // Acquire the configuration data we will need
        ValidatorResources resources = (ValidatorResources)
          servletContext.getAttribute(Globals.VALIDATOR_RESOURCES);
        Map vamap = resources.getValidatorActions();
        Map actions = (Map)
          servletContext.getAttribute(Globals.VALIDATOR_ACTIONS);

        // The precalculated map will not include an entry for
        // "includeJavaScriptUtilities" because it is not a real validation type
        assertEquals(vamap.size() - 1, actions.size());

        // Verify the number of actions for each precalculated validator
        // This also indirectly checks that all entries that should be
        // precalculated are actually present
        Iterator entries = ACTION_COUNTS.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry entry = (Map.Entry) entries.next();
            String key = (String) entry.getKey();
            Integer value = (Integer) entry.getValue();
            ValidatorAction va = resources.getValidatorAction(key);
            assertTrue("ValidatorAction " + key + " is present", va != null);
            ShaleValidatorAction[] action = (ShaleValidatorAction[])
              actions.get(key);
            assertTrue("ShaleValidatorAction[] " + key + " is present", action != null);
            assertEquals("ShaleValidatorAction[] " + key + " has correct size",
View Full Code Here

    // Test a pristine instance of the listener
    public void testPristine() {

        assertNotNull(listener);

        ValidatorResources resources = (ValidatorResources)
          servletContext.getAttribute(Globals.VALIDATOR_RESOURCES);
        assertNotNull(resources);
        Map vamap = resources.getValidatorActions();

        Map actions = (Map)
          servletContext.getAttribute(Globals.VALIDATOR_ACTIONS);
        assertNotNull(actions);
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

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.