mirror of
https://github.com/angryip/ipscan.git
synced 2025-10-26 11:18:17 +00:00
bugfix #89: export selection now exports only selected rows
This commit is contained in:
parent
ba2a8127be
commit
5ed26afcaa
@ -5,14 +5,14 @@
|
||||
*/
|
||||
package net.azib.ipscan.exporters;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.List;
|
||||
|
||||
import net.azib.ipscan.core.ScanningResult;
|
||||
import net.azib.ipscan.core.ScanningResultList;
|
||||
import net.azib.ipscan.fetchers.Fetcher;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Export Processor controls the actual exporting using the provided Exporter.
|
||||
*
|
||||
@ -57,7 +57,7 @@ public class ExportProcessor {
|
||||
|
||||
int index = 0;
|
||||
for (ScanningResult scanningResult : scanningResults) {
|
||||
if (filter == null || filter.isResultSelected(index, scanningResult)) {
|
||||
if (filter == null || filter.apply(index++, scanningResult)) {
|
||||
exporter.nextAdressResults(scanningResult.getValues().toArray());
|
||||
}
|
||||
}
|
||||
@ -75,15 +75,15 @@ public class ExportProcessor {
|
||||
try {
|
||||
outputStream.close();
|
||||
}
|
||||
catch (Exception e) {}
|
||||
catch (Exception ignore) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ScanningResultSelector can be implemented and passed to {@link ExportProcessor#process(ScanningResultList, String)}
|
||||
* ScanningResultSelector can be implemented and passed to {@link ExportProcessor#process(ScanningResultList, ScanningResultFilter)}
|
||||
*/
|
||||
public static interface ScanningResultFilter {
|
||||
boolean isResultSelected(int index, ScanningResult result);
|
||||
boolean apply(int index, ScanningResult result);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,10 +5,6 @@
|
||||
*/
|
||||
package net.azib.ipscan.gui.actions;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.azib.ipscan.Main;
|
||||
import net.azib.ipscan.config.Labels;
|
||||
import net.azib.ipscan.config.Version;
|
||||
@ -17,18 +13,21 @@ import net.azib.ipscan.core.UserErrorException;
|
||||
import net.azib.ipscan.core.state.ScanningState;
|
||||
import net.azib.ipscan.core.state.StateMachine;
|
||||
import net.azib.ipscan.exporters.ExportProcessor;
|
||||
import net.azib.ipscan.exporters.ExportProcessor.ScanningResultFilter;
|
||||
import net.azib.ipscan.exporters.Exporter;
|
||||
import net.azib.ipscan.exporters.ExporterRegistry;
|
||||
import net.azib.ipscan.exporters.ExportProcessor.ScanningResultFilter;
|
||||
import net.azib.ipscan.gui.ResultTable;
|
||||
import net.azib.ipscan.gui.StatusBar;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.FileDialog;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.MessageBox;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* FileActions
|
||||
*
|
||||
@ -90,7 +89,6 @@ public class ScanMenuActions {
|
||||
|
||||
// check the received file name
|
||||
if (fileName != null) {
|
||||
// create exporter instance
|
||||
Exporter exporter = exporterRegistry.createExporter(fileName);
|
||||
|
||||
statusBar.setStatusText(Labels.getLabel("state.exporting"));
|
||||
@ -99,22 +97,22 @@ public class ScanMenuActions {
|
||||
ExportProcessor exportProcessor = new ExportProcessor(exporter, new File(fileName), false);
|
||||
|
||||
// in case of isSelection we need to create our filter
|
||||
ScanningResultFilter scanningResultSelector = null;
|
||||
ScanningResultFilter filter = null;
|
||||
if (isSelection) {
|
||||
scanningResultSelector = new ScanningResultFilter() {
|
||||
public boolean isResultSelected(int index, ScanningResult result) {
|
||||
filter = new ScanningResultFilter() {
|
||||
public boolean apply(int index, ScanningResult result) {
|
||||
return resultTable.isSelected(index);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exportProcessor.process(resultTable.getScanningResults(), scanningResultSelector);
|
||||
exportProcessor.process(resultTable.getScanningResults(), filter);
|
||||
|
||||
statusBar.setStatusText(null);
|
||||
}
|
||||
}
|
||||
|
||||
private final void addFileExtensions(List<String> extensions, List<String> descriptions, StringBuffer sb) {
|
||||
private void addFileExtensions(List<String> extensions, List<String> descriptions, StringBuffer sb) {
|
||||
sb.append(" (");
|
||||
for (Exporter exporter : exporterRegistry) {
|
||||
extensions.add("*." + exporter.getFilenameExtension());
|
||||
|
||||
@ -3,17 +3,6 @@
|
||||
*/
|
||||
package net.azib.ipscan.exporters;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Collections;
|
||||
|
||||
import net.azib.ipscan.core.ScanningResult;
|
||||
import net.azib.ipscan.core.ScanningResultList;
|
||||
import net.azib.ipscan.exporters.ExportProcessor.ScanningResultFilter;
|
||||
@ -21,11 +10,17 @@ import net.azib.ipscan.feeders.Feeder;
|
||||
import net.azib.ipscan.fetchers.Fetcher;
|
||||
import net.azib.ipscan.fetchers.FetcherRegistry;
|
||||
import net.azib.ipscan.fetchers.IPFetcher;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* ExportProcessorTest
|
||||
*
|
||||
@ -73,7 +68,7 @@ public class ExportProcessorTest {
|
||||
scanningResultList.registerAtIndex(2, scanningResultList.createResult(InetAddress.getByName("192.168.13.76")));
|
||||
|
||||
exportProcessor.process(scanningResultList, new ScanningResultFilter() {
|
||||
public boolean isResultSelected(int index, ScanningResult result) {
|
||||
public boolean apply(int index, ScanningResult result) {
|
||||
// select only IP addresses ending with 6
|
||||
return ((String)result.getValues().get(0)).endsWith("6");
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user