Examples of UrlValidator


Examples of org.apache.commons.validator.UrlValidator

    private UrlValidator validator;

    public NewWidgetValidator() {
        super();
        String[] allowedSchemes = {"http", "https"};
        validator = new UrlValidator(allowedSchemes);
    }
View Full Code Here

Examples of org.apache.commons.validator.UrlValidator

    private UrlValidator validator;

    public NewWidgetValidator() {
        super();
        String[] allowedSchemes = {"http", "https"};
        validator = new UrlValidator(allowedSchemes);
    }
View Full Code Here

Examples of org.apache.commons.validator.UrlValidator

     */
    protected static URL getLicenseURL( MavenProject project, String url )
        throws IOException
    {
        URL licenseUrl = null;
        UrlValidator urlValidator = new UrlValidator( UrlValidator.ALLOW_ALL_SCHEMES );
        // UrlValidator does not accept file URLs because the file
        // URLs do not contain a valid authority (no hostname).
        // As a workaround accept license URLs that start with the
        // file scheme.
        if ( urlValidator.isValid( url ) || StringUtils.defaultString( url ).startsWith( "file://" ) )
        {
            try
            {
                licenseUrl = new URL( url );
            }
View Full Code Here

Examples of org.apache.commons.validator.UrlValidator

        }

        href = href.trim();

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

        if ( emailValidator.isValid( href )
            || ( href.contains( "?" ) && emailValidator.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
        {
            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

     */
    protected static URL getLicenseURL( MavenProject project, String url )
        throws IOException
    {
        URL licenseUrl = null;
        UrlValidator urlValidator = new UrlValidator( UrlValidator.ALLOW_ALL_SCHEMES );
        // UrlValidator does not accept file URLs because the file
        // URLs do not contain a valid authority (no hostname).
        // As a workaround accept license URLs that start with the
        // file scheme.
        if ( urlValidator.isValid( url ) || StringUtils.defaultString( url ).startsWith( "file://" ) )
        {
            try
            {
                licenseUrl = new URL( url );
            }
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(request, va, field));
            return false;
        }
View Full Code Here

Examples of org.apache.commons.validator.UrlValidator

            // we will accept href in case of <A>
            if ("a".equals(tag) && "href".equals(attr)) { // <a
                                    // href="......">
              String[] customSchemes = { "http", "https" };
              if (new UrlValidator(customSchemes).isValid(val)) {
                foundURL = true;
              } else {
                // may be it is a mailto?
                // case <a
                // href="mailto:pippo@pippo.com?subject=...."
                if (val.toLowerCase().startsWith("mailto:")
                    && val.indexOf("@") >= 0) {
                  String val1 = "http://www."
                      + val
                          .substring(val.indexOf("@") + 1);
                  if (new UrlValidator(customSchemes)
                      .isValid(val1)) {
                    foundURL = true;
                  } else {
                    ret.invalidTags.add(attr + " " + val);
                    val = "";
                  }
                } else {
                  ret.invalidTags.add(attr + " " + val);
                  val = "";
                }
              }

            } else if (tag.matches("img|embed")
                && "src".equals(attr)) { // <img src="......">
              String[] customSchemes = { "http", "https" };
              if (new UrlValidator(customSchemes).isValid(val)) {
                foundURL = true;
              } else {
                ret.invalidTags.add(attr + " " + val);
                val = "";
              }

            } else if ("href".equals(attr) || "src".equals(attr)) { // <tag
                                        // src/href="......">
                                        // skipped
              ret.invalidTags.add(tag + " " + attr + " " + val);
              continue;

            } else if (attr.matches("width|height")) { // <tag
                                  // width/height="......">
              if (!val.toLowerCase().matches("\\d+%|\\d+$")) { // test
                                        // numeric
                                        // values
                ret.invalidTags.add(tag + " " + attr + " "
                    + val);
                continue;
              }

            } else if ("style".equals(attr)) { // <tag
                              // style="......">

              // then test properties
              Matcher styles = stylePattern.matcher(val);
              String cleanStyle = "";

              while (styles.find()) {
                String styleName = styles.group(1)
                    .toLowerCase();
                String styleValue = styles.group(2);

                // suppress invalid styles values
                if (forbiddenStylePattern.matcher(styleValue)
                    .find()) {
                  ret.invalidTags.add(tag + " " + attr + " "
                      + styleValue);
                  continue;
                }

                // check if valid url
                Matcher urlStyleMatcher = urlStylePattern
                    .matcher(styleValue);
                if (urlStyleMatcher.find()) {
                  String[] customSchemes = { "http", "https" };
                  String url = urlStyleMatcher.group(1);
                  if (!new UrlValidator(customSchemes)
                      .isValid(url)) {
                    ret.invalidTags.add(tag + " " + attr
                        + " " + styleValue);
                    continue;
                  }
View Full Code Here

Examples of org.apache.commons.validator.UrlValidator

       
      }

    } else if (validatorName.equalsIgnoreCase("URL")){
      SpagoBITracer.info("SpagoBI", "Validator", "automaticValidator", "Apply the URL VALIDATOR to field ["+fieldName+"] with value ["+value+"]");
      UrlValidator urlValidator = new SpagoURLValidator();
      if (!GenericValidator.isBlankOrNull(value) && !urlValidator.isValid(value)){
        params = new ArrayList();
        params.add(fieldLabel);
        return new EMFValidationError(EMFErrorSeverity.ERROR, fieldName, ERROR_URL,params);
       
      }
View Full Code Here

Examples of org.apache.commons.validator.UrlValidator

       
      }

    } else if (validatorName.equalsIgnoreCase("URL")){
      logger.debug("Apply the URL VALIDATOR to field ["+fieldName+"] with value ["+value+"]");
      UrlValidator urlValidator = new SpagoURLValidator();
      if (!GenericValidator.isBlankOrNull(value) && !urlValidator.isValid(value)){
        params = new ArrayList();
        params.add(fieldLabel);
        return new EMFValidationError(EMFErrorSeverity.ERROR, fieldName, ERROR_URL,params);
       
      }
View Full Code Here

Examples of org.apache.commons.validator.UrlValidator

             
            }

          }else if (validatorName.equalsIgnoreCase("URL")){
            SpagoBITracer.info("SpagoBI", "Validator", "automaticValidator", "Apply the URL VALIDATOR to field ["+field+"] with value ["+value+"]");
            UrlValidator urlValidator = new SpagoURLValidator();
            if (!GenericValidator.isBlankOrNull(value) && !urlValidator.isValid(value)){
              params = new Vector();
              params.add(fieldLabel);
              errorHandler.addError(new EMFUserError(EMFErrorSeverity.ERROR, ERROR_URL,params));
             
            }
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.