*/
public class SetViewerCmdValidator extends AbstractCmdValidator {
public AbstractParsedCommand validateArguments(CmdLineHandler cmdLineHandler) throws ConsoleException {
SetViewerParsedCommand parsedCommandDTO = new SetViewerParsedCommand();
if(cmdLineHandler != null){
//-o
FileParam oOption = (FileParam) cmdLineHandler.getOption(SetViewerParsedCommand.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(SetViewerParsedCommand.P_ARG);
if(pOption.isSet()){
parsedCommandDTO.setOutputFilesPrefix(pOption.getValue());
}
//-mode
StringParam mOption = (StringParam) cmdLineHandler.getOption(SetViewerParsedCommand.M_ARG);
if(mOption.isSet()){
parsedCommandDTO.setMode(getMode(mOption.getValue()));
}
//-layout
StringParam lOption = (StringParam) cmdLineHandler.getOption(SetViewerParsedCommand.L_ARG);
if(lOption.isSet()){
parsedCommandDTO.setLayout(getLayout(lOption.getValue()));
}
//-nfsmode
StringParam nfsmOption = (StringParam) cmdLineHandler.getOption(SetViewerParsedCommand.NFSM_ARG);
if(nfsmOption.isSet()){
parsedCommandDTO.setNfsmode(getNFSMode(nfsmOption.getValue()));
}
//-direction
StringParam directionOption = (StringParam) cmdLineHandler.getOption(SetViewerParsedCommand.DIRECTION_ARG);
if(directionOption.isSet()){
parsedCommandDTO.setDirection(getDirection(directionOption.getValue()));
}
//-f -d
PdfFileParam fOption = (PdfFileParam) cmdLineHandler.getOption(SetViewerParsedCommand.F_ARG);
FileParam dOption = (FileParam) cmdLineHandler.getOption(SetViewerParsedCommand.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);
}
//-hidemenu
parsedCommandDTO.setHideMenu(((BooleanParam) cmdLineHandler.getOption(SetViewerParsedCommand.HIDEMENU_ARG)).isTrue());
//-hidetoolbar
parsedCommandDTO.setHideToolBar(((BooleanParam) cmdLineHandler.getOption(SetViewerParsedCommand.HIDETOOLBAR_ARG)).isTrue());
//-hide window ui
parsedCommandDTO.setHideWindowUI(((BooleanParam) cmdLineHandler.getOption(SetViewerParsedCommand.HIDEWINDOWUI_ARG)).isTrue());
//-fit window
parsedCommandDTO.setFitWindow(((BooleanParam) cmdLineHandler.getOption(SetViewerParsedCommand.FITWINDOW_ARG)).isTrue());
//-center window
parsedCommandDTO.setCenterWindow(((BooleanParam) cmdLineHandler.getOption(SetViewerParsedCommand.CENTERWINDOW_ARG)).isTrue());
//-display doc title
parsedCommandDTO.setDisplayDocTitle(((BooleanParam) cmdLineHandler.getOption(SetViewerParsedCommand.DOCTITLE_ARG)).isTrue());
//-noprintscaling
parsedCommandDTO.setNoPrintScaling(((BooleanParam) cmdLineHandler.getOption(SetViewerParsedCommand.NOPRINTSCALING_ARG)).isTrue());
}else{
throw new ConsoleException(ConsoleException.CMD_LINE_HANDLER_NULL);
}
return parsedCommandDTO;