Examples of UrlValidator


Examples of org.apache.commons.validator.UrlValidator

          }

        }

        // Create UrlValidator and validate with options/schemes
        UrlValidator urlValidator = new UrlValidator(schemes, options);
        if (urlValidator.isValid(value)) {
            return true;
        } else {
            errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
            return false;
        }
View Full Code Here

Examples of org.apache.commons.validator.UrlValidator

      }
      return true;
   }

   private static boolean isValidUrl(String url) {
      UrlValidator urlValidator = new UrlValidator();
      return urlValidator.isValid(url);
   }
View Full Code Here

Examples of org.apache.commons.validator.UrlValidator

    private static String getValidHref( String href )
    {
        href = href.trim();

        String[] schemes = {"http", "https"};
        UrlValidator urlValidator = new UrlValidator( schemes );

        if ( ( EmailValidator.getInstance().isValid( href ) ) ||
             ( ( href.indexOf( "?" ) != -1 ) &&
               ( EmailValidator.getInstance().isValid( href.substring( 0, href.indexOf( "?" ) ) ) ) ) )
        {
            return "mailto:" + href;
        }
        else if ( href.toLowerCase().startsWith( "mailto:" ) )
        {
            return href;
        }
        else if ( urlValidator.isValid( href ) )
        {
            return href;
        }
        else
        {
            // TODO Waiting for new release of Validator
            // http://issues.apache.org/bugzilla/show_bug.cgi?id=30686
            String hrefTmp;
            if ( !href.endsWith( "/" ) )
            {
                hrefTmp = href + "/index.html";
            }
            else
            {
                hrefTmp = href + "index.html";
            }

            if ( urlValidator.isValid( hrefTmp ) )
            {
                return href;
            }

            if ( href.startsWith( "./" ) )
View Full Code Here

Examples of org.apache.commons.validator.UrlValidator

          }

        }

        // Create UrlValidator and validate with options/schemes
        UrlValidator urlValidator = new UrlValidator(schemes, options);
        if (urlValidator.isValid(value)) {
            return true;
        } else {
            errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
            return false;
        }
View Full Code Here

Examples of org.apache.commons.validator.routines.UrlValidator

    * Testing the same method of URL validator used in validate method. Its was really hard to create Error object
    */
@Test
public void testValidation() throws Exception {
      RegexValidator regex = new RegexValidator(new String[]{"http","https","((localhost)(:[0-9]+))",".*\\.linux-server(:[0-9]+)"});
      UrlValidator validator = new UrlValidator(regex, 0);
      assertTrue("localhost URL should validate",
                validator.isValid("http://localhost:8080/demogadgets/CTSSResourcesMapView.xml"));
        assertTrue("127.0.0.1 should validate",
                validator.isValid("http://127.0.0.1:8080/demogadgets/CTSSResourcesMapView.xml"));
        assertTrue("my.linux-server should validate",
                validator.isValid("http://my.linux-server:8080/demogadgets/CTSSResourcesMapView.xml"));

        assertFalse("broke.my-test should not validate",
                validator.isValid("http://broke.my-test/test/index.html"));

        assertTrue("www.apache.org should still validate",
                validator.isValid("http://www.apache.org/test/index.html"));
    }
View Full Code Here

Examples of org.apache.commons.validator.routines.UrlValidator

    private final UrlValidator urlValidator;

    public WidgetValidator() {
        super();
        RegexValidator regex = new RegexValidator(new String[] {"http", "https","((localhost)(:[0-9]+))"});
        urlValidator = new UrlValidator(regex, 0);
    }
View Full Code Here

Examples of org.apache.commons.validator.routines.UrlValidator

      return false;
    } else {
      if (logger.isDebugEnabled()) {
        logger.debug("Required configuration found. Validating {}", stratosURL);
      }
      UrlValidator urlValidator = new UrlValidator(new String[] { "https" });
      if (!urlValidator.isValid(stratosURL)) {
        if (logger.isDebugEnabled()) {
          logger.debug("Stratos Controller URL {} is not valid", stratosURL);
        }
        System.out.format(
            "The \"%s\" variable in your environment is not a valid URL. You have provided \"%s\".%n"
View Full Code Here

Examples of org.apache.commons.validator.routines.UrlValidator

    private final UrlValidator urlValidator;

    public WidgetValidator() {
        super();
        RegexValidator regex = new RegexValidator(new String[] {"http", "https","((localhost)(:[0-9]+))"});
        urlValidator = new UrlValidator(regex, 0);
    }
View Full Code Here

Examples of org.apache.commons.validator.routines.UrlValidator

    * Testing the same method of URL validator used in validate method. Its was really hard to create Error object
    */
@Test
public void testValidation() throws Exception {
      RegexValidator regex = new RegexValidator(new String[]{"http","https","((localhost)(:[0-9]+))",".*\\.linux-server(:[0-9]+)"});
      UrlValidator validator = new UrlValidator(regex, 0);
      assertTrue("localhost URL should validate",
                validator.isValid("http://localhost:8080/demogadgets/CTSSResourcesMapView.xml"));
        assertTrue("127.0.0.1 should validate",
                validator.isValid("http://127.0.0.1:8080/demogadgets/CTSSResourcesMapView.xml"));
        assertTrue("my.linux-server should validate",
                validator.isValid("http://my.linux-server:8080/demogadgets/CTSSResourcesMapView.xml"));

        assertFalse("broke.my-test should not validate",
                validator.isValid("http://broke.my-test/test/index.html"));

        assertTrue("www.apache.org should still validate",
                validator.isValid("http://www.apache.org/test/index.html"));
    }
View Full Code Here

Examples of org.apache.commons.validator.routines.UrlValidator

      return false;
    } else {
      if (logger.isDebugEnabled()) {
        logger.debug("Required configuration found. Validating {}", stratosURL);
      }
      UrlValidator urlValidator = new UrlValidator(new String[] { "https" },UrlValidator.ALLOW_LOCAL_URLS);
      if (!urlValidator.isValid(stratosURL)) {
        if (logger.isDebugEnabled()) {
          logger.debug("Stratos Controller URL {} is not valid", stratosURL);
        }
        System.out.format(
            "The \"%s\" variable in your environment is not a valid URL. You have provided \"%s\".%n"
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.