Package com.opensymphony.xwork2.validator.validators

Examples of com.opensymphony.xwork2.validator.validators.RegexFieldValidator


  }

  protected ClassLoaderInterface getClassLoaderInterface() {
    if (isReloadEnabled()) return new ClassLoaderInterfaceDelegate(reloadingClassLoader);
    else {
      ClassLoaderInterface classLoaderInterface = null;
      ActionContext ctx = ActionContext.getContext();
      if (ctx != null) classLoaderInterface = (ClassLoaderInterface) ctx
          .get(ClassLoaderInterface.CLASS_LOADER_INTERFACE);
      return (ClassLoaderInterface) ObjectUtils.defaultIfNull(classLoaderInterface,
          new ClassLoaderInterfaceDelegate(getClassLoader()));
View Full Code Here


  }

  private Set<URL> buildUrls() {
    Set<URL> urls = CollectUtils.newHashSet();
    Enumeration<URL> em;
    ClassLoaderInterface classloader = getClassLoaderInterface();
    try {
      em = classloader.getResources("struts-plugin.xml");
      while (em.hasMoreElements()) {
        URL url = em.nextElement();
        urls.add(new URL(substringBeforeLast(url.toExternalForm(), "struts-plugin.xml")));
      }
      em = classloader.getResources("struts.xml");
      while (em.hasMoreElements()) {
        URL url = em.nextElement();
        urls.add(new URL(substringBeforeLast(url.toExternalForm(), "struts.xml")));
      }
    } catch (IOException e) {
View Full Code Here

    logger.info("Action scan completely,create {} action in {} ms", newActions,
        System.currentTimeMillis() - start);
  }

  protected ClassLoaderInterface getClassLoaderInterface() {
    if (isReloadEnabled()) return new ClassLoaderInterfaceDelegate(reloadingClassLoader);
    else {
      ClassLoaderInterface classLoaderInterface = null;
      ActionContext ctx = ActionContext.getContext();
      if (ctx != null) classLoaderInterface = (ClassLoaderInterface) ctx
          .get(ClassLoaderInterface.CLASS_LOADER_INTERFACE);
      return (ClassLoaderInterface) ObjectUtils.defaultIfNull(classLoaderInterface,
          new ClassLoaderInterfaceDelegate(getClassLoader()));
    }
  }
View Full Code Here

        // happen
        // This is a critical exception, so we better throw a
        // ValidationException
        // no need to continue
        logger.error(e);
        throw new ValidationException("Could not open inputstream for "
            + i);
      }
      imageSize = (int) i.length();
    } else {
      // it's .. uhm, something else. A football ? A hot blonde's address
      // ? Fourty Two ? We'll never know ..
      throw new ValidationException(
          "Invalid object. Expect either a String or File object. Object is "
              + image.getClass().getName());
    }
    if (!ii.check()) {
      setMessageKey(getMessageKey() + ".invalid");
View Full Code Here

        validator.setExpression("^Hello.*");
        assertEquals("^Hello.*", validator.getExpression());
    }

    public void testIsTrimmed() throws Exception {
        RegexFieldValidator validator = new RegexFieldValidator();
        assertEquals(true, validator.isTrimed());
        validator.setTrim(false);
        assertEquals(false, validator.isTrimed());
    }
View Full Code Here

        testPerson.setUsername("");

        ValueStack stack = ActionContext.getContext().getValueStack();
        ActionContext.getContext().setValueStack(stack);

        RegexFieldValidator validator = new RegexFieldValidator();
        validator.setExpression("^Sec.*");
        validator.setValidatorContext(new GenericValidatorContext(new Object()));
        validator.setFieldName("username");
        validator.setValueStack(ActionContext.getContext().getValueStack());
        validator.validate(testPerson);

        assertFalse(validator.getValidatorContext().hasErrors());
        assertFalse(validator.getValidatorContext().hasActionErrors());
        assertFalse(validator.getValidatorContext().hasActionMessages());
        assertFalse(validator.getValidatorContext().hasFieldErrors());
    }
View Full Code Here

        testPerson.setAge(33);

        ValueStack stack = ActionContext.getContext().getValueStack();
        ActionContext.getContext().setValueStack(stack);

        RegexFieldValidator validator = new RegexFieldValidator();
        validator.setExpression("[0-9][0-9]");
        validator.setValidatorContext(new GenericValidatorContext(new Object()));
        validator.setFieldName("age");
        validator.setValueStack(ActionContext.getContext().getValueStack());
        validator.validate(testPerson);

        assertFalse(validator.getValidatorContext().hasErrors());
        assertFalse(validator.getValidatorContext().hasActionErrors());
        assertFalse(validator.getValidatorContext().hasActionMessages());
        assertFalse(validator.getValidatorContext().hasFieldErrors());
    }
View Full Code Here

        testPerson.setUsername("Secret");

        ValueStack stack = ActionContext.getContext().getValueStack();
        ActionContext.getContext().setValueStack(stack);

        RegexFieldValidator validator = new RegexFieldValidator();
        validator.setExpression("^Sec.*");
        validator.setValidatorContext(new GenericValidatorContext(new Object()));
        validator.setFieldName("username");
        validator.setValueStack(ActionContext.getContext().getValueStack());
        validator.validate(testPerson);

        assertFalse(validator.getValidatorContext().hasErrors());
        assertFalse(validator.getValidatorContext().hasActionErrors());
        assertFalse(validator.getValidatorContext().hasActionMessages());
        assertFalse(validator.getValidatorContext().hasFieldErrors());
    }
View Full Code Here

        testPerson.setUsername("Secret "); // must end with one whitespace

        ValueStack stack = ActionContext.getContext().getValueStack();
        ActionContext.getContext().setValueStack(stack);

        RegexFieldValidator validator = new RegexFieldValidator();
        validator.setTrim(false);
        validator.setExpression("^Sec.*\\s");
        validator.setValidatorContext(new GenericValidatorContext(new Object()));
        validator.setFieldName("username");
        validator.setValueStack(ActionContext.getContext().getValueStack());
        validator.validate(testPerson);

        assertFalse(validator.getValidatorContext().hasErrors());
        assertFalse(validator.getValidatorContext().hasActionErrors());
        assertFalse(validator.getValidatorContext().hasActionMessages());
        assertFalse(validator.getValidatorContext().hasFieldErrors());
    }
View Full Code Here

        testPerson.setUsername("Superman");

        ValueStack stack = ActionContext.getContext().getValueStack();
        ActionContext.getContext().setValueStack(stack);

        RegexFieldValidator validator = new RegexFieldValidator();
        validator.setExpression("^Sec.*");
        validator.setValidatorContext(new GenericValidatorContext(new Object()));
        validator.setFieldName("username");
        validator.setValueStack(ActionContext.getContext().getValueStack());
        validator.validate(testPerson);

        assertTrue(validator.getValidatorContext().hasErrors());
        assertTrue(validator.getValidatorContext().hasFieldErrors());
        List<String> msgs = validator.getValidatorContext().getFieldErrors().get("username");
        assertNotNull(msgs);
        assertTrue(msgs.size() == 1); // should contain 1 error message

        // when failing the validator will not add action errors/msg
        assertFalse(validator.getValidatorContext().hasActionErrors());
        assertFalse(validator.getValidatorContext().hasActionMessages());
    }
View Full Code Here

TOP

Related Classes of com.opensymphony.xwork2.validator.validators.RegexFieldValidator

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.