List of usage examples for javax.swing.filechooser FileFilter FileFilter
FileFilter
From source file:org.zaproxy.zap.extension.customFire.CustomFireDialog.java
/** * //w ww . j a v a2 s .c o m * @return TechnologyTreePanel ` */ private TechnologyTreePanel getTechTree() { TechnologyTreePanel ttp = new TechnologyTreePanel( Constant.messages.getString("customFire.custom.tab.tech.node")); 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(".ser")) { return true; } return false; } @Override public String getDescription() { return Constant.messages.getString("customFire.custom.file.format.csp.ser"); } }); File file = null; chooser.setDialogTitle("Open Technology"); int rc = chooser.showOpenDialog(View.getSingleton().getMainFrame()); if (rc == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); if (file == null || !file.getName().equalsIgnoreCase("Tech.ser")) { View.getSingleton().showWarningDialog( Constant.messages.getString("customFire.custom.tech.ser.mismatch.error")); return ttp; } try { FileInputStream fis = new FileInputStream(file.getPath()); ObjectInputStream ois = new ObjectInputStream(fis); ttp = (TechnologyTreePanel) ois.readObject(); ttp.addTechTreeListener(ttp, true); ois.close(); fis.close(); } catch (IOException | ClassNotFoundException e1) { View.getSingleton() .showWarningDialog(Constant.messages.getString("customFire.custom.ser.load.error")); } } techTree = ttp; return techTree; }
From source file:org.zaproxy.zap.extension.customFire.CustomFireDialog.java
/** * Not used as of now/* w ww. j a v a2 s . co m*/ * @return ScriptTreePanel ` */ public ScriptTreePanel getSTree() { //if (sTree == null) { ScriptTreePanel stp = new ScriptTreePanel(Constant.messages.getString("customFire.custom.tab.script.node")); 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(".ser")) { return true; } return false; } @Override public String getDescription() { return Constant.messages.getString("customFire.custom.file.format.csp.ser"); } }); File file = null; chooser.setDialogTitle("Open Scripts settings"); int rc = chooser.showOpenDialog(View.getSingleton().getMainFrame()); if (rc == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); if (file == null || !file.getName().equalsIgnoreCase("Scripts.ser")) { View.getSingleton().showWarningDialog( Constant.messages.getString("customFire.custom.scripts.ser.mismatch.error")); return stp; } try { FileInputStream fis = new FileInputStream(file.getPath()); ObjectInputStream ois = new ObjectInputStream(fis); stp = (ScriptTreePanel) ois.readObject(); stp.addScriptTreeListener(stp, true); ois.close(); fis.close(); } catch (IOException | ClassNotFoundException e1) { View.getSingleton() .showWarningDialog(Constant.messages.getString("customFire.custom.ser.load.error")); } } sTree = stp; return sTree; }
From source file:org.zaproxy.zap.extension.customFire.CustomFireDialog.java
/** * Gets Input Vectors tab/*from www . ja v a2 s .c o m*/ * void ` */ private ScannerParam getScannerParam() { ScannerParam sp = new ScannerParam(); 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(".ser")) { return true; } return false; } @Override public String getDescription() { return Constant.messages.getString("customFire.custom.file.format.csp.ser"); } }); File file = null; chooser.setDialogTitle("Open Input Vectors"); int rc = chooser.showOpenDialog(View.getSingleton().getMainFrame()); if (rc == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); if (file == null || !file.getName().equalsIgnoreCase("Input Vectors.ser")) { View.getSingleton().showWarningDialog( Constant.messages.getString("customFire.custom.inputVectors.ser.mismatch.error")); return scannerParam; } try { FileInputStream fis = new FileInputStream(file.getPath()); ObjectInputStream ois = new ObjectInputStream(fis); sp = (ScannerParam) ois.readObject(); ois.close(); fis.close(); return sp; } catch (IOException | ClassNotFoundException e1) { View.getSingleton() .showWarningDialog(Constant.messages.getString("customFire.custom.ser.load.error")); return scannerParam; } } return scannerParam; }
From source file:org.zaproxy.zap.extension.customFire.CustomFireDialog.java
/** * Saves custom vectors tab/* w w w . j a v a 2 s . c o m*/ * @param list * @param httpRequest void ` */ protected void saveCustomVectors(ArrayList list, String httpRequest) { JFileChooser chooser = new JFileChooser(Constant.getPoliciesDir()); File file = new File(Constant.getZapHome(), "Custom Vectors.ser"); chooser.setSelectedFile(file); chooser.setFileFilter(new FileFilter() { @Override public boolean accept(File file) { if (file.isDirectory()) { return true; } else if (file.isFile() && file.getName().endsWith(".ser")) { return true; } return false; } @Override public String getDescription() { return Constant.messages.getString("customFire.custom.file.format.csp.ser"); } }); int rc = chooser.showSaveDialog(View.getSingleton().getMainFrame()); if (rc == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); if (file == null) { return; } ArrayList woi = new ArrayList<>(); woi.add(list); woi.add(httpRequest); try { FileOutputStream fos = new FileOutputStream(file); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(woi); oos.close(); fos.close(); View.getSingleton() .showMessageDialog(Constant.messages.getString("customFire.custom.ser.saveCV.success")); } catch (IOException e1) { e1.printStackTrace(); View.getSingleton() .showWarningDialog(Constant.messages.getString("customFire.custom.ser.saveCV.error")); return; } } }
From source file:org.zaproxy.zap.extension.customFire.CustomFireDialog.java
/** * Saves input vectors tab/*w ww. j a v a2 s .c om*/ * @param scannerParam void ` */ protected void saveScannerParam(ScannerParam scannerParam) { JFileChooser chooser = new JFileChooser(Constant.getPoliciesDir()); File file = new File(Constant.getZapHome(), "Input Vectors.ser"); chooser.setSelectedFile(file); chooser.setFileFilter(new FileFilter() { @Override public boolean accept(File file) { if (file.isDirectory()) { return true; } else if (file.isFile() && file.getName().endsWith(".ser")) { return true; } return false; } @Override public String getDescription() { return Constant.messages.getString("customFire.custom.file.format.csp.ser"); } }); int rc = chooser.showSaveDialog(View.getSingleton().getMainFrame()); if (rc == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); if (file == null) { return; } try { FileOutputStream fos = new FileOutputStream(file); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(scannerParam); oos.close(); fos.close(); View.getSingleton() .showMessageDialog(Constant.messages.getString("customFire.custom.ser.saveIV.success")); } catch (IOException e1) { View.getSingleton() .showWarningDialog(Constant.messages.getString("customFire.custom.ser.saveIV.error")); return; } } if (rc == JFileChooser.CANCEL_OPTION) { chooser.setVisible(false); return; } }
From source file:org.zaproxy.zap.extension.customFire.PolicyManagerDialog.java
private JButton getImportButton() { if (this.importButton == null) { this.importButton = new JButton( Constant.messages.getString("customFire.custom.policymgr.button.import")); this.importButton.addActionListener(new ActionListener() { @Override// w ww .j a v a2s . co m 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("customFire.custom.policy.load.error")); } } } }); } return this.importButton; }
From source file:org.zaproxy.zap.extension.customFire.PolicyManagerDialog.java
private JButton getExportButton() { if (this.exportButton == null) { this.exportButton = new JButton( Constant.messages.getString("customFire.custom.policymgr.button.export")); this.exportButton.setEnabled(false); this.exportButton.addActionListener(new ActionListener() { @Override// w w w. jav a 2 s . c o m public void actionPerformed(ActionEvent e) { String name = (String) getParamsModel().getValueAt(getParamsTable().getSelectedRow(), 0); if (name != null) { JFileChooser chooser = new JFileChooser(Constant.getPoliciesDir()); File file = new File(Constant.getZapHome(), name + PolicyManager.POLICY_EXTENSION); chooser.setSelectedFile(file); 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"); } }); int rc = chooser.showSaveDialog(View.getSingleton().getMainFrame()); if (rc == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); if (file == null) { return; } try { CustomScanPolicy policy = extension.getPolicyManager().getPolicy(name); if (policy != null) { extension.getPolicyManager().exportPolicy(policy, file); } } catch (ConfigurationException e1) { logger.error(e1.getMessage(), e1); View.getSingleton().showWarningDialog( Constant.messages.getString("customFire.custom.policy.load.error")); } } } } }); } return this.exportButton; }
From source file:org.zaproxy.zap.extension.customFire.TechnologyTreePanel.java
/** * To save tech settings/*from w w w.j a va 2s.c om*/ * void ` */ public void saveTechState() { //Do Tech ser JFileChooser chooser = new JFileChooser(Constant.getPoliciesDir()); File file = new File(Constant.getZapHome(), "Tech.ser"); chooser.setSelectedFile(file); chooser.setFileFilter(new FileFilter() { @Override public boolean accept(File file) { if (file.isDirectory()) { return true; } else if (file.isFile() && file.getName().endsWith(".ser")) { return true; } return false; } @Override public String getDescription() { return Constant.messages.getString("customFire.custom.file.format.csp.ser"); } }); int rc = chooser.showSaveDialog(View.getSingleton().getMainFrame()); if (rc == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); if (file == null) { return; } try { FileOutputStream fos = new FileOutputStream(file); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(TechnologyTreePanel.this); oos.close(); fos.close(); View.getSingleton() .showMessageDialog(Constant.messages.getString("customFire.custom.ser.saveTech.success")); } catch (IOException e1) { View.getSingleton() .showWarningDialog(Constant.messages.getString("customFire.custom.ser.saveTech.error")); return; } } if (rc == JFileChooser.CANCEL_OPTION) { chooser.setVisible(false); return; } }
From source file:org.zaproxy.zap.extension.dynssl.DynamicSSLPanel.java
/** * Import Root CA certificate from other ZAP configuration files. */// www.j a va 2 s.co m 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); } } }
From source file:org.zaproxy.zap.extension.history.PopupMenuExportURLs.java
private File getOutputFile() { JFileChooser chooser = new JFileChooser(extension.getModel().getOptionsParam().getUserDirectory()); chooser.setFileFilter(new FileFilter() { public boolean accept(File file) { if (file.isDirectory()) { return true; } else if (file.isFile() && file.getName().toLowerCase().endsWith(".txt")) { return true; } else if (file.isFile() && file.getName().toLowerCase().endsWith(".htm")) { return true; } else if (file.isFile() && file.getName().toLowerCase().endsWith(".html")) { return true; }/*from w w w . ja v a 2 s. c o m*/ return false; } public String getDescription() { return Constant.messages.getString("file.format.textOrHtml"); } }); 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().toLowerCase(); if (!fileName.endsWith(".txt") && !fileName.endsWith(".htm") && !fileName.endsWith(".html")) { fileName += ".txt"; file = new File(fileName); } return file; } return file; }