List of usage examples for javax.swing.filechooser FileFilter FileFilter
FileFilter
From source file:org.richie.codeGen.ui.CodeGenMainUI.java
/** * //from w ww. j a v a 2s .c o m */ private void openPdmFile() { JFileChooser jfc = new JFileChooser();// LastOperateVo lastOperateVo = null; try { lastOperateVo = GlobalData.getLastOperateVo(); } catch (Exception e2) { log.error("??", e2); } if (lastOperateVo != null && lastOperateVo.getPdmFilePath() != null) { jfc.setCurrentDirectory(new File(lastOperateVo.getPdmFilePath()));// ?d } else { jfc.setCurrentDirectory(new File("d:\\"));// ?d } jfc.setFileSelectionMode(0);// ? jfc.setFileFilter(new FileFilter() { public boolean accept(File f) { if (f.getName().endsWith(".pdm") || f.isDirectory()) { return true; } return false; } public String getDescription() { return "pdm(*.pdm)"; } }); int state = jfc.showOpenDialog(null); if (state == 1) { return; } else { File f = jfc.getSelectedFile(); initTree(f.getAbsolutePath()); try { if (lastOperateVo == null) { lastOperateVo = new LastOperateVo(); } lastOperateVo.setPdmFilePath(f.getAbsolutePath()); GlobalData.saveLastOperateVo(); } catch (Exception e1) { log.error("???pdm", e1); } } }
From source file:org.squidy.designer.Designer.java
/** * Initializes menu bar.//from w ww .j a v a 2 s . co m */ private void initMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu workspace = new JMenu("Workspace"); workspace.add(new AbstractAction("Open from...") { /* * (non-Javadoc) * * @see * java.awt.event.ActionListener#actionPerformed(java.awt.event. * ActionEvent) */ public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileHidingEnabled(true); fileChooser.setFileFilter(new FileFilter() { /* * (non-Javadoc) * * @see * javax.swing.filechooser.FileFilter#accept(java.io.File) */ @Override public boolean accept(File f) { return f.isDirectory() || f.getName().endsWith(".sdy"); } /* * (non-Javadoc) * * @see javax.swing.filechooser.FileFilter#getDescription() */ @Override public String getDescription() { return "Squidy Workspace"; } }); int option = fileChooser.showOpenDialog(Designer.this); if (option == JFileChooser.APPROVE_OPTION) { // Stop replacing workspace if currently running. if (data != null) { data.getWorkspace().stop(); } File workspaceFile = fileChooser.getSelectedFile(); if (storage instanceof LocalJAXBStorage) { ((LocalJAXBStorage) storage).setWorkspaceFile(workspaceFile); load(); } else { try { data = ModelViewHandler.getModelViewHandler().load(new FileInputStream(workspaceFile)); WorkspaceShape workspace = data.getWorkspaceShape(); workspace.setModel(data); workspace.setStorageHandler(Designer.this); workspace.initialize(); LayoutConstraint lc = workspace.getLayoutConstraint(); workspace.setScale(lc.getScale()); workspace.setOffset(lc.getX(), lc.getY()); getCanvas().getLayer().addChild(workspace); zoomToZoomedShape(data); } catch (SquidyException e1) { e1.printStackTrace(); } catch (FileNotFoundException e1) { e1.printStackTrace(); } } } } }); workspace.add(new AbstractAction("Export as...") { /* * (non-Javadoc) * * @see * java.awt.event.ActionListener#actionPerformed(java.awt.event. * ActionEvent) */ public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileHidingEnabled(true); fileChooser.setFileFilter(new FileFilter() { /* * (non-Javadoc) * * @see * javax.swing.filechooser.FileFilter#accept(java.io.File) */ @Override public boolean accept(File f) { return f.isDirectory() || f.getName().endsWith(".sdy"); } /* * (non-Javadoc) * * @see javax.swing.filechooser.FileFilter#getDescription() */ @Override public String getDescription() { return "Squidy Workspace"; } }); if (storage instanceof LocalJAXBStorage) { fileChooser.setSelectedFile(((LocalJAXBStorage) storage).getWorkspaceFile()); } int option = fileChooser.showSaveDialog(Designer.this); if (option == JFileChooser.APPROVE_OPTION) { File workspaceFile = fileChooser.getSelectedFile(); try { ModelViewHandler.getModelViewHandler().save(new FileOutputStream(workspaceFile), data); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } }); JMenu options = new JMenu("Options"); rendering.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { VisualShape.setRenderPrimitiveRect(rendering.isSelected()); data.setRenderPrimitiveRect(rendering.isSelected()); storage.store(data); repaint(); } }); options.add(rendering); JMenu storage = new JMenu("Storage"); ButtonGroup group = new ButtonGroup(); final JRadioButtonMenuItem storageLocalJAXB = new JRadioButtonMenuItem("Local JAXB"); storageLocalJAXB.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (storageLocalJAXB.isSelected()) { setStorageMode(StorageMode.FILE); } } }); storage.add(storageLocalJAXB); group.add(storageLocalJAXB); final JRadioButtonMenuItem storageBaseX = new JRadioButtonMenuItem("BaseX"); storageBaseX.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (storageBaseX.isSelected()) { setStorageMode(StorageMode.BASEX); } } }); storageBaseX.setSelected(storageType.equals(BaseXStorage.class)); storage.add(storageBaseX); group.add(storageBaseX); options.add(storage); menuBar.add(workspace); menuBar.add(options); setJMenuBar(menuBar); }
From source file:org.stanwood.nwn2.gui.MainWindow.java
private void addNewGUIFile() { File dir = settings.getGUIXMLBrowseDirLastDir( new File(settings.getNWN2Dir(NWN2GuiSettings.DEFAULT_NWN2_DIR), "UI" + File.separator + "default")); JFileChooser fc = new JFileChooser(dir); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setFileFilter(new FileFilter() { @Override//from w w w .jav a2 s . co m public String getDescription() { return "NWN2 GUI (*.xml)"; } @Override public boolean accept(File f) { return f.isDirectory() || f.getName().toLowerCase().endsWith(".xml"); } }); fc.showOpenDialog(MainWindow.this); File selFile = fc.getSelectedFile(); if (selFile != null) { guiFileListModel.addElement(selFile); guiFileList.setSelectedIndex(guiFileListModel.getSize() - 1); settings.setGUIXMLBrowseDirLastDir(selFile.getParentFile()); updateEnabledState(); saveChanges(); } }
From source file:org.thelq.stackexchange.dbimport.gui.GUI.java
public GUI(Controller passedController) { //Initialize logger logAppender = new GUILogAppender(this); //Set our Look&Feel try {//from w w w . j a v a2 s . c om if (SystemUtils.IS_OS_WINDOWS) UIManager.setLookAndFeel(new WindowsLookAndFeel()); else UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { log.warn("Defaulting to Swing L&F due to exception", e); } this.controller = passedController; frame = new JFrame(); frame.setTitle("Unified StackExchange Data Dump Importer v" + Controller.VERSION); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); //Setup menu JMenuBar menuBar = new JMenuBar(); menuAdd = new JMenuItem("Add Folders/Archives"); menuAdd.setMnemonic(KeyEvent.VK_F); menuBar.add(menuAdd); frame.setJMenuBar(menuBar); //Primary panel FormLayout primaryLayout = new FormLayout("5dlu, pref:grow, 5dlu, 5dlu, pref", "pref, top:pref, pref, fill:140dlu:grow, pref, fill:80dlu"); PanelBuilder primaryBuilder = new PanelBuilder(primaryLayout) .border(BorderFactory.createEmptyBorder(5, 5, 5, 5)); //DB Config panel primaryBuilder.addSeparator("Database Configuration", CC.xyw(1, 1, 2)); FormLayout configLayout = new FormLayout("pref, 3dlu, pref:grow, 6dlu, pref", "pref, pref:grow, 3dlu, pref:grow, 3dlu, pref:grow, 3dlu, pref:grow, 3dlu, pref:grow, 3dlu, pref:grow"); configLayout.setHonorsVisibility(true); final PanelBuilder configBuilder = new PanelBuilder(configLayout); configBuilder.addLabel("Server", CC.xy(1, 2), dbType = new JComboBox<DatabaseOption>(), CC.xy(3, 2)); configBuilder.add(dbAdvanced = new JCheckBox("Show advanced options"), CC.xy(5, 2)); configBuilder.addLabel("JDBC Connection", CC.xy(1, 4), jdbcString = new JTextField(15), CC.xyw(3, 4, 3)); configBuilder.addLabel("Username", CC.xy(1, 6), username = new JTextField(10), CC.xy(3, 6)); configBuilder.addLabel("Password", CC.xy(1, 8), password = new JPasswordField(10), CC.xy(3, 8)); configBuilder.add(importButton = new JButton("Import"), CC.xywh(5, 6, 1, 3)); //Add hidden JLabel dialectLabel = new JLabel("Dialect"); dialectLabel.setVisible(false); configBuilder.add(dialectLabel, CC.xy(1, 10), dialect = new JTextField(10), CC.xyw(3, 10, 3)); dialect.setVisible(false); JLabel driverLabel = new JLabel("Driver"); driverLabel.setVisible(false); configBuilder.add(driverLabel, CC.xy(1, 12), driver = new JTextField(10) { @Override public void setText(String text) { if (StringUtils.isBlank(text)) log.debug("Text is blank", new RuntimeException("Text " + text + " is blank")); super.setText(text); } }, CC.xyw(3, 12, 3)); driver.setVisible(false); primaryBuilder.add(configBuilder.getPanel(), CC.xy(2, 2)); //Options primaryBuilder.addSeparator("Options", CC.xyw(4, 1, 2)); FormLayout optionsLayout = new FormLayout("pref, 3dlu, pref:grow", ""); DefaultFormBuilder optionsBuilder = new DefaultFormBuilder(optionsLayout); optionsBuilder.append(disableCreateTables = new JCheckBox("Disable Creating Tables"), 3); optionsBuilder.append("Global Table Prefix", globalTablePrefix = new JTextField(7)); optionsBuilder.append("Threads", threads = new JSpinner()); //Save a core for the database int numThreads = Runtime.getRuntime().availableProcessors(); numThreads = (numThreads != 1) ? numThreads - 1 : numThreads; threads.setModel(new SpinnerNumberModel(numThreads, 1, 100, 1)); optionsBuilder.append("Batch Size", batchSize = new JSpinner()); batchSize.setModel(new SpinnerNumberModel(500, 1, 500000, 1)); primaryBuilder.add(optionsBuilder.getPanel(), CC.xy(5, 2)); //Locations primaryBuilder.addSeparator("Dump Locations", CC.xyw(1, 3, 5)); FormLayout locationsLayout = new FormLayout("pref, 15dlu, pref, 5dlu, pref, 5dlu, pref:grow, 2dlu, pref", ""); locationsBuilder = new DefaultFormBuilder(locationsLayout, new ScrollablePanel()).background(Color.WHITE) .lineGapSize(Sizes.ZERO); locationsPane = new JScrollPane(locationsBuilder.getPanel()); locationsPane.getViewport().setBackground(Color.white); locationsPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); locationsPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); primaryBuilder.add(locationsPane, CC.xyw(2, 4, 4)); //Logger primaryBuilder.addSeparator("Log", CC.xyw(1, 5, 5)); loggerText = new JTextPane(); loggerText.setEditable(false); JPanel loggerTextPanel = new JPanel(new BorderLayout()); loggerTextPanel.add(loggerText); JScrollPane loggerPane = new JScrollPane(loggerTextPanel); loggerPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); loggerPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); JPanel loggerPanePanel = new JPanel(new BorderLayout()); loggerPanePanel.add(loggerPane); primaryBuilder.add(loggerPanePanel, CC.xyw(2, 6, 4)); menuAdd.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //TODO: Allow 7z files but handle corner cases final JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fc.setMultiSelectionEnabled(true); fc.setDialogTitle("Select Folders/Archives"); fc.addChoosableFileFilter(new FileNameExtensionFilter("Archives", "7z", "zip")); fc.addChoosableFileFilter(new FileFilter() { @Getter protected String description = "Folders"; @Override public boolean accept(File file) { return file.isDirectory(); } }); if (fc.showOpenDialog(frame) != JFileChooser.APPROVE_OPTION) return; //Add files and folders in a seperate thread while updating gui in EDT importButton.setEnabled(false); for (File curFile : fc.getSelectedFiles()) { DumpContainer dumpContainer = null; try { if (curFile.isDirectory()) dumpContainer = new FolderDumpContainer(curFile); else dumpContainer = new ArchiveDumpContainer(controller, curFile); controller.addDumpContainer(dumpContainer); } catch (Exception ex) { String type = (dumpContainer != null) ? dumpContainer.getType() : ""; LoggerFactory.getLogger(getClass()).error("Cannot open " + type, ex); String location = (dumpContainer != null) ? Utils.getLongLocation(dumpContainer) : ""; showErrorDialog(ex, "Cannot open " + location, curFile.getAbsolutePath()); continue; } } updateLocations(); importButton.setEnabled(true); } }); //Add options (Could be in a map, but this is cleaner) dbType.addItem(new DatabaseOption().name("MySQL 5.5.3+") .jdbcString("jdbc:mysql://127.0.0.1:3306/stackexchange?rewriteBatchedStatements=true") .dialect("org.hibernate.dialect.MySQL5Dialect").driver("com.mysql.jdbc.Driver")); dbType.addItem(new DatabaseOption().name("PostgreSQL 8.1") .jdbcString("jdbc:postgresql://127.0.0.1:5432/stackexchange") .dialect("org.hibernate.dialect.PostgreSQL81Dialect").driver("org.postgresql.Driver")); dbType.addItem(new DatabaseOption().name("PostgreSQL 8.2+") .jdbcString("jdbc:postgresql://127.0.0.1:5432/stackexchange") .dialect("org.hibernate.dialect.PostgreSQL82Dialect").driver("org.postgresql.Driver")); dbType.addItem(new DatabaseOption().name("SQL Server") .jdbcString("jbdc:jtds:mssql://127.0.0.1:1433/stackexchange") .dialect("org.hibernate.dialect.SQLServerDialect").driver("net.sourceforge.jtds.jdbc.Driver")); dbType.addItem(new DatabaseOption().name("SQL Server 2005+") .jdbcString("jbdc:jtds:mssql://127.0.0.1:1433/stackexchange") .dialect("org.hibernate.dialect.SQLServer2005Dialect").driver("net.sourceforge.jtds.jdbc.Driver")); dbType.addItem(new DatabaseOption().name("SQL Server 2008+") .jdbcString("jbdc:jtds:mssql://127.0.0.1:1433/stackexchange") .dialect("org.hibernate.dialect.SQLServer2008Dialect").driver("net.sourceforge.jtds.jdbc.Driver")); dbType.addItem(new DatabaseOption().name("H2").jdbcString("jdbc:h2:stackexchange") .dialect("org.hibernate.dialect.H2Dialect").driver("org.h2.Driver")); dbType.setSelectedItem(null); dbType.addItemListener(new ItemListener() { boolean shownMysqlWarning = false; public void itemStateChanged(ItemEvent e) { //Don't run this twice for a single select if (e.getStateChange() == ItemEvent.DESELECTED) return; DatabaseOption selectedOption = (DatabaseOption) dbType.getSelectedItem(); if (selectedOption.name().startsWith("MySQL") && !shownMysqlWarning) { //Hide popup so you don't have to click twice on the dialog dbType.setPopupVisible(false); JOptionPane.showMessageDialog(frame, "Warning: Your server must be configured with character_set_server=utf8mb4" + "\nOtherwise, data dumps that contain 4 byte UTF-8 characters will fail", "MySQL Warning", JOptionPane.WARNING_MESSAGE); shownMysqlWarning = true; } setDbOption(selectedOption); } }); //Show and hide advanced options with checkbox dbAdvanced.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean selected = ((JCheckBox) e.getSource()).isSelected(); driver.setVisible(selected); ((JLabel) driver.getClientProperty("labeledBy")).setVisible(selected); dialect.setVisible(selected); ((JLabel) dialect.getClientProperty("labeledBy")).setVisible(selected); } }); importButton.addActionListener(new ActionListener() { protected void showImportError(String error) { JOptionPane.showMessageDialog(frame, error, "Configuration Error", JOptionPane.ERROR_MESSAGE); } protected void showInputErrorDatabase(String error) { if (dbType.getSelectedItem() == null) showImportError("No dbType specified, " + StringUtils.uncapitalize(error)); else showImportError(error); } public void actionPerformed(ActionEvent e) { boolean validationPassed = false; if (controller.getDumpContainers().isEmpty()) showImportError("Please add dump folders/archives"); else if (StringUtils.isBlank(jdbcString.getText())) showInputErrorDatabase("Must specify JDBC String"); else if (StringUtils.isBlank(driver.getText())) showInputErrorDatabase("Must specify driver"); else if (StringUtils.isBlank(dialect.getText())) showInputErrorDatabase("Must specify hibernate dialect"); else validationPassed = true; if (!validationPassed) return; //Disable all GUI components so they can't change anything during processing setGuiEnabled(false); //Run in new thread controller.getGeneralThreadPool().execute(new Runnable() { public void run() { try { start(); } catch (final Exception e) { //Show an error message box SwingUtilities.invokeLater(new Runnable() { public void run() { LoggerFactory.getLogger(getClass()).error("Cannot import", e); showErrorDialog(e, "Cannot import", null); } }); } //Renable GUI SwingUtilities.invokeLater(new Runnable() { public void run() { setGuiEnabled(true); } }); } }); } }); //Done, init logger logAppender.init(); log.info("Finished creating GUI"); //Display frame.setContentPane(primaryBuilder.getPanel()); frame.pack(); frame.setMinimumSize(frame.getSize()); frame.setVisible(true); }
From source file:org.zaproxy.zap.extension.ascan.PolicyManagerDialog.java
private JButton getImportButton() { if (this.importButton == null) { this.importButton = new JButton(Constant.messages.getString("ascan.policymgr.button.import")); this.importButton.addActionListener(new ActionListener() { @Override//ww w.j a va 2s.com 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; }
From source file:org.zaproxy.zap.extension.ascan.PolicyManagerDialog.java
private JButton getExportButton() { if (this.exportButton == null) { this.exportButton = new JButton(Constant.messages.getString("ascan.policymgr.button.export")); this.exportButton.setEnabled(false); this.exportButton.addActionListener(new ActionListener() { @Override//w w w . j a v a 2 s .co 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 { ScanPolicy 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("ascan.policy.load.error")); } } } } }); } return this.exportButton; }
From source file:org.zaproxy.zap.extension.autoupdate.ExtensionAutoUpdate.java
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/*from w w w . ja v a 2s. co m*/ 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() && file.getName().endsWith(".zap")) { 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); } } catch (Exception e1) { logger.error(e1.getMessage(), e1); } } }); } return menuItemLoadAddOn; }
From source file:org.zaproxy.zap.extension.compare.ExtensionCompare.java
private void compareSessions() { JFileChooser chooser = new JFileChooser(Model.getSingleton().getOptionsParam().getUserDirectory()); File file = null;//from w w w.j a v a2s .com 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() { return Constant.messages.getString("file.format.zap.session"); } }); int rc = chooser.showOpenDialog(View.getSingleton().getMainFrame()); if (rc == JFileChooser.APPROVE_OPTION) { try { file = chooser.getSelectedFile(); if (file == null) { return; } Model cmpModel = new Model(); Session session = cmpModel.getSession(); //log.info("opening session file " + file.getAbsolutePath()); //WaitMessageDialog waitMessageDialog = View.getSingleton().getWaitMessageDialog("Loading session file. Please wait ..."); cmpModel.openSession(file, this); // TODO support other implementations in the future Database db = new ParosDatabase(); db.open(file.getAbsolutePath()); Map<String, String> curMap = new HashMap<>(); Map<String, String> cmpMap = new HashMap<>(); // Load the 2 sessions into 2 maps this.buildHistoryMap(Model.getSingleton().getDb().getTableHistory(), curMap); this.buildHistoryMap(db.getTableHistory(), cmpMap); File outputFile = this.getOutputFile(); if (outputFile != null) { // Write the result to the specified file try { TreeSet<String> sset = new TreeSet<>(); // Combine the keys for both maps sset.addAll(curMap.keySet()); sset.addAll(cmpMap.keySet()); StringBuilder sb = new StringBuilder(500); sb.append("<?xml version=\"1.0\"?>"); sb.append(CRLF); sb.append("<report>"); sb.append(CRLF); sb.append("<session-names>"); sb.append(CRLF); sb.append("<session1>"); sb.append(Model.getSingleton().getSession().getSessionName()); sb.append("</session1>"); sb.append(CRLF); sb.append("<session2>"); sb.append(session.getSessionName()); sb.append("</session2>"); sb.append(CRLF); sb.append("</session-names>"); sb.append(CRLF); Iterator<String> iter = sset.iterator(); while (iter.hasNext()) { sb.append("<urlrow>"); sb.append(CRLF); String key = iter.next(); String method = key.substring(0, key.indexOf(" ")); String url = key.substring(key.indexOf(" ") + 1); sb.append("<method>"); sb.append(method); sb.append("</method>"); sb.append(CRLF); sb.append("<url>"); sb.append(url); sb.append("</url>"); sb.append(CRLF); sb.append("<code1>"); if (curMap.containsKey(key)) { sb.append(curMap.get(key)); } else { sb.append("---"); } sb.append("</code1>"); sb.append(CRLF); sb.append("<code2>"); if (cmpMap.containsKey(key)) { sb.append(cmpMap.get(key)); } else { sb.append("---"); } sb.append("</code2>"); sb.append(CRLF); sb.append("</urlrow>"); sb.append(CRLF); } sb.append("</report>"); sb.append(CRLF); ReportGenerator.stringToHtml(sb.toString(), Constant.getZapInstall() + File.separator + "xml" + File.separator + "reportCompare.xsl", outputFile.getAbsolutePath()); try { DesktopUtils.openUrlInBrowser(outputFile.toURI()); } catch (Exception e) { log.error(e.getMessage(), e); View.getSingleton() .showMessageDialog(MessageFormat.format( Constant.messages.getString("report.complete.warning"), new Object[] { outputFile.getAbsolutePath() })); } } catch (Exception e1) { log.warn(e1.getMessage(), e1); } } //waitMessageDialog.setVisible(true); } catch (Exception e) { log.warn(e.getMessage(), e); } } }
From source file:org.zaproxy.zap.extension.compare.ExtensionCompare.java
private File getOutputFile() { JFileChooser chooser = new JFileChooser(getModel().getOptionsParam().getUserDirectory()); chooser.setFileFilter(new FileFilter() { @Override//w w w . j a v a2s . c om public boolean accept(File file) { if (file.isDirectory()) { return true; } else if (file.isFile() && file.getName().toLowerCase().endsWith(".htm")) { return true; } else if (file.isFile() && file.getName().toLowerCase().endsWith(".html")) { return true; } return false; } @Override public String getDescription() { return Constant.messages.getString("file.format.html"); } }); File file = null; int rc = chooser.showSaveDialog(getView().getMainFrame()); if (rc == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); if (file == null) { return file; } getModel().getOptionsParam().setUserDirectory(chooser.getCurrentDirectory()); String fileNameLc = file.getAbsolutePath().toLowerCase(); if (!fileNameLc.endsWith(".htm") && !fileNameLc.endsWith(".html")) { file = new File(file.getAbsolutePath() + ".html"); } return file; } return file; }
From source file:org.zaproxy.zap.extension.customFire.CustomFireDialog.java
/** * // ww w . ja v a 2 s . co m * @return JPanel - customPanel with saved injectionList */ private JPanel getSerCustomPanel() { customPanel = getCustomPanel(); ArrayList highlightList = new ArrayList<>(); ArrayList textAreaList = new ArrayList<>(); 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 Custom Vectors"); int rc = chooser.showOpenDialog(View.getSingleton().getMainFrame()); if (rc == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); if (file == null || !file.getName().equalsIgnoreCase("Custom Vectors.ser")) { View.getSingleton().showWarningDialog( Constant.messages.getString("customFire.custom.tech.ser.mismatch.error")); return customPanel; } try { FileInputStream fis = new FileInputStream(file.getPath()); ObjectInputStream ois = new ObjectInputStream(fis); textAreaList = (ArrayList<String>) ois.readObject(); ois.close(); fis.close(); highlightList = (ArrayList) textAreaList.get(0); String httpReq = (String) textAreaList.get(1); customPanel = getSavedCustomPanel(highlightList, httpReq); reset = true; } catch (IOException | ClassNotFoundException e1) { View.getSingleton() .showWarningDialog(Constant.messages.getString("customFire.custom.ser.load.error")); return customPanel; } } return customPanel; }