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);
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations