public class SplitCmdValidator extends AbstractCmdValidator {
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()){