SearchMediator.java

Index Score
com.limegroup.gnutella.gui.search
FrostWire

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0034JAVA0034 Missing braces in if statement
DECL_COMMENTSComments in declarations
EXITSProcedure exits
SIZESize of the file in bytes
UNIQUE_OPERANDSNumber of unique operands
PARAMSNumber of formal parameter declarations
INTERFACE_COMPLEXITYInterface complexity
CYCLOMATICCyclomatic complexity
PROGRAM_VOCABHalstead program vocabulary
EXEC_COMMENTSComments in executable code
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
OPERATORSNumber of operators
PROGRAM_LENGTHHalstead program length
RETURNSNumber of return points from functions
FUNCTIONSNumber of function declarations
OPERANDSNumber of operands
DOC_COMMENTNumber of javadoc comment lines
LINE_COMMENTNumber of line comments
LINESNumber of lines in the source file
COMPARISONSNumber of comparison operators
ELOCEffective lines of code
LOGICAL_LINESNumber of statements
COMMENTSComment lines
LOCLines of code
BLOCKSNumber of blocks
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0144JAVA0144 Line exceeds maximum M characters
JAVA0138JAVA0138 N parameters defined for method (maximum: M)
JAVA0068JAVA0068 Modifiers not declared in recommended order
UNIQUE_OPERATORSNumber of unique operators
JAVA0143JAVA0143 Synchronized method
JAVA0077JAVA0077 Private field not used in declaring class
NEST_DEPTHMaximum nesting depth
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0035JAVA0035 Missing braces in for statement
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0123JAVA0123 Use all three components of for loop
WHITESPACENumber of whitespace lines
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0287JAVA0287 Unnecessary null check
package com.limegroup.gnutella.gui.search; import java.io.File; import java.lang.reflect.InvocationTargetException; import java.net.InetSocketAddress; import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Set; import javax.swing.JComponent; import javax.swing.SwingUtilities; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.limewire.io.Connectable; import org.limewire.io.ConnectableImpl; import org.limewire.io.IpPort; import org.limewire.io.IpPortSet; import org.limewire.rudp.RUDPUtils; import org.limewire.service.ErrorService; import org.limewire.setting.FileSetting; import org.limewire.setting.evt.SettingEvent; import org.limewire.setting.evt.SettingListener; import org.limewire.util.I18NConvert; import org.limewire.util.StringUtils; import com.limegroup.gnutella.BrowseHostHandler; import com.limegroup.gnutella.Downloader; import com.limegroup.gnutella.GUID; import com.limegroup.gnutella.MediaType; import com.limegroup.gnutella.PushEndpoint; import com.limegroup.gnutella.RemoteFileDesc; import com.limegroup.gnutella.gui.DialogOption; import com.limegroup.gnutella.gui.GUIMediator; import com.limegroup.gnutella.gui.GuiCoreMediator; import com.limegroup.gnutella.gui.I18n; import com.limegroup.gnutella.gui.banner.Ad; import com.limegroup.gnutella.gui.banner.Banner; import com.limegroup.gnutella.gui.download.DownloaderUtils; import com.limegroup.gnutella.gui.download.GuiDownloaderFactory; import com.limegroup.gnutella.gui.download.SearchResultDownloaderFactory; import com.limegroup.gnutella.search.HostData; import com.limegroup.gnutella.settings.QuestionsHandler; import com.limegroup.gnutella.settings.SearchSettings; import com.limegroup.gnutella.settings.SharingSettings; import com.limegroup.gnutella.util.LimeWireUtils; import com.limegroup.gnutella.xml.LimeXMLDocument; import com.limegroup.gnutella.xml.LimeXMLProperties; /** * This class acts as a mediator between the various search components -- * the hub that all traffic passes through. This allows the decoupling of * the various search packages and simplfies the responsibilities of the * underlying classes. */ public final class SearchMediator { /** * Query text is valid. */ public static final int QUERY_VALID = 0; /** * Query text is empty. */ public static final int QUERY_EMPTY = 1; /** * Query text is too short. */ public static final int QUERY_TOO_SHORT = 2; /** * Query text is too long. */ public static final int QUERY_TOO_LONG = 3; /** * Query xml is too long. */ public static final int QUERY_XML_TOO_LONG = 4; /** * Query contains invalid characters. */ public static final int QUERY_INVALID_CHARACTERS = 5; static final String DOWNLOAD_STRING = I18n.tr("Download"); static final String KILL_STRING = I18n.tr("Close Search"); static final String STOP_STRING = I18n.tr("Stop Search"); static final String LAUNCH_STRING = I18n.tr("Launch Action"); static final String BROWSE_STRING = I18n.tr("Browse Host"); static final String CHAT_STRING = I18n.tr("Chat With Host"); static final String REPEAT_SEARCH_STRING = I18n.tr("Repeat Search"); static final String BROWSE_HOST_STRING = I18n.tr("Browse Host"); static final String BITZI_LOOKUP_STRING = I18n.tr("Lookup File with Bitzi"); static final String BLOCK_STRING = I18n.tr("Block Hosts"); static final String MARK_AS_STRING = I18n.tr("Mark As"); static final String SPAM_STRING = I18n.tr("Junk"); static final String NOT_SPAM_STRING = I18n.tr("Not Junk"); static final String REPEAT_SEARCH_NO_CLEAR_STRING = I18n.tr("Get More Results"); /** A name of attribute, which holds a query in state of downloaded file. */ public static final String SEARCH_INFORMATION_KEY = "searchInformationMap"; /** * Variable for the component that handles all search input from the user. */ private static final SearchInputManager INPUT_MANAGER = new SearchInputManager(); /** * The LimeWire Store&#8482; song DB for the sponsored results. */ private static final RemoteStringBasicSpecialResultsDatabaseImpl thirdPartyDatabase = new RemoteStringBasicSpecialResultsDatabaseImpl(GuiCoreMediator.getLimeXMLDocumentFactory()); /** * This instance handles the display of all search results. * TODO: Changed to package-protected for testing to add special results */ public static final SearchResultDisplayer RESULT_DISPLAYER = new SearchResultDisplayer(); /** Banner that shows a message in the search result panel. */ private static volatile Banner banner; /** * Constructs the UI components of the search result display area of the * search tab. */ public SearchMediator() { // Set the splash screen text... final String splashScreenString = I18n.tr("Loading Search Window..."); GUIMediator.setSplashScreenString(splashScreenString); GUIMediator.addRefreshListener(RESULT_DISPLAYER); // Link up the tabs of results with the filters of the input screen. RESULT_DISPLAYER.setSearchListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { ResultPanel panel = RESULT_DISPLAYER.getSelectedResultPanel(); if(panel == null) INPUT_MANAGER.clearFilters(); else INPUT_MANAGER.setFiltersFor(panel); } }); initBanner(); } /** * initializes a banner and registers a listener for its change. */ private static void initBanner() { reloadBanner(); SearchSettings.SEARCH_WARNING.addSettingListener(new SettingListener() { public void settingChanged(SettingEvent evt) { if (evt.getEventType() == SettingEvent.EventType.VALUE_CHANGED) reloadBanner(); } }); } /** * reloads a banner with the current value from the settings. */ private static void reloadBanner() { Banner newBanner = banner; try { newBanner = new Banner(SearchSettings.SEARCH_WARNING.getValue()); } catch (IllegalArgumentException badSimpp) {} if (newBanner == null) newBanner = Banner.getDefaultBanner(); banner = newBanner; } /** * Rebuilds the INPUT_MANAGER's panel. */ public static void rebuildInputPanel() { INPUT_MANAGER.rebuild(); } /** * Notification that the address has changed -- pass it along. */ public static void addressChanged() { INPUT_MANAGER.addressChanged(); } /** * Informs the INPUT_MANAGER that we want to display the searching * window. */ public static void showSearchInput() { INPUT_MANAGER.goToSearch(); } /** * Requests the search focus in the INPUT_MANAGER. */ public static void requestSearchFocus() { INPUT_MANAGER.requestSearchFocus(); } /** * Updates all current results. */ public static void updateResults() { RESULT_DISPLAYER.updateResults(); } /** * Placehold for repeatSearch */ static byte[] repeatSearch(ResultPanel rp, SearchInformation info) { return repeatSearch (rp,info,true); } /** * Repeats the given search. */ static byte[] repeatSearch(ResultPanel rp, SearchInformation info, boolean clearingResults) { if(!validate(info)) return null; // 1. Update panel with new GUID byte [] guidBytes = GuiCoreMediator.getSearchServices().newQueryGUID(); final GUID newGuid = new GUID(guidBytes); GuiCoreMediator.getSearchServices().stopQuery(new GUID(rp.getGUID())); rp.setGUID(newGuid); if ( clearingResults ) { INPUT_MANAGER.panelReset(rp); } if(info.isBrowseHostSearch()) { IpPort ipport = info.getIpPort(); String host = ipport.getAddress(); int port = ipport.getPort(); if(host != null && port != 0) { GUIMediator.instance().setSearching(true); reBrowseHost(new ConnectableImpl(ipport, false), rp); } } else { GUIMediator.instance().setSearching(true); doSearch(guidBytes, info); } return guidBytes; } /** * Browses the first selected host. Fails silently if couldn't browse. */ static void doBrowseHost(ResultPanel rp) { TableLine line = rp.getSelectedLine(); if(line == null) return; // Get the browse-host RFD from the line. RemoteFileDesc rfd = line.getBrowseHostEnabledRFD(); if(rfd == null) return; // See if it is firewalled byte[] serventIDBytes = rfd.getClientGUID(); // if the reply is to a multicast query, don't use any // push proxies so we definitely will send a UDP push request Set<? extends IpPort> proxies = rfd.isReplyToMulticast() ? IpPort.EMPTY_SET : rfd.getPushProxies(); GUID serventID = new GUID(serventIDBytes); doBrowseHost2(rfd, serventID, proxies, rfd.supportsFWTransfer()); } /** * Allows for browsing of a host from outside of the search package. */ public static void doBrowseHost(final RemoteFileDesc rfd) { doBrowseHost2(rfd, new GUID(rfd.getClientGUID()), rfd.getPushProxies(), rfd.supportsFWTransfer()); } /** * Allows for browsing of a host from outside of the search package * without an rfd. */ public static void doBrowseHost(Connectable connectable, GUID guid) { if (guid == null) doBrowseHost2(connectable, null, null, false); else doBrowseHost2(connectable, new GUID(guid.bytes()), null, false); } /** * Re-browses the host. Fails silently if browse failed... * TODO: WILL NOT WORK FOR RE-BROWSES THAT REQUIRES A PUSH!!! */ private static void reBrowseHost(Connectable host, ResultPanel in) { // Update the GUID final GUID guid = new GUID(GUID.makeGuid()); in.setGUID(guid); BrowseHostHandler bhh = GuiCoreMediator.getSearchServices().doAsynchronousBrowseHost(host, guid, new GUID(GUID.makeGuid()), null, false); in.setBrowseHostHandler(bhh); INPUT_MANAGER.panelReset(in); } /** * Performs a browse host on a push end point. */ public static void doBrowseHost(PushEndpoint pushEndpoint) { InetSocketAddress inetSocketAddress = pushEndpoint.getInetSocketAddress(); Connectable host = inetSocketAddress != null ? new ConnectableImpl(inetSocketAddress, false) : null; doBrowseHost2(host, new GUID(pushEndpoint.getClientGUID()), pushEndpoint.getProxies(), pushEndpoint.supportsFWTVersion() >= RUDPUtils.VERSION); } /** * Browses the passed host at the passed port. * Fails silently if couldn't browse. * @param host The host to browse, can be null for firewalled endpoints * @param port The port at which to browse */ static private void doBrowseHost2(Connectable host, GUID serventID, Set<? extends IpPort> proxies, boolean canDoFWTransfer) { // Update the GUI GUID guid = new GUID(GUID.makeGuid()); String title = host != null ? host.getAddress() + ":" + host.getPort() : I18n.tr("Firewalled Host"); ResultPanel rp = addBrowseHostTab(guid, title); // Do the actual browse host BrowseHostHandler bhh = GuiCoreMediator.getSearchServices().doAsynchronousBrowseHost( host, guid, serventID, proxies, canDoFWTransfer); rp.setBrowseHostHandler(bhh); } /** * Call this when a Browse Host fails. * @param guid The guid associated with this Browse. */ public static void browseHostFailed(GUID guid) { RESULT_DISPLAYER.browseHostFailed(guid); } /** * Initiates a new search with the specified SearchInformation. * * Returns the GUID of the search if a search was initiated, * otherwise returns null. */ public static byte[] triggerSearch(final SearchInformation info) { if(!validate(info)) return null; // generate a guid for the search. final byte[] guid = GuiCoreMediator.getSearchServices().newQueryGUID(); // only add tab if this isn't a browse-host search. if(!info.isBrowseHostSearch()) { addResultTab(new GUID(guid), info); } doSearch(guid, info); // Here is where we can intercept the query and look for terms GuiCoreMediator.getCoreBackgroundExecutor().execute(new Runnable() { public void run() { thirdPartyDatabase.find(info, new ThirdPartyResultsDatabase.SearchResultsCallback() { public void process(final List<SearchResult> results, SearchInformation info) { if (results == null) return; final ResultPanel rp = SearchMediator.getResultPanelForGUID(new GUID(guid)); if (rp == null) return; try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { for (final SearchResult sr : results) { SearchMediator.RESULT_DISPLAYER.addQueryResult(guid, sr, rp); } }}); } catch (InterruptedException e) { ErrorService.error(e, "invokeAndWait for store song result"); } catch (InvocationTargetException e) { ErrorService.error(e, "invokeAndWait for store song result"); } }}); }}); return guid; } /** * Triggers a search given the text in the search field. For testing * purposes returns the 16-byte GUID of the search or null if the search * didn't happen because it was greedy, etc. */ public static byte[] triggerSearch(String query) { return triggerSearch( SearchInformation.createKeywordSearch(query, null, MediaType.getAnyTypeMediaType()) ); } /** Shows a search result tab with your files, with the given title. */ public static void showMyFiles(String title) { addMyFilesResultTab(title); } /** * Validates the given search information. */ private static boolean validate(SearchInformation info) { switch (validateInfo(info)) { case QUERY_EMPTY: return false; case QUERY_TOO_SHORT: GUIMediator.showError(I18n.tr("Your search must be at least three characters to avoid congesting the network.")); return false; case QUERY_TOO_LONG: String xml = info.getXML(); if (xml == null || xml.length() == 0) { GUIMediator.showError(I18n.tr("Your search is too long. Please make your search smaller and try again.")); } else { GUIMediator.showError(I18n.tr("Your search is too specific. Please make your search smaller and try again.")); } return false; case QUERY_XML_TOO_LONG: GUIMediator.showError(I18n.tr("Your search is too specific. Please make your search smaller and try again.")); return false; case QUERY_VALID: default: if(!GuiCoreMediator.getLifecycleManager().isStarted()) { GUIMediator.showMessage(I18n.tr("Please wait, FrostWire must finish loading before a search can be started.")); return false; } // only show search messages if not doing browse host. if(!info.isBrowseHostSearch()) { if(!GuiCoreMediator.getConnectionServices().isConnected()) { if(!GuiCoreMediator.getConnectionServices().isConnecting()) { // if not connected or connecting, show one message. GUIMediator.showMessage(I18n.tr("You are not connected to the network. To connect, select \"Connect\" from the \"File\" menu. Your search may not return any results until you connect."), QuestionsHandler.NO_NOT_CONNECTED); } else { // if attempting to connect, show another. GUIMediator.showMessage(I18n.tr("FrostWire is currently connecting to the network. Your search may not return many results until you are fully connected to the network."), QuestionsHandler.NO_STILL_CONNECTING); } } } return true; } } /** * Validates the a search info and returns {@link #QUERY_VALID} if it is * valid. * @param info * @return one of the static <code>QUERY*</code> fields */ public static int validateInfo(SearchInformation info) { String query = I18NConvert.instance().getNorm(info.getQuery()); String xml = info.getXML(); if (query.length() == 0) { return QUERY_EMPTY; } else if (query.length() <= 2 && !(query.length() == 2 && ((Character.isDigit(query.charAt(0)) && Character.isLetter(query.charAt(1))) || (Character.isLetter(query.charAt(0)) && Character.isDigit(query.charAt(1)))))) { return QUERY_TOO_SHORT; } else if (query.length() > SearchSettings.MAX_QUERY_LENGTH.getValue()) { return QUERY_TOO_LONG; } else if (xml != null && xml.length() > SearchSettings.MAX_XML_QUERY_LENGTH.getValue()) { return QUERY_XML_TOO_LONG; } else if (StringUtils.containsCharacters(query,SearchSettings.ILLEGAL_CHARS.getValue())) { return QUERY_INVALID_CHARACTERS; } else { return QUERY_VALID; } } /** * Does the actual search. */ private static void doSearch(byte[] guid, SearchInformation info) { String query = info.getQuery(); String xml = info.getXML(); MediaType media = info.getMediaType(); if(info.isXMLSearch()) { GuiCoreMediator.getSearchServices().query(guid, query, xml, media); } else if(info.isKeywordSearch()) { GuiCoreMediator.getSearchServices().query(guid, query, media); } else if(info.isWhatsNewSearch()) { GuiCoreMediator.getSearchServices().queryWhatIsNew(guid, media); } else if(info.isBrowseHostSearch()) { IpPort ipport = info.getIpPort(); doBrowseHost(new ConnectableImpl(ipport, false), null); } } /** * Adds a single result tab for the specified GUID, type, * standard query string, and XML query string. */ private static ResultPanel addResultTab(GUID guid, SearchInformation info) { return RESULT_DISPLAYER.addResultTab(guid, info); } /** Adds a tab to search results that displays your files. */ private static ResultPanel addMyFilesResultTab(String title) { return RESULT_DISPLAYER.addMyFilesResultTab(title); } /** * Adds a browse host tab with the given description. */ private static ResultPanel addBrowseHostTab(GUID guid, String desc) { return RESULT_DISPLAYER.addResultTab(guid, SearchInformation.createBrowseHostSearch(desc) ); } /** * If i rp is no longer the i'th panel of this, returns silently. * Otherwise adds line to rp under the given group. Updates the count * on the tab in this and restarts the spinning lime. * @requires this is called from Swing thread * @modifies this */ public static void handleQueryResult(RemoteFileDesc rfd, HostData data, Set<? extends IpPort> alts) { byte[] replyGUID = data.getMessageGUID(); ResultPanel rp = getResultPanelForGUID(new GUID(replyGUID)); if(rp != null) { SearchResult sr = new GnutellaSearchResult(rfd, data, alts); RESULT_DISPLAYER.addQueryResult(replyGUID, sr, rp); } } /** * Downloads all the selected table lines from the given result panel. */ public static void downloadFromPanel(ResultPanel rp, TableLine[] lines) { downloadAll(lines, new GUID(rp.getGUID()), rp.getSearchInformation()); rp.refresh(); } /** * Downloads the selected files in the currently displayed * <tt>ResultPanel</tt> if there is one. */ static void doDownload(final ResultPanel rp) { final TableLine[] lines = rp.getAllSelectedLines(); SwingUtilities.invokeLater(new Runnable() { public void run() { SearchMediator.downloadAll(lines, new GUID(rp.getGUID()), rp.getSearchInformation()); rp.refresh(); } }); } /** * Opens a dialog where you can specify the download directory and final * filename for the selected file. * @param panel * @throws IllegalStateException when there is more than one file selected * for download or there is no file selected. */ static void doDownloadAs(final ResultPanel panel) { final TableLine[] lines = panel.getAllSelectedLines(); if (lines.length != 1) { throw new IllegalStateException("There should only be one search result selected: " + lines.length); } downloadLine(lines[0], new GUID(panel.getGUID()), null, null, true, panel.getSearchInformation()); } /** * Downloads all the selected lines. */ private static void downloadAll(TableLine[] lines, GUID guid, SearchInformation searchInfo) { for(int i = 0; i < lines.length; i++) downloadLine(lines[i], guid, null, null, false, searchInfo); } /** * Downloads the given TableLine. * @param line * @param guid * @param saveDir optionally the directory where the final file should be * saved to, can be <code>null</code> * @param fileName the optional filename of the final file, can be * <code>null</code> * @param searchInfo The query used to find the file being downloaded. */ private static void downloadLine(TableLine line, GUID guid, File saveDir, String fileName, boolean saveAs, SearchInformation searchInfo) { if (line == null) throw new NullPointerException("Tried to download null line"); line.takeAction(line, guid, saveDir, fileName, saveAs, searchInfo); } public static void downloadGnutellaLine(TableLine line, GUID guid, File saveDir, String fileName, boolean saveAs, SearchInformation searchInfo) { if (line == null) throw new NullPointerException("Tried to download null line"); // do not download if no license and user does not acknowledge //if ((!line.isLicenseAvailable() && !line.isSecure()) && !GUIMediator.showFirstDownloadDialog()) // return; RemoteFileDesc[] rfds; Set<IpPort> alts = new IpPortSet(); List<RemoteFileDesc> otherRFDs = new LinkedList<RemoteFileDesc>(); rfds = line.getAllRemoteFileDescs(); alts.addAll(line.getAlts()); // Iterate through RFDs and remove matching alts. // Also store the first SHA1 capable RFD for collecting alts. RemoteFileDesc sha1RFD = null; for(int i = 0; i < rfds.length; i++) { RemoteFileDesc next = rfds[i]; // this has been moved down until the download is actually started // next.setDownloading(true); next.setRetryAfter(0); if(next.getSHA1Urn() != null) sha1RFD = next; alts.remove(next); } // If no SHA1 rfd, just use the first. if(sha1RFD == null) sha1RFD = rfds[0]; // Now iterate through alts & add more rfds. for(IpPort next : alts) { otherRFDs.add(GuiCoreMediator.getRemoteFileDescFactory().createRemoteFileDesc(sha1RFD, next)); } // determine per mediatype directory if saveLocation == null // and only pass it through if directory is different from default // save directory == !isDefault() if (saveDir == null && line.getNamedMediaType() != null) { FileSetting fs = SharingSettings.getFileSettingForMediaType (line.getNamedMediaType().getMediaType()); if (!fs.isDefault()) { saveDir = fs.getValue(); } } downloadWithOverwritePrompt(rfds, otherRFDs, guid, saveDir, fileName, saveAs, searchInfo); } /** * Downloads the given files, prompting the user if the file already exists. * @param queryGUID the guid of the query you ar downloading rfds for. * @param searchInfo The query used to find the file being downloaded. */ private static void downloadWithOverwritePrompt(RemoteFileDesc[] rfds, List<? extends RemoteFileDesc> alts, GUID queryGUID, File saveDir, String fileName, boolean saveAs, SearchInformation searchInfo) { if (rfds.length < 1) return; if (containsExe(rfds)) { if (!userWantsExeDownload()) return; } // Before proceeding...check if there is an rfd withpure metadata // ie no file int actLine = 0; boolean pureFound = false; for (; actLine < rfds.length; actLine++) { if (rfds[actLine].getIndex() == LimeXMLProperties.DEFAULT_NONFILE_INDEX) { // we have our line pureFound = true; break; } } if (pureFound) { LimeXMLDocument doc = rfds[actLine].getXMLDocument(); if(doc != null) { String action = doc.getAction(); if (action != null && !action.equals("")) { // valid action if (doc.actionDetailRequested()) action = LimeWireUtils.addLWInfoToUrl(action, GuiCoreMediator.getApplicationServices().getMyGUID()); if (action.length() > 255) // trim to make sure its not too long action = action.substring(0, 255); GUIMediator.openURL(action); return; // goodbye } } } // No pure metadata lines found...continue as usual... GuiDownloaderFactory factory = new SearchResultDownloaderFactory (rfds, alts, queryGUID, saveDir, fileName); Downloader dl = saveAs ? DownloaderUtils.createDownloaderAs(factory) : DownloaderUtils.createDownloader(factory); if (dl != null) { setAsDownloading(rfds); if (validateInfo(searchInfo) == QUERY_VALID) dl.setAttribute(SEARCH_INFORMATION_KEY, searchInfo.toMap(), false); } } private static void setAsDownloading(RemoteFileDesc[] rfds) { for (int i = 0; i < rfds.length; i++) { rfds[i].setDownloading(true); } } /** * Returns true if any of the entries of rfd contains a .exe file. */ private static boolean containsExe(RemoteFileDesc[] rfd) { for (int i = 0; i < rfd.length; i++) { if (rfd[i].getFileName().toLowerCase(Locale.US).endsWith("exe")) return true; } return false; } /** * Prompts the user if they want to download an .exe file. * Returns true s/he said yes. */ private static boolean userWantsExeDownload() { DialogOption response = GUIMediator.showYesNoMessage(I18n.tr("One of the selected files is an executable program and could contain a virus. Are you sure you want to download it?"), QuestionsHandler.PROMPT_FOR_EXE, DialogOption.NO); return response == DialogOption.YES; } ////////////////////////// Other Controls /////////////////////////// /** * called by ResultPanel when the views are changed. Used to set the * tab to indicate the correct number of TableLines in the current * view. */ static void setTabDisplayCount(ResultPanel rp) { RESULT_DISPLAYER.setTabDisplayCount(rp); } /** * @modifies tabbed pane, entries * @effects removes the currently selected result window (if any) * from this */ static void killSearch() { RESULT_DISPLAYER.killSearch(); } /** * Notification that a given ResultPanel has been selected */ static void panelSelected(ResultPanel panel) { INPUT_MANAGER.setFiltersFor(panel); } /** * Notification that a search has been killed. */ static void searchKilled(ResultPanel panel) { INPUT_MANAGER.panelRemoved(panel); ResultPanel rp = RESULT_DISPLAYER.getSelectedResultPanel(); if (rp != null) { INPUT_MANAGER.setFiltersFor(rp); } panel.cleanup(); } /** * Checks to see if the spinning lime should be stopped. */ static void checkToStopLime() { RESULT_DISPLAYER.checkToStopLime(); } /** * Returns the <tt>ResultPanel</tt> for the specified GUID. * * @param rguid the guid to search for * @return the <tt>ResultPanel</tt> that matches the GUID, or null * if none match. */ static ResultPanel getResultPanelForGUID(GUID rguid) { return RESULT_DISPLAYER.getResultPanelForGUID(rguid); } /** @returns true if the user is still using the query results for the input * guid, else false. */ public static boolean queryIsAlive(GUID guid) { return (getResultPanelForGUID(guid) != null); } /** * Returns the search input panel component. * * @return the search input panel component */ public static JComponent getSearchComponent() { return INPUT_MANAGER.getComponent(); } /** * Returns the <tt>JComponent</tt> instance containing all of the * search result UI components. * * @return the <tt>JComponent</tt> instance containing all of the * search result UI components */ public static JComponent getResultComponent() { return RESULT_DISPLAYER.getComponent(); } /** * @return an Ad message that should be displayed on top * of the search pannel. */ public synchronized static Ad getAd() { if (banner == null) initBanner(); return banner.getAd(); } }

The table below shows all metrics for SearchMediator.java.

MetricValueDescription
BLOCKS97.00Number of blocks
BLOCK_COMMENT 0.00Number of block comment lines
COMMENTS251.00Comment lines
COMMENT_DENSITY 0.59Comment density
COMPARISONS75.00Number of comparison operators
CYCLOMATIC131.00Cyclomatic complexity
DECL_COMMENTS58.00Comments in declarations
DOC_COMMENT218.00Number of javadoc comment lines
ELOC422.00Effective lines of code
EXEC_COMMENTS24.00Comments in executable code
EXITS149.00Procedure exits
FUNCTIONS53.00Number of function declarations
HALSTEAD_DIFFICULTY70.77Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY145.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 0.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 1.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 1.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA003423.00JAVA0034 Missing braces in if statement
JAVA0035 1.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 1.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 2.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA0076 2.00JAVA0076 Use of magic number
JAVA0077 1.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 0.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA010846.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 1.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA011011.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 1.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 1.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 1.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 0.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 3.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 1.00JAVA0143 Synchronized method
JAVA0144 4.00JAVA0144 Line exceeds maximum M characters
JAVA0145244.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 0.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 1.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 0.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 4.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 1.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES870.00Number of lines in the source file
LINE_COMMENT33.00Number of line comments
LOC508.00Lines of code
LOGICAL_LINES256.00Number of statements
LOOPS 5.00Number of loops
NEST_DEPTH 6.00Maximum nesting depth
OPERANDS1312.00Number of operands
OPERATORS2525.00Number of operators
PARAMS69.00Number of formal parameter declarations
PROGRAM_LENGTH3837.00Halstead program length
PROGRAM_VOCAB534.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS76.00Number of return points from functions
SIZE31567.00Size of the file in bytes
UNIQUE_OPERANDS482.00Number of unique operands
UNIQUE_OPERATORS52.00Number of unique operators
WHITESPACE111.00Number of whitespace lines