From e7552bd71999b160a6643d63c6c48052fd9221be Mon Sep 17 00:00:00 2001 From: low012 Date: Sat, 27 Nov 2010 00:54:59 +0000 Subject: [PATCH] *) cleaning up the code a little bit git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7343 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/AccessTracker_p.java | 117 ++++++++++++------------ htroot/BlacklistCleaner_p.java | 9 +- htroot/Blacklist_p.java | 2 +- htroot/BlogComments.java | 37 +++----- htroot/Bookmarks.java | 6 +- htroot/ConfigAccounts_p.java | 10 +- htroot/ConfigBasic.java | 78 +++++++++------- htroot/ConfigHTCache_p.java | 20 ++-- htroot/ConfigLanguage_p.java | 30 +++--- htroot/ConfigNetwork_p.java | 111 ++++++++++++---------- htroot/ConfigParser.java | 10 +- htroot/ConfigPortal.java | 27 +++--- htroot/ConfigProperties_p.java | 4 +- htroot/ConfigUpdate_p.java | 47 +++++----- htroot/Connections_p.java | 36 ++++---- htroot/CookieTest_p.java | 64 ++++++------- htroot/CrawlMonitorRemoteStart.java | 26 ++++-- htroot/CrawlProfileEditor_p.java | 34 +++---- htroot/Crawler_p.java | 110 +++++++++++----------- htroot/yacy/crawlReceipt.java | 7 +- source/de/anomic/data/BookmarkDate.java | 6 +- 21 files changed, 412 insertions(+), 379 deletions(-) diff --git a/htroot/AccessTracker_p.java b/htroot/AccessTracker_p.java index 1ddbce23f..28f68281a 100644 --- a/htroot/AccessTracker_p.java +++ b/htroot/AccessTracker_p.java @@ -24,7 +24,6 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -import java.util.ArrayList; import java.util.Collection; import java.util.ConcurrentModificationException; import java.util.Date; @@ -47,18 +46,19 @@ import de.anomic.server.serverObjects; import de.anomic.server.serverSwitch; import de.anomic.server.serverAccessTracker.Track; import de.anomic.yacy.yacySeed; +import java.util.List; public class AccessTracker_p { - private static SimpleDateFormat SimpleFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.US); - - private static final Collection listclone(final Collection m) { + private static SimpleDateFormat SimpleFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.US); + + private static Collection listclone (final Collection m) { final Collection accessClone = new ConcurrentLinkedQueue(); try { accessClone.addAll(m); } catch (final ConcurrentModificationException e) {} return accessClone; - } + } public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { final Switchboard sb = (Switchboard) env; @@ -67,7 +67,9 @@ public class AccessTracker_p { final serverObjects prop = new serverObjects(); prop.setLocalized(!(header.get(HeaderFramework.CONNECTION_PROP_PATH)).endsWith(".xml")); int page = 0; - if (post != null) page = post.getInt("page", 0); + if (post != null) { + page = post.getInt("page", 0); + } prop.put("page", page); final int maxCount = 1000; @@ -77,70 +79,68 @@ public class AccessTracker_p { String host; int entCount = 0; try { - while ((entCount < maxCount) && (i.hasNext())) { - host = i.next(); - prop.putHTML("page_list_" + entCount + "_host", host); - prop.putNum("page_list_" + entCount + "_countSecond", sb.latestAccessCount(host, 1000)); - prop.putNum("page_list_" + entCount + "_countMinute", sb.latestAccessCount(host, 1000 * 60)); - prop.putNum("page_list_" + entCount + "_count10Minutes", sb.latestAccessCount(host, 1000 * 60 * 10)); - prop.putNum("page_list_" + entCount + "_countHour", sb.latestAccessCount(host, 1000 * 60 * 60)); - entCount++; - } + while ((entCount < maxCount) && (i.hasNext())) { + host = i.next(); + prop.putHTML("page_list_" + entCount + "_host", host); + prop.putNum("page_list_" + entCount + "_countSecond", sb.latestAccessCount(host, 1000)); + prop.putNum("page_list_" + entCount + "_countMinute", sb.latestAccessCount(host, 1000 * 60)); + prop.putNum("page_list_" + entCount + "_count10Minutes", sb.latestAccessCount(host, 1000 * 60 * 10)); + prop.putNum("page_list_" + entCount + "_countHour", sb.latestAccessCount(host, 1000 * 60 * 60)); + entCount++; + } } catch (final ConcurrentModificationException e) {} // we don't want to synchronize this prop.put("page_list", entCount); prop.put("page_num", entCount); entCount = 0; try { - for (final Map.Entry bfe: serverCore.bfHost.entrySet()) { - prop.putHTML("page_bflist_" + entCount + "_host", bfe.getKey()); - prop.putNum("page_bflist_" + entCount + "_countSecond", bfe.getValue()); - entCount++; - } + for (final Map.Entry bfe: serverCore.bfHost.entrySet()) { + prop.putHTML("page_bflist_" + entCount + "_host", bfe.getKey()); + prop.putNum("page_bflist_" + entCount + "_countSecond", bfe.getValue()); + entCount++; + } } catch (final ConcurrentModificationException e) {} // we dont want to synchronize this prop.put("page_bflist", entCount); - } - if (page == 1) { + } else if (page == 1) { String host = (post == null) ? "" : post.get("host", ""); int entCount = 0; Collection access; Track entry; if (host.length() > 0) { - access = sb.accessTrack(host); - if (access != null) { - try { - final Iterator ii = listclone(access).iterator(); - while (ii.hasNext()) { - entry = ii.next(); - prop.putHTML("page_list_" + entCount + "_host", host); - prop.put("page_list_" + entCount + "_date", SimpleFormatter.format(new Date(entry.getTime()))); - prop.putHTML("page_list_" + entCount + "_path", entry.getPath()); - entCount++; - } - } catch (final ConcurrentModificationException e) {} // we don't want to synchronize this - } - } else { + access = sb.accessTrack(host); + if (access != null) { + try { + final Iterator ii = listclone(access).iterator(); + while (ii.hasNext()) { + entry = ii.next(); + prop.putHTML("page_list_" + entCount + "_host", host); + prop.put("page_list_" + entCount + "_date", SimpleFormatter.format(new Date(entry.getTime()))); + prop.putHTML("page_list_" + entCount + "_path", entry.getPath()); + entCount++; + } + } catch (final ConcurrentModificationException e) {} // we don't want to synchronize this + } + } else { try { - final Iterator i = sb.accessHosts(); + final Iterator i = sb.accessHosts(); while ((entCount < maxCount) && (i.hasNext())) { - host = i.next(); - access = sb.accessTrack(host); - final Iterator ii = listclone(access).iterator(); - while (ii.hasNext()) { - entry = ii.next(); - prop.putHTML("page_list_" + entCount + "_host", host); - prop.put("page_list_" + entCount + "_date", SimpleFormatter.format(new Date(entry.getTime()))); - prop.putHTML("page_list_" + entCount + "_path", entry.getPath()); - entCount++; - } - } - } catch (final ConcurrentModificationException e) {} // we dont want to synchronize this - } + host = i.next(); + access = sb.accessTrack(host); + final Iterator ii = listclone(access).iterator(); + while (ii.hasNext()) { + entry = ii.next(); + prop.putHTML("page_list_" + entCount + "_host", host); + prop.put("page_list_" + entCount + "_date", SimpleFormatter.format(new Date(entry.getTime()))); + prop.putHTML("page_list_" + entCount + "_path", entry.getPath()); + entCount++; + } + } + } catch (final ConcurrentModificationException e) {} // we dont want to synchronize this + } prop.put("page_list", entCount); prop.put("page_num", entCount); - } - if ((page == 2) || (page == 4)) { - final ArrayList array = (page == 2) ? sb.localSearches : sb.remoteSearches; + } else if ((page == 2) || (page == 4)) { + final List array = (page == 2) ? sb.localSearches : sb.remoteSearches; QueryParams searchProfile; int m = Math.min(maxCount, array.size()); long qcountSum = 0; @@ -229,8 +229,7 @@ public class AccessTracker_p { prop.putNum("page_snippettime_avg1", (double) stimeSum1 / rcount); prop.putNum("page_resulttime_avg1", (double) rtimeSum1 / rcount); prop.putNum("page_total", (page == 2) ? sb.localSearches.size() : sb.remoteSearches.size()); - } - if ((page == 3) || (page == 5)) { + } else if ((page == 3) || (page == 5)) { final Iterator>> i = (page == 3) ? sb.localSearchTracker.entrySet().iterator() : sb.remoteSearchTracker.entrySet().iterator(); String host; TreeSet handles; @@ -246,10 +245,10 @@ public class AccessTracker_p { int dateCount = 0; final Iterator ii = handles.iterator(); while (ii.hasNext()) { - final Long timestamp = ii.next(); - prop.put("page_list_" + entCount + "_dates_" + dateCount + "_date", SimpleFormatter.format(new Date(timestamp.longValue()))); - prop.put("page_list_" + entCount + "_dates_" + dateCount + "_timestamp", timestamp.toString()); - dateCount++; + final Long timestamp = ii.next(); + prop.put("page_list_" + entCount + "_dates_" + dateCount + "_date", SimpleFormatter.format(new Date(timestamp.longValue()))); + prop.put("page_list_" + entCount + "_dates_" + dateCount + "_timestamp", timestamp.toString()); + dateCount++; } prop.put("page_list_" + entCount + "_dates", dateCount); final int qph = handles.tailSet(Long.valueOf(System.currentTimeMillis() - 1000 * 60 * 60)).size(); diff --git a/htroot/BlacklistCleaner_p.java b/htroot/BlacklistCleaner_p.java index abbc04bc5..fb450e9fc 100644 --- a/htroot/BlacklistCleaner_p.java +++ b/htroot/BlacklistCleaner_p.java @@ -153,7 +153,7 @@ public class BlacklistCleaner_p { prop.put("disabled", "0"); prop.put(DISABLED + "blacklists", lists.size()); int count = 0; - for (String list : lists) { + for (final String list : lists) { prop.putHTML(DISABLED + BLACKLISTS + count + "_name", list); prop.put(DISABLED + BLACKLISTS + count + "_selected", (list.equals(selected)) ? "1" : "0"); count++; @@ -214,13 +214,13 @@ public class BlacklistCleaner_p { } if (useKeys) { - for (String entry : post.keySet()) { + for (final String entry : post.keySet()) { if (entry.indexOf(prefix) == 0) { r.add(entry.substring(prefix.length())); } } } else { - for (Map.Entry entry : post.entrySet()) { + for (final Map.Entry entry : post.entrySet()) { if (entry.getKey().indexOf(prefix) == 0) { r.add(entry.getValue()); } @@ -295,8 +295,7 @@ public class BlacklistCleaner_p { } if (list.contains(s)) { - list.remove(s); - listChanged = true; + listChanged = list.remove(s); } } diff --git a/htroot/Blacklist_p.java b/htroot/Blacklist_p.java index 1b39f5da5..aeb9430a0 100644 --- a/htroot/Blacklist_p.java +++ b/htroot/Blacklist_p.java @@ -241,7 +241,7 @@ public class Blacklist_p { } else { // inactive list -> enable ListManager.updateListSet(BLACKLIST_SHARED, blacklistToUse); } - } else if (action.equals("deleteBlacklistEntry")) { + } else if ("deleteBlacklistEntry".equals(action)) { /* =========================================================== * Delete an entry from a blacklist diff --git a/htroot/BlogComments.java b/htroot/BlogComments.java index 1b6095c00..d00b1d0bd 100644 --- a/htroot/BlogComments.java +++ b/htroot/BlogComments.java @@ -6,7 +6,6 @@ // Frankfurt, Germany, 2004 // // This File is contributed by Jan Sandbrink -// Contains contributions from Marc Nause [MN] // //$LastChangedDate$ //$LastChangedRevision$ @@ -56,34 +55,32 @@ import de.anomic.yacy.yacyCore; public class BlogComments { - private static SimpleDateFormat SimpleFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.US); + private final static SimpleDateFormat SIMPLE_FORMATTER = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.US); // TODO: make userdefined date/time-strings (localisation) public static String dateString(final Date date) { - return SimpleFormatter.format(date); + return SIMPLE_FORMATTER.format(date); } public static serverObjects respond(final RequestHeader header, serverObjects post, final serverSwitch env) { final Switchboard sb = (Switchboard) env; final serverObjects prop = new serverObjects(); - BlogBoard.BlogEntry page = null; boolean hasRights = sb.verifyAuthentication(header, true); - if (hasRights) prop.put("mode_admin", "1"); - else prop.put("mode_admin", "0"); + prop.put("mode_admin", hasRights ? "1" : "0"); if (post == null) { post = new serverObjects(); post.put("page", "blog_default"); } - if(!hasRights){ + if (!hasRights) { final UserDB.Entry userentry = sb.userDB.proxyAuth(header.get(RequestHeader.AUTHORIZATION, "xxxxxx")); - if(userentry != null && userentry.hasRight(UserDB.Entry.BLOG_RIGHT)){ - hasRights=true; + if (userentry != null && userentry.hasRight(UserDB.Entry.BLOG_RIGHT)) { + hasRights = true; } - //opens login window if login link is clicked - contrib [MN] - else if(post.containsKey("login")){ + //opens login window if login link is clicked + else if (post.containsKey("login")) { prop.put("AUTHENTICATE","admin log-in"); } } @@ -99,8 +96,7 @@ public class BlogComments { if (StrAuthor == null || StrAuthor.length() == 0) { if (sb.peers.mySeed() == null) { StrAuthor = "anonymous"; - } - else { + } else { StrAuthor = sb.peers.mySeed().get("Name", "anonymous"); } } @@ -113,15 +109,11 @@ public class BlogComments { author = StrAuthor.getBytes(); } - page = sb.blogDB.readBlogEntry(pagename); //maybe "if(page == null)" - final boolean pageExists = sb.blogDB.contains(pagename); // [MN] + final BlogBoard.BlogEntry page = sb.blogDB.readBlogEntry(pagename); //maybe "if(page == null)" + final boolean pageExists = sb.blogDB.contains(pagename); // comments not allowed - if (page.getCommentMode() == 0) { - prop.put("mode_allow", 0); - } else { - prop.put("mode_allow", 1); - } + prop.put("mode_allow", (page.getCommentMode() == 0) ? 0 : 1); if (post.containsKey("submit") && page.getCommentMode() != 0 && pageExists) { // store a new/edited blog-entry @@ -245,10 +237,7 @@ public class BlogComments { final int commentMode = page.getCommentMode(); String pageid; BlogBoardComments.CommentEntry entry; - boolean xml = false; - if (post.containsKey("xml")) { - xml = true; - } + final boolean xml = post.containsKey("xml"); int count = 0; //counts how many entries are shown to the user int start = post.getInt("start",0); //indicates from where entries should be shown int num = post.getInt("num",10); //indicates how many entries should be shown diff --git a/htroot/Bookmarks.java b/htroot/Bookmarks.java index d09ed0757..9d7d6e605 100644 --- a/htroot/Bookmarks.java +++ b/htroot/Bookmarks.java @@ -160,7 +160,7 @@ public class Bookmarks { bookmark.setOwner(user.getUserName()); } - if ((post.get("public")).equals("public")) { + if ("public".equals(post.get("public"))) { bookmark.setPublic(true); publishNews(url, title, description, tagsString); } else { @@ -242,7 +242,7 @@ public class Bookmarks { Log.logInfo("BOOKMARKS", "Trying to import bookmarks from HTML-file"); try { - final File file=new File(post.get("htmlfile")); + final File file = new File(post.get("htmlfile")); BookmarkHelper.importFromBookmarks(sb.bookmarksDB, new DigestURI(file), post.get("htmlfile$file"), tags, isPublic); } catch (final MalformedURLException e) {} @@ -415,7 +415,7 @@ public class Bookmarks { return count; } - if (fn.startsWith((root.equals("/") ? root : root+"/"))) { + if (fn.startsWith(("/".equals(root) ? root : root + "/"))) { prop.put("display_folderlist_"+count+"_folder", "
  • "+fn.replaceFirst(root+"/*","")+"
      "); count++; final Iterator bit = sb.bookmarksDB.getBookmarksIterator(fn, isAdmin); diff --git a/htroot/ConfigAccounts_p.java b/htroot/ConfigAccounts_p.java index aa87141fe..292e331a7 100644 --- a/htroot/ConfigAccounts_p.java +++ b/htroot/ConfigAccounts_p.java @@ -77,7 +77,7 @@ public class ConfigAccounts_p { sb.setConfig("adminAccountForLocalhost", true); // if an localhost access is configured, check if a local password is given // if not, set a random password - if (post != null && env.getConfig(HTTPDemon.ADMIN_ACCOUNT_B64MD5, "").length() == 0) { + if (env.getConfig(HTTPDemon.ADMIN_ACCOUNT_B64MD5, "").length() == 0) { // make a 'random' password env.setConfig(HTTPDemon.ADMIN_ACCOUNT_B64MD5, "0000" + Digest.encodeMD5Hex(System.getProperties().toString() + System.currentTimeMillis())); env.setConfig("adminAccount", ""); @@ -154,7 +154,7 @@ public class ConfigAccounts_p { } prop.put("rights", count); } - } else if (post.containsKey("delete_user") && !post.get("user").equals("newuser")){ + } else if (post.containsKey("delete_user") && !"newuser".equals(post.get("user"))){ sb.userDB.removeEntry(post.get("user")); } } else if (post.containsKey("change")) { //New User / edit User @@ -178,13 +178,13 @@ public class ConfigAccounts_p { final Map rightsSet = new HashMap(); for(final String right : rights) { - rightsSet.put(right, post.containsKey(right)&&(post.get(right)).equals("on") ? "true" : "false"); + rightsSet.put(right, post.containsKey(right)&&"on".equals(post.get(right)) ? "true" : "false"); } final Map mem = new HashMap(); - if( post.get("current_user").equals("newuser")){ //new user + if( "newuser".equals(post.get("current_user"))){ //new user - if(!"".equals(pw1)){ //change only if set + if (!"".equals(pw1)) { //change only if set mem.put(UserDB.Entry.MD5ENCODED_USERPWD_STRING, Digest.encodeMD5Hex(username + ":" + pw1)); } diff --git a/htroot/ConfigBasic.java b/htroot/ConfigBasic.java index e39870549..c3f16c9f3 100644 --- a/htroot/ConfigBasic.java +++ b/htroot/ConfigBasic.java @@ -1,4 +1,4 @@ -// ConfigBasic_p.java +// ConfigBasic.java // ----------------------- // part of YaCy // (C) by Michael Peter Christen; mc@yacy.net @@ -83,39 +83,48 @@ public class ConfigBasic { } // language settings - if ((post != null) && (!(post.get("language", "default").equals(lang)))) { - if (Translator.changeLang(env, langPath, post.get("language", "default") + ".lng")) - prop.put("changedLanguage", "1"); + if (post != null && !lang.equals(post.get("language", "default")) && + (Translator.changeLang(env, langPath, post.get("language", "default") + ".lng"))) { + prop.put("changedLanguage", "1"); } // peer name settings final String peerName = (post == null) ? env.getConfig("peerName","") : post.get("peername", ""); // port settings - long port = env.getConfigLong("port", 8080); //this allows a low port, but it will only get one, if the user edits the config himself. - if (post != null && post.containsKey("port") && Integer.parseInt(post.get("port")) > 1023) { - port = post.getLong("port", 8080); - } + final long port; + if (post != null && post.containsKey("port") && Integer.parseInt(post.get("port")) > 1023) { + port = post.getLong("port", 8080); + } else { + port = env.getConfigLong("port", 8080); //this allows a low port, but it will only get one, if the user edits the config himself. + } // check if peer name already exists final yacySeed oldSeed = sb.peers.lookupByName(peerName); - if ((oldSeed == null) && (!(env.getConfig("peerName", "").equals(peerName)))) { + if (oldSeed == null && !env.getConfig("peerName", "").equals(peerName)) { // the name is new - final boolean nameOK = Pattern.compile("[A-Za-z0-9\\-_]{3,80}").matcher(peerName).matches(); - if (nameOK) env.setConfig("peerName", peerName); + if (Pattern.compile("[A-Za-z0-9\\-_]{3,80}").matcher(peerName).matches()) { + env.setConfig("peerName", peerName); + } } // UPnP config - boolean upnp = false; + final boolean upnp; if(post != null && post.containsKey("port")) { // hack to allow checkbox - if (post.containsKey("enableUpnp")) upnp = true; - if (upnp && !sb.getConfigBool(SwitchboardConstants.UPNP_ENABLED, false)) UPnP.addPortMapping(); + upnp = post.containsKey("enableUpnp"); + if (upnp && !sb.getConfigBool(SwitchboardConstants.UPNP_ENABLED, false)) { + UPnP.addPortMapping(); + } sb.setConfig(SwitchboardConstants.UPNP_ENABLED, upnp); - if(!upnp) UPnP.deletePortMapping(); + if (!upnp) { + UPnP.deletePortMapping(); + } + } else { + upnp = false; } // check port - boolean reconnect = false; + final boolean reconnect; if (!(env.getConfigLong("port", port) == port)) { // validate port final serverCore theServerCore = (serverCore) env.getThread("10_httpd"); @@ -125,7 +134,9 @@ public class ConfigBasic { reconnect = true; // renew upnp port mapping - if (upnp) UPnP.addPortMapping(); + if (upnp) { + UPnP.addPortMapping(); + } String host = null; if (header.containsKey(HeaderFramework.HOST)) { @@ -151,36 +162,37 @@ public class ConfigBasic { // force reconnection in 7 seconds theServerCore.reconnect(7000); } else { + reconnect = false; prop.put("reconnect", "0"); } // set a use case String networkName = sb.getConfig(SwitchboardConstants.NETWORK_NAME, ""); if (post != null && post.containsKey("usecase")) { - if (post.get("usecase", "").equals("freeworld") && !networkName.equals("freeworld")) { + if ("freeworld".equals(post.get("usecase", "")) && !"freeworld".equals(networkName)) { // switch to freeworld network sb.switchNetwork("defaults/yacy.network.freeworld.unit"); // switch to p2p mode sb.setConfig(SwitchboardConstants.INDEX_DIST_ALLOW, true); sb.setConfig(SwitchboardConstants.INDEX_RECEIVE_ALLOW, true); } - if (post.get("usecase", "").equals("portal") && !networkName.equals("webportal")) { + if ("portal".equals(post.get("usecase", "")) && !"webprotal".equals(networkName)) { // switch to webportal network sb.switchNetwork("defaults/yacy.network.webportal.unit"); // switch to robinson mode sb.setConfig(SwitchboardConstants.INDEX_DIST_ALLOW, false); sb.setConfig(SwitchboardConstants.INDEX_RECEIVE_ALLOW, false); } - if (post.get("usecase", "").equals("intranet") && !networkName.equals("intranet")) { + if ("intranet".equals(post.get("usecase", "")) && !"intranet".equals(networkName)) { // switch to intranet network sb.switchNetwork("defaults/yacy.network.intranet.unit"); // switch to p2p mode: enable ad-hoc networks between intranet users sb.setConfig(SwitchboardConstants.INDEX_DIST_ALLOW, false); sb.setConfig(SwitchboardConstants.INDEX_RECEIVE_ALLOW, false); } - if (post.get("usecase", "").equals("intranet")) { - String repositoryPath = post.get("repositoryPath", "/DATA/HTROOT/repository"); - File repository = ((repositoryPath.length() > 0 && repositoryPath.charAt(0) == '/') || (repositoryPath.length() > 1 && repositoryPath.charAt(1) == ':')) ? new File(repositoryPath) : new File(sb.getDataPath(), repositoryPath); + if ("intranet".equals(post.get("usecase", ""))) { + final String repositoryPath = post.get("repositoryPath", "/DATA/HTROOT/repository"); + final File repository = ((repositoryPath.length() > 0 && repositoryPath.charAt(0) == '/') || (repositoryPath.length() > 1 && repositoryPath.charAt(1) == ':')) ? new File(repositoryPath) : new File(sb.getDataPath(), repositoryPath); if (repository.exists() && repository.isDirectory()) { sb.setConfig("repositoryPath", repositoryPath); } @@ -188,13 +200,13 @@ public class ConfigBasic { } networkName = sb.getConfig(SwitchboardConstants.NETWORK_NAME, ""); - if (networkName.equals("freeworld")) { + if ("freeworld".equals(networkName)) { prop.put("setUseCase", 1); prop.put("setUseCase_freeworldChecked", 1); - } else if (networkName.equals("webportal")) { + } else if ("webportal".equals(networkName)) { prop.put("setUseCase", 1); prop.put("setUseCase_portalChecked", 1); - } else if (networkName.equals("intranet")) { + } else if ("intranet".equals(networkName)) { prop.put("setUseCase", 1); prop.put("setUseCase_intranetChecked", 1); } else { @@ -231,22 +243,26 @@ public class ConfigBasic { final boolean upnp_enabled = env.getConfigBool(SwitchboardConstants.UPNP_ENABLED, false); prop.put("upnp", "1"); prop.put("upnp_enabled", upnp_enabled ? "1" : "0"); - if (upnp_enabled) prop.put("upnp_success", (UPnP.getMappedPort() > 0) ? "2" : "1"); - else prop.put("upnp_success", "0"); + if (upnp_enabled) { + prop.put("upnp_success", (UPnP.getMappedPort() > 0) ? "2" : "1"); + } + else { + prop.put("upnp_success", "0"); + } // set default values prop.putHTML("defaultName", env.getConfig("peerName", "")); prop.putHTML("defaultPort", env.getConfig("port", "8080")); lang = env.getConfig("locale.language", "default"); // re-assign lang, may have changed - if (lang.equals("default")) { + if ("default".equals(lang)) { prop.put("langDeutsch", "0"); prop.put("langFrancais", "0"); prop.put("langEnglish", "1"); - } else if (lang.equals("fr")) { + } else if ("fr".equals(lang)) { prop.put("langDeutsch", "0"); prop.put("langFrancais", "1"); prop.put("langEnglish", "0"); - } else if (lang.equals("de")) { + } else if ("de".equals(lang)) { prop.put("langDeutsch", "1"); prop.put("langFrancais", "0"); prop.put("langEnglish", "0"); diff --git a/htroot/ConfigHTCache_p.java b/htroot/ConfigHTCache_p.java index 4a0d82946..e3bc15c36 100644 --- a/htroot/ConfigHTCache_p.java +++ b/htroot/ConfigHTCache_p.java @@ -43,33 +43,31 @@ public class ConfigHTCache_p { final Switchboard sb = (Switchboard) env; final serverObjects prop = new serverObjects(); - String oldProxyCachePath, newProxyCachePath; - int newProxyCacheSize; - if (post != null && post.containsKey("set")) { // proxyCache - check and create the directory - oldProxyCachePath = env.getConfig(SwitchboardConstants.HTCACHE_PATH, SwitchboardConstants.HTCACHE_PATH_DEFAULT); - newProxyCachePath = post.get("HTCachePath", SwitchboardConstants.HTCACHE_PATH_DEFAULT); + final String oldProxyCachePath = env.getConfig(SwitchboardConstants.HTCACHE_PATH, SwitchboardConstants.HTCACHE_PATH_DEFAULT); + String newProxyCachePath = post.get("HTCachePath", SwitchboardConstants.HTCACHE_PATH_DEFAULT); newProxyCachePath = newProxyCachePath.replace('\\', '/'); if (newProxyCachePath.endsWith("/")) { newProxyCachePath = newProxyCachePath.substring(0, newProxyCachePath.length() - 1); } env.setConfig(SwitchboardConstants.HTCACHE_PATH, newProxyCachePath); final File cache = env.getDataPath(SwitchboardConstants.HTCACHE_PATH, oldProxyCachePath); - if (!cache.isDirectory() && !cache.isFile()) cache.mkdirs(); + if (!cache.isDirectory() && !cache.isFile()) { + cache.mkdirs(); + } // proxyCacheSize - newProxyCacheSize = post.getInt("maxCacheSize", 64); - if (newProxyCacheSize < 4) { newProxyCacheSize = 4; } + final int newProxyCacheSize = Math.max(post.getInt("maxCacheSize", 64), 4); env.setConfig(SwitchboardConstants.PROXY_CACHE_SIZE, newProxyCacheSize); Cache.setMaxCacheSize(newProxyCacheSize * 1024 * 1024); } if (post != null && post.containsKey("deletecomplete")) { - if (post.get("deleteCache", "").equals("on")) { + if ("on".equals(post.get("deleteCache", ""))) { Cache.clear(); } - if (post.get("deleteRobots", "").equals("on")) { + if ("on".equals(post.get("deleteRobots", ""))) { sb.robots.clear(); } } @@ -80,4 +78,4 @@ public class ConfigHTCache_p { // return rewrite properties return prop; } -} \ No newline at end of file +} diff --git a/htroot/ConfigLanguage_p.java b/htroot/ConfigLanguage_p.java index adeb30868..3c91ac5ef 100644 --- a/htroot/ConfigLanguage_p.java +++ b/htroot/ConfigLanguage_p.java @@ -65,18 +65,18 @@ public class ConfigLanguage_p { prop.put("status", "0");//nothing List langFiles = FileUtils.getDirListing(langPath, LANG_FILENAME_FILTER); - if(langFiles == null){ + if (langFiles == null) { return prop; } - if (post != null){ - String selectedLanguage = post.get("language"); + if (post != null) { + final String selectedLanguage = post.get("language"); // store this call as api call ((Switchboard) env).tables.recordAPICall(post, "ConfigLanguage_p.html", WorkTables.TABLE_API_TYPE_CONFIGURATION, "language settings: " + selectedLanguage); //change language - if(post.containsKey("use_button") && selectedLanguage != null){ + if (post.containsKey("use_button") && selectedLanguage != null){ /* Only change language if filename is contained in list of filesnames * read from the language directory. This is very important to prevent * directory traversal attacks! @@ -86,7 +86,7 @@ public class ConfigLanguage_p { } //delete language file - }else if(post.containsKey("delete")){ + } else if (post.containsKey("delete")) { /* Only delete file if filename is contained in list of filesnames * read from the language directory. This is very important to prevent @@ -101,15 +101,15 @@ public class ConfigLanguage_p { } else if (post.containsKey("url")){ final String url = post.get("url"); Iterator it; - try{ + try { final DigestURI u = new DigestURI(url); it = FileUtils.strings(u.get(MultiProtocolURI.yacybotUserAgent, 10000)); - }catch(final IOException e){ + } catch(final IOException e) { prop.put("status", "1");//unable to get url prop.put("status_url", url); return prop; } - try{ + try { final File langFile = new File(langPath, url.substring(url.lastIndexOf('/'), url.length())); final BufferedWriter bw = new BufferedWriter(new PrintWriter(new FileWriter(langFile))); @@ -117,21 +117,20 @@ public class ConfigLanguage_p { bw.write(it.next() + "\n"); } bw.close(); - }catch(final IOException e){ + } catch(final IOException e) { prop.put("status", "2");//error saving the language file return prop; } - if(post.containsKey("use_lang") && (post.get("use_lang")).equals("on")){ + if (post.containsKey("use_lang") && "on".equals(post.get("use_lang"))) { Translator.changeLang(env, langPath, url.substring(url.lastIndexOf('/'), url.length())); } } } - //reread language files + //re-read language files langFiles = FileUtils.getDirListing(langPath, LANG_FILENAME_FILTER); Collections.sort(langFiles); final Map langNames = Translator.langMap(env); - String langKey, langName; //virtual entry prop.put("langlist_0_file", "default"); @@ -139,12 +138,13 @@ public class ConfigLanguage_p { prop.put("langlist_0_selected", "selected=\"selected\""); int count = 0; - for(final String langFile : langFiles){ + for (final String langFile : langFiles) { //+1 because of the virtual entry "default" at top - langKey = langFile.substring(0, langFile.length() -4); - langName = langNames.get(langKey); + final String langKey = langFile.substring(0, langFile.length() -4); + final String langName = langNames.get(langKey); prop.put("langlist_" + (count + 1) + "_file", langFile); prop.put("langlist_" + (count + 1) + "_name", ((langName == null) ? langKey : langName)); + if(env.getConfig("locale.language", "default").equals(langKey)) { prop.put("langlist_" + (count + 1) + "_selected", "selected=\"selected\""); prop.put("langlist_0_selected", " "); // reset Default diff --git a/htroot/ConfigNetwork_p.java b/htroot/ConfigNetwork_p.java index 8eee35d27..816f15d3b 100644 --- a/htroot/ConfigNetwork_p.java +++ b/htroot/ConfigNetwork_p.java @@ -26,7 +26,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import java.io.File; -import java.util.HashSet; +import java.util.Set; import net.yacy.cora.protocol.RequestHeader; import net.yacy.kelondro.util.FileUtils; @@ -49,8 +49,7 @@ public class ConfigNetwork_p { // load all options for network definitions final File networkBootstrapLocationsFile = new File(new File(sb.getAppPath(), "defaults"), "yacy.networks"); - final HashSet networkBootstrapLocations = FileUtils.loadList(networkBootstrapLocationsFile); - + final Set networkBootstrapLocations = FileUtils.loadList(networkBootstrapLocationsFile); if (post != null) { @@ -76,9 +75,9 @@ public class ConfigNetwork_p { if (post.containsKey("save")) { // DHT control - boolean indexDistribute = post.get("indexDistribute", "").equals("on"); - boolean indexReceive = post.get("indexReceive", "").equals("on"); - final boolean robinsonmode = post.get("network", "").equals("robinson"); + boolean indexDistribute = "on".equals(post.get("indexDistribute", "")); + boolean indexReceive = "on".equals(post.get("indexReceive", "")); + final boolean robinsonmode = "robinson".equals(post.get("network", "")); if (robinsonmode) { indexDistribute = false; indexReceive = false; @@ -90,7 +89,9 @@ public class ConfigNetwork_p { } else if (indexDistribute && indexReceive) { commit = 1; } else { - if (!indexReceive) prop.put("commitDHTNoGlobalSearch", "1"); + if (!indexReceive) { + prop.put("commitDHTNoGlobalSearch", "1"); + } commit = 1; } } @@ -101,13 +102,13 @@ public class ConfigNetwork_p { sb.setConfig(SwitchboardConstants.INDEX_DIST_ALLOW, false); } - if (post.get("indexDistributeWhileCrawling","").equals("on")) { + if ("on".equals(post.get("indexDistributeWhileCrawling",""))) { sb.setConfig(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_CRAWLING, true); } else { sb.setConfig(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_CRAWLING, false); } - if (post.get("indexDistributeWhileIndexing","").equals("on")) { + if ("on".equals(post.get("indexDistributeWhileIndexing",""))) { sb.setConfig(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_INDEXING, true); } else { sb.setConfig(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_INDEXING, false); @@ -122,7 +123,7 @@ public class ConfigNetwork_p { sb.setConfig(SwitchboardConstants.INDEX_RECEIVE_AUTODISABLED, false); } - if (post.get("indexReceiveBlockBlacklist", "").equals("on")) { + if ("on".equals(post.get("indexReceiveBlockBlacklist", ""))) { sb.setConfig("indexReceiveBlockBlacklist", true); } else { sb.setConfig("indexReceiveBlockBlacklist", false); @@ -153,16 +154,16 @@ public class ConfigNetwork_p { final int RTCppm = (int) (60000L / RTCbusySleep); prop.put("acceptCrawlLimit", RTCppm); - final boolean indexDistribute = sb.getConfig(SwitchboardConstants.INDEX_DIST_ALLOW, "true").equals("true"); - final boolean indexReceive = sb.getConfig(SwitchboardConstants.INDEX_RECEIVE_ALLOW, "true").equals("true"); + final boolean indexDistribute = "true".equals(sb.getConfig(SwitchboardConstants.INDEX_DIST_ALLOW, "true")); + final boolean indexReceive = "true".equals(sb.getConfig(SwitchboardConstants.INDEX_RECEIVE_ALLOW, "true")); prop.put("indexDistributeChecked", (indexDistribute) ? "1" : "0"); - prop.put("indexDistributeWhileCrawling.on", (sb.getConfig(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_CRAWLING, "true").equals("true")) ? "1" : "0"); - prop.put("indexDistributeWhileCrawling.off", (sb.getConfig(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_CRAWLING, "true").equals("true")) ? "0" : "1"); - prop.put("indexDistributeWhileIndexing.on", (sb.getConfig(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_INDEXING, "true").equals("true")) ? "1" : "0"); - prop.put("indexDistributeWhileIndexing.off", (sb.getConfig(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_INDEXING, "true").equals("true")) ? "0" : "1"); + prop.put("indexDistributeWhileCrawling.on", ("true".equals(sb.getConfig(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_CRAWLING, "true"))) ? "1" : "0"); + prop.put("indexDistributeWhileCrawling.off", ("true".equals(sb.getConfig(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_CRAWLING, "true"))) ? "0" : "1"); + prop.put("indexDistributeWhileIndexing.on", ("true".equals(sb.getConfig(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_INDEXING, "true"))) ? "1" : "0"); + prop.put("indexDistributeWhileIndexing.off", ("true".equals(sb.getConfig(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_INDEXING, "true"))) ? "0" : "1"); prop.put("indexReceiveChecked", (indexReceive) ? "1" : "0"); - prop.put("indexReceiveBlockBlacklistChecked.on", (sb.getConfig("indexReceiveBlockBlacklist", "true").equals("true")) ? "1" : "0"); - prop.put("indexReceiveBlockBlacklistChecked.off", (sb.getConfig("indexReceiveBlockBlacklist", "true").equals("true")) ? "0" : "1"); + prop.put("indexReceiveBlockBlacklistChecked.on", ("true".equals(sb.getConfig("indexReceiveBlockBlacklist", "true"))) ? "1" : "0"); + prop.put("indexReceiveBlockBlacklistChecked.off", ("true".equals(sb.getConfig("indexReceiveBlockBlacklist", "true"))) ? "0" : "1"); prop.putHTML("peertags", MapTools.set2string(sb.peers.mySeed().getPeerTags(), ",", false)); // set seed information directly @@ -174,16 +175,21 @@ public class ConfigNetwork_p { prop.put("robinson.checked", (indexDistribute || indexReceive) ? "0" : "1"); prop.putHTML("cluster.peers.ipport", sb.getConfig("cluster.peers.ipport", "")); prop.putHTML("cluster.peers.yacydomain", sb.getConfig("cluster.peers.yacydomain", "")); - String hashes = ""; - for (byte[] h:sb.clusterhashes.keySet()) hashes += ", " + new String(h); - if (hashes.length() > 2) hashes = hashes.substring(2); - prop.put("cluster.peers.yacydomain.hashes", hashes); + StringBuilder hashes = new StringBuilder(); + for (final byte[] h : sb.clusterhashes.keySet()) { + hashes.append(", ").append(new String(h)); + } + if (hashes.length() > 2) { + hashes = hashes.delete(0, 2); + } + + prop.put("cluster.peers.yacydomain.hashes", hashes.toString()); // set p2p mode flags - prop.put("privatepeerChecked", (sb.getConfig("cluster.mode", "").equals("privatepeer")) ? "1" : "0"); - prop.put("privateclusterChecked", (sb.getConfig("cluster.mode", "").equals("privatecluster")) ? "1" : "0"); - prop.put("publicclusterChecked", (sb.getConfig("cluster.mode", "").equals("publiccluster")) ? "1" : "0"); - prop.put("publicpeerChecked", (sb.getConfig("cluster.mode", "").equals("publicpeer")) ? "1" : "0"); + prop.put("privatepeerChecked", ("privatepeer".equals(sb.getConfig("cluster.mode", ""))) ? "1" : "0"); + prop.put("privateclusterChecked", ("privatecluster".equals(sb.getConfig("cluster.mode", ""))) ? "1" : "0"); + prop.put("publicclusterChecked", ("publiccluster".equals(sb.getConfig("cluster.mode", ""))) ? "1" : "0"); + prop.put("publicpeerChecked", ("publicpeer".equals(sb.getConfig("cluster.mode", ""))) ? "1" : "0"); // set network configuration prop.putHTML("network.unit.definition", sb.getConfig("network.unit.definition", "")); @@ -193,7 +199,9 @@ public class ConfigNetwork_p { prop.putHTML("network.unit.dht", sb.getConfig("network.unit.dht", "")); networkBootstrapLocations.remove(sb.getConfig("network.unit.definition", "")); int c = 0; - for (final String s: networkBootstrapLocations) prop.put("networks_" + c++ + "_network", s); + for (final String s: networkBootstrapLocations) { + prop.put("networks_" + c++ + "_network", s); + } prop.put("networks", c); return prop; @@ -203,31 +211,42 @@ public class ConfigNetwork_p { input = input.replace(' ', ','); input = input.replace(' ', ';'); input = input.replaceAll(",,", ","); - if (input.length() > 0 && input.charAt(0) == ',') input = input.substring(1); - if (input.endsWith(",")) input = input.substring(0, input.length() - 1); + if (input.length() > 0 && input.charAt(0) == ',') { + input = input.substring(1); + } + if (input.endsWith(",")) { + input = input.substring(0, input.length() - 1); + } return input; } - private static String checkYaCyDomainList(String input) { - input = normalizedList(input); - final String[] s = input.split(","); - input = ""; - for (int i = 0; i < s.length; i++) { - if ((s[i].endsWith(".yacyh")) || (s[i].endsWith(".yacy")) || - (s[i].indexOf(".yacyh=") > 0) || (s[i].indexOf(".yacy=") > 0)) input += "," + s[i]; + private static String checkYaCyDomainList(final String input) { + final String[] array = normalizedList(input).split(","); + final StringBuilder output = new StringBuilder(); + for (final String element : array) { + if ((element.endsWith(".yacyh")) || (element.endsWith(".yacy")) || + (element.indexOf(".yacyh=") > 0) || (element.indexOf(".yacy=") > 0)) { + output.append(",").append(element); + } + } + + if (output.length() == 0) { + return input; } - if (input.length() == 0) return input; - return input.substring(1); + return output.delete(0, 1).toString(); } - private static String checkIPPortList(String input) { - input = normalizedList(input); - final String[] s = input.split(","); - input = ""; - for (int i = 0; i < s.length; i++) { - if (s[i].indexOf(':') >= 9) input += "," + s[i]; + private static String checkIPPortList(final String input) { + final String[] array = normalizedList(input).split(","); + StringBuilder output = new StringBuilder(); + for (final String element :array) { + if (element.indexOf(':') >= 9) { + output.append(",").append(element); + } + } + if (input.length() == 0) { + return input; } - if (input.length() == 0) return input; - return input.substring(1); + return output.delete(0, 1).toString(); } } diff --git a/htroot/ConfigParser.java b/htroot/ConfigParser.java index 633944e0b..0f824a8b4 100644 --- a/htroot/ConfigParser.java +++ b/htroot/ConfigParser.java @@ -52,9 +52,9 @@ public class ConfigParser { if (post.containsKey("parserSettings")) { post.remove("parserSettings"); - for (Parser parser: TextParser.parsers()) { - for (String mimeType: parser.supportedMimeTypes()) { - TextParser.grantMime(mimeType, post.get("mimename_" + mimeType, "").equals("on")); + for (final Parser parser: TextParser.parsers()) { + for (final String mimeType: parser.supportedMimeTypes()) { + TextParser.grantMime(mimeType, "on".equals(post.get("mimename_" + mimeType, ""))); } } env.setConfig(SwitchboardConstants.PARSER_MIME_DENY, TextParser.getDenyMime()); @@ -62,11 +62,11 @@ public class ConfigParser { } int i = 0; - for (Parser parser: TextParser.parsers()) { + for (final Parser parser: TextParser.parsers()) { prop.put("parser_" + i + "_name", parser.getName()); int mimeIdx = 0; - for (String mimeType: parser.supportedMimeTypes()) { + for (final String mimeType: parser.supportedMimeTypes()) { prop.put("parser_" + i + "_mime_" + mimeIdx + "_mimetype", mimeType); prop.put("parser_" + i + "_mime_" + mimeIdx + "_status", (TextParser.supportsMime(mimeType) == null) ? 1 : 0); mimeIdx++; diff --git a/htroot/ConfigPortal.java b/htroot/ConfigPortal.java index 524fc7628..f7e51b216 100644 --- a/htroot/ConfigPortal.java +++ b/htroot/ConfigPortal.java @@ -46,19 +46,19 @@ public class ConfigPortal { } if (post.containsKey("popup")) { - String popup = post.get("popup", "status"); - if (popup.equals("front")) { + final String popup = post.get("popup", "status"); + if ("front".equals(popup)) { sb.setConfig(SwitchboardConstants.BROWSER_POP_UP_PAGE, "index.html?display=2"); - } else if (popup.equals("search")) { + } else if ("search".equals(popup)) { sb.setConfig(SwitchboardConstants.BROWSER_POP_UP_PAGE, "yacysearch.html?display=2"); - } else if (popup.equals("interactive")) { + } else if ("interactive".equals(popup)) { sb.setConfig(SwitchboardConstants.BROWSER_POP_UP_PAGE, "yacyinteractive.html?display=2"); } else { sb.setConfig(SwitchboardConstants.BROWSER_POP_UP_PAGE, "Status.html"); } } if (post.containsKey("searchpage_set")) { - String newGreeting = post.get(SwitchboardConstants.GREETING, ""); + final String newGreeting = post.get(SwitchboardConstants.GREETING, ""); // store this call as api call sb.tables.recordAPICall(post, "ConfigPortal.html", WorkTables.TABLE_API_TYPE_CONFIGURATION, "new portal design. greeting: " + newGreeting); @@ -97,15 +97,18 @@ public class ConfigPortal { } else { prop.put("popupStatus", 1); } - String target = sb.getConfig(SwitchboardConstants.SEARCH_TARGET, "_self"); - prop.put("selected_blank", target.equals("_blank") ? 1 : 0); - prop.put("selected_self", target.equals("_self") ? 1 : 0); - prop.put("selected_parent", target.equals("_parent") ? 1 : 0); - prop.put("selected_top", target.equals("_top") ? 1 : 0); - prop.put("selected_searchresult", target.equals("searchresult") ? 1 : 0); + + final String target = sb.getConfig(SwitchboardConstants.SEARCH_TARGET, "_self"); + prop.put("selected_blank", "_blank".equals(target) ? 1 : 0); + prop.put("selected_self", "_self".equals(target) ? 1 : 0); + prop.put("selected_parent", "_parent".equals(target) ? 1 : 0); + prop.put("selected_top", "_top".equals(target) ? 1 : 0); + prop.put("selected_searchresult", "searchresult".equals(target) ? 1 : 0); String myaddress = sb.peers.mySeed().getPublicAddress(); - if (myaddress == null) myaddress = "localhost:" + sb.getConfig("port", "8080"); + if (myaddress == null) { + myaddress = "localhost:" + sb.getConfig("port", "8080"); + } prop.put("myaddress", myaddress); return prop; } diff --git a/htroot/ConfigProperties_p.java b/htroot/ConfigProperties_p.java index 6df9f1449..e5b79483f 100644 --- a/htroot/ConfigProperties_p.java +++ b/htroot/ConfigProperties_p.java @@ -50,18 +50,20 @@ public class ConfigProperties_p { if(post != null && post.containsKey("key") && post.containsKey("value")){ key = post.get("key"); final String value = post.get("value"); - if (!key.equals("")) { + if (!"".equals(key)) { env.setConfig(key, value); } } Iterator keys = env.configKeys(); final List list = new ArrayList(250); + while(keys.hasNext()){ list.add(keys.next()); } Collections.sort(list); + keys = list.iterator(); while(keys.hasNext()){ key = keys.next(); diff --git a/htroot/ConfigUpdate_p.java b/htroot/ConfigUpdate_p.java index fa8392a1c..03aa9c018 100644 --- a/htroot/ConfigUpdate_p.java +++ b/htroot/ConfigUpdate_p.java @@ -27,6 +27,7 @@ import java.io.File; import java.io.IOException; import java.util.Date; +import java.util.Set; import java.util.TreeSet; import net.yacy.cora.protocol.RequestHeader; @@ -85,9 +86,9 @@ public class ConfigUpdate_p { // replace this version with version which contains public key yacyRelease.DevAndMainVersions allReleases = yacyRelease.allReleases(false, false); - TreeSet mostReleases = versionToDownload.isMainRelease() ? allReleases.main : allReleases.dev; - for(yacyRelease rel : mostReleases) { - if(rel.equals(versionToDownload)) { + final Set mostReleases = versionToDownload.isMainRelease() ? allReleases.main : allReleases.dev; + for (final yacyRelease rel : mostReleases) { + if (rel.equals(versionToDownload)) { versionToDownload = rel; break; } @@ -103,9 +104,10 @@ public class ConfigUpdate_p { if (post.containsKey("checkRelease")) { yacyRelease.allReleases(true, false); } + if (post.containsKey("deleteRelease")) { final String release = post.get("releaseinstall", ""); - if(release.length() > 0) { + if (release.length() > 0) { try { FileUtils.deletedelete(new File(sb.releasePath, release)); FileUtils.deletedelete(new File(sb.releasePath, release + ".sig")); @@ -142,11 +144,11 @@ public class ConfigUpdate_p { if (post.containsKey("configSubmit")) { prop.put("candeploy_configCommit", "1"); - sb.setConfig("update.process", (post.get("updateMode", "manual").equals("manual")) ? "manual" : "auto"); + sb.setConfig("update.process", ("manual".equals(post.get("updateMode", "manual"))) ? "manual" : "auto"); sb.setConfig("update.cycle", Math.max(12, post.getLong("cycle", 168))); sb.setConfig("update.blacklist", post.get("blacklist", "")); - sb.setConfig("update.concept", (post.get("releaseType", "any").equals("any")) ? "any" : "main"); - sb.setConfig("update.onlySignedFiles", (post.get("onlySignedFiles", "false").equals("true")) ? "1" : "0"); + sb.setConfig("update.concept", ("any".equals(post.get("releaseType", "any"))) ? "any" : "main"); + sb.setConfig("update.onlySignedFiles", ("true".equals(post.get("onlySignedFiles", "false"))) ? "1" : "0"); } } @@ -156,7 +158,9 @@ public class ConfigUpdate_p { final boolean devenvironment = new File(sb.getAppPath(), ".svn").exists(); double thisVersion = Double.parseDouble(yacyBuildProperties.getVersion()); // cut off the SVN Rev in the Version - try {thisVersion = Math.round(thisVersion*1000.0)/1000.0;} catch (final NumberFormatException e) {} + try { + thisVersion = Math.round(thisVersion*1000.0)/1000.0; + } catch (final NumberFormatException e) {} // list downloaded releases @@ -165,7 +169,7 @@ public class ConfigUpdate_p { prop.put("candeploy_deployenabled", (downloadedFiles.length == 0) ? "0" : ((devenvironment) ? "1" : "2")); // prevent that a developer-version is over-deployed final TreeSet downloadedReleases = new TreeSet(); - for(File downloaded : downloadedFiles) { + for (final File downloaded : downloadedFiles) { try { yacyRelease release = new yacyRelease(downloaded); downloadedReleases.add(release); @@ -173,8 +177,9 @@ public class ConfigUpdate_p { // not a valid release // can be also a restart- or deploy-file final File invalid = downloaded; - if (!(invalid.getName().endsWith(".bat") || invalid.getName().endsWith(".sh"))) // Windows & Linux don't like deleted scripts while execution! - invalid.deleteOnExit(); + if (!(invalid.getName().endsWith(".bat") || invalid.getName().endsWith(".sh"))) { // Windows & Linux don't like deleted scripts while execution! + invalid.deleteOnExit(); + } } } // latest downloaded release @@ -184,7 +189,7 @@ public class ConfigUpdate_p { prop.put("candeploy_deployenabled_buttonsActive", (downloadedReleases.isEmpty() || devenvironment) ? "0" : "1"); int relcount = 0; - for(yacyRelease release : downloadedReleases) { + for(final yacyRelease release : downloadedReleases) { prop.put("candeploy_downloadedreleases_" + relcount + "_name", ((release.isMainRelease()) ? "main" : "dev") + " " + release.getReleaseNr() + "/" + release.getSvn()); prop.put("candeploy_downloadedreleases_" + relcount + "_signature", (release.getSignatureFile().exists() ? "1" : "0")); prop.putHTML("candeploy_downloadedreleases_" + relcount + "_file", release.getName()); @@ -198,9 +203,9 @@ public class ConfigUpdate_p { relcount = 0; // main - final TreeSet remoteMainReleases = releasess.main; + final Set remoteMainReleases = releasess.main; remoteMainReleases.removeAll(downloadedReleases); - for (yacyRelease release : remoteMainReleases) { + for (final yacyRelease release : remoteMainReleases) { prop.put("candeploy_availreleases_" + relcount + "_name", ((release.isMainRelease()) ? "main" : "dev") + " " + release.getReleaseNr() + "/" + release.getSvn()); prop.put("candeploy_availreleases_" + relcount + "_url", release.getUrl().toString()); prop.put("candeploy_availreleases_" + relcount + "_signatures", (release.getPublicKey()!=null?"1":"0")); @@ -210,9 +215,9 @@ public class ConfigUpdate_p { // dev dflt = (releasess.dev.isEmpty()) ? null : releasess.dev.last(); - final TreeSet remoteDevReleases = releasess.dev; + final Set remoteDevReleases = releasess.dev; remoteDevReleases.removeAll(downloadedReleases); - for(yacyRelease release : remoteDevReleases) { + for (final yacyRelease release : remoteDevReleases) { prop.put("candeploy_availreleases_" + relcount + "_name", ((release.isMainRelease()) ? "main" : "dev") + " " + release.getReleaseNr() + "/" + release.getSvn()); prop.put("candeploy_availreleases_" + relcount + "_url", release.getUrl().toString()); prop.put("candeploy_availreleases_" + relcount + "_signatures", (release.getPublicKey()!=null?"1":"0")); @@ -222,19 +227,19 @@ public class ConfigUpdate_p { prop.put("candeploy_availreleases", relcount); // properties for automated system update - prop.put("candeploy_manualUpdateChecked", (sb.getConfig("update.process", "manual").equals("manual")) ? "1" : "0"); - prop.put("candeploy_autoUpdateChecked", (sb.getConfig("update.process", "manual").equals("auto")) ? "1" : "0"); + prop.put("candeploy_manualUpdateChecked", ("manual".equals(sb.getConfig("update.process", "manual"))) ? "1" : "0"); + prop.put("candeploy_autoUpdateChecked", ("auto".equals(sb.getConfig("update.process", "manual"))) ? "1" : "0"); prop.put("candeploy_cycle", sb.getConfigLong("update.cycle", 168)); prop.putHTML("candeploy_blacklist", sb.getConfig("update.blacklist", "")); - prop.put("candeploy_releaseTypeMainChecked", (sb.getConfig("update.concept", "any").equals("any")) ? "0" : "1"); - prop.put("candeploy_releaseTypeAnyChecked", (sb.getConfig("update.concept", "any").equals("any")) ? "1" : "0"); + prop.put("candeploy_releaseTypeMainChecked", ("any".equals(sb.getConfig("update.concept", "any"))) ? "0" : "1"); + prop.put("candeploy_releaseTypeAnyChecked", ("any".equals(sb.getConfig("update.concept", "any"))) ? "1" : "0"); prop.put("candeploy_lastlookup", (sb.getConfigLong("update.time.lookup", 0) == 0) ? "0" : "1"); prop.put("candeploy_lastlookup_time", new Date(sb.getConfigLong("update.time.lookup", 0)).toString()); prop.put("candeploy_lastdownload", (sb.getConfigLong("update.time.download", 0) == 0) ? "0" : "1"); prop.put("candeploy_lastdownload_time", new Date(sb.getConfigLong("update.time.download", 0)).toString()); prop.put("candeploy_lastdeploy", (sb.getConfigLong("update.time.deploy", 0) == 0) ? "0" : "1"); prop.put("candeploy_lastdeploy_time", new Date(sb.getConfigLong("update.time.deploy", 0)).toString()); - prop.put("candeploy_onlySignedFiles", (sb.getConfig("update.onlySignedFiles", "1").equals("1")) ? "1" : "0"); + prop.put("candeploy_onlySignedFiles", ("1".equals(sb.getConfig("update.onlySignedFiles", "1"))) ? "1" : "0"); /* if ((adminaccess) && (yacyVersion.latestRelease >= (thisVersion+0.01))) { // only new Versions(not new SVN) diff --git a/htroot/Connections_p.java b/htroot/Connections_p.java index dd0d44bc1..f07419bb1 100644 --- a/htroot/Connections_p.java +++ b/htroot/Connections_p.java @@ -64,58 +64,60 @@ public final class Connections_p { final WorkflowThread httpd = sb.getThread("10_httpd"); // determines if name lookup should be done or not - boolean doNameLookup = false; + final boolean doNameLookup; if (post != null) { - if (post.containsKey("nameLookup") && post.get("nameLookup","true").equals("true")) { - doNameLookup = true; - } + doNameLookup = (post.containsKey("nameLookup") && "true".equals(post.get("nameLookup","true"))); if (post.containsKey("closeServerSession")) { final String sessionName = post.get("closeServerSession", null); sb.closeSessions("10_httpd", sessionName); prop.put("LOCATION",""); return prop; } - } + } else { + doNameLookup = false; + } // waiting for all threads to finish int idx = 0, numActiveRunning = 0, numActivePending = 0; boolean dark = true; - for (Session s: ((serverCore) httpd).getJobList()) { + for (final Session s: ((serverCore) httpd).getJobList()) { if (!s.isAlive()) continue; // get the session runtime final long sessionTime = s.getTime(); // get the request command line - boolean blockingRequest = false; String commandLine = s.getCommandLine(); - if (commandLine == null) blockingRequest = true; + final boolean blockingRequest = (commandLine == null);; final int commandCount = s.getCommandCount(); // get the source ip address and port final InetAddress userAddress = s.getUserAddress(); final int userPort = s.getUserPort(); - if (userAddress == null) continue; + if (userAddress == null) { + continue; + } String dest = null; String prot = "http"; // only httpd sessions listed - - if ((dest != null) && (dest.equals(virtualHost))) dest = sb.peers.mySeed().getName() + ".yacy"; + + // What is the purpose of the following lines? Condition can never be true anyway. [MN wonders...] + if ((dest != null) && (dest.equals(virtualHost))) { + dest = sb.peers.mySeed().getName() + ".yacy"; + } // determining if the source is a yacy host yacySeed seed = null; if (doNameLookup) { seed = sb.peers.lookupByIP(userAddress,true,false,false); - if (seed != null) { - if ((seed.hash.equals(sb.peers.mySeed().hash)) && - (!seed.get(yacySeed.PORT,"").equals(Integer.toString(userPort)))) { - seed = null; - } + if (seed != null && (seed.hash.equals(sb.peers.mySeed().hash)) && + (!seed.get(yacySeed.PORT,"").equals(Integer.toString(userPort)))) { + seed = null; } } prop.put("list_" + idx + "_dark", dark ? "1" : "0"); - dark=!dark; + dark = !dark; try { prop.put("list_" + idx + "_serverSessionID",URLEncoder.encode(s.getName(),"UTF8")); } catch (final UnsupportedEncodingException e) { diff --git a/htroot/CookieTest_p.java b/htroot/CookieTest_p.java index 4c717a9f2..4fd015ee2 100644 --- a/htroot/CookieTest_p.java +++ b/htroot/CookieTest_p.java @@ -1,4 +1,4 @@ -// index.java +// CookieTest_p.java // ----------------------- // part of the AnomicHTTPD caching proxy // (C) by Michael Peter Christen; mc@yacy.net @@ -50,43 +50,37 @@ public class CookieTest_p { } final servletProperties prop = new servletProperties(); - if(post.containsKey("act")&&post.get("act").equals("clear_cookie")) { + if (post.containsKey("act") && "clear_cookie".equals(post.get("act"))) { final ResponseHeader outgoingHeader = new ResponseHeader(); - final Iterator> it = header.entrySet().iterator(); - Map.Entry e; - while (it.hasNext()) { - e = it.next(); - if (e.getKey().equals("Cookie")) { - final String coockie[]=e.getValue().split(";"); - for(int i=0;i1?(nameValue[1].trim()):"","Thu, 01-Jan-99 00:00:01 GMT"); - } - } - - - - } + final Iterator> it = header.entrySet().iterator(); + Map.Entry e; + while (it.hasNext()) { + e = it.next(); + if (e.getKey().equals("Cookie")) { + final String cookies[] = e.getValue().split(";"); + for(final String cookie : cookies) + { + final String nameValue[] = cookie.split("="); + outgoingHeader.setCookie(nameValue[0].trim(),nameValue.length>1 ? (nameValue[1].trim()) : "","Thu, 01-Jan-99 00:00:01 GMT"); + } + } + } - prop.setOutgoingHeader(outgoingHeader); - prop.put("coockiesout", "0"); - //header. + prop.setOutgoingHeader(outgoingHeader); + prop.put("coockiesout", "0"); + //header. - } - else if(post.containsKey("act")&&post.get("act").equals("set_cookie")) - { - final String cookieName = post.get("cookie_name").trim(); - final String cookieValue = post.get("cookie_value").trim(); - final ResponseHeader outgoingHeader=new ResponseHeader(); - - outgoingHeader.setCookie(cookieName,cookieValue); - prop.setOutgoingHeader(outgoingHeader); - prop.put("cookiesin", "1"); - prop.putHTML("cookiesin_0_name", cookieName); - prop.putHTML("cookiesin_0_value", cookieValue); - //header. - + } else if (post.containsKey("act") && post.get("act").equals("set_cookie")) { + final String cookieName = post.get("cookie_name").trim(); + final String cookieValue = post.get("cookie_value").trim(); + final ResponseHeader outgoingHeader = new ResponseHeader(); + + outgoingHeader.setCookie(cookieName,cookieValue); + prop.setOutgoingHeader(outgoingHeader); + prop.put("cookiesin", "1"); + prop.putHTML("cookiesin_0_name", cookieName); + prop.putHTML("cookiesin_0_value", cookieValue); + //header. } prop.put("cookiesout", "1"); diff --git a/htroot/CrawlMonitorRemoteStart.java b/htroot/CrawlMonitorRemoteStart.java index 5bf30cc5f..3f9506975 100644 --- a/htroot/CrawlMonitorRemoteStart.java +++ b/htroot/CrawlMonitorRemoteStart.java @@ -39,8 +39,8 @@ public class CrawlMonitorRemoteStart { public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { // return variable that accumulates replacements - Switchboard sb = (Switchboard) env; - serverObjects prop = new serverObjects(); + final Switchboard sb = (Switchboard) env; + final serverObjects prop = new serverObjects(); boolean dark = true; @@ -52,19 +52,24 @@ public class CrawlMonitorRemoteStart { String peername; while (recordIterator.hasNext()) { record = recordIterator.next(); - if (record == null) continue; + if (record == null) { + continue; + } if (record.category().equals(yacyNewsPool.CATEGORY_CRAWL_START)) { peer = sb.peers.get(record.originator()); - if (peer == null) peername = record.originator(); else peername = peer.getName(); + peername = (peer == null) ? record.originator() : peer.getName(); + prop.put("otherCrawlStartInProgress_" + showedCrawl + "_dark", dark ? "1" : "0"); prop.put("otherCrawlStartInProgress_" + showedCrawl + "_cre", record.created().toString()); prop.put("otherCrawlStartInProgress_" + showedCrawl + "_peername", peername); prop.put("otherCrawlStartInProgress_" + showedCrawl + "_startURL", record.attributes().get("startURL").toString()); prop.put("otherCrawlStartInProgress_" + showedCrawl + "_intention", record.attributes().get("intention").toString()); prop.put("otherCrawlStartInProgress_" + showedCrawl + "_generalDepth", record.attributes().get("generalDepth")); - prop.put("otherCrawlStartInProgress_" + showedCrawl + "_crawlingQ", (record.attributes().get("crawlingQ").equals("true")) ? "1" : "0"); + prop.put("otherCrawlStartInProgress_" + showedCrawl + "_crawlingQ", ("true".equals(record.attributes().get("crawlingQ"))) ? "1" : "0"); showedCrawl++; - if (showedCrawl > 20) break; + if (showedCrawl > 20) { + break; + } } } prop.put("otherCrawlStartInProgress", showedCrawl); @@ -74,17 +79,20 @@ public class CrawlMonitorRemoteStart { showedCrawl = 0; while (recordIterator.hasNext()) { record = recordIterator.next(); - if (record == null) continue; + if (record == null) { + continue; + } if (record.category().equals(yacyNewsPool.CATEGORY_CRAWL_START)) { peer = sb.peers.get(record.originator()); - if (peer == null) peername = record.originator(); else peername = peer.getName(); + peername = (peer == null) ? record.originator() : peer.getName(); + prop.put("otherCrawlStartFinished_" + showedCrawl + "_dark", dark ? "1" : "0"); prop.put("otherCrawlStartFinished_" + showedCrawl + "_cre", record.created().toString()); prop.putHTML("otherCrawlStartFinished_" + showedCrawl + "_peername", peername); prop.putHTML("otherCrawlStartFinished_" + showedCrawl + "_startURL", record.attributes().get("startURL").toString()); prop.put("otherCrawlStartFinished_" + showedCrawl + "_intention", record.attributes().get("intention").toString()); prop.put("otherCrawlStartFinished_" + showedCrawl + "_generalDepth", record.attributes().get("generalDepth")); - prop.put("otherCrawlStartFinished_" + showedCrawl + "_crawlingQ", (record.attributes().get("crawlingQ").equals("true")) ? "1" : "0"); + prop.put("otherCrawlStartFinished_" + showedCrawl + "_crawlingQ", ("true".equals(record.attributes().get("crawlingQ"))) ? "1" : "0"); showedCrawl++; if (showedCrawl > 20) break; } diff --git a/htroot/CrawlProfileEditor_p.java b/htroot/CrawlProfileEditor_p.java index 1c3ef1c0b..ad6d83cd9 100644 --- a/htroot/CrawlProfileEditor_p.java +++ b/htroot/CrawlProfileEditor_p.java @@ -28,6 +28,7 @@ import java.text.DateFormat; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; @@ -79,7 +80,7 @@ public class CrawlProfileEditor_p { } } - private static final ArrayList labels = new ArrayList(); + private static final List labels = new ArrayList(); static { labels.add(new eentry(CrawlProfile.NAME, "Name", true, eentry.STRING)); labels.add(new eentry(CrawlProfile.START_URL, "Start URL", true, eentry.STRING)); @@ -120,7 +121,7 @@ public class CrawlProfileEditor_p { sb.crawler.profilesPassiveCrawls.remove(handle.getBytes()); } if (post.containsKey("deleteTerminatedProfiles")) { - for (byte[] h: sb.crawler.profilesPassiveCrawls.keySet()) { + for (final byte[] h: sb.crawler.profilesPassiveCrawls.keySet()) { sb.crawler.profilesPassiveCrawls.remove(h); } } @@ -128,15 +129,15 @@ public class CrawlProfileEditor_p { // generate handle list: first sort by handle name CrawlProfile selentry; - TreeMap orderdHandles = new TreeMap(); - for (byte[] h: sb.crawler.profilesActiveCrawls.keySet()) { + Map orderdHandles = new TreeMap(); + for (final byte[] h : sb.crawler.profilesActiveCrawls.keySet()) { selentry = new CrawlProfile(sb.crawler.profilesActiveCrawls.get(h)); if (ignoreNames.contains(selentry.name())) continue; orderdHandles.put(selentry.name(), selentry.handle()); } // then write into pop-up menu list int count = 0; - for (Map.Entry NameHandle: orderdHandles.entrySet()) { + for (final Map.Entry NameHandle: orderdHandles.entrySet()) { prop.put("profiles_" + count + "_name", NameHandle.getKey()); prop.put("profiles_" + count + "_handle", NameHandle.getValue()); if (handle.equals(NameHandle.getValue())) { @@ -146,7 +147,7 @@ public class CrawlProfileEditor_p { } prop.put("profiles", count); final Map mp = sb.crawler.profilesActiveCrawls.get(handle.getBytes()); - selentry = mp == null ? null : new CrawlProfile(mp); + selentry = (mp == null) ? null : new CrawlProfile(mp); assert selentry == null || selentry.handle() != null; // read post for change submit if ((post != null) && (selentry != null)) { @@ -177,7 +178,7 @@ public class CrawlProfileEditor_p { final int domlistlength = (post == null) ? 160 : post.getInt("domlistlength", 160); CrawlProfile profile; // put active crawls into list - for (byte[] h: sb.crawler.profilesActiveCrawls.keySet()) { + for (final byte[] h: sb.crawler.profilesActiveCrawls.keySet()) { profile = new CrawlProfile(sb.crawler.profilesActiveCrawls.get(h)); putProfileEntry(prop, profile, true, dark, count, domlistlength); dark = !dark; @@ -185,7 +186,7 @@ public class CrawlProfileEditor_p { } // put passive crawls into list boolean existPassiveCrawls = false; - for (byte[] h: sb.crawler.profilesPassiveCrawls.keySet()) { + for (final byte[] h: sb.crawler.profilesPassiveCrawls.keySet()) { profile = new CrawlProfile(sb.crawler.profilesPassiveCrawls.get(h)); putProfileEntry(prop, profile, false, dark, count, domlistlength); dark = !dark; @@ -193,13 +194,9 @@ public class CrawlProfileEditor_p { existPassiveCrawls = true; } prop.put("crawlProfiles", count); - - if (existPassiveCrawls) { - prop.put("existPassiveCrawls", "1"); - } else { - prop.put("existPassiveCrawls", "0"); - } - + + prop.put("existPassiveCrawls", existPassiveCrawls ? "1" : "0"); + // generate edit field if (selentry == null) { prop.put("edit", "0"); @@ -248,16 +245,15 @@ public class CrawlProfileEditor_p { // start contrib [MN] int i = 0; String item; - while ((i <= domlistlength) && !((item = profile.domName(true, i)).equals(""))){ - if(i == domlistlength){ + while (i <= domlistlength && !"".equals(item = profile.domName(true, i))){ + if (i == domlistlength) { item = item + " ..."; } - prop.putHTML(CRAWL_PROFILE_PREFIX+count+"_crawlingDomFilterContent_"+i+"_item", item); + prop.putHTML(CRAWL_PROFILE_PREFIX + count + "_crawlingDomFilterContent_" + i + "_item", item); i++; } prop.put(CRAWL_PROFILE_PREFIX+count+"_crawlingDomFilterContent", i); - // end contrib [MN] prop.put(CRAWL_PROFILE_PREFIX + count + "_crawlingDomMaxPages", (profile.domMaxPages() == Integer.MAX_VALUE) ? "unlimited" : Integer.toString(profile.domMaxPages())); prop.put(CRAWL_PROFILE_PREFIX + count + "_withQuery", (profile.crawlingQ()) ? "1" : "0"); diff --git a/htroot/Crawler_p.java b/htroot/Crawler_p.java index 0c21b272a..d114a3e15 100644 --- a/htroot/Crawler_p.java +++ b/htroot/Crawler_p.java @@ -102,9 +102,9 @@ public class Crawler_p { if (post != null && post.containsKey("continue")) { // continue queue final String queue = post.get("continue", ""); - if (queue.equals("localcrawler")) { + if ("localcrawler".equals(queue)) { sb.continueCrawlJob(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL); - } else if (queue.equals("remotecrawler")) { + } else if ("remotecrawler".equals(queue)) { sb.continueCrawlJob(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL); } } @@ -112,9 +112,9 @@ public class Crawler_p { if (post != null && post.containsKey("pause")) { // pause queue final String queue = post.get("pause", ""); - if (queue.equals("localcrawler")) { + if ("localcrawler".equals(queue)) { sb.pauseCrawlJob(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL); - } else if (queue.equals("remotecrawler")) { + } else if ("remotecrawler".equals(queue)) { sb.pauseCrawlJob(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL); } } @@ -135,8 +135,8 @@ public class Crawler_p { crawlingStart = (crawlingStartURL == null) ? null : crawlingStartURL.toNormalform(true, true); // set new properties - final boolean fullDomain = post.get("range", "wide").equals("domain"); // special property in simple crawl start - final boolean subPath = post.get("range", "wide").equals("subpath"); // special property in simple crawl start + final boolean fullDomain = "domain".equals(post.get("range", "wide")); // special property in simple crawl start + final boolean subPath = "subpath".equals(post.get("range", "wide")); // special property in simple crawl start // set the crawl filter String newcrawlingMustMatch = post.get("mustmatch", CrawlProfile.MATCH_ALL); @@ -165,21 +165,21 @@ public class Crawler_p { // recrawl final String recrawl = post.get("recrawl", "nodoubles"); // nodoubles, reload, scheduler - boolean crawlingIfOlderCheck = post.get("crawlingIfOlderCheck", "off").equals("on"); + boolean crawlingIfOlderCheck = "on".equals(post.get("crawlingIfOlderCheck", "off")); int crawlingIfOlderNumber = Integer.parseInt(post.get("crawlingIfOlderNumber", "-1")); String crawlingIfOlderUnit = post.get("crawlingIfOlderUnit","year"); // year, month, day, hour int repeat_time = Integer.parseInt(post.get("repeat_time", "-1")); final String repeat_unit = post.get("repeat_unit", "seldays"); // selminutes, selhours, seldays - if (recrawl.equals("scheduler") && repeat_time > 0) { + if ("scheduler".equals(recrawl) && repeat_time > 0) { // set crawlingIfOlder attributes that are appropriate for scheduled crawling crawlingIfOlderCheck = true; - crawlingIfOlderNumber = repeat_unit.equals("selminutes") ? 1 : repeat_unit.equals("selhours") ? repeat_time / 2 : repeat_time * 12; + crawlingIfOlderNumber = "selminutes".equals(repeat_unit) ? 1 : "selhours".equals(repeat_unit) ? repeat_time / 2 : repeat_time * 12; crawlingIfOlderUnit = "hour"; - } else if (recrawl.equals("reload")) { + } else if ("reload".equals(recrawl)) { repeat_time = -1; crawlingIfOlderCheck = true; - } else if (recrawl.equals("nodoubles")) { + } else if ("nodoubles".equals(recrawl)) { repeat_time = -1; crawlingIfOlderCheck = false; } @@ -195,37 +195,37 @@ public class Crawler_p { sb.tables.recordAPICall(post, "Crawler_p.html", WorkTables.TABLE_API_TYPE_CRAWLER, "crawl start for " + crawlingStart); } - final boolean crawlingDomMaxCheck = post.get("crawlingDomMaxCheck", "off").equals("on"); + final boolean crawlingDomMaxCheck = "on".equals(post.get("crawlingDomMaxCheck", "off")); final int crawlingDomMaxPages = (crawlingDomMaxCheck) ? Integer.parseInt(post.get("crawlingDomMaxPages", "-1")) : -1; env.setConfig("crawlingDomMaxPages", Integer.toString(crawlingDomMaxPages)); - final boolean crawlingQ = post.get("crawlingQ", "off").equals("on"); + final boolean crawlingQ = "on".equals(post.get("crawlingQ", "off")); env.setConfig("crawlingQ", (crawlingQ) ? "true" : "false"); - final boolean indexText = post.get("indexText", "off").equals("on"); + final boolean indexText = "on".equals(post.get("indexText", "off")); env.setConfig("indexText", (indexText) ? "true" : "false"); - final boolean indexMedia = post.get("indexMedia", "off").equals("on"); + final boolean indexMedia = "on".equals(post.get("indexMedia", "off")); env.setConfig("indexMedia", (indexMedia) ? "true" : "false"); - boolean storeHTCache = post.get("storeHTCache", "off").equals("on"); + boolean storeHTCache = "on".equals(post.get("storeHTCache", "off")); if (crawlingStartURL!= null &&(crawlingStartURL.isFile() || crawlingStartURL.isSMB())) storeHTCache = false; env.setConfig("storeHTCache", (storeHTCache) ? "true" : "false"); CrawlProfile.CacheStrategy cachePolicy = CrawlProfile.CacheStrategy.parse(post.get("cachePolicy", "iffresh")); if (cachePolicy == null) cachePolicy = CrawlProfile.CacheStrategy.IFFRESH; - final boolean xsstopw = post.get("xsstopw", "off").equals("on"); + final boolean xsstopw = "on".equals(post.get("xsstopw", "off")); env.setConfig("xsstopw", (xsstopw) ? "true" : "false"); - final boolean xdstopw = post.get("xdstopw", "off").equals("on"); + final boolean xdstopw = "on".equals(post.get("xdstopw", "off")); env.setConfig("xdstopw", (xdstopw) ? "true" : "false"); - final boolean xpstopw = post.get("xpstopw", "off").equals("on"); + final boolean xpstopw = "on".equals(post.get("xpstopw", "off")); env.setConfig("xpstopw", (xpstopw) ? "true" : "false"); final String crawlingMode = post.get("crawlingMode","url"); - if (crawlingMode.equals("url")) { + if ("url".equals(crawlingMode)) { // check if pattern matches if ((crawlingStart == null || crawlingStartURL == null) /* || (!(crawlingStart.matches(newcrawlingfilter))) */) { @@ -278,18 +278,18 @@ public class Crawler_p { )); if (reasonString == null) { - // create a bookmark from crawl start url - Set tags=ListManager.string2set(BookmarkHelper.cleanTagsString(post.get("bookmarkFolder","/crawlStart"))); + // create a bookmark from crawl start url + Set tags=ListManager.string2set(BookmarkHelper.cleanTagsString(post.get("bookmarkFolder","/crawlStart"))); tags.add("crawlStart"); - if (post.get("createBookmark","off").equals("on")) { - BookmarksDB.Bookmark bookmark = sb.bookmarksDB.createBookmark(crawlingStart, "admin"); - if(bookmark != null){ - bookmark.setProperty(BookmarksDB.Bookmark.BOOKMARK_TITLE, post.get("bookmarkTitle", crawlingStart)); - bookmark.setOwner("admin"); - bookmark.setPublic(false); - bookmark.setTags(tags, true); - sb.bookmarksDB.saveBookmark(bookmark); - } + if ("on".equals(post.get("createBookmark","off"))) { + BookmarksDB.Bookmark bookmark = sb.bookmarksDB.createBookmark(crawlingStart, "admin"); + if (bookmark != null) { + bookmark.setProperty(BookmarksDB.Bookmark.BOOKMARK_TITLE, post.get("bookmarkTitle", crawlingStart)); + bookmark.setOwner("admin"); + bookmark.setPublic(false); + bookmark.setTags(tags, true); + sb.bookmarksDB.saveBookmark(bookmark); + } } // liftoff! prop.put("info", "8");//start msg @@ -318,20 +318,20 @@ public class Crawler_p { prop.putHTML("info_reasonString", reasonString); sb.crawlQueues.errorURL.push( - new Request( - sb.peers.mySeed().hash.getBytes(), - crawlingStartURL, - null, - "", - new Date(), - pe.handle(), - 0, - 0, - 0), - sb.peers.mySeed().hash.getBytes(), - new Date(), - 1, - reasonString); + new Request( + sb.peers.mySeed().hash.getBytes(), + crawlingStartURL, + null, + "", + new Date(), + pe.handle(), + 0, + 0, + 0), + sb.peers.mySeed().hash.getBytes(), + new Date(), + 1, + reasonString); } } catch (final PatternSyntaxException e) { prop.put("info", "4"); //crawlfilter does not match url @@ -345,7 +345,7 @@ public class Crawler_p { Log.logException(e); } - } else if (crawlingMode.equals("file")) { + } else if ("file".equals(crawlingMode)) { if (post.containsKey("crawlingFile")) { final String fileName = post.get("crawlingFile"); try { @@ -410,7 +410,7 @@ public class Crawler_p { } sb.continueCrawlJob(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL); } - } else if (crawlingMode.equals("sitemap")) { + } else if ("sitemap".equals(crawlingMode)) { String sitemapURLStr = post.get("sitemapURL",""); try { final DigestURI sitemapURL = new DigestURI(sitemapURLStr); @@ -441,7 +441,7 @@ public class Crawler_p { prop.putHTML("info_error", e.getMessage()); Log.logException(e); } - } else if (crawlingMode.equals("sitelist")) { + } else if ("sitelist".equals(crawlingMode)) { try { final DigestURI sitelistURL = new DigestURI(crawlingStart); // download document @@ -451,7 +451,7 @@ public class Crawler_p { // String description = scraper.getDescription(); // get links and generate filter - StringBuilder filter = new StringBuilder(); + final StringBuilder filter = new StringBuilder(); final Map hyperlinks = scraper.getAnchors(); for (MultiProtocolURI uri: hyperlinks.keySet()) { filter.append('|').append(uri.getProtocol()).append("://").append(uri.getHost()).append(".*"); @@ -530,10 +530,10 @@ public class Crawler_p { private static long recrawlIfOlderC(final boolean recrawlIfOlderCheck, final int recrawlIfOlderNumber, final String crawlingIfOlderUnit) { if (!recrawlIfOlderCheck) return 0L; - if (crawlingIfOlderUnit.equals("year")) return System.currentTimeMillis() - (long) recrawlIfOlderNumber * 1000L * 60L * 60L * 24L * 365L; - if (crawlingIfOlderUnit.equals("month")) return System.currentTimeMillis() - (long) recrawlIfOlderNumber * 1000L * 60L * 60L * 24L * 30L; - if (crawlingIfOlderUnit.equals("day")) return System.currentTimeMillis() - (long) recrawlIfOlderNumber * 1000L * 60L * 60L * 24L; - if (crawlingIfOlderUnit.equals("hour")) return System.currentTimeMillis() - (long) recrawlIfOlderNumber * 1000L * 60L * 60L; + if ("year".equals(crawlingIfOlderUnit)) return System.currentTimeMillis() - (long) recrawlIfOlderNumber * 1000L * 60L * 60L * 24L * 365L; + if ("month".equals(crawlingIfOlderUnit)) return System.currentTimeMillis() - (long) recrawlIfOlderNumber * 1000L * 60L * 60L * 24L * 30L; + if ("day".equals(crawlingIfOlderUnit)) return System.currentTimeMillis() - (long) recrawlIfOlderNumber * 1000L * 60L * 60L * 24L; + if ("hour".equals(crawlingIfOlderUnit)) return System.currentTimeMillis() - (long) recrawlIfOlderNumber * 1000L * 60L * 60L; return System.currentTimeMillis() - (long) recrawlIfOlderNumber; } @@ -544,8 +544,8 @@ public class Crawler_p { try { wantedPPM = Integer.parseInt(post.get("customPPM", Integer.toString(wantedPPM))); } catch (final NumberFormatException e) {} - if (crawlingPerformance.toLowerCase().equals("minimum")) wantedPPM = 10; - if (crawlingPerformance.toLowerCase().equals("maximum")) wantedPPM = 30000; + if ("minimum".equals(crawlingPerformance.toLowerCase())) wantedPPM = 10; + if ("maximum".equals(crawlingPerformance.toLowerCase())) wantedPPM = 30000; sb.setPerformance(wantedPPM); } diff --git a/htroot/yacy/crawlReceipt.java b/htroot/yacy/crawlReceipt.java index 967a69a59..94f042162 100644 --- a/htroot/yacy/crawlReceipt.java +++ b/htroot/yacy/crawlReceipt.java @@ -53,8 +53,9 @@ public final class crawlReceipt { // return variable that accumulates replacements final Switchboard sb = (Switchboard) env; final serverObjects prop = new serverObjects(); - if ((post == null) || (env == null)) return prop; - if (!yacyNetwork.authentifyRequest(post, env)) return prop; + if ((post == null) || (env == null) || !yacyNetwork.authentifyRequest(post, env)) { + return prop; + } final Log log = sb.getLog(); @@ -137,7 +138,7 @@ public final class crawlReceipt { return prop; } - if (result.equals("fill")) try { + if ("fill".equals(result)) try { // put new entry into database sb.indexSegments.urlMetadata(Segments.Process.RECEIPTS).store(entry); sb.crawlResults.stack(entry, youare.getBytes(), iam.getBytes(), EventOrigin.REMOTE_RECEIPTS); diff --git a/source/de/anomic/data/BookmarkDate.java b/source/de/anomic/data/BookmarkDate.java index 576efdee0..c2f266e6f 100644 --- a/source/de/anomic/data/BookmarkDate.java +++ b/source/de/anomic/data/BookmarkDate.java @@ -46,7 +46,7 @@ import net.yacy.kelondro.order.NaturalOrder; public class BookmarkDate { - MapHeap datesTable; + private MapHeap datesTable; public BookmarkDate(final File datesFile) throws IOException { this.datesTable = new MapHeap(datesFile, 20, NaturalOrder.naturalOrder, 1024 * 64, 500, '_'); @@ -66,7 +66,9 @@ public class BookmarkDate { } catch (RowSpaceExceededException e) { map = null; } - if (map == null) return new Entry(date); + if (map == null) { + return new Entry(date); + } return new Entry(date, map); }