Package de.mhus.lib.form2.validation

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


        .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


    // Options for the command line
    // /////////////////////////////////////////////////////////////////////
    inputLocationOpt = optionBuilder.withShortName("s").withLongName(
        "source_directory").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(
                      "Only one location can be chosen");
                final File source = new File((String) args
                    .get(0));
                if (!source.isFile() || !source.exists())
                  throw new InvalidArgumentException(
                      new StringBuilder(
                          "The provided source is invalid! ")

                      .toString());
              }

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

    outputLocationOpt = optionBuilder
        .withShortName("d")
        .withLongName("dest_directory")
        .withArgument(
            argumentBuilder.withName("destination").withMinimum(0)
                .withMaximum(1).create())
        .withDescription(
            "output directory, if none is provided, the \"tiled\" directory will be used")
        .withRequired(false).create();

    tileDimOpt = optionBuilder.withShortName("t").withLongName(
        "tiled_dimension").withArgument(
        argumentBuilder.withName("t").withMinimum(1).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 StringBuilder(
                              "The provided scale factor is negative! ")

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

                }).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 StringBuilder(
                              "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();

    outFormatOpt = optionBuilder
        .withShortName("o")
        .withLongName("out_format")
        .withArgument(
            argumentBuilder.withName("o").withMinimum(0)
                .withMaximum(1)
                .withDescription("output format")
                // .withDefault("gtiff")
                .withValidator(new Validator() {

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

                  }
                }).create()).withDescription("output format")
        .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

    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

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.