Package org.pdfsam.console.business.dto.commands

Examples of org.pdfsam.console.business.dto.commands.SplitParsedCommand


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()){
View Full Code Here


    private PdfReader pdfReader = null;

    public void execute(AbstractParsedCommand parsedCommand) throws ConsoleException {

        if ((parsedCommand != null) && (parsedCommand instanceof SplitParsedCommand)) {
            SplitParsedCommand inputCommand = (SplitParsedCommand) parsedCommand;
            setPercentageOfWorkDone(0);
            try {
                prefixParser = new PrefixParser(inputCommand.getOutputFilesPrefix(), inputCommand.getInputFile()
                        .getFile().getName());
                if (SplitParsedCommand.S_BURST.equals(inputCommand.getSplitType())) {
                    executeBurst(inputCommand);
                } else if (SplitParsedCommand.S_NSPLIT.equals(inputCommand.getSplitType())) {
                    executeNSplit(inputCommand);
                } else if (SplitParsedCommand.S_SPLIT.equals(inputCommand.getSplitType())) {
                    executeSplit(inputCommand);
                } else if (SplitParsedCommand.S_EVEN.equals(inputCommand.getSplitType())
                        || SplitParsedCommand.S_ODD.equals(inputCommand.getSplitType())) {
                    executeSplitOddEven(inputCommand);
                } else if (SplitParsedCommand.S_SIZE.equals(inputCommand.getSplitType())) {
                    executeSizeSplit(inputCommand);
                } else if (SplitParsedCommand.S_BLEVEL.equals(inputCommand.getSplitType())) {
                    executeBookmarksSplit(inputCommand);
                } else {
                    throw new SplitException(SplitException.ERR_NOT_VALID_SPLIT_TYPE, new String[] { inputCommand
                            .getSplitType() });
                }
            } catch (Exception e) {
                throw new SplitException(e);
            } finally {
View Full Code Here

TOP

Related Classes of org.pdfsam.console.business.dto.commands.SplitParsedCommand

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.