Package org.apache.commons.validator

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


       
      }

    } 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

       
      }

    } 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

             
            }

          }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

          }

        }

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

      }
      return true;
   }

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

    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

          }

        }

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

        schemes[i++] = st.nextToken().trim();
      }
    }

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

          }

        }

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

TOP

Related Classes of org.apache.commons.validator.UrlValidator

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.