public AbstractParsedCommand validate(CmdLineHandler cmdLineHandler) throws ConsoleException {
   AbstractParsedCommand parsedCommand = validateArguments(cmdLineHandler);
   if (cmdLineHandler.getOption(AbstractParsedCommand.OVERWRITE_ARG) != null) {
     parsedCommand.setOverwrite(
         ((BooleanParam) cmdLineHandler.getOption(AbstractParsedCommand.OVERWRITE_ARG)).isTrue());
   }
   if (cmdLineHandler.getOption(AbstractParsedCommand.COMPRESSED_ARG) != null) {
     parsedCommand.setCompress(
         ((BooleanParam) cmdLineHandler.getOption(AbstractParsedCommand.COMPRESSED_ARG)).isTrue());
   }
   if (cmdLineHandler.getOption(AbstractParsedCommand.LOG_ARG) != null) {
     FileParam logOption = (FileParam) cmdLineHandler.getOption(AbstractParsedCommand.LOG_ARG);
     if (logOption.isSet()) {
       parsedCommand.setLogFile(logOption.getFile());
     }
   }
   if (cmdLineHandler.getOption(AbstractParsedCommand.PDFVERSION_ARG) != null) {
     StringParam pdfversionOption =
         (StringParam) cmdLineHandler.getOption(AbstractParsedCommand.PDFVERSION_ARG);
     if (pdfversionOption.isSet()) {
       parsedCommand.setOutputPdfVersion(pdfversionOption.getValue().charAt(0));
     }
   }
   return parsedCommand;
 }
  protected AbstractParsedCommand validateArguments(CmdLineHandler cmdLineHandler)
      throws ConsoleException {

    UnpackParsedCommand parsedCommandDTO = new UnpackParsedCommand();

    if (cmdLineHandler != null) {
      // -o
      FileParam oOption = (FileParam) cmdLineHandler.getOption(UnpackParsedCommand.O_ARG);
      if ((oOption.isSet())) {
        File outFile = oOption.getFile();
        ValidationUtility.assertValidDirectory(outFile);
        parsedCommandDTO.setOutputFile(outFile);
      } else {
        throw new ParseException(ParseException.ERR_NO_O);
      }

      // -f and -d
      PdfFileParam fOption = (PdfFileParam) cmdLineHandler.getOption(UnpackParsedCommand.F_ARG);
      FileParam dOption = (FileParam) cmdLineHandler.getOption(UnpackParsedCommand.D_ARG);
      if (fOption.isSet() || dOption.isSet()) {
        // -f
        if (fOption.isSet()) {
          // validate file extensions
          for (Iterator fIterator = fOption.getPdfFiles().iterator(); fIterator.hasNext(); ) {
            PdfFile currentFile = (PdfFile) fIterator.next();
            ValidationUtility.assertValidPdfExtension(currentFile.getFile().getName());
          }
          parsedCommandDTO.setInputFileList(FileUtility.getPdfFiles(fOption.getPdfFiles()));
        }
        // -d
        if ((dOption.isSet())) {
          File inputDir = dOption.getFile();
          ValidationUtility.assertValidDirectory(inputDir);
          parsedCommandDTO.setInputDirectory(inputDir);
        }
      } else {
        throw new ParseException(ParseException.ERR_NO_F_OR_D);
      }
    } else {
      throw new ConsoleException(ConsoleException.CMD_LINE_HANDLER_NULL);
    }
    return parsedCommandDTO;
  }
  public AbstractParsedCommand validateArguments(CmdLineHandler cmdLineHandler)
      throws ConsoleException {

    SplitParsedCommand parsedCommandDTO = new SplitParsedCommand();

    if (cmdLineHandler != null) {
      // -o
      FileParam oOption = (FileParam) cmdLineHandler.getOption(SplitParsedCommand.O_ARG);
      if ((oOption.isSet())) {
        File outFile = oOption.getFile();
        ValidationUtility.assertValidDirectory(outFile);
        parsedCommandDTO.setOutputFile(outFile);
      } else {
        throw new ParseException(ParseException.ERR_NO_O);
      }

      // -p
      StringParam pOption = (StringParam) cmdLineHandler.getOption(SplitParsedCommand.P_ARG);
      if (pOption.isSet()) {
        parsedCommandDTO.setOutputFilesPrefix(pOption.getValue());
      }

      // -f
      PdfFileParam fOption = (PdfFileParam) cmdLineHandler.getOption(SplitParsedCommand.F_ARG);
      if (fOption.isSet()) {
        PdfFile inputFile = fOption.getPdfFile();
        ValidationUtility.assertValidPdfExtension(inputFile.getFile().getName());
        parsedCommandDTO.setInputFile(FileUtility.getPdfFile(inputFile));
      } else {
        throw new ParseException(ParseException.ERR_NO_F);
      }

      // -s
      StringParam sOption = (StringParam) cmdLineHandler.getOption(SplitParsedCommand.S_ARG);
      if (sOption.isSet()) {
        parsedCommandDTO.setSplitType(sOption.getValue());
      } else {
        throw new ParseException(ParseException.ERR_NO_S);
      }

      // -b
      LongParam bOption = (LongParam) cmdLineHandler.getOption(SplitParsedCommand.B_ARG);
      if (SplitParsedCommand.S_SIZE.equals(parsedCommandDTO.getSplitType())) {
        if (bOption.isSet()) {
          parsedCommandDTO.setSplitSize(new Long(bOption.longValue()));
        } else {
          throw new ParseException(ParseException.ERR_NO_B);
        }
      } else {
        if (bOption.isSet()) {
          throw new ParseException(ParseException.ERR_B_NOT_NEEDED);
        }
      }

      // -bl
      IntParam blOption = (IntParam) cmdLineHandler.getOption(SplitParsedCommand.BL_ARG);
      if (SplitParsedCommand.S_BLEVEL.equals(parsedCommandDTO.getSplitType())) {
        if (blOption.isSet()) {
          parsedCommandDTO.setBookmarksLevel(new Integer(blOption.intValue()));
        } else {
          throw new ParseException(ParseException.ERR_NO_BL);
        }
      } else {
        if (blOption.isSet()) {
          throw new ParseException(ParseException.ERR_BL_NOT_NEEDED);
        }
      }

      // -n
      StringParam nOption = (StringParam) cmdLineHandler.getOption("n");
      if (SplitParsedCommand.S_NSPLIT.equals(parsedCommandDTO.getSplitType())
          || SplitParsedCommand.S_SPLIT.equals(parsedCommandDTO.getSplitType())) {
        if (nOption.isSet()) {
          String nValue = nOption.getValue().trim().replaceAll(",", "-").replaceAll(" ", "-");
          if (SplitParsedCommand.S_NSPLIT.equals(parsedCommandDTO.getSplitType())) {
            Pattern p = Pattern.compile("([0-9]+)*");
            if (!(p.matcher(nValue).matches())) {
              throw new ParseException(ParseException.ERR_N_NOT_NUM);
            }
          }
          if (SplitParsedCommand.S_SPLIT.equals(parsedCommandDTO.getSplitType())) {
            Pattern p = Pattern.compile("([0-9]+)([-][0-9]+)*");
            if (!(p.matcher(nValue).matches())) {
              throw new ParseException(ParseException.ERR_N_NOT_NUM_OR_SEQ);
            }
          }
          parsedCommandDTO.setSplitPageNumbers(getSplitPageNumbers(nValue));
        } else {
          throw new ParseException(ParseException.ERR_NO_N);
        }
      } else {
        if (nOption.isSet()) {
          throw new ParseException(ParseException.ERR_N_NOT_NEEDED);
        }
      }
    } else {
      throw new ConsoleException(ConsoleException.CMD_LINE_HANDLER_NULL);
    }
    return parsedCommandDTO;
  }
  public AbstractParsedCommand validateArguments(CmdLineHandler cmdLineHandler)
      throws ConsoleException {

    EncryptParsedCommand parsedCommandDTO = new EncryptParsedCommand();

    if (cmdLineHandler != null) {
      // -o
      FileParam oOption = (FileParam) cmdLineHandler.getOption(EncryptParsedCommand.O_ARG);
      if ((oOption.isSet())) {
        File outFile = oOption.getFile();
        ValidationUtility.checkValidDirectory(outFile);
        parsedCommandDTO.setOutputFile(outFile);
      } else {
        throw new ParseException(ParseException.ERR_NO_O);
      }

      // -p
      StringParam pOption = (StringParam) cmdLineHandler.getOption(EncryptParsedCommand.P_ARG);
      if (pOption.isSet()) {
        parsedCommandDTO.setOutputFilesPrefix(pOption.getValue());
      }

      // -apwd
      StringParam apwdOption =
          (StringParam) cmdLineHandler.getOption(EncryptParsedCommand.APWD_ARG);
      if (apwdOption.isSet()) {
        parsedCommandDTO.setOwnerPwd(apwdOption.getValue());
      }

      // -upwd
      StringParam upwdOption =
          (StringParam) cmdLineHandler.getOption(EncryptParsedCommand.UPWD_ARG);
      if (upwdOption.isSet()) {
        parsedCommandDTO.setUserPwd(upwdOption.getValue());
      }

      // -etype
      StringParam etypeOption =
          (StringParam) cmdLineHandler.getOption(EncryptParsedCommand.ETYPE_ARG);
      if (etypeOption.isSet()) {
        parsedCommandDTO.setEncryptionType(etypeOption.getValue());
      }

      // -f - d
      PdfFileParam fOption = (PdfFileParam) cmdLineHandler.getOption(EncryptParsedCommand.F_ARG);
      FileParam dOption = (FileParam) cmdLineHandler.getOption(EncryptParsedCommand.D_ARG);
      if (fOption.isSet() || dOption.isSet()) {
        // -f
        if (fOption.isSet()) {
          // validate file extensions
          for (Iterator fIterator = fOption.getPdfFiles().iterator(); fIterator.hasNext(); ) {
            PdfFile currentFile = (PdfFile) fIterator.next();
            ValidationUtility.checkValidPdfExtension(currentFile.getFile().getName());
          }
          parsedCommandDTO.setInputFileList(FileUtility.getPdfFiles(fOption.getPdfFiles()));
        }
        // -d
        if ((dOption.isSet())) {
          File inputDir = dOption.getFile();
          ValidationUtility.checkValidDirectory(inputDir);
          parsedCommandDTO.setInputDirectory(inputDir);
        }
      } else {
        throw new ParseException(ParseException.ERR_NO_F_OR_D);
      }

      // -allow
      StringParam allowOption =
          (StringParam) cmdLineHandler.getOption(EncryptParsedCommand.ALLOW_ARG);
      if (allowOption.isSet()) {
        Hashtable permissionsMap = getPermissionsMap(parsedCommandDTO.getEncryptionType());
        int permissions = 0;
        if (!permissionsMap.isEmpty()) {
          for (Iterator permIterator = allowOption.getValues().iterator();
              permIterator.hasNext(); ) {
            String currentPermission = (String) permIterator.next();
            Object value = permissionsMap.get(currentPermission);
            if (value != null) {
              permissions |= ((Integer) value).intValue();
            }
          }
        }
        permissionsMap = null;
        parsedCommandDTO.setPermissions(permissions);
      }
    } else {
      throw new ConsoleException(ConsoleException.CMD_LINE_HANDLER_NULL);
    }
    return parsedCommandDTO;
  }
  public AbstractParsedCommand validateArguments(CmdLineHandler cmdLineHandler)
      throws ConsoleException {
    ConcatParsedCommand parsedCommandDTO = new ConcatParsedCommand();

    if (cmdLineHandler != null) {
      // -o
      FileParam oOption = (FileParam) cmdLineHandler.getOption("o");
      if ((oOption.isSet())) {
        File outFile = oOption.getFile();
        // checking extension
        if ((outFile.getName().toLowerCase().endsWith(PDF_EXTENSION))
            && (outFile.getName().length() > PDF_EXTENSION.length())) {
          parsedCommandDTO.setOutputFile(outFile);
        } else {
          throw new ParseException(
              ParseException.ERR_OUT_NOT_PDF, new String[] {outFile.getPath()});
        }
      } else {
        throw new ParseException(ParseException.ERR_NO_O);
      }

      // -f -l
      FileParam lOption = (FileParam) cmdLineHandler.getOption("l");
      PdfFileParam fOption = (PdfFileParam) cmdLineHandler.getOption("f");
      if (lOption.isSet() || fOption.isSet()) {
        if (!(lOption.isSet() && fOption.isSet())) {
          if (fOption.isSet()) {
            // validate file extensions
            for (Iterator fIterator = fOption.getPdfFiles().iterator(); fIterator.hasNext(); ) {
              PdfFile currentFile = (PdfFile) fIterator.next();
              if (!((currentFile.getFile().getName().toLowerCase().endsWith(PDF_EXTENSION))
                  && (currentFile.getFile().getName().length() > PDF_EXTENSION.length()))) {
                throw new ParseException(
                    ParseException.ERR_IN_NOT_PDF, new String[] {currentFile.getFile().getPath()});
              }
            }
            parsedCommandDTO.setInputFileList(FileUtility.getPdfFiles(fOption.getPdfFiles()));
          } else {
            if (lOption.getFile().getPath().toLowerCase().endsWith(CSV_EXTENSION)
                || lOption.getFile().getPath().toLowerCase().endsWith(XML_EXTENSION)) {
              parsedCommandDTO.setInputCvsOrXmlFile(lOption.getFile());
            } else {
              throw new ParseException(ParseException.ERR_NOT_CSV_OR_XML);
            }
          }
        } else {
          throw new ParseException(ParseException.ERR_BOTH_F_OR_L);
        }
      } else {
        throw new ParseException(ParseException.ERR_NO_F_OR_L);
      }

      // -u
      StringParam uOption = (StringParam) cmdLineHandler.getOption("u");
      // if it's set we proceed with validation
      if (uOption.isSet()) {
        Pattern p = Pattern.compile("(([0-9]*[-][0-9]*[:])|(all:))+", Pattern.CASE_INSENSITIVE);
        if ((p.matcher(uOption.getValue()).matches())) {
          parsedCommandDTO.setPageSelection(uOption.getValue());
        } else {
          throw new ParseException(ParseException.ERR_ILLEGAL_U);
        }
      }

      // -copyfields
      parsedCommandDTO.setCopyFields(
          ((BooleanParam) cmdLineHandler.getOption("copyfields")).isTrue());
    } else {
      throw new ParseException(ParseException.CMD_LINE_HANDLER_NULL);
    }
    return parsedCommandDTO;
  }