Comment fetcher implemented (with the exception of a TODO)

git-svn-id: https://ipscan.svn.sourceforge.net/svnroot/ipscan/trunk@221 375186e5-ef17-0410-b0b6-91563547dcda
This commit is contained in:
angryziber 2007-10-16 21:13:56 +00:00
parent 600aa090e3
commit 6ab01e19fd
8 changed files with 93 additions and 5 deletions

View File

@ -19,6 +19,7 @@ menu.commands.delete=&Delete IP(s)
menu.commands.copy=&Copy IP
menu.commands.copyDetails=Co&py details
menu.commands.show=Show
menu.commands.editComment=S&et IP comment...
menu.commands.open=Open
menu.commands.open.edit=Edit openers...
menu.favorites=Fa&vorites
@ -66,6 +67,7 @@ title.favorite.edit=Edit favorites
title.openers.edit=Edit Openers
title.fetchers.select=Select Fetchers
title.find=Find
title.editComment=Set comment
text.error=Error
text.userError=Problem
text.ip=IP
@ -78,6 +80,7 @@ text.favorite.edit=Below you can rearrange or delete favorites
text.find=Enter the text to search for
text.find.notFound=Nothing was found.
text.find.restart=Would you like to start from the beginning?
text.editComment=Specify comment for the IP address
text.configDetect=We will try to detect the number of threads that works reliably on this machine by connecting to a known host many times simultaneously using the configured port timeout.\n\nPlease provide host and port that is 100% open and works, e.g. a proxy or web server on your network.
text.configDetect.host=Host:
text.configDetect.port=Port:

View File

@ -0,0 +1,31 @@
/**
* This file is a part of Angry IP Scanner source code,
* see http://www.azib.net/ for more information.
* Licensed under GPLv2.
*/
package net.azib.ipscan.config;
import java.net.InetAddress;
import java.util.prefs.Preferences;
/**
* CommentsConfig - a class for encapsulating of loading/storing of comments.
*
* @author Anton Keks
*/
public class CommentsConfig {
private Preferences preferences;
public CommentsConfig(Preferences preferences) {
this.preferences = preferences;
}
public String getComment(InetAddress address) {
return preferences.get(address.getHostAddress(), null);
}
public void setComment(InetAddress address, String comment) {
preferences.put(address.getHostAddress(), comment);
}
}

View File

@ -16,6 +16,7 @@ import net.azib.ipscan.exporters.ExporterRegistry;
import net.azib.ipscan.exporters.IPListExporter;
import net.azib.ipscan.exporters.TXTExporter;
import net.azib.ipscan.exporters.XMLExporter;
import net.azib.ipscan.fetchers.CommentFetcher;
import net.azib.ipscan.fetchers.FetcherRegistry;
import net.azib.ipscan.fetchers.FetcherRegistryImpl;
import net.azib.ipscan.fetchers.FilteredPortsFetcher;
@ -78,6 +79,7 @@ public class ComponentRegistry {
container.registerComponentInstance(Config.getOpenersConfig());
container.registerComponentInstance(Config.getFavoritesConfig());
container.registerComponentInstance(Labels.getInstance());
container.registerComponentImplementation(CommentsConfig.class);
container.registerComponentImplementation(ConfigDetector.class);
container.registerComponentImplementation(ExporterRegistry.class);
@ -94,6 +96,7 @@ public class ComponentRegistry {
container.registerComponentImplementation(PortsFetcher.class);
container.registerComponentImplementation(FilteredPortsFetcher.class);
container.registerComponentImplementation(WebDetectFetcher.class);
container.registerComponentImplementation(CommentFetcher.class);
container.registerComponentImplementation(PingerRegistry.class, PingerRegistryImpl.class);
container.registerComponentImplementation(ScanningResultList.class);

View File

@ -4,6 +4,7 @@
*/
package net.azib.ipscan.fetchers;
import net.azib.ipscan.config.CommentsConfig;
import net.azib.ipscan.core.ScanningSubject;
/**
@ -16,7 +17,13 @@ import net.azib.ipscan.core.ScanningSubject;
*/
public class CommentFetcher implements Fetcher {
static final String LABEL = "fetcher.comment";
public static final String LABEL = "fetcher.comment";
private CommentsConfig commentsConfig;
public CommentFetcher(CommentsConfig commentsConfig) {
this.commentsConfig = commentsConfig;
}
/**
* @see net.azib.ipscan.fetchers.Fetcher#getLabel()
@ -29,7 +36,7 @@ public class CommentFetcher implements Fetcher {
* @see net.azib.ipscan.fetchers.Fetcher#scan(net.azib.ipscan.core.ScanningSubject)
*/
public Object scan(ScanningSubject subject) {
return "a dummy comment!!!";
return commentsConfig.getComment(subject.getAddress());
}
public void init() {

View File

@ -78,8 +78,10 @@ public class InputDialog extends AbstractModalDialog {
}
private void setText(String text) {
this.text.setText(text);
this.text.setSelection(0, -1);
if (text != null) {
this.text.setText(text);
this.text.setSelection(0, -1);
}
}
/**

View File

@ -116,6 +116,8 @@ public class MainMenu {
initMenuItem(menu, null, null, null, null);
initMenuItem(menu, "menu.commands.copy", "Ctrl+C", /* this is not a global key binding */ null, initListener(CommandsActions.CopyIP.class));
initMenuItem(menu, "menu.commands.copyDetails", null, null, initListener(CommandsActions.CopyIPDetails.class));
initMenuItem(menu, null, null, null, null);
initMenuItem(menu, "menu.commands.editComment", "Ctrl+E", new Integer(SWT.MOD1 | 'E'), initListener(CommandsActions.EditComment.class));
initMenuItem(menu, null, null, null, null);
createOpenersMenu(menu);
// initMenuItem(subMenu, "menu.commands.show", null, initListener());

View File

@ -5,16 +5,21 @@
*/
package net.azib.ipscan.gui.actions;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Iterator;
import net.azib.ipscan.config.CommentsConfig;
import net.azib.ipscan.config.Config;
import net.azib.ipscan.config.Labels;
import net.azib.ipscan.config.OpenersConfig.Opener;
import net.azib.ipscan.core.UserErrorException;
import net.azib.ipscan.core.state.StateMachine;
import net.azib.ipscan.fetchers.CommentFetcher;
import net.azib.ipscan.fetchers.FetcherRegistry;
import net.azib.ipscan.gui.DetailsDialog;
import net.azib.ipscan.gui.EditOpenersDialog;
import net.azib.ipscan.gui.InputDialog;
import net.azib.ipscan.gui.ResultTable;
import net.azib.ipscan.gui.StatusBar;
@ -173,6 +178,41 @@ public class CommandsActions {
}
}
public static class EditComment implements Listener {
private ResultTable resultTable;
private CommentsConfig commentsConfig;
private FetcherRegistry fetcherRegistry;
public EditComment(ResultTable resultTable, CommentsConfig commentsConfig, FetcherRegistry fetcherRegistry) {
this.resultTable = resultTable;
this.commentsConfig = commentsConfig;
this.fetcherRegistry = fetcherRegistry;
}
public void handleEvent(Event event) {
checkSelection(resultTable);
try {
int index = resultTable.getSelectionIndex();
InetAddress address = InetAddress.getByName(resultTable.getItem(index).getText());
String comment = commentsConfig.getComment(address);
String newComment = new InputDialog(Labels.getLabel("title.editComment"), Labels.getLabel("text.editComment")).open(comment);
if (newComment != null) {
commentsConfig.setComment(address, newComment);
// now update the result table for user to immediately see the change
int fetcherIndex = fetcherRegistry.getSelectedFetcherIndex(CommentFetcher.LABEL);
if (fetcherIndex >= 0) {
// we have comment fetcher in the table
// TODO: update the value in the results list, otherwise old values will be exported
resultTable.getItem(index).setText(fetcherIndex, newComment);
}
}
}
catch (UnknownHostException e) {
// should not happen
}
}
}
public static class EditOpeners implements Listener {
FetcherRegistry fetcherRegistry;

View File

@ -34,7 +34,7 @@ public class FetcherRegistryImplTest {
ipFetcher = new IPFetcher();
pingFetcher = new PingFetcher(null, null);
hostnameFetcher = new HostnameFetcher();
commentFetcher = new CommentFetcher();
commentFetcher = new CommentFetcher(null);
portsFetcher = new PortsFetcher(null);
fetcherRegistry = new FetcherRegistryImpl(new Fetcher[] {ipFetcher, pingFetcher, hostnameFetcher, commentFetcher, portsFetcher}, preferences);
}