Search in sources :

Example 6 with FileFilter

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

the class DynamicSSLPanel method doImport.

/**
	 * Import Root CA certificate from other ZAP configuration files.
	 */
private void doImport() {
    if (checkExistingCertificate()) {
        // prevent overwriting
        return;
    }
    final JFileChooser fc = new JFileChooser(System.getProperty("user.home"));
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setMultiSelectionEnabled(false);
    fc.setSelectedFile(new File(CONFIGURATION_FILENAME));
    fc.setFileFilter(new FileFilter() {

        @Override
        public String getDescription() {
            // config.xml or *.pem files
            return Constant.messages.getString("dynssl.filter.file");
        }

        @Override
        public boolean accept(File f) {
            return f.getName().toLowerCase().endsWith(CONFIGURATION_FILENAME) || f.getName().toLowerCase().endsWith("pem") || f.isDirectory();
        }
    });
    final int result = fc.showOpenDialog(this);
    final File f = fc.getSelectedFile();
    if (result == JFileChooser.APPROVE_OPTION && f.exists()) {
        if (logger.isInfoEnabled()) {
            logger.info("Loading Root CA certificate from " + f);
        }
        KeyStore ks = null;
        if (f.getName().toLowerCase().endsWith("pem")) {
            ks = convertPemFileToKeyStore(f.toPath());
        } else {
            try {
                final ZapXmlConfiguration conf = new ZapXmlConfiguration(f);
                final String rootcastr = conf.getString(DynSSLParam.PARAM_ROOT_CA);
                ks = SslCertificateUtils.string2Keystore(rootcastr);
            } catch (final Exception e) {
                logger.error("Error importing Root CA cert from config file:", e);
                JOptionPane.showMessageDialog(this, Constant.messages.getString("dynssl.message1.filecouldntloaded"), Constant.messages.getString("dynssl.message1.title"), JOptionPane.ERROR_MESSAGE);
            }
        }
        if (ks != null) {
            setRootca(ks);
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) KeyStore(java.security.KeyStore) IOException(java.io.IOException)

Example 7 with FileFilter

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

the class ExtensionAutoUpdate method getMenuItemLoadAddOn.

private ZapMenuItem getMenuItemLoadAddOn() {
    if (menuItemLoadAddOn == null) {
        menuItemLoadAddOn = new ZapMenuItem("cfu.file.menu.loadaddon", KeyStroke.getKeyStroke(KeyEvent.VK_L, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));
        menuItemLoadAddOn.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent e) {
                try {
                    JFileChooser chooser = new JFileChooser(Model.getSingleton().getOptionsParam().getUserDirectory());
                    File file = null;
                    chooser.setFileFilter(new FileFilter() {

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

                        @Override
                        public String getDescription() {
                            return Constant.messages.getString("file.format.zap.addon");
                        }
                    });
                    int rc = chooser.showOpenDialog(View.getSingleton().getMainFrame());
                    if (rc == JFileChooser.APPROVE_OPTION) {
                        file = chooser.getSelectedFile();
                        if (file == null) {
                            return;
                        }
                        installLocalAddOn(file.toPath());
                    }
                } catch (Exception e1) {
                    logger.error(e1.getMessage(), e1);
                }
            }
        });
    }
    return menuItemLoadAddOn;
}
Also used : ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) ZapMenuItem(org.zaproxy.zap.view.ZapMenuItem) FileFilter(javax.swing.filechooser.FileFilter) ActionEvent(java.awt.event.ActionEvent) File(java.io.File) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException)

Example 8 with FileFilter

use of javax.swing.filechooser.FileFilter in project SKMCLauncher by SKCraft.

the class FileField method getFileChooser.

@Override
protected JFileChooser getFileChooser() {
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle(title);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setFileFilter(new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            return true;
        }

        @Override
        public String getDescription() {
            return description;
        }
    });
    return chooser;
}
Also used : JFileChooser(javax.swing.JFileChooser) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File)

Example 9 with FileFilter

use of javax.swing.filechooser.FileFilter in project jphp by jphp-compiler.

the class UIFileChooser method addChoosableExtensions.

@Signature({ @Arg(value = "extensions", type = HintType.ARRAY), @Arg(value = "description"), @Arg(value = "showDirectories", optional = @Optional(value = "1", type = HintType.BOOLEAN)) })
public Memory addChoosableExtensions(final Environment env, final Memory... args) {
    final Set<String> extensions = new HashSet<String>();
    ForeachIterator iterator = args[0].getNewIterator(env, false, false);
    while (iterator.next()) {
        extensions.add(iterator.getValue().toString());
    }
    final String description = args[1].toString();
    component.addChoosableFileFilter(new FileFilter() {

        @Override
        public boolean accept(File f) {
            if (f.isDirectory()) {
                return args[2].toBoolean();
            }
            String path = f.getPath();
            for (String ext : extensions) {
                if (Constants.PATH_NAME_CASE_INSENSITIVE) {
                    if (path.endsWith("." + ext))
                        return true;
                } else {
                    if (path.toLowerCase().endsWith("." + ext.toLowerCase()))
                        return true;
                }
            }
            return false;
        }

        @Override
        public String getDescription() {
            return description;
        }
    });
    return Memory.NULL;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) HashSet(java.util.HashSet)

Example 10 with FileFilter

use of javax.swing.filechooser.FileFilter in project jphp by jphp-compiler.

the class UIFileChooser method addChoosableFilter.

@Signature({ @Arg(value = "filter", type = HintType.CALLABLE), @Arg(value = "description") })
public Memory addChoosableFilter(final Environment env, Memory... args) {
    final Invoker invoker = Invoker.valueOf(env, null, args[0]);
    final String description = args[1].toString();
    component.addChoosableFileFilter(new FileFilter() {

        @Override
        public boolean accept(File f) {
            return invoker.callNoThrow(new ObjectMemory(new FileObject(env, f))).toBoolean();
        }

        @Override
        public String getDescription() {
            return description;
        }
    });
    return Memory.NULL;
}
Also used : Invoker(php.runtime.invoke.Invoker) FileObject(php.runtime.ext.core.classes.stream.FileObject) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File)

Aggregations

FileFilter (javax.swing.filechooser.FileFilter)59 File (java.io.File)48 JFileChooser (javax.swing.JFileChooser)39 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)15 IOException (java.io.IOException)10 ActionEvent (java.awt.event.ActionEvent)7 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 TopLevelWindowManager (cbit.vcell.client.TopLevelWindowManager)3 UserPreferences (cbit.vcell.client.server.UserPreferences)3 ArrayList (java.util.ArrayList)3 Preferences (java.util.prefs.Preferences)3 JButton (javax.swing.JButton)3 Session (org.parosproxy.paros.model.Session)3 Component (java.awt.Component)2 Cursor (java.awt.Cursor)2 Dimension (java.awt.Dimension)2 FileDialog (java.awt.FileDialog)2