Examples of DecryptParsedCommand


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

 
  public void execute(AbstractParsedCommand parsedCommand) throws ConsoleException {
   
    if((parsedCommand != null) && (parsedCommand instanceof DecryptParsedCommand)){
     
      DecryptParsedCommand inputCommand = (DecryptParsedCommand) parsedCommand;
      setPercentageOfWorkDone(0);
      PrefixParser prefixParser;
      try{
        PdfFile[] fileList = inputCommand.getInputFileList();
        for(int i = 0; i<fileList.length; i++){
          try{           
               
            prefixParser = new PrefixParser(inputCommand.getOutputFilesPrefix(), fileList[i].getFile().getName());
            File tmpFile = FileUtility.generateTmpFile(inputCommand.getOutputFile());
            pdfReader = new PdfReader(new RandomAccessFileOrArray(fileList[i].getFile().getAbsolutePath()),fileList[i].getPasswordBytes());
            pdfReader.removeUnusedObjects();
            pdfReader.consolidateNamedDestinations();
           
            //version
            LOG.debug("Creating a new document.");
            Character pdfVersion = inputCommand.getOutputPdfVersion();
            if(pdfVersion != null){
              pdfStamper = new PdfStamper(pdfReader, new FileOutputStream(tmpFile), inputCommand.getOutputPdfVersion().charValue());
            }else{
              pdfStamper = new PdfStamper(pdfReader, new FileOutputStream(tmpFile), pdfReader.getPdfVersion());
            }
 
            HashMap meta = pdfReader.getInfo();
            meta.put("Creator", ConsoleServicesFacade.CREATOR);
           
            setCompressionSettingOnStamper(inputCommand, pdfStamper);
           
            pdfStamper.setMoreInfo(meta);
            pdfStamper.close();
            pdfReader.close();
            File outFile = new File(inputCommand.getOutputFile() ,prefixParser.generateFileName());
              FileUtility.renameTemporaryFile(tmpFile, outFile, inputCommand.isOverwrite());
                    LOG.debug("Decrypted file "+outFile.getCanonicalPath()+" created.");             
              setPercentageOfWorkDone(((i+1)*WorkDoneDataModel.MAX_PERGENTAGE)/fileList.length)
            }
            catch(Exception e){
              LOG.error("Error decrypting file "+fileList[i].getFile().getName(), e);
            }
        }
        LOG.info("Pdf files decrypted in "+inputCommand.getOutputFile().getAbsolutePath()+".");
      }finally{
        setWorkCompleted();
      }
    }else{
      throw new ConsoleException(ConsoleException.ERR_BAD_COMMAND);
View Full Code Here

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

*/
public class DecryptCmdValidator extends AbstractCmdValidator {

  protected AbstractParsedCommand validateArguments(CmdLineHandler cmdLineHandler) throws ConsoleException {
   
    DecryptParsedCommand parsedCommandDTO = new DecryptParsedCommand();
   
    if(cmdLineHandler != null){
      //-o
      FileParam oOption = (FileParam) cmdLineHandler.getOption(DecryptParsedCommand.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(DecryptParsedCommand.P_ARG);
          if(pOption.isSet()){
            parsedCommandDTO.setOutputFilesPrefix(pOption.getValue());
          }         
         
          //-f
          PdfFileParam fOption = (PdfFileParam) cmdLineHandler.getOption(DecryptParsedCommand.F_ARG);
          if(fOption.isSet()){
        //validate file extensions
            for(Iterator fIterator = fOption.getPdfFiles().iterator(); fIterator.hasNext();){
              PdfFile currentFile = (PdfFile) fIterator.next();
                //checking extension
                ValidationUtility.assertValidPdfExtension(currentFile.getFile().getName());
            }
            parsedCommandDTO.setInputFileList(FileUtility.getPdfFiles(fOption.getPdfFiles()));
          }
         
    }else{
      throw new ConsoleException(ConsoleException.CMD_LINE_HANDLER_NULL);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.