Package de.mhus.lib.form2.validation

Examples of de.mhus.lib.form2.validation.Validator


    return builder.withLongName(name).withDescription(desc).create();
  }
 
  private void setupOptions(){

    final Validator fileValidator = new Validator(){
      public void validate(final List values) throws InvalidArgumentException {
        // Note : This code doesnt belong here, it should be changed to
        // an can exec check in java 6
        for (String file : (List<String>)values) {
          File f = new File(file)
          if ( ! f.exists() ) {
            throw new InvalidArgumentException("Argument : " +
                f.getAbsolutePath() + " doesn't exist.");
          }
          if ( ! f.isFile() ) {
            throw new InvalidArgumentException("Argument : " +
                f.getAbsolutePath() + " is not a file.");
          }
          if ( ! f.canRead() ) {
            throw new InvalidArgumentException("Argument : " +
                f.getAbsolutePath() + " is not accessible");
          }
        }
      }     
    };

    // Note: not extending CLI2's FileValidator, that overwrites
    // the String arg into File and causes ClassCastException
    // in inheritance tree.
    final Validator execValidator = new Validator(){
      public void validate(final List values) throws InvalidArgumentException {
        // Note : This code doesnt belong here, it should be changed to
        // an can exec check in java 6
        for (String file : (List<String>)values) {
          try{
View Full Code Here


        argCommand = new ArgumentBuilder()
            .withName("command")
            .withDescription("Sync Command")
            .withMinimum(0)
            .withMaximum(1)
            .withValidator(new Validator() {
                public void validate(List list) throws InvalidArgumentException {
                    if (list.size() > 0) {
                        String cmd = list.get(0).toString();
                        try {
                            list.set(0, Sync.Command.valueOf(cmd.toUpperCase()));
View Full Code Here

    return builder.withLongName(name).withDescription(desc).create();
  }
 
  private void setupOptions(){

    final Validator fileValidator = new Validator(){
        public void validate(final List values) throws InvalidArgumentException {
          // Note : This code doesnt belong here, it should be changed to
          // an can exec check in java 6
          for (String file : (List<String>)values) {
            File f = new File(file)
            if (!f.exists()) {
              throw new InvalidArgumentException("Argument : " +
                                                 f.getAbsolutePath() + " doesn't exist.");
            }
            if (!f.isFile()) {
              throw new InvalidArgumentException("Argument : " +
                                                 f.getAbsolutePath() + " is not a file.");
            }
            if (!f.canRead()) {
              throw new InvalidArgumentException("Argument : " +
                                                 f.getAbsolutePath() + " is not accessible");
            }
          }
        }     
      };

    // Note: not extending CLI2's FileValidator, that overwrites
    // the String arg into File and causes ClassCastException
    // in inheritance tree.
    final Validator execValidator = new Validator(){
        public void validate(final List values) throws InvalidArgumentException {
          // Note : This code doesnt belong here, it should be changed to
          // an can exec check in java 6
          for (String file : (List<String>)values) {
            try{
View Full Code Here

    return builder.withLongName(name).withDescription(desc).create();
  }
 
  private void setupOptions(){

    final Validator fileValidator = new Validator(){
        public void validate(final List values) throws InvalidArgumentException {
          // Note : This code doesnt belong here, it should be changed to
          // an can exec check in java 6
          for (String file : (List<String>)values) {
            File f = new File(file)
            if (!f.exists()) {
              throw new InvalidArgumentException("Argument : " +
                                                 f.getAbsolutePath() + " doesn't exist.");
            }
            if (!f.isFile()) {
              throw new InvalidArgumentException("Argument : " +
                                                 f.getAbsolutePath() + " is not a file.");
            }
            if (!f.canRead()) {
              throw new InvalidArgumentException("Argument : " +
                                                 f.getAbsolutePath() + " is not accessible");
            }
          }
        }     
      };

    // Note: not extending CLI2's FileValidator, that overwrites
    // the String arg into File and causes ClassCastException
    // in inheritance tree.
    final Validator execValidator = new Validator(){
        public void validate(final List values) throws InvalidArgumentException {
          // Note : This code doesnt belong here, it should be changed to
          // an can exec check in java 6
          for (String file : (List<String>)values) {
            try{
View Full Code Here

    return builder.withLongName(name).withDescription(desc).create();
  }
 
  private void setupOptions(){

    final Validator fileValidator = new Validator(){
        public void validate(final List values) throws InvalidArgumentException {
          // Note : This code doesnt belong here, it should be changed to
          // an can exec check in java 6
          for (String file : (List<String>)values) {
            File f = new File(file)
            if (!f.exists()) {
              throw new InvalidArgumentException("Argument : " +
                                                 f.getAbsolutePath() + " doesn't exist.");
            }
            if (!f.isFile()) {
              throw new InvalidArgumentException("Argument : " +
                                                 f.getAbsolutePath() + " is not a file.");
            }
            if (!f.canRead()) {
              throw new InvalidArgumentException("Argument : " +
                                                 f.getAbsolutePath() + " is not accessible");
            }
          }
        }     
      };

    // Note: not extending CLI2's FileValidator, that overwrites
    // the String arg into File and causes ClassCastException
    // in inheritance tree.
    final Validator execValidator = new Validator(){
        public void validate(final List values) throws InvalidArgumentException {
          // Note : This code doesnt belong here, it should be changed to
          // an can exec check in java 6
          for (String file : (List<String>)values) {
            try{
View Full Code Here

    return builder.withLongName(name).withDescription(desc).create();
  }
 
  private void setupOptions(){

    final Validator fileValidator = new Validator(){
        public void validate(final List values) throws InvalidArgumentException {
          // Note : This code doesnt belong here, it should be changed to
          // an can exec check in java 6
          for (String file : (List<String>)values) {
            File f = new File(file)
            if (!f.exists()) {
              throw new InvalidArgumentException("Argument : " +
                                                 f.getAbsolutePath() + " doesn't exist.");
            }
            if (!f.isFile()) {
              throw new InvalidArgumentException("Argument : " +
                                                 f.getAbsolutePath() + " is not a file.");
            }
            if (!f.canRead()) {
              throw new InvalidArgumentException("Argument : " +
                                                 f.getAbsolutePath() + " is not accessible");
            }
          }
        }     
      };

    // Note: not extending CLI2's FileValidator, that overwrites
    // the String arg into File and causes ClassCastException
    // in inheritance tree.
    final Validator execValidator = new Validator(){
        public void validate(final List values) throws InvalidArgumentException {
          // Note : This code doesnt belong here, it should be changed to
          // an can exec check in java 6
          for (String file : (List<String>)values) {
            try{
View Full Code Here

    return builder.withLongName(name).withDescription(desc).create();
  }
 
  private void setupOptions(){

    final Validator fileValidator = new Validator(){
        public void validate(final List values) throws InvalidArgumentException {
          // Note : This code doesnt belong here, it should be changed to
          // an can exec check in java 6
          for (String file : (List<String>)values) {
            File f = new File(file)
            if (!f.exists()) {
              throw new InvalidArgumentException("Argument : " +
                                                 f.getAbsolutePath() + " doesn't exist.");
            }
            if (!f.isFile()) {
              throw new InvalidArgumentException("Argument : " +
                                                 f.getAbsolutePath() + " is not a file.");
            }
            if (!f.canRead()) {
              throw new InvalidArgumentException("Argument : " +
                                                 f.getAbsolutePath() + " is not accessible");
            }
          }
        }     
      };

    // Note: not extending CLI2's FileValidator, that overwrites
    // the String arg into File and causes ClassCastException
    // in inheritance tree.
    final Validator execValidator = new Validator(){
        public void validate(final List values) throws InvalidArgumentException {
          // Note : This code doesnt belong here, it should be changed to
          // an can exec check in java 6
          for (String file : (List<String>)values) {
            try{
View Full Code Here

    return builder.withLongName(name).withDescription(desc).create();
  }
 
  private void setupOptions(){

    final Validator fileValidator = new Validator(){
        public void validate(final List values) throws InvalidArgumentException {
          // Note : This code doesnt belong here, it should be changed to
          // an can exec check in java 6
          for (String file : (List<String>)values) {
            File f = new File(file)
            if (!f.exists()) {
              throw new InvalidArgumentException("Argument : " +
                                                 f.getAbsolutePath() + " doesn't exist.");
            }
            if (!f.isFile()) {
              throw new InvalidArgumentException("Argument : " +
                                                 f.getAbsolutePath() + " is not a file.");
            }
            if (!f.canRead()) {
              throw new InvalidArgumentException("Argument : " +
                                                 f.getAbsolutePath() + " is not accessible");
            }
          }
        }     
      };

    // Note: not extending CLI2's FileValidator, that overwrites
    // the String arg into File and causes ClassCastException
    // in inheritance tree.
    final Validator execValidator = new Validator(){
        public void validate(final List values) throws InvalidArgumentException {
          // Note : This code doesnt belong here, it should be changed to
          // an can exec check in java 6
          for (String file : (List<String>)values) {
            try{
View Full Code Here

    locationOpt = optionBuilder
        .withShortName("s")
        .withLongName("source")
        .withArgument(
            argumentBuilder.withName("source").withMinimum(1)
                .withMaximum(1).withValidator(new Validator() {

                  public void validate(List args)
                      throws InvalidArgumentException {
                    final int size = args.size();
                    if (size > 1)
                      throw new InvalidArgumentException("Source can be a single file or  directory ");
                    final File source = new File(
                        (String) args.get(0));
                    if (!source.exists())
                      throw new InvalidArgumentException(
                          new StringBuilder(
                              "The provided source is invalid! ")

                          .toString());
                  }

                }).create()).withDescription(
            "path where files are located").withRequired(true)
        .create();

    tileDimOpt = optionBuilder.withShortName("t").withLongName(
        "tiled_dimension").withArgument(
        argumentBuilder.withName("t").withMinimum(0).withMaximum(1)
            .create()).withDescription(
        "tile dimensions as a couple width,height in pixels")
        .withRequired(false).create();
   
                externalOpt = optionBuilder.withShortName("ext").withLongName(
                    "external_overviews").withArgument(
                    argumentBuilder.withName("extt").withMinimum(0).withMaximum(1)
                                    .create()).withDescription(
                    "create externalOverviews overviews")
                .withRequired(false).create();   

    scaleFactorOpt = optionBuilder
        .withShortName("f")
        .withLongName("scale_factor")
        .withArgument(
            argumentBuilder.withName("f").withMinimum(1)
                .withMaximum(1).withValidator(new Validator() {
                  public void validate(List args)
                      throws InvalidArgumentException {
                    final int size = args.size();
                    if (size > 1)
                      throw new InvalidArgumentException(
                          "Only one scale factor at a time can be chosen");
                    int factor = Integer
                        .parseInt((String) args.get(0));
                    if (factor <= 0)
                      throw new InvalidArgumentException(
                          new StringBuilder(
                              "The provided scale factor is negative! ")

                          .toString());
                    if (factor == 1) {
                      LOGGER
                          .warning("The scale factor is 1, program will exit!");
                      System.exit(0);
                    }
                  }

                }).create()).withDescription(
            "integer scale factor")
        .withRequired(true).create();

    wildcardOpt = optionBuilder.withShortName("w").withLongName(
        "wildcardOpt").withArgument(
        argumentBuilder.withName("wildcardOpt").withMinimum(0)
            .withMaximum(1).create()).withDescription(
        "wildcardOpt to use for selecting files").withRequired(false)
        .create();

    numStepsOpt = optionBuilder.withShortName("n")
        .withLongName("num_steps").withArgument(
            argumentBuilder.withName("n").withMinimum(1)
                .withMaximum(1).withValidator(new Validator() {

                  public void validate(List args)
                      throws InvalidArgumentException {
                    final int size = args.size();
                    if (size > 1)
                      throw new InvalidArgumentException(
                          "Only one  number of step at a time can be chosen");
                    int steps = Integer
                        .parseInt((String) args.get(0));
                    if (steps <= 0)
                      throw new InvalidArgumentException(
                          new StringBuilder(
                              "The provided number of step is negative! ")

                          .toString());

                  }

                }).create()).withDescription(
            "integer scale factor").withRequired(true).create();

    scaleAlgorithmOpt = optionBuilder
        .withShortName("a")
        .withLongName("scaling_algorithm")
        .withArgument(
            argumentBuilder.withName("a").withMinimum(0)
                .withMaximum(1).withValidator(new Validator() {

                  public void validate(List args)
                      throws InvalidArgumentException {
                    final int size = args.size();
                    if (size > 1)
                      throw new InvalidArgumentException(
                          "Only one scaling algorithm at a time can be chosen");
                    final SubsampleAlgorithm algorithm=SubsampleAlgorithm.valueOf((String)args.get(0));
                    if (algorithm==null)
                      throw new InvalidArgumentException(
                          new StringBuilder(
                              "The scaling algorithm ")
                              .append(args.get(0))
                              .append(
                                  " is not supported")
                              .toString());

                  }
                }).create())
        .withDescription(
            "name of the scaling algorithm, eeither one of average (a), filtered   (f), bilinear (bil), nearest neigbhor (nn)")
        .withRequired(false).create();

    compressionTypeOpt = optionBuilder
        .withShortName("z")
        .withLongName("compressionType")
        .withDescription("compression type.")
        .withArgument(
            argumentBuilder.withName("compressionType")
                .withMinimum(0).withMaximum(1).withValidator(
                    new Validator() {

                      public void validate(List args)
                          throws InvalidArgumentException {
                        final int size = args.size();
                        if (size > 1)
                          throw new InvalidArgumentException(
                              "Only one scaling algorithm at a time can be chosen");

                      }
                    }).create()).withRequired(false)
        .create();

    compressionRatioOpt = optionBuilder
        .withShortName("r")
        .withLongName("compressionRatio")
        .withDescription("compression ratio.")
        .withArgument(
            argumentBuilder.withName("compressionRatio")
                .withMinimum(0).withMaximum(1).withValidator(
                    new Validator() {

                      public void validate(List args)
                          throws InvalidArgumentException {
                        final int size = args.size();
                        if (size > 1)
View Full Code Here

    locationOpt = optionBuilder
        .withShortName("s")
        .withLongName("source")
        .withArgument(
            argumentBuilder.withName("source").withMinimum(1)
                .withMaximum(1).withValidator(new Validator() {

                  public void validate(List args)
                      throws InvalidArgumentException {
                    final int size = args.size();
                    if (size > 1)
                      throw new InvalidArgumentException(
                          "Source can be a single file or directory ");
                    final File source = new File(
                        (String) args.get(0));
                    if (!source.exists())
                      throw new InvalidArgumentException(
                          new StringBuffer(
                              "The provided source is invalid! ")

                          .toString());
                  }

                }).create()).withDescription(
            "path where files are located").withRequired(true)
        .create();

    nameOpt = optionBuilder.withShortName("name").withLongName(
        "pyramid_name").withArgument(
        argumentBuilder.withName("name").withMinimum(0).withMaximum(1)
            .create()).withDescription(
        "name for the pyramid property file").withRequired(false)
        .create();

    tileDimOpt = optionBuilder.withShortName("t").withLongName(
        "tiled_dimension").withArgument(
        argumentBuilder.withName("t").withMinimum(0).withMaximum(1)
            .create()).withDescription(
        "tile dimensions as a couple width,height in pixels")
        .withRequired(true).create();

    scaleFactorOpt = optionBuilder
        .withShortName("f")
        .withLongName("scale_factor")
        .withArgument(
            argumentBuilder.withName("f").withMinimum(1)
                .withMaximum(1).withValidator(new Validator() {

                  public void validate(List args)
                      throws InvalidArgumentException {
                    final int size = args.size();
                    if (size > 1)
                      throw new InvalidArgumentException(
                          "Only one scaling algorithm at a time can be chosen");
                    int factor = Integer
                        .parseInt((String) args.get(0));
                    if (factor <= 0)
                      throw new InvalidArgumentException(
                          new StringBuffer(
                              "The provided scale factor is negative! ")

                          .toString());
                    if (factor == 1) {
                      LOGGER
                          .warning("The scale factor is 1, program will exit!");
                      System.exit(0);
                    }
                  }

                }).create()).withDescription(
            "integer scale factor")
        .withRequired(true).create();

    numStepsOpt = optionBuilder.withShortName("n")
        .withLongName("num_steps").withArgument(
            argumentBuilder.withName("n").withMinimum(1)
                .withMaximum(1).withValidator(new Validator() {

                  public void validate(List args)
                      throws InvalidArgumentException {
                    final int size = args.size();
                    if (size > 1)
                      throw new InvalidArgumentException(
                          "Only one scaling algorithm at a time can be chosen");
                    int steps = Integer
                        .parseInt((String) args.get(0));
                    if (steps <= 0)
                      throw new InvalidArgumentException(
                          new StringBuffer(
                              "The provided scale factor is negative! ")

                          .toString());

                  }

                }).create()).withDescription(
            "integer scale factor").withRequired(true).create();

    scaleAlgorithmOpt = optionBuilder
        .withShortName("a")
        .withLongName("scaling_algorithm")
        .withArgument(
            argumentBuilder.withName("a").withMinimum(0)
                .withMaximum(1).withValidator(new Validator() {

                  public void validate(List args)
                      throws InvalidArgumentException {
                    final int size = args.size();
                    if (size > 1)
                      throw new InvalidArgumentException(
                          "Only one scaling algorithm at a time can be chosen");
                    if (!scalingAlgorithms.contains(args
                        .get(0)))
                      throw new InvalidArgumentException(
                          new StringBuffer(
                              "The output format ")
                              .append(args.get(0))
                              .append(
                                  " is not permitted")
                              .toString());

                  }
                }).create())
        .withDescription(
            "name of the scaling algorithm, eeither one of average (a), filtered (f), bilinear (bil), nearest neigbhor (nn)")
        .withRequired(false).create();

    overwriteOpt = optionBuilder.withShortName("w").withLongName(
        "overwrite").withDescription(
        "completely wipe out existing layer dirs before proceeding.")
        .withRequired(false).create();

    compressionTypeOpt = optionBuilder
        .withShortName("z")
        .withLongName("compressionType")
        .withDescription("compression type.")
        .withArgument(
            argumentBuilder.withName("compressionType")
                .withMinimum(0).withMaximum(1).withValidator(
                    new Validator() {

                      public void validate(List args)
                          throws InvalidArgumentException {
                        final int size = args.size();
                        if (size > 1)
                          throw new InvalidArgumentException(
                              "Only one scaling algorithm at a time can be chosen");

                      }
                    }).create()).withRequired(false)
        .create();

    compressionRatioOpt = optionBuilder
        .withShortName("r")
        .withLongName("compressionRatio")
        .withDescription("compression ratio.")
        .withArgument(
            argumentBuilder.withName("compressionRatio")
                .withMinimum(0).withMaximum(1).withValidator(
                    new Validator() {

                      public void validate(List args)
                          throws InvalidArgumentException {
                        final int size = args.size();
                        if (size > 1)
View Full Code Here

TOP

Related Classes of de.mhus.lib.form2.validation.Validator

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.