public void run() { try { if (inputFile != null) { if (new PdfFilter(false).accept(inputFile)) { wipText = GettextResource.gettext( Configuration.getInstance().getI18nResourceBundle(), "Please wait while reading") + " " + inputFile.getName() + " ..."; panel.addWipText(wipText); panel.updateTableRow( index, getPdfSelectionTableItem(inputFile, password, pageSelection)); panel.removeWipText(wipText); } else { log.warn( GettextResource.gettext( Configuration.getInstance().getI18nResourceBundle(), "Selected file is not a pdf document.") + " " + inputFile.getName()); } } } catch (Throwable e) { log.error( GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Error: "), e); } }
/** adds a file or many files depending on the value of singleSelection */ public void showFileChooserAndAddFiles(boolean singleSelection) { if (panel.getMainTable().getModel().getRowCount() >= panel.getMaxSelectableFiles()) { JOptionPane.showMessageDialog( panel, GettextResource.gettext( Configuration.getInstance().getI18nResourceBundle(), "Selection table is full, please remove some pdf document."), GettextResource.gettext( Configuration.getInstance().getI18nResourceBundle(), "Table full"), JOptionPane.INFORMATION_MESSAGE); } else { if (singleSelection) { fileChooser.setMultiSelectionEnabled(false); } else { fileChooser.setMultiSelectionEnabled(true); } if (!(workQueue.getRunning() > 0)) { if (fileChooser.showOpenDialog(panel) == JFileChooser.APPROVE_OPTION) { if (fileChooser.isMultiSelectionEnabled()) { addFiles(fileChooser.getSelectedFiles(), true); } else { addFile(fileChooser.getSelectedFile()); } } } else { log.info( GettextResource.gettext( Configuration.getInstance().getI18nResourceBundle(), "Please wait while all files are processed..")); } } }
public void loadJobNode(Node arg0) throws LoadJobException { try { selectionPanel.getClearButton().doClick(); List fileList = arg0.selectNodes("filelist/file"); for (int i = 0; fileList != null && i < fileList.size(); i++) { Node fileNode = (Node) fileList.get(i); if (fileNode != null) { Node fileName = (Node) fileNode.selectSingleNode("@name"); if (fileName != null && fileName.getText().length() > 0) { Node filePwd = (Node) fileNode.selectSingleNode("@password"); selectionPanel .getLoader() .addFile( new File(fileName.getText()), (filePwd != null) ? filePwd.getText() : null); } } } Node fileDestination = (Node) arg0.selectSingleNode("destination/@value"); if (fileDestination != null) { destinationTextField.setText(fileDestination.getText()); } Node fileOverwrite = (Node) arg0.selectSingleNode("overwrite/@value"); if (fileOverwrite != null) { overwriteCheckbox.setSelected(fileOverwrite.getText().equals("true")); } Node fileCompressed = (Node) arg0.selectSingleNode("compressed/@value"); if (fileCompressed != null && TRUE.equals(fileCompressed.getText())) { outputCompressedCheck.doClick(); } Node filePrefix = (Node) arg0.selectSingleNode("prefix/@value"); if (filePrefix != null) { outPrefixTextField.setText(filePrefix.getText()); } Node pdfVersion = (Node) arg0.selectSingleNode("pdfversion/@value"); if (pdfVersion != null) { for (int i = 0; i < versionCombo.getItemCount(); i++) { if (((StringItem) versionCombo.getItemAt(i)).getId().equals(pdfVersion.getText())) { versionCombo.setSelectedIndex(i); break; } } } log.info(GettextResource.gettext(config.getI18nResourceBundle(), "Decrypt section loaded.")); } catch (Exception ex) { log.error(GettextResource.gettext(config.getI18nResourceBundle(), "Error: "), ex); } }
/** * @param fileToAdd file to add * @param password password to open the file * @return the item to add to the table */ PdfSelectionTableItem getPdfSelectionTableItem( File fileToAdd, String password, String pageSelection) { PdfSelectionTableItem tableItem = null; PdfReader pdfReader = null; if (fileToAdd != null) { tableItem = new PdfSelectionTableItem(); tableItem.setInputFile(fileToAdd); tableItem.setPassword(password); tableItem.setPageSelection(pageSelection); try { // fix 03/07 for memory usage pdfReader = new PdfReader( new RandomAccessFileOrArray(new FileInputStream(fileToAdd)), (password != null) ? password.getBytes() : null); tableItem.setEncrypted(pdfReader.isEncrypted()); tableItem.setPagesNumber(Integer.toString(pdfReader.getNumberOfPages())); tableItem.setPdfVersion(pdfReader.getPdfVersion()); } catch (Exception e) { tableItem.setLoadedWithErrors(true); log.error( GettextResource.gettext( Configuration.getInstance().getI18nResourceBundle(), "Error loading ") + fileToAdd.getAbsolutePath() + " :", e); } finally { if (pdfReader != null) { pdfReader.close(); pdfReader = null; } } } return tableItem; }
public PdfLoader(JPdfSelectionPanel panel) { this.panel = panel; fileChooser = new JFileChooser(Configuration.getInstance().getDefaultWorkingDir()); fileChooser.setFileFilter(new PdfFilter()); fileChooser.setMultiSelectionEnabled(true); // number of threads in workqueue based on the number of selectable documents if (panel.getMaxSelectableFiles() <= 1) { workQueue = new WorkQueue(1, 1); } else { workQueue = new WorkQueue(10, 1); // // fileChooser.setAccessory(CommonComponentsFactory.getInstance().createCheckBox(CommonComponentsFactory.DONT_PRESERVER_ORDER_CHECKBOX_TYPE)); } }
/** @return the Plugin name */ public String getPluginName() { return GettextResource.gettext(config.getI18nResourceBundle(), "Decrypt"); }
private void initialize() { config = Configuration.getInstance(); setPanelIcon("/images/decrypt.png"); setPreferredSize(new Dimension(500, 450)); setLayout(new GridBagLayout()); topPanel.setLayout(new GridBagLayout()); GridBagConstraints topConst = new GridBagConstraints(); topConst.fill = GridBagConstraints.BOTH; topConst.ipady = 5; topConst.weightx = 1.0; topConst.weighty = 1.0; topConst.gridwidth = 3; topConst.gridheight = 2; topConst.gridx = 0; topConst.gridy = 0; topPanel.add(selectionPanel, topConst); selectionPanel.addPropertyChangeListener(this); selectionPanel.enableSetOutputPathMenuItem(); // DESTINATION_PANEL destinationPanelLayout = new SpringLayout(); destinationPanel.setLayout(destinationPanelLayout); TitledBorder titledBorder = BorderFactory.createTitledBorder( GettextResource.gettext(config.getI18nResourceBundle(), "Destination folder")); destinationPanel.setBorder(titledBorder); destinationPanel.setPreferredSize(new Dimension(200, 160)); destinationPanel.setMinimumSize(new Dimension(160, 150)); // END_DESTINATION_PANEL destinationPanel.add(destinationTextField); topConst.fill = GridBagConstraints.HORIZONTAL; topConst.weightx = 0.0; topConst.weighty = 0.0; topConst.gridwidth = 3; topConst.gridheight = 1; topConst.gridx = 0; topConst.gridy = 2; topPanel.add(destinationPanel, topConst); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.ipady = 5; c.weightx = 1.0; c.weighty = 1.0; c.gridwidth = 3; c.gridx = 0; c.gridy = 0; add(topPanel, c); // BROWSE_BUTTON browseButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (browseDirChooser == null) { browseDirChooser = new JFileChooser(Configuration.getInstance().getDefaultWorkingDir()); browseDirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); } File chosenFile = null; if (destinationTextField.getText().length() > 0) { browseDirChooser.setCurrentDirectory(new File(destinationTextField.getText())); } if (browseDirChooser.showOpenDialog(browseButton.getParent()) == JFileChooser.APPROVE_OPTION) { chosenFile = browseDirChooser.getSelectedFile(); } // write the destination in text field if (chosenFile != null) { try { destinationTextField.setText(chosenFile.getAbsolutePath()); } catch (Exception ex) { log.error(GettextResource.gettext(config.getI18nResourceBundle(), "Error: "), ex); } } } }); destinationPanel.add(browseButton); // END_BROWSE_BUTTON overwriteCheckbox.setSelected(true); destinationPanel.add(overwriteCheckbox); outputCompressedCheck.addItemListener(new CompressCheckBoxItemListener(versionCombo)); outputCompressedCheck.setSelected(true); destinationPanel.add(outputCompressedCheck); destinationPanel.add(versionCombo); destinationPanel.add(outputVersionLabel); // HELP_LABEL_DESTINATION String helpTextDest = "<html><body><b>" + GettextResource.gettext( config.getI18nResourceBundle(), "Destination output directory") + "</b>" + "<p>" + GettextResource.gettext( config.getI18nResourceBundle(), "To choose a folder browse or enter the full path to the destination output directory.") + "</p>" + "<p>" + GettextResource.gettext( config.getI18nResourceBundle(), "Check the box if you want to overwrite the output files if they already exist.") + "</p>" + "</body></html>"; destinationHelpLabel = new JHelpLabel(helpTextDest, true); destinationPanel.add(destinationHelpLabel); // END_HELP_LABEL_DESTINATION outputOptionsPanel.setBorder( BorderFactory.createTitledBorder( GettextResource.gettext(config.getI18nResourceBundle(), "Output options"))); outputOptionsPanel.setPreferredSize(new Dimension(200, 55)); outputOptionsPanel.setMinimumSize(new Dimension(160, 50)); outputOptionsPanelLayout = new SpringLayout(); outputOptionsPanel.setLayout(outputOptionsPanelLayout); outPrefixLabel.setText( GettextResource.gettext(config.getI18nResourceBundle(), "Output file names prefix:")); outputOptionsPanel.add(outPrefixLabel); outPrefixTextField.setPreferredSize(new Dimension(180, 20)); outputOptionsPanel.add(outPrefixTextField); // END_S_PANEL // HELP_LABEL_PREFIX String helpTextPrefix = "<html><body><b>" + GettextResource.gettext(config.getI18nResourceBundle(), "Output files prefix") + "</b>" + "<p> " + GettextResource.gettext( config.getI18nResourceBundle(), "If it contains \"[TIMESTAMP]\" it performs variable substitution.") + "</p>" + "<p> " + GettextResource.gettext( config.getI18nResourceBundle(), "Ex. [BASENAME]_prefix_[TIMESTAMP] generates FileName_prefix_20070517_113423471.pdf.") + "</p>" + "<br><p> " + GettextResource.gettext( config.getI18nResourceBundle(), "If it doesn't contain \"[TIMESTAMP]\" it generates oldstyle output file names.") + "</p>" + "<br><p> " + GettextResource.gettext( config.getI18nResourceBundle(), "Available variables: [TIMESTAMP], [BASENAME].") + "</p>" + "</body></html>"; prefixHelpLabel = new JHelpLabel(helpTextPrefix, true); outputOptionsPanel.add(prefixHelpLabel); // END_HELP_LABEL_PREFIX c.fill = GridBagConstraints.HORIZONTAL; c.ipady = 5; c.weightx = 1.0; c.weighty = 0.0; c.gridwidth = 3; c.gridx = 0; c.gridy = 1; add(outputOptionsPanel, c); // RUN_BUTTON runButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (WorkExecutor.getInstance().getRunningThreads() > 0 || selectionPanel.isAdding()) { log.info( GettextResource.gettext( config.getI18nResourceBundle(), "Please wait while all files are processed..")); return; } final LinkedList args = new LinkedList(); // validation and permission check are demanded to the CmdParser object try { PdfSelectionTableItem item = null; PdfSelectionTableItem[] items = selectionPanel.getTableRows(); if (items != null && items.length >= 1) { for (int i = 0; i < items.length; i++) { item = items[i]; args.add("-" + DecryptParsedCommand.F_ARG); String f = item.getInputFile().getAbsolutePath(); if ((item.getPassword()) != null && (item.getPassword()).length() > 0) { log.debug( GettextResource.gettext( config.getI18nResourceBundle(), "Found a password for input file.")); f += ":" + item.getPassword(); } args.add(f); } args.add("-" + DecryptParsedCommand.O_ARG); if (destinationTextField.getText() == null || destinationTextField.getText().length() == 0) { String suggestedDir = Configuration.getInstance().getDefaultWorkingDir(); if (suggestedDir != null) { int chosenOpt = DialogUtility.showConfirmOuputLocationDialog(getParent(), suggestedDir); if (JOptionPane.YES_OPTION == chosenOpt) { destinationTextField.setText(suggestedDir); } else if (JOptionPane.CANCEL_OPTION == chosenOpt) { return; } } } args.add(destinationTextField.getText()); if (overwriteCheckbox.isSelected()) { args.add("-" + DecryptParsedCommand.OVERWRITE_ARG); } if (outputCompressedCheck.isSelected()) { args.add("-" + DecryptParsedCommand.COMPRESSED_ARG); } args.add("-" + EncryptParsedCommand.P_ARG); args.add(outPrefixTextField.getText()); args.add("-" + DecryptParsedCommand.PDFVERSION_ARG); args.add(((StringItem) versionCombo.getSelectedItem()).getId()); args.add(AbstractParsedCommand.COMMAND_DECRYPT); final String[] myStringArray = (String[]) args.toArray(new String[args.size()]); WorkExecutor.getInstance().execute(new WorkThread(myStringArray)); } else { JOptionPane.showMessageDialog( getParent(), GettextResource.gettext( config.getI18nResourceBundle(), "Please select at least one pdf document."), GettextResource.gettext(config.getI18nResourceBundle(), "Warning"), JOptionPane.WARNING_MESSAGE); } } catch (Exception ex) { log.error(GettextResource.gettext(config.getI18nResourceBundle(), "Error: "), ex); SoundPlayer.getInstance().playErrorSound(); } } }); runButton.setToolTipText( GettextResource.gettext(config.getI18nResourceBundle(), "Decrypt selected files")); runButton.setSize(new Dimension(88, 25)); c.fill = GridBagConstraints.NONE; c.ipadx = 5; c.weightx = 0.0; c.weighty = 0.0; c.anchor = GridBagConstraints.LAST_LINE_END; c.gridwidth = 1; c.gridx = 2; c.gridy = 2; c.insets = new Insets(10, 10, 10, 10); add(runButton, c); // END_RUN_BUTTON destinationTextField.addKeyListener(runEnterkeyListener); runButton.addKeyListener(runEnterkeyListener); browseButton.addKeyListener(browseEnterkeyListener); setLayout(); }