Search in sources :

Example 36 with FileFilter

use of javax.swing.filechooser.FileFilter in project zaproxy by zaproxy.

the class PolicyManagerDialog method getImportButton.

private JButton getImportButton() {
    if (this.importButton == null) {
        this.importButton = new JButton(Constant.messages.getString("ascan.policymgr.button.import"));
        this.importButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                // Default to ZAP home dir - we dont want to import/export to the policy dir
                JFileChooser chooser = new JFileChooser(Constant.getZapHome());
                chooser.setFileFilter(new FileFilter() {

                    @Override
                    public boolean accept(File file) {
                        if (file.isDirectory()) {
                            return true;
                        } else if (file.isFile() && file.getName().endsWith(".policy")) {
                            return true;
                        }
                        return false;
                    }

                    @Override
                    public String getDescription() {
                        return Constant.messages.getString("file.format.zap.policy");
                    }
                });
                File file = null;
                int rc = chooser.showOpenDialog(View.getSingleton().getMainFrame());
                if (rc == JFileChooser.APPROVE_OPTION) {
                    file = chooser.getSelectedFile();
                    if (file == null) {
                        return;
                    }
                    try {
                        extension.getPolicyManager().importPolicy(file);
                        policyNamesChanged();
                    } catch (ConfigurationException | IOException e1) {
                        logger.error(e1.getMessage(), e1);
                        View.getSingleton().showWarningDialog(Constant.messages.getString("ascan.policy.load.error"));
                    }
                }
            }
        });
    }
    return this.importButton;
}
Also used : ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File)

Example 37 with FileFilter

use of javax.swing.filechooser.FileFilter in project zaproxy by zaproxy.

the class OptionsCertificatePanel method browseButtonActionPerformed.

//GEN-LAST:event_addPkcs12ButtonActionPerformed
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {
    //GEN-FIRST:event_browseButtonActionPerformed
    JFileChooser fc = new JFileChooser();
    fc.setFileFilter(new FileFilter() {

        @Override
        public String getDescription() {
            return Constant.messages.getString("options.cert.label.client.cert") + " (*.p12, *.pfx)";
        }

        @Override
        public boolean accept(File f) {
            return f.isDirectory() || f.getName().toLowerCase().endsWith(".p12") || f.getName().toLowerCase().endsWith(".pfx");
        }
    });
    int state = fc.showOpenDialog(null);
    if (state == JFileChooser.APPROVE_OPTION) {
        fileTextField.setText(fc.getSelectedFile().toString());
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File)

Example 38 with FileFilter

use of javax.swing.filechooser.FileFilter in project zaproxy by zaproxy.

the class PopupMenuExportMessage method getOutputFile.

private File getOutputFile() {
    JFileChooser chooser = new JFileChooser(extension.getModel().getOptionsParam().getUserDirectory());
    chooser.setFileFilter(new FileFilter() {

        @Override
        public boolean accept(File file) {
            if (file.isDirectory()) {
                return true;
            } else if (file.isFile() && file.getName().endsWith(".txt")) {
                return true;
            }
            return false;
        }

        @Override
        public String getDescription() {
            return Constant.messages.getString("file.format.ascii");
        }
    });
    File file = null;
    int rc = chooser.showSaveDialog(extension.getView().getMainFrame());
    if (rc == JFileChooser.APPROVE_OPTION) {
        file = chooser.getSelectedFile();
        if (file == null) {
            return file;
        }
        extension.getModel().getOptionsParam().setUserDirectory(chooser.getCurrentDirectory());
        String fileName = file.getAbsolutePath();
        if (!fileName.endsWith(".txt")) {
            fileName += ".txt";
            file = new File(fileName);
        }
        return file;
    }
    return file;
}
Also used : JFileChooser(javax.swing.JFileChooser) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File)

Example 39 with FileFilter

use of javax.swing.filechooser.FileFilter in project zaproxy by zaproxy.

the class ReportLastScan method generateReport.

/** 
     * Generates a report. Defaults to HTML report if reportType is null.
     * @param view
     * @param model
     * @param reportType
     */
public void generateReport(ViewDelegate view, Model model, ReportType reportType) {
    // ZAP: Allow scan report file name to be specified
    final ReportType localReportType;
    if (reportType == null) {
        localReportType = ReportType.HTML;
    } else {
        localReportType = reportType;
    }
    try {
        JFileChooser chooser = new WritableFileChooser(Model.getSingleton().getOptionsParam().getUserDirectory());
        chooser.setFileFilter(new FileFilter() {

            @Override
            public boolean accept(File file) {
                if (file.isDirectory()) {
                    return true;
                } else if (file.isFile()) {
                    String lcFileName = file.getName().toLowerCase(Locale.ROOT);
                    switch(localReportType) {
                        case XML:
                            return lcFileName.endsWith(XML_FILE_EXTENSION);
                        case MD:
                            return lcFileName.endsWith(MD_FILE_EXTENSION);
                        case HTML:
                        default:
                            return (lcFileName.endsWith(HTM_FILE_EXTENSION) || lcFileName.endsWith(HTML_FILE_EXTENSION));
                    }
                }
                return false;
            }

            @Override
            public String getDescription() {
                switch(localReportType) {
                    case XML:
                        return Constant.messages.getString("file.format.xml");
                    case MD:
                        return Constant.messages.getString("file.format.md");
                    case HTML:
                    default:
                        return Constant.messages.getString("file.format.html");
                }
            }
        });
        String reportXSL = "";
        String fileExtension = "";
        switch(localReportType) {
            case XML:
                fileExtension = XML_FILE_EXTENSION;
                // Dont use XSLT
                reportXSL = null;
                break;
            case MD:
                fileExtension = MD_FILE_EXTENSION;
                reportXSL = (Constant.getZapInstall() + "/xml/report.md.xsl");
                break;
            case HTML:
            default:
                fileExtension = HTML_FILE_EXTENSION;
                reportXSL = (Constant.getZapInstall() + "/xml/report.html.xsl");
                break;
        }
        //Default the filename to a reasonable extension;
        chooser.setSelectedFile(new File(fileExtension));
        int rc = chooser.showSaveDialog(View.getSingleton().getMainFrame());
        File file = null;
        if (rc == JFileChooser.APPROVE_OPTION) {
            file = chooser.getSelectedFile();
            File report = generate(file.getAbsolutePath(), model, reportXSL);
            if (report == null) {
                view.showMessageDialog(MessageFormat.format(Constant.messages.getString("report.unknown.error"), new Object[] { file.getAbsolutePath() }));
                return;
            }
            try {
                DesktopUtils.openUrlInBrowser(report.toURI());
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
                view.showMessageDialog(MessageFormat.format(Constant.messages.getString("report.complete.warning"), new Object[] { report.getAbsolutePath() }));
            }
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        view.showWarningDialog(Constant.messages.getString("report.unexpected.error"));
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) WritableFileChooser(org.zaproxy.zap.view.widgets.WritableFileChooser)

Example 40 with FileFilter

use of javax.swing.filechooser.FileFilter in project zaproxy by zaproxy.

the class MenuFileControl method openFileBasedSession.

private void openFileBasedSession() {
    JFileChooser chooser = new JFileChooser(model.getOptionsParam().getUserDirectory());
    // By default ZAP on linux puts timestamped sessions under a 'dot' directory 
    chooser.setFileHidingEnabled(false);
    File file = null;
    chooser.setFileFilter(new FileFilter() {

        @Override
        public boolean accept(File file) {
            if (file.isDirectory()) {
                return true;
            } else if (file.isFile() && file.getName().endsWith(".session")) {
                return true;
            }
            return false;
        }

        @Override
        public String getDescription() {
            // ZAP: Rebrand
            return Constant.messages.getString("file.format.zap.session");
        }
    });
    int rc = chooser.showOpenDialog(view.getMainFrame());
    if (rc == JFileChooser.APPROVE_OPTION) {
        try {
            file = chooser.getSelectedFile();
            if (file == null) {
                return;
            }
            model.getOptionsParam().setUserDirectory(chooser.getCurrentDirectory());
            log.info("opening session file " + file.getAbsolutePath());
            waitMessageDialog = view.getWaitMessageDialog(Constant.messages.getString("menu.file.loadSession"));
            control.openSession(file, this);
            waitMessageDialog.setVisible(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) IllegalContextNameException(org.zaproxy.zap.model.IllegalContextNameException) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Aggregations

FileFilter (javax.swing.filechooser.FileFilter)55 File (java.io.File)44 JFileChooser (javax.swing.JFileChooser)39 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)15 IOException (java.io.IOException)10 ActionEvent (java.awt.event.ActionEvent)6 ActionListener (java.awt.event.ActionListener)5 DatabaseException (org.parosproxy.paros.db.DatabaseException)5 PCGFile (pcgen.io.PCGFile)5 IllegalContextNameException (org.zaproxy.zap.model.IllegalContextNameException)4 Preferences (java.util.prefs.Preferences)3 JButton (javax.swing.JButton)3 Session (org.parosproxy.paros.model.Session)3 Cursor (java.awt.Cursor)2 Dimension (java.awt.Dimension)2 FileDialog (java.awt.FileDialog)2 BufferedImage (java.awt.image.BufferedImage)2 FileOutputStream (java.io.FileOutputStream)2 FilenameFilter (java.io.FilenameFilter)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2