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

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


 
  public void execute(AbstractParsedCommand parsedCommand) throws ConsoleException {
   
    if((parsedCommand != null) && (parsedCommand instanceof SlideShowParsedCommand)){ 
     
      SlideShowParsedCommand inputCommand = (SlideShowParsedCommand) parsedCommand;
      PrefixParser prefixParser;
      setPercentageOfWorkDone(0);     
      Transitions transitions = new Transitions();
      transitions.setDefaultTransition(inputCommand.getDefaultTransition());
      transitions.setTransitions(inputCommand.getTransitions());     
      transitions = parseXmlInput(inputCommand.getInputXmlFile(), transitions);
      try{
        prefixParser = new PrefixParser(inputCommand.getOutputFilesPrefix(), inputCommand.getInputFile().getFile().getName());       
        File tmpFile = FileUtility.generateTmpFile(inputCommand.getOutputFile());
       
        pdfReader = new PdfReader(new RandomAccessFileOrArray(inputCommand.getInputFile().getFile().getAbsolutePath()),inputCommand.getInputFile().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());
        }
       
        //creator
        HashMap meta = pdfReader.getInfo();
        meta.put("Creator", ConsoleServicesFacade.CREATOR);
       
        //compression
        setCompressionSettingOnStamper(inputCommand, pdfStamper);
        pdfStamper.setMoreInfo(meta);
       
        //fullscreen
        if(inputCommand.isFullScreen()){
          pdfStamper.setViewerPreferences(PdfWriter.PageModeFullScreen);
        }
       
        //sets transitions
        if(transitions.getDefaultTransition()==null){
          setTransitionsWithoutDefault(transitions);       
        }else{
          int totalPages = pdfReader.getNumberOfPages();
          setTransitionsWithDefault(transitions, totalPages);
        }
       
        pdfStamper.close();
        pdfReader.close();
       
        File outFile = new File(inputCommand.getOutputFile() ,prefixParser.generateFileName());
          FileUtility.renameTemporaryFile(tmpFile, outFile, inputCommand.isOverwrite());
          LOG.debug("File "+outFile.getCanonicalPath()+" created.");
          LOG.info("Slide show options set.");
      }catch(Exception e){       
        throw new SlideShowException(e);
      }finally{
View Full Code Here


*/
public class SlideShowCmdValidator extends AbstractCmdValidator {

  protected AbstractParsedCommand validateArguments(CmdLineHandler cmdLineHandler) throws ConsoleException {
   
    SlideShowParsedCommand parsedCommandDTO = new SlideShowParsedCommand();
   
    if(cmdLineHandler != null){
      //-o
      FileParam oOption = (FileParam) cmdLineHandler.getOption(SlideShowParsedCommand.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(SlideShowParsedCommand.P_ARG);
          if(pOption.isSet()){
            parsedCommandDTO.setOutputFilesPrefix(pOption.getValue());
          }

          //-f
          PdfFileParam fOption = (PdfFileParam) cmdLineHandler.getOption(SlideShowParsedCommand.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)
          }
         
          //-t
          StringParam tOption = (StringParam) cmdLineHandler.getOption(SlideShowParsedCommand.T_ARG);
          if(tOption.isSet()){
            HashSet transitionsList = new HashSet(tOption.getValues().size());
            for(Iterator tIterator = tOption.getValues().iterator(); tIterator.hasNext();){
              String transition = (String) tIterator.next();
              Transition transitionObject = stringToTransition(transition);
              if(!transitionsList.add(transitionObject)){
                throw new SlideShowException(SlideShowException.UNABLE_TO_ADD_TRANSITION, new String[]{transition,transitionObject.toString()});
              }
            }
            parsedCommandDTO.setTransitions((Transition[])transitionsList.toArray(new Transition[transitionsList.size()]));
          }
         
          //-dt
          StringParam dtOption = (StringParam) cmdLineHandler.getOption(SlideShowParsedCommand.DT_ARG);
          if(dtOption.isSet()){
            parsedCommandDTO.setDefaultTransition(stringToTransition(dtOption.getValue()));
          }
         
          //-l
          FileParam lOption = (FileParam) cmdLineHandler.getOption(SlideShowParsedCommand.L_ARG);
          if(lOption.isSet()){
            if(lOption.getFile().getPath().toLowerCase().endsWith(XML_EXTENSION)){
          parsedCommandDTO.setInputXmlFile(lOption.getFile());
        }else{
          throw new ParseException(ParseException.ERR_NOT_XML);
        }
          }
         
          //-fullscreen
          parsedCommandDTO.setFullScreen(((BooleanParam) cmdLineHandler.getOption(SlideShowParsedCommand.FULLSCREEN_ARG)).isTrue());

    }else{
      throw new ConsoleException(ConsoleException.CMD_LINE_HANDLER_NULL);
    }
    return parsedCommandDTO; 
View Full Code Here

TOP

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

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.