diff --git a/htroot/AccessPicture_p.java b/htroot/AccessPicture_p.java index 480786e90..2298a6b1e 100644 --- a/htroot/AccessPicture_p.java +++ b/htroot/AccessPicture_p.java @@ -65,7 +65,7 @@ public class AccessPicture_p { color_grid = post.get("colorgrid", color_grid); color_dot = post.get("colordot", color_dot); color_line = post.get("colorline", color_line); - corona = post.get("corona", "true").equals("true"); + corona = post.getBoolean("corona", true); coronaangle = (corona) ? post.getInt("coronaangle", 0) : -1; } if (coronaangle < 0) corona = false; diff --git a/htroot/BlogComments.java b/htroot/BlogComments.java index eafa1203a..2b4ef5f94 100644 --- a/htroot/BlogComments.java +++ b/htroot/BlogComments.java @@ -281,7 +281,7 @@ public class BlogComments { private static void messageForwardingViaEmail(final Switchboard sb, final MessageBoard.entry msgEntry) { try { - if (!Boolean.parseBoolean(sb.getConfig("msgForwardingEnabled","false"))) { + if (!sb.getConfigBool("msgForwardingEnabled",false)) { return; } diff --git a/htroot/Bookmarks.java b/htroot/Bookmarks.java index 6a7a23738..6fa361b6d 100644 --- a/htroot/Bookmarks.java +++ b/htroot/Bookmarks.java @@ -265,11 +265,11 @@ public class Bookmarks { } if (post.containsKey("start")) { - start = Integer.parseInt(post.get("start")); + start = post.getInt("start", 0); } if (post.containsKey("num")) { - max_count = Integer.parseInt(post.get("num")); + max_count = post.getInt("num", 10); } } // END if(post != null) diff --git a/htroot/ConfigAccounts_p.java b/htroot/ConfigAccounts_p.java index 8f50950c8..dd0217e1b 100644 --- a/htroot/ConfigAccounts_p.java +++ b/htroot/ConfigAccounts_p.java @@ -172,7 +172,7 @@ public class ConfigAccounts_p { final Map rightsSet = new HashMap(); for(final String right : rights) { - rightsSet.put(right, post.containsKey(right)&&"on".equals(post.get(right)) ? "true" : "false"); + rightsSet.put(right, post.containsKey(right) && "on".equals(post.get(right)) ? "true" : "false"); } final Map mem = new HashMap(); diff --git a/htroot/ConfigBasic.java b/htroot/ConfigBasic.java index b1d3cca1e..431217546 100644 --- a/htroot/ConfigBasic.java +++ b/htroot/ConfigBasic.java @@ -95,7 +95,7 @@ public class ConfigBasic { // port settings final long port; - if (post != null && post.containsKey("port") && Integer.parseInt(post.get("port")) > 1023) { + if (post != null && post.getInt("port", 0) > 1023) { port = post.getLong("port", 8090); } else { port = env.getConfigLong("port", 8090); //this allows a low port, but it will only get one, if the user edits the config himself. @@ -103,7 +103,7 @@ public class ConfigBasic { // check if peer name already exists final yacySeed oldSeed = sb.peers.lookupByName(peerName); - if (oldSeed == null && !sb.peers.mySeed().getName().equals(peerName)) { + if (oldSeed == null && !peerName.equals(sb.peers.mySeed().getName())) { // the name is new if (Pattern.compile("[A-Za-z0-9\\-_]{3,80}").matcher(peerName).matches()) { sb.peers.mySeed().setName(peerName); @@ -112,15 +112,15 @@ public class ConfigBasic { // UPnP config final boolean upnp; - if(post != null && post.containsKey("port")) { // hack to allow checkbox - 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 (post != null && post.containsKey("port")) { // hack to allow checkbox + upnp = post.containsKey("enableUpnp"); + if (upnp && !sb.getConfigBool(SwitchboardConstants.UPNP_ENABLED, false)) { + UPnP.addPortMapping(); + } + sb.setConfig(SwitchboardConstants.UPNP_ENABLED, upnp); + if (!upnp) { + UPnP.deletePortMapping(); + } } else { upnp = false; } @@ -223,9 +223,9 @@ public class ConfigBasic { final boolean properPort = (sb.peers.mySeed().isSenior()) || (sb.peers.mySeed().isPrincipal()); if ((env.getConfig("defaultFiles", "").startsWith("ConfigBasic.html,"))) { - env.setConfig("defaultFiles", env.getConfig("defaultFiles", "").substring(17)); - env.setConfig("browserPopUpPage", "Status.html"); - HTTPDFileHandler.initDefaultPath(); + env.setConfig("defaultFiles", env.getConfig("defaultFiles", "").substring(17)); + env.setConfig("browserPopUpPage", "Status.html"); + HTTPDFileHandler.initDefaultPath(); } prop.put("statusName", properName ? "1" : "0"); diff --git a/htroot/ConfigNetwork_p.java b/htroot/ConfigNetwork_p.java index 69644e0c1..8b560e589 100644 --- a/htroot/ConfigNetwork_p.java +++ b/htroot/ConfigNetwork_p.java @@ -145,23 +145,20 @@ public class ConfigNetwork_p { // write remote crawl request settings prop.put("crawlResponse", sb.getConfigBool("crawlResponse", false) ? "1" : "0"); - long RTCbusySleep = 100; - try { - RTCbusySleep = Math.max(1, Integer.parseInt(env.getConfig(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL_BUSYSLEEP, "100"))); - } catch (final NumberFormatException e) {} + final long RTCbusySleep = Math.max(1, env.getConfigInt(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL_BUSYSLEEP, 100)); final int RTCppm = (int) (60000L / RTCbusySleep); prop.put("acceptCrawlLimit", RTCppm); - final boolean indexDistribute = "true".equals(sb.getConfig(SwitchboardConstants.INDEX_DIST_ALLOW, "true")); - final boolean indexReceive = "true".equals(sb.getConfig(SwitchboardConstants.INDEX_RECEIVE_ALLOW, "true")); + final boolean indexDistribute = sb.getConfigBool(SwitchboardConstants.INDEX_DIST_ALLOW, true); + final boolean indexReceive = sb.getConfigBool(SwitchboardConstants.INDEX_RECEIVE_ALLOW, true); prop.put("indexDistributeChecked", (indexDistribute) ? "1" : "0"); - 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("indexDistributeWhileCrawling.on", (sb.getConfigBool(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_CRAWLING, true)) ? "1" : "0"); + prop.put("indexDistributeWhileCrawling.off", (sb.getConfigBool(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_CRAWLING, true)) ? "0" : "1"); + prop.put("indexDistributeWhileIndexing.on", (sb.getConfigBool(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_INDEXING, true)) ? "1" : "0"); + prop.put("indexDistributeWhileIndexing.off", (sb.getConfigBool(SwitchboardConstants.INDEX_DIST_ALLOW_WHILE_INDEXING, true)) ? "0" : "1"); prop.put("indexReceiveChecked", (indexReceive) ? "1" : "0"); - 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.put("indexReceiveBlockBlacklistChecked.on", (sb.getConfigBool("indexReceiveBlockBlacklist", true)) ? "1" : "0"); + prop.put("indexReceiveBlockBlacklistChecked.off", (sb.getConfigBool("indexReceiveBlockBlacklist", true)) ? "0" : "1"); prop.putHTML("peertags", MapTools.set2string(sb.peers.mySeed().getPeerTags(), ",", false)); // set seed information directly diff --git a/htroot/ConfigPortal.java b/htroot/ConfigPortal.java index beaa60c56..2c3c44700 100644 --- a/htroot/ConfigPortal.java +++ b/htroot/ConfigPortal.java @@ -70,13 +70,13 @@ public class ConfigPortal { sb.setConfig(SwitchboardConstants.SEARCH_TARGET, post.get("target", "_self")); sb.setConfig(SwitchboardConstants.INDEX_FORWARD, post.get(SwitchboardConstants.INDEX_FORWARD, "")); HTTPDFileHandler.indexForward = post.get(SwitchboardConstants.INDEX_FORWARD, ""); - sb.setConfig("publicTopmenu", post.get("publicTopmenu", "true")); - sb.setConfig("search.options", post.getBoolean("search.options", false) ? "true" : "false"); - sb.setConfig("search.result.show.date", post.getBoolean("search.result.show.date", false) ? "true" : "false"); - sb.setConfig("search.result.show.size", post.getBoolean("search.result.show.size", false) ? "true" : "false"); - sb.setConfig("search.result.show.metadata", post.getBoolean("search.result.show.metadata", false) ? "true" : "false"); - sb.setConfig("search.result.show.parser", post.getBoolean("search.result.show.parser", false) ? "true" : "false"); - sb.setConfig("search.result.show.pictures", post.getBoolean("search.result.show.pictures", false) ? "true" : "false"); + sb.setConfig("publicTopmenu", post.getBoolean("publicTopmenu", true)); + sb.setConfig("search.options", post.getBoolean("search.options", false)); + sb.setConfig("search.result.show.date", post.getBoolean("search.result.show.date", false)); + sb.setConfig("search.result.show.size", post.getBoolean("search.result.show.size", false)); + sb.setConfig("search.result.show.metadata", post.getBoolean("search.result.show.metadata", false)); + sb.setConfig("search.result.show.parser", post.getBoolean("search.result.show.parser", false)); + sb.setConfig("search.result.show.pictures", post.getBoolean("search.result.show.pictures", false)); } if (post.containsKey("searchpage_default")) { sb.setConfig(SwitchboardConstants.GREETING, "P2P Web Search"); @@ -87,13 +87,13 @@ public class ConfigPortal { sb.setConfig(SwitchboardConstants.INDEX_FORWARD, ""); HTTPDFileHandler.indexForward = ""; sb.setConfig(SwitchboardConstants.SEARCH_TARGET, "_self"); - sb.setConfig("publicTopmenu", "true"); - sb.setConfig("search.options", "true"); - sb.setConfig("search.result.show.date", "true"); - sb.setConfig("search.result.show.size", "true"); - sb.setConfig("search.result.show.metadata", "true"); - sb.setConfig("search.result.show.parser", "true"); - sb.setConfig("search.result.show.pictures", "true"); + sb.setConfig("publicTopmenu", true); + sb.setConfig("search.options", true); + sb.setConfig("search.result.show.date", true); + sb.setConfig("search.result.show.size", true); + sb.setConfig("search.result.show.metadata", true); + sb.setConfig("search.result.show.parser", true); + sb.setConfig("search.result.show.pictures", true); } } diff --git a/htroot/ConfigUpdate_p.java b/htroot/ConfigUpdate_p.java index 48287c426..a418285d1 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.NavigableSet; import java.util.Set; import java.util.TreeSet; @@ -69,7 +70,7 @@ public class ConfigUpdate_p { if (post != null) { // check if update is supposed to be installed and a release is defined - if (post.containsKey("update") && post.get("releaseinstall", "").length() > 0) { + if (post.containsKey("update") && !post.get("releaseinstall", "").isEmpty()) { prop.put("forwardToSteering", "1"); prop.putHTML("forwardToSteering_release",post.get("releaseinstall", "")); prop.put("deploys", "1"); @@ -80,7 +81,7 @@ public class ConfigUpdate_p { if (post.containsKey("downloadRelease")) { // download a release final String release = post.get("releasedownload", ""); - if (release.length() > 0) { + if (!release.isEmpty()) { try { yacyRelease versionToDownload = new yacyRelease(new DigestURI(release)); @@ -107,7 +108,7 @@ public class ConfigUpdate_p { if (post.containsKey("deleteRelease")) { final String release = post.get("releaseinstall", ""); - if (release.length() > 0) { + if (!release.isEmpty()) { try { FileUtils.deletedelete(new File(sb.releasePath, release)); FileUtils.deletedelete(new File(sb.releasePath, release + ".sig")); @@ -148,7 +149,7 @@ public class ConfigUpdate_p { sb.setConfig("update.cycle", Math.max(12, post.getLong("cycle", 168))); sb.setConfig("update.blacklist", post.get("blacklist", "")); sb.setConfig("update.concept", ("any".equals(post.get("releaseType", "any"))) ? "any" : "main"); - sb.setConfig("update.onlySignedFiles", ("true".equals(post.get("onlySignedFiles", "false"))) ? "1" : "0"); + sb.setConfig("update.onlySignedFiles", (post.getBoolean("onlySignedFiles", false)) ? "1" : "0"); } } @@ -168,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(); + final NavigableSet downloadedReleases = new TreeSet(); for (final File downloaded : downloadedFiles) { try { yacyRelease release = new yacyRelease(downloaded); diff --git a/htroot/Connections_p.java b/htroot/Connections_p.java index 9002c3cd2..3855c8e3a 100644 --- a/htroot/Connections_p.java +++ b/htroot/Connections_p.java @@ -61,7 +61,7 @@ public final class Connections_p { // determines if name lookup should be done or not final boolean doNameLookup; if (post != null) { - doNameLookup = (post.containsKey("nameLookup") && "true".equals(post.get("nameLookup","true"))); + doNameLookup = (post.containsKey("nameLookup") && post.getBoolean("nameLookup", true)); if (post.containsKey("closeServerSession")) { final String sessionName = post.get("closeServerSession", null); sb.closeSessions("10_httpd", sessionName); @@ -83,7 +83,7 @@ public final class Connections_p { // get the request command line String commandLine = s.getCommandLine(); - final boolean blockingRequest = (commandLine == null);; + final boolean blockingRequest = (commandLine == null); final int commandCount = s.getCommandCount(); // get the source ip address and port diff --git a/htroot/CrawlResults.java b/htroot/CrawlResults.java index bb80fee99..fff252d13 100644 --- a/htroot/CrawlResults.java +++ b/htroot/CrawlResults.java @@ -70,7 +70,7 @@ public class CrawlResults { // find process number EventOrigin tabletype; try { - tabletype = EventOrigin.getEvent(Integer.parseInt(post.get("process", "0"))); + tabletype = EventOrigin.getEvent(post.getInt("process", 0)); } catch (final NumberFormatException e) { tabletype = EventOrigin.UNKNOWN; } @@ -105,7 +105,7 @@ public class CrawlResults { if (post != null) { // custom number of lines if (post.containsKey("count")) { - lines = Integer.parseInt(post.get("count", "500")); + lines = post.getInt("count", 500); } // do the commands @@ -134,7 +134,7 @@ public class CrawlResults { } if (post.containsKey("moreIndexed")) { - lines = Integer.parseInt(post.get("showIndexed", "500")); + lines = post.getInt("showIndexed", 500); } if (post.get("si") != null) showInit = !("0".equals(post.get("si"))); diff --git a/htroot/CrawlStartExpert_p.java b/htroot/CrawlStartExpert_p.java index 836d0516c..e2c267160 100644 --- a/htroot/CrawlStartExpert_p.java +++ b/htroot/CrawlStartExpert_p.java @@ -51,28 +51,28 @@ public class CrawlStartExpert_p { prop.put("crawlingIfOlderUnitHourCheck", "0"); prop.put("crawlingIfOlderNumber", "7"); - final int crawlingDomFilterDepth = (int) env.getConfigLong("crawlingDomFilterDepth", -1); + final int crawlingDomFilterDepth = env.getConfigInt("crawlingDomFilterDepth", -1); prop.put("crawlingDomFilterCheck", (crawlingDomFilterDepth == -1) ? "0" : "1"); prop.put("crawlingDomFilterDepth", (crawlingDomFilterDepth == -1) ? 1 : crawlingDomFilterDepth); - final int crawlingDomMaxPages = (int) env.getConfigLong("crawlingDomMaxPages", -1); + final int crawlingDomMaxPages = env.getConfigInt("crawlingDomMaxPages", -1); prop.put("crawlingDomMaxCheck", (crawlingDomMaxPages == -1) ? "0" : "1"); prop.put("crawlingDomMaxPages", (crawlingDomMaxPages == -1) ? 10000 : crawlingDomMaxPages); - prop.put("crawlingQChecked", env.getConfig("crawlingQ", "").equals("true") ? "1" : "0"); - prop.put("storeHTCacheChecked", env.getConfig("storeHTCache", "").equals("true") ? "1" : "0"); - prop.put("indexingTextChecked", env.getConfig("indexText", "").equals("true") ? "1" : "0"); - prop.put("indexingMediaChecked", env.getConfig("indexMedia", "").equals("true") ? "1" : "0"); - prop.put("crawlOrderChecked", env.getConfig("crawlOrder", "").equals("true") ? "1" : "0"); + prop.put("crawlingQChecked", env.getConfigBool("crawlingQ", true) ? "1" : "0"); + prop.put("storeHTCacheChecked", env.getConfigBool("storeHTCache", true) ? "1" : "0"); + prop.put("indexingTextChecked", env.getConfigBool("indexText", true) ? "1" : "0"); + prop.put("indexingMediaChecked", env.getConfigBool("indexMedia", true) ? "1" : "0"); + prop.put("crawlOrderChecked", env.getConfigBool("crawlOrder", true) ? "1" : "0"); - final long LCbusySleep = Integer.parseInt(env.getConfig(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL_BUSYSLEEP, "100")); + final long LCbusySleep = env.getConfigLong(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL_BUSYSLEEP, 100L); final int LCppm = (LCbusySleep == 0) ? 1000 : (int) (60000L / LCbusySleep); prop.put("crawlingSpeedMaxChecked", (LCppm >= 1000) ? "1" : "0"); prop.put("crawlingSpeedCustChecked", ((LCppm > 10) && (LCppm < 1000)) ? "1" : "0"); prop.put("crawlingSpeedMinChecked", (LCppm <= 10) ? "1" : "0"); prop.put("customPPMdefault", ((LCppm > 10) && (LCppm < 1000)) ? Integer.toString(LCppm) : ""); - prop.put("xsstopwChecked", env.getConfig("xsstopw", "").equals("true") ? "1" : "0"); - prop.put("xdstopwChecked", env.getConfig("xdstopw", "").equals("true") ? "1" : "0"); - prop.put("xpstopwChecked", env.getConfig("xpstopw", "").equals("true") ? "1" : "0"); + prop.put("xsstopwChecked", env.getConfigBool("xsstopw", true) ? "1" : "0"); + prop.put("xdstopwChecked", env.getConfigBool("xdstopw", true) ? "1" : "0"); + prop.put("xpstopwChecked", env.getConfigBool("xpstopw", true) ? "1" : "0"); // return rewrite properties return prop; diff --git a/htroot/CrawlStartScanner_p.java b/htroot/CrawlStartScanner_p.java index 03d6cf7c1..7d02afd6a 100644 --- a/htroot/CrawlStartScanner_p.java +++ b/htroot/CrawlStartScanner_p.java @@ -84,7 +84,7 @@ public class CrawlStartScanner_p { // check scheduler if (post.get("rescan", "").equals("scheduler")) { - repeat_time = Integer.parseInt(post.get("repeat_time", "-1")); + repeat_time = post.getInt("repeat_time", -1); repeat_unit = post.get("repeat_unit", "selminutes"); // selminutes, selhours, seldays if (repeat_unit.equals("selminutes")) validTime = repeat_time * 60 * 1000; if (repeat_unit.equals("selhours")) validTime = repeat_time * 60 * 60 * 1000; @@ -92,9 +92,9 @@ public class CrawlStartScanner_p { } // case: an IP range was given; scan the range for services and display result - if (post.containsKey("scan") && post.get("source", "").equals("hosts")) { - Set ia = new HashSet(); - for (String host: hosts.split(",")) { + if (post.containsKey("scan") && "hosts".equals(post.get("source", ""))) { + final Set ia = new HashSet(); + for (String host : hosts.split(",")) { if (host.startsWith("http://")) host = host.substring(7); if (host.startsWith("https://")) host = host.substring(8); if (host.startsWith("ftp://")) host = host.substring(6); @@ -103,32 +103,40 @@ public class CrawlStartScanner_p { if (p >= 0) host = host.substring(0, p); ia.add(Domains.dnsResolve(host)); } - Scanner scanner = new Scanner(ia, 100, sb.isIntranetMode() ? 1000 : 5000); + final Scanner scanner = new Scanner(ia, 100, sb.isIntranetMode() ? 1000 : 5000); if (post.get("scanftp", "").equals("on")) scanner.addFTP(false); if (post.get("scanhttp", "").equals("on")) scanner.addHTTP(false); if (post.get("scanhttps", "").equals("on")) scanner.addHTTPS(false); if (post.get("scansmb", "").equals("on")) scanner.addSMB(false); scanner.start(); scanner.terminate(); - if (post.get("accumulatescancache", "").equals("on") && !post.get("rescan", "").equals("scheduler")) Scanner.scancacheExtend(scanner, validTime); else Scanner.scancacheReplace(scanner, validTime); + if ("on".equals(post.get("accumulatescancache", "")) && !"scheduler".equals(post.get("rescan", ""))) { + Scanner.scancacheExtend(scanner, validTime); + } else { + Scanner.scancacheReplace(scanner, validTime); + } } - if (post.containsKey("scan") && post.get("source", "").equals("intranet")) { - Scanner scanner = new Scanner(Domains.myIntranetIPs(), 100, sb.isIntranetMode() ? 100 : 3000); - if (post.get("scanftp", "").equals("on")) scanner.addFTP(false); - if (post.get("scanhttp", "").equals("on")) scanner.addHTTP(false); - if (post.get("scanhttps", "").equals("on")) scanner.addHTTPS(false); - if (post.get("scansmb", "").equals("on")) scanner.addSMB(false); + if (post.containsKey("scan") && "intranet".equals(post.get("source", ""))) { + final Scanner scanner = new Scanner(Domains.myIntranetIPs(), 100, sb.isIntranetMode() ? 100 : 3000); + if ("on".equals(post.get("scanftp", ""))) scanner.addFTP(false); + if ("on".equals(post.get("scanhttp", ""))) scanner.addHTTP(false); + if ("on".equals(post.get("scanhttps", ""))) scanner.addHTTPS(false); + if ("on".equals(post.get("scansmb", ""))) scanner.addSMB(false); scanner.start(); scanner.terminate(); - if (post.get("accumulatescancache", "").equals("on") && !post.get("rescan", "").equals("scheduler")) Scanner.scancacheExtend(scanner, validTime); else Scanner.scancacheReplace(scanner, validTime); + if ("on".equals(post.get("accumulatescancache", "")) && !"scheduler".equals(post.get("rescan", ""))) { + Scanner.scancacheExtend(scanner, validTime); + } else { + Scanner.scancacheReplace(scanner, validTime); + } } // check crawl request if (post.containsKey("crawl")) { // make a pk/url mapping - Iterator> se = Scanner.scancacheEntries(); - Map pkmap = new TreeMap(Base64Order.enhancedCoder); + final Iterator> se = Scanner.scancacheEntries(); + final Map pkmap = new TreeMap(Base64Order.enhancedCoder); while (se.hasNext()) { Scanner.Service u = se.next().getKey(); DigestURI uu; @@ -140,7 +148,7 @@ public class CrawlStartScanner_p { } } // search for crawl start requests in this mapping - for (Map.Entry entry: post.entrySet()) { + for (final Map.Entry entry: post.entrySet()) { if (entry.getValue().startsWith("mark_")) { byte [] pk = entry.getValue().substring(5).getBytes(); DigestURI url = pkmap.get(pk); @@ -154,7 +162,7 @@ public class CrawlStartScanner_p { } // check scheduler - if (post.get("rescan", "").equals("scheduler")) { + if ("scheduler".equals(post.get("rescan", ""))) { // store this call as api call if (repeat_time > 0) { @@ -165,13 +173,13 @@ public class CrawlStartScanner_p { // execute the scan results if (Scanner.scancacheSize() > 0) { // make a comment cache - Map apiCommentCache = WorkTables.commentCache(sb); + final Map apiCommentCache = WorkTables.commentCache(sb); String urlString; DigestURI u; try { int i = 0; - Iterator> se = Scanner.scancacheEntries(); + final Iterator> se = Scanner.scancacheEntries(); Map.Entry host; while (se.hasNext()) { host = se.next(); @@ -197,7 +205,7 @@ public class CrawlStartScanner_p { // write scan table if (Scanner.scancacheSize() > 0) { // make a comment cache - Map apiCommentCache = WorkTables.commentCache(sb); + final Map apiCommentCache = WorkTables.commentCache(sb); // show scancache table prop.put("servertable", 1); @@ -206,7 +214,7 @@ public class CrawlStartScanner_p { table: while (true) { try { int i = 0; - Iterator> se = Scanner.scancacheEntries(); + final Iterator> se = Scanner.scancacheEntries(); Map.Entry host; while (se.hasNext()) { host = se.next(); diff --git a/htroot/Crawler_p.java b/htroot/Crawler_p.java index f70411049..a1013c263 100644 --- a/htroot/Crawler_p.java +++ b/htroot/Crawler_p.java @@ -164,18 +164,18 @@ public class Crawler_p { } final boolean crawlOrder = post.get("crawlOrder", "off").equals("on"); - env.setConfig("crawlOrder", (crawlOrder) ? "true" : "false"); + env.setConfig("crawlOrder", crawlOrder); - int newcrawlingdepth = Integer.parseInt(post.get("crawlingDepth", "8")); + int newcrawlingdepth = post.getInt("crawlingDepth", 8); env.setConfig("crawlingDepth", Integer.toString(newcrawlingdepth)); if ((crawlOrder) && (newcrawlingdepth > 8)) newcrawlingdepth = 8; // recrawl final String recrawl = post.get("recrawl", "nodoubles"); // nodoubles, reload, scheduler boolean crawlingIfOlderCheck = "on".equals(post.get("crawlingIfOlderCheck", "off")); - int crawlingIfOlderNumber = Integer.parseInt(post.get("crawlingIfOlderNumber", "-1")); + int crawlingIfOlderNumber = post.getInt("crawlingIfOlderNumber", -1); String crawlingIfOlderUnit = post.get("crawlingIfOlderUnit","year"); // year, month, day, hour - int repeat_time = Integer.parseInt(post.get("repeat_time", "-1")); + int repeat_time = post.getInt("repeat_time", -1); final String repeat_unit = post.get("repeat_unit", "seldays"); // selminutes, selhours, seldays if ("scheduler".equals(recrawl) && repeat_time > 0) { @@ -210,33 +210,33 @@ public class Crawler_p { } final boolean crawlingDomMaxCheck = "on".equals(post.get("crawlingDomMaxCheck", "off")); - final int crawlingDomMaxPages = (crawlingDomMaxCheck) ? Integer.parseInt(post.get("crawlingDomMaxPages", "-1")) : -1; + final int crawlingDomMaxPages = (crawlingDomMaxCheck) ? post.getInt("crawlingDomMaxPages", -1) : -1; env.setConfig("crawlingDomMaxPages", Integer.toString(crawlingDomMaxPages)); final boolean crawlingQ = "on".equals(post.get("crawlingQ", "off")); - env.setConfig("crawlingQ", (crawlingQ) ? "true" : "false"); + env.setConfig("crawlingQ", crawlingQ); final boolean indexText = "on".equals(post.get("indexText", "on")); - env.setConfig("indexText", (indexText) ? "true" : "false"); + env.setConfig("indexText", indexText); final boolean indexMedia = "on".equals(post.get("indexMedia", "on")); - env.setConfig("indexMedia", (indexMedia) ? "true" : "false"); + env.setConfig("indexMedia", indexMedia); boolean storeHTCache = "on".equals(post.get("storeHTCache", "on")); if (crawlingStartURL!= null &&(crawlingStartURL.isFile() || crawlingStartURL.isSMB())) storeHTCache = false; - env.setConfig("storeHTCache", (storeHTCache) ? "true" : "false"); + env.setConfig("storeHTCache", storeHTCache); CrawlProfile.CacheStrategy cachePolicy = CrawlProfile.CacheStrategy.parse(post.get("cachePolicy", "iffresh")); if (cachePolicy == null) cachePolicy = CrawlProfile.CacheStrategy.IFFRESH; final boolean xsstopw = "on".equals(post.get("xsstopw", "off")); - env.setConfig("xsstopw", (xsstopw) ? "true" : "false"); + env.setConfig("xsstopw", xsstopw); final boolean xdstopw = "on".equals(post.get("xdstopw", "off")); - env.setConfig("xdstopw", (xdstopw) ? "true" : "false"); + env.setConfig("xdstopw", xdstopw); final boolean xpstopw = "on".equals(post.get("xpstopw", "off")); - env.setConfig("xpstopw", (xpstopw) ? "true" : "false"); + env.setConfig("xpstopw", xpstopw); final String crawlingMode = post.get("crawlingMode","url"); if (crawlingStart != null && crawlingStart.startsWith("ftp")) { @@ -555,7 +555,7 @@ public class Crawler_p { } // performance settings - final long LCbusySleep = Integer.parseInt(env.getConfig(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL_BUSYSLEEP, "1000")); + final long LCbusySleep = env.getConfigLong(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL_BUSYSLEEP, 1000L); final int LCppm = (int) (60000L / Math.max(1,LCbusySleep)); prop.put("crawlingSpeedMaxChecked", (LCppm >= 30000) ? "1" : "0"); prop.put("crawlingSpeedCustChecked", ((LCppm > 10) && (LCppm < 30000)) ? "1" : "0"); @@ -577,10 +577,10 @@ public class Crawler_p { private static void setPerformance(final Switchboard sb, final serverObjects post) { final String crawlingPerformance = post.get("crawlingPerformance", "custom"); - final long LCbusySleep = Integer.parseInt(sb.getConfig(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL_BUSYSLEEP, "1000")); + final long LCbusySleep = sb.getConfigLong(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL_BUSYSLEEP, 1000L); int wantedPPM = (LCbusySleep == 0) ? 30000 : (int) (60000L / LCbusySleep); try { - wantedPPM = Integer.parseInt(post.get("customPPM", Integer.toString(wantedPPM))); + wantedPPM = post.getInt("customPPM", wantedPPM); } catch (final NumberFormatException e) {} if ("minimum".equals(crawlingPerformance.toLowerCase())) wantedPPM = 10; if ("maximum".equals(crawlingPerformance.toLowerCase())) wantedPPM = 30000; diff --git a/htroot/IndexControlRWIs_p.java b/htroot/IndexControlRWIs_p.java index f69970cbc..e2012ffad 100644 --- a/htroot/IndexControlRWIs_p.java +++ b/htroot/IndexControlRWIs_p.java @@ -281,13 +281,13 @@ public class IndexControlRWIs_p { } // transport to other peer - final String gzipBody = sb.getConfig("indexControl.gzipBody","false"); - final int timeout = (int) sb.getConfigLong("indexControl.timeout",60000); + final boolean gzipBody = sb.getConfigBool("indexControl.gzipBody", false); + final int timeout = (int) sb.getConfigLong("indexControl.timeout", 60000); final String error = yacyClient.transferIndex( seed, icc, knownURLs, - "true".equalsIgnoreCase(gzipBody), + gzipBody, timeout); prop.put("result", (error == null) ? ("Successfully transferred " + knownURLs.size() + " words in " + ((System.currentTimeMillis() - starttime) / 1000) + " seconds, " + unknownURLEntries.size() + " URL not found") : "error: " + error); index = null; diff --git a/htroot/IndexCreateDomainCrawl_p.java b/htroot/IndexCreateDomainCrawl_p.java index a6011d698..6b32bae86 100644 --- a/htroot/IndexCreateDomainCrawl_p.java +++ b/htroot/IndexCreateDomainCrawl_p.java @@ -79,7 +79,7 @@ public class IndexCreateDomainCrawl_p { prop.put("indexingMediaChecked", env.getConfigBool("indexMedia", false) ? "1" : "0"); prop.put("crawlOrderChecked", env.getConfigBool("crawlOrder", false) ? "1" : "0"); - long LCbusySleep = Integer.parseInt(env.getConfig(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL_BUSYSLEEP, "100")); + long LCbusySleep = env.getConfigLong(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL_BUSYSLEEP, 100L); int LCppm = (LCbusySleep == 0) ? 1000 : (int) (60000L / LCbusySleep); prop.put("crawlingSpeedMaxChecked", (LCppm >= 1000) ? "1" : "0"); prop.put("crawlingSpeedCustChecked", ((LCppm > 10) && (LCppm < 1000)) ? "1" : "0"); diff --git a/htroot/IndexCreateWWWGlobalQueue_p.java b/htroot/IndexCreateWWWGlobalQueue_p.java index b6916d3b9..b3dea65b5 100644 --- a/htroot/IndexCreateWWWGlobalQueue_p.java +++ b/htroot/IndexCreateWWWGlobalQueue_p.java @@ -58,11 +58,7 @@ public class IndexCreateWWWGlobalQueue_p { int showLimit = 100; if (post != null) { - if (post.containsKey("limit")) { - try { - showLimit = Integer.parseInt(post.get("limit")); - } catch (final NumberFormatException e) {} - } + showLimit = post.getInt("limit", 100); if (post.containsKey("clearcrawlqueue")) { final int c = sb.crawlQueues.noticeURL.stackSize(NoticedURL.StackType.LIMIT); diff --git a/htroot/IndexCreateWWWLocalQueue_p.java b/htroot/IndexCreateWWWLocalQueue_p.java index 8ea2819f2..445c428d5 100644 --- a/htroot/IndexCreateWWWLocalQueue_p.java +++ b/htroot/IndexCreateWWWLocalQueue_p.java @@ -72,11 +72,7 @@ public class IndexCreateWWWLocalQueue_p { int showLimit = 100; if (post != null) { - if (post.containsKey("limit")) { - try { - showLimit = Integer.parseInt(post.get("limit")); - } catch (final NumberFormatException e) {} - } + showLimit = post.getInt("limit", 100); if (post.containsKey("deleteEntries")) { int c = 0; diff --git a/htroot/IndexCreateWWWRemoteQueue_p.java b/htroot/IndexCreateWWWRemoteQueue_p.java index a46397d7e..c4b81ccdf 100644 --- a/htroot/IndexCreateWWWRemoteQueue_p.java +++ b/htroot/IndexCreateWWWRemoteQueue_p.java @@ -55,11 +55,7 @@ public class IndexCreateWWWRemoteQueue_p { int showLimit = 100; if (post != null) { - if (post.containsKey("limit")) { - try { - showLimit = Integer.parseInt(post.get("limit")); - } catch (final NumberFormatException e) { } - } + showLimit = post.getInt("limit", 100); if (post.containsKey("clearcrawlqueue")) { final int c = sb.crawlQueues.noticeURL.stackSize(NoticedURL.StackType.REMOTE); diff --git a/htroot/IndexShare_p.java b/htroot/IndexShare_p.java index 56b3df875..3ae8548f5 100644 --- a/htroot/IndexShare_p.java +++ b/htroot/IndexShare_p.java @@ -66,10 +66,10 @@ public class IndexShare_p { } if (post.containsKey("indexsharesetting")) { - sb.setConfig(SwitchboardConstants.INDEX_DIST_ALLOW, (post.containsKey("distribute")) ? "true" : "false"); - sb.setConfig("allowReceiveIndex", (post.containsKey("receive")) ? "true" : "false"); - sb.setConfig("defaultLinkReceiveFrequency", post.get("linkfreq", "30")); - sb.setConfig("defaultWordReceiveFrequency", post.get("wordfreq", "10")); + sb.setConfig(SwitchboardConstants.INDEX_DIST_ALLOW, post.containsKey("distribute")); + sb.setConfig("allowReceiveIndex", post.containsKey("receive")); + sb.setConfig("defaultLinkReceiveFrequency", post.getInt("linkfreq", 30)); + sb.setConfig("defaultWordReceiveFrequency", post.getInt("wordfreq", 10)); } // insert constants diff --git a/htroot/Load_RSS_p.java b/htroot/Load_RSS_p.java index de67a9de3..26ed02eba 100644 --- a/htroot/Load_RSS_p.java +++ b/htroot/Load_RSS_p.java @@ -239,9 +239,9 @@ public class Load_RSS_p { prop.put("url", post.get("url", "")); - int repeat_time = Integer.parseInt(post.get("repeat_time", "-1")); + int repeat_time = post.getInt("repeat_time", -1); final String repeat_unit = post.get("repeat_unit", "seldays"); // selminutes, selhours, seldays - if (!post.get("repeat", "off").equals("on") && repeat_time > 0) repeat_time = -1; + if (!"on".equals(post.get("repeat", "off")) && repeat_time > 0) repeat_time = -1; boolean record_api = false; @@ -256,7 +256,7 @@ public class Load_RSS_p { RSSReader rss = null; if (url != null) try { prop.put("url", url.toNormalform(true, false)); - Response response = sb.loader.load(sb.loader.request(url, true, false), CrawlProfile.CacheStrategy.NOCACHE, Long.MAX_VALUE, true); + final Response response = sb.loader.load(sb.loader.request(url, true, false), CrawlProfile.CacheStrategy.NOCACHE, Long.MAX_VALUE, true); byte[] resource = response == null ? null : response.getContent(); rss = resource == null ? null : RSSReader.parse(RSSFeed.DEFAULT_MAXSIZE, resource); } catch (IOException e) { @@ -266,10 +266,10 @@ public class Load_RSS_p { // index all selected items: description only if (rss != null && post.containsKey("indexSelectedItemContent")) { RSSFeed feed = rss.getFeed(); - loop: for (Map.Entry entry: post.entrySet()) { + loop: for (final Map.Entry entry: post.entrySet()) { if (entry.getValue().startsWith("mark_")) try { - RSSMessage message = feed.getMessage(entry.getValue().substring(5)); - DigestURI messageurl = new DigestURI(message.getLink()); + final RSSMessage message = feed.getMessage(entry.getValue().substring(5)); + final DigestURI messageurl = new DigestURI(message.getLink()); if (RSSLoader.indexTriggered.containsKey(messageurl.hash())) continue loop; if (sb.urlExists(Segments.Process.LOCALCRAWLING, messageurl.hash()) != null) continue loop; sb.addToIndex(messageurl, null, null); @@ -284,7 +284,7 @@ public class Load_RSS_p { if (rss != null && post.containsKey("indexAllItemContent")) { record_api = true; - RSSFeed feed = rss.getFeed(); + final RSSFeed feed = rss.getFeed(); RSSLoader.indexAllRssFeed(sb, url, feed); } @@ -296,8 +296,8 @@ public class Load_RSS_p { // show items from rss if (rss != null) { prop.put("showitems", 1); - RSSFeed feed = rss.getFeed(); - RSSMessage channel = feed.getChannel(); + final RSSFeed feed = rss.getFeed(); + final RSSMessage channel = feed.getChannel(); prop.putHTML("showitems_title", channel == null ? "" : channel.getTitle()); String author = channel == null ? "" : channel.getAuthor(); if (author == null || author.length() == 0) author = channel == null ? "" : channel.getCopyright(); @@ -312,7 +312,7 @@ public class Load_RSS_p { int i = 0; for (final Hit item: feed) { try { - DigestURI messageurl = new DigestURI(item.getLink()); + final DigestURI messageurl = new DigestURI(item.getLink()); author = item.getAuthor(); if (author == null) author = item.getCopyright(); pubDate = item.getPubDate(); diff --git a/htroot/MessageSend_p.java b/htroot/MessageSend_p.java index db82e4689..5d819d9a5 100644 --- a/htroot/MessageSend_p.java +++ b/htroot/MessageSend_p.java @@ -51,12 +51,12 @@ public class MessageSend_p { final Switchboard sb = (Switchboard) env; final serverObjects prop = new serverObjects(); - if ((post == null) || (post.get("hash","").length() == 0)) { + if ((post == null) || (post.get("hash","").isEmpty())) { prop.put("mode", "2"); return prop; } - final String hash = post.get("hash", ""); + final String hash = post.get("hash", ""); String subject = post.get("subject", ""); String message = post.get("message", ""); @@ -121,14 +121,13 @@ public class MessageSend_p { // send written message to peer try { prop.put("mode_status", "0"); - int messagesize = Integer.parseInt(post.get("messagesize", "0")); + int messagesize = post.getInt("messagesize", 0); //int attachmentsize = Integer.parseInt(post.get("attachmentsize", "0")); if (messagesize < 1000) messagesize = 1000; // debug if (subject.length() > 100) subject = subject.substring(0, 100); if (message.length() > messagesize) message = message.substring(0, messagesize); - byte[] mb; - mb = UTF8.getBytes(message); + final byte[] mb = UTF8.getBytes(message); final Map result = yacyClient.postMessage(sb.peers, hash, subject, mb); //message has been sent diff --git a/htroot/Network.java b/htroot/Network.java index 92a7e824d..6d266194f 100644 --- a/htroot/Network.java +++ b/htroot/Network.java @@ -52,6 +52,7 @@ import de.anomic.yacy.yacyNewsPool; import de.anomic.yacy.yacyPeerActions; import de.anomic.yacy.yacySeed; import de.anomic.yacy.yacyVersion; +import java.util.concurrent.ConcurrentMap; public class Network { @@ -98,14 +99,9 @@ public class Network { // update seed info sb.updateMySeed(); - long LCount; - long ICount; - long RCount; - try { - LCount = seed.getLinkCount(); - ICount = seed.getWordCount(); - RCount = Long.parseLong(seed.get(yacySeed.RCOUNT, "0")); - } catch (final Exception e) {LCount = 0; ICount = 0; RCount = 0;} + final long LCount = seed.getLinkCount(); + final long ICount = seed.getWordCount(); + final long RCount = seed.getLong(yacySeed.RCOUNT, 0L); // my-info prop.putHTML("table_my-name", seed.get(yacySeed.NAME, "-") ); @@ -133,20 +129,20 @@ public class Network { myqph = 60d * sb.averageQPM(); prop.put("table_my-version", seed.get(yacySeed.VERSION, "-")); prop.put("table_my-utc", seed.get(yacySeed.UTC, "-")); - prop.put("table_my-uptime", yacyPeerActions.formatInterval(60000 * Long.parseLong(seed.get(yacySeed.UPTIME, "")))); + prop.put("table_my-uptime", yacyPeerActions.formatInterval(60000 * seed.getLong(yacySeed.UPTIME, 0))); prop.putNum("table_my-LCount", LCount); prop.putNum("table_my-ICount", ICount); prop.putNum("table_my-RCount", RCount); - prop.putNum("table_my-sI", Long.parseLong(seed.get(yacySeed.INDEX_OUT, "0"))); - prop.putNum("table_my-sU", Long.parseLong(seed.get(yacySeed.URL_OUT, "0"))); - prop.putNum("table_my-rI", Long.parseLong(seed.get(yacySeed.INDEX_IN, "0"))); - prop.putNum("table_my-rU", Long.parseLong(seed.get(yacySeed.URL_IN, "0"))); + prop.putNum("table_my-sI", seed.getLong(yacySeed.INDEX_OUT, 0L)); + prop.putNum("table_my-sU", seed.getLong(yacySeed.URL_OUT, 0L)); + prop.putNum("table_my-rI", seed.getLong(yacySeed.INDEX_IN, 0L)); + prop.putNum("table_my-rU", seed.getLong(yacySeed.URL_IN, 0L)); prop.putNum("table_my-ppm", myppm); prop.putNum("table_my-qph", Math.round(100d * myqph) / 100d); prop.putNum("table_my-qph-publocal", Math.round(6000d * sb.averageQPMPublicLocal()) / 100d); prop.putNum("table_my-qph-pubremote", Math.round(6000d * sb.averageQPMGlobal()) / 100d); - prop.putNum("table_my-seeds", Long.parseLong(seed.get(yacySeed.SCOUNT, "0"))); - prop.putNum("table_my-connects", Float.parseFloat(seed.get(yacySeed.CCOUNT, "0"))); + prop.putNum("table_my-seeds", seed.getLong(yacySeed.SCOUNT, 0L)); + prop.putNum("table_my-connects", seed.getFloat(yacySeed.CCOUNT, 0F)); prop.put("table_my-url", seed.get(yacySeed.SEEDLISTURL, "")); // generating the location string @@ -183,7 +179,7 @@ public class Network { prop.putNum("table_gqph", Math.round(6000d * otherqpm + 100d * ((iAmActive) ? myqph : 0d)) / 100d); prop.put("table", 2); // triggers overview prop.put("page", 0); - } else if (post != null && Integer.parseInt(post.get("page", "1")) == 4) { + } else if (post != null && post.getInt("page", 1) == 4) { prop.put("table", 4); // triggers overview prop.put("page", 4); @@ -201,7 +197,7 @@ public class Network { return prop; } - final ConcurrentHashMap map = new ConcurrentHashMap(); + final ConcurrentMap map = new ConcurrentHashMap(); map.put(yacySeed.IP, post.get("peerIP")); map.put(yacySeed.PORT, post.get("peerPort")); yacySeed peer = new yacySeed(post.get("peerHash"), map); @@ -236,8 +232,8 @@ public class Network { } } else { // generate table - final int page = (post == null ? 1 : Integer.parseInt(post.get("page", "1"))); - final int maxCount = (post == null ? 300 : Integer.parseInt(post.get("maxCount", "300"))); + final int page = (post == null ? 1 : post.getInt("page", 1)); + final int maxCount = (post == null ? 300 : post.getInt("maxCount", 300)); int conCount = 0; if (sb.peers == null) { prop.put("table", 0);//no remote senior/principal proxies known" @@ -383,8 +379,8 @@ public class Network { prop.put(STR_TABLE_LIST + conCount + "_complete_port", seed.get(yacySeed.PORT, "-") ); prop.put(STR_TABLE_LIST + conCount + "_complete_hash", seed.hash); prop.put(STR_TABLE_LIST + conCount + "_complete_age", seed.getAge()); - prop.putNum(STR_TABLE_LIST + conCount + "_complete_seeds", Long.parseLong(seed.get(yacySeed.SCOUNT, "0"))); - prop.putNum(STR_TABLE_LIST + conCount + "_complete_connects", Float.parseFloat(seed.get(yacySeed.CCOUNT, "0"))); + prop.putNum(STR_TABLE_LIST + conCount + "_complete_seeds", seed.getLong(yacySeed.SCOUNT, 0L)); + prop.putNum(STR_TABLE_LIST + conCount + "_complete_connects", seed.getFloat(yacySeed.CCOUNT, 0F)); prop.putHTML(STR_TABLE_LIST + conCount + "_complete_userAgent", userAgent); } else { prop.put(STR_TABLE_LIST + conCount + "_complete", 0); @@ -437,7 +433,7 @@ public class Network { prop.putHTML(STR_TABLE_LIST + conCount + "_version", yacyVersion.combined2prettyVersion(seed.get(yacySeed.VERSION, "0.1"), shortname)); prop.putNum(STR_TABLE_LIST + conCount + "_lastSeen", /*seed.getLastSeenString() + " " +*/ lastseen); prop.put(STR_TABLE_LIST + conCount + "_utc", seed.get(yacySeed.UTC, "-")); - prop.putHTML(STR_TABLE_LIST + conCount + "_uptime", yacyPeerActions.formatInterval(60000 * Long.parseLong(seed.get(yacySeed.UPTIME, "0")))); + prop.putHTML(STR_TABLE_LIST + conCount + "_uptime", yacyPeerActions.formatInterval(60000 * seed.getLong(yacySeed.UPTIME, 0))); prop.putNum(STR_TABLE_LIST + conCount + "_LCount", seed.getLinkCount()); prop.putNum(STR_TABLE_LIST + conCount + "_ICount", seed.getWordCount()); prop.putNum(STR_TABLE_LIST + conCount + "_RCount", seed.getLong(yacySeed.RCOUNT, 0)); diff --git a/htroot/NetworkPicture.java b/htroot/NetworkPicture.java index d122d23d7..b49a05fad 100644 --- a/htroot/NetworkPicture.java +++ b/htroot/NetworkPicture.java @@ -49,7 +49,7 @@ public class NetworkPicture { long timeSeconds = System.currentTimeMillis() / 1000; if (buffer != null && !authorized && timeSeconds - lastAccessSeconds < 2) { - Log.logInfo("NetworkPicture", "cache hit (1); authorized = " + (authorized ? "true" : "false") + ", timeSeconds - lastAccessSeconds = " + (timeSeconds - lastAccessSeconds)); + Log.logInfo("NetworkPicture", "cache hit (1); authorized = " + authorized + ", timeSeconds - lastAccessSeconds = " + (timeSeconds - lastAccessSeconds)); return buffer; } @@ -57,7 +57,7 @@ public class NetworkPicture { sync.acquireUninterruptibly(); if (buffer != null && !authorized && timeSeconds - lastAccessSeconds < 2) { - Log.logInfo("NetworkPicture", "cache hit (2); authorized = " + (authorized ? "true" : "false") + ", timeSeconds - lastAccessSeconds = " + (timeSeconds - lastAccessSeconds)); + Log.logInfo("NetworkPicture", "cache hit (2); authorized = " + authorized + ", timeSeconds - lastAccessSeconds = " + (timeSeconds - lastAccessSeconds)); sync.release(); return buffer; } @@ -78,7 +78,7 @@ public class NetworkPicture { passiveLimit = post.getInt("pal", passiveLimit); potentialLimit = post.getInt("pol", potentialLimit); maxCount = post.getInt("max", maxCount); - corona = post.get("corona", "true").equals("true"); + corona = post.getBoolean("corona", true); coronaangle = (corona) ? post.getInt("coronaangle", 0) : -1; communicationTimeout = post.getLong("ct", -1); bgcolor = post.get("bgcolor", bgcolor); diff --git a/htroot/News.java b/htroot/News.java index 662c2376d..20d6a95e7 100644 --- a/htroot/News.java +++ b/htroot/News.java @@ -44,8 +44,8 @@ public class News { public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { final Switchboard sb = (Switchboard) env; final serverObjects prop = new serverObjects(); - final boolean overview = (post == null) || (post.get("page", "0").equals("0")); - final int tableID = (overview) ? -1 : (post == null ? 0 : Integer.parseInt(post.get("page", "0"))) - 1; + final boolean overview = (post == null) || "0".equals(post.get("page", "0")); + final int tableID = (overview) ? -1 : (post == null ? 0 : post.getInt("page", 0)) - 1; // execute commands if (post != null) { @@ -60,7 +60,7 @@ public class News { String id; while (e.hasNext()) { check = e.next(); - if ((check.startsWith("del_")) && (post.get(check, "off").equals("on"))) { + if ((check.startsWith("del_")) && "on".equals(post.get(check, "off"))) { id = check.substring(4); try { sb.peers.newsPool.moveOff(tableID, id); @@ -126,11 +126,11 @@ public class News { prop.putHTML("table_list_" + i + "_att", attributeMap.toString()); int j = 0; if (!attributeMap.isEmpty()) { - for (Entry attribute: attributeMap.entrySet()) { - prop.put("table_list_" + i + "_attributes_" + j + "_name", attribute.getKey()); - prop.putHTML("table_list_" + i + "_attributes_" + j + "_value", attribute.getValue()); - j++; - } + for (final Entry attribute: attributeMap.entrySet()) { + prop.put("table_list_" + i + "_attributes_" + j + "_name", attribute.getKey()); + prop.putHTML("table_list_" + i + "_attributes_" + j + "_value", attribute.getValue()); + j++; + } } prop.put("table_list_" + i + "_attributes", j); @@ -138,7 +138,7 @@ public class News { String link, title, description; if (category.equals(yacyNewsPool.CATEGORY_CRAWL_START)) { link = record.attribute("startURL", ""); - title = (record.attribute("intention", "").length() == 0) ? link : record.attribute("intention", ""); + title = (record.attribute("intention", "").isEmpty()) ? link : record.attribute("intention", ""); description = "Crawl Start Point"; } else if (category.equals(yacyNewsPool.CATEGORY_PROFILE_UPDATE)) { link = record.attribute("homepage", ""); @@ -157,11 +157,11 @@ public class News { title = record.attribute("title", ""); description = record.attribute("url", ""); } else if (category.equals(yacyNewsPool.CATEGORY_WIKI_UPDATE)) { - link = (seed==null)?"":"http://" + seed.getPublicAddress() + "/Wiki.html?page=" + record.attribute("page", ""); + link = (seed == null)? "" : "http://" + seed.getPublicAddress() + "/Wiki.html?page=" + record.attribute("page", ""); title = record.attribute("author", "Anonymous") + ": " + record.attribute("page", ""); description = "Wiki Update: " + record.attribute("description", ""); } else if (category.equals(yacyNewsPool.CATEGORY_BLOG_ADD)) { - link = (seed==null)?"":"http://" + seed.getPublicAddress() + "/Blog.html?page=" + record.attribute("page", ""); + link = (seed == null)? "" : "http://" + seed.getPublicAddress() + "/Blog.html?page=" + record.attribute("page", ""); title = record.attribute("author", "Anonymous") + ": " + record.attribute("page", ""); description = "Blog Entry: " + record.attribute("subject", ""); } else { diff --git a/htroot/PeerLoadPicture.java b/htroot/PeerLoadPicture.java index c37944e91..c7db7ff63 100644 --- a/htroot/PeerLoadPicture.java +++ b/htroot/PeerLoadPicture.java @@ -23,7 +23,7 @@ public class PeerLoadPicture { if (post != null) { width = post.getInt("width", 800); height = post.getInt("height", 600); - showidle = post.get("showidle", "true").equals("true"); + showidle = post.getBoolean("showidle", true); } final CircleThreadPiece idle = new CircleThreadPiece("Idle", new Color(170, 255, 170)); diff --git a/htroot/PerformanceMemory_p.java b/htroot/PerformanceMemory_p.java index b9b5e05f9..ef50be35c 100644 --- a/htroot/PerformanceMemory_p.java +++ b/htroot/PerformanceMemory_p.java @@ -66,13 +66,13 @@ public class PerformanceMemory_p { } final long memoryFreeNow = MemoryControl.free(); - final long memoryFreeAfterInitBGC = Long.parseLong(env.getConfig("memoryFreeAfterInitBGC", "0")); - final long memoryFreeAfterInitAGC = Long.parseLong(env.getConfig("memoryFreeAfterInitAGC", "0")); - final long memoryFreeAfterStartup = Long.parseLong(env.getConfig("memoryFreeAfterStartup", "0")); + final long memoryFreeAfterInitBGC = env.getConfigLong("memoryFreeAfterInitBGC", 0L); + final long memoryFreeAfterInitAGC = env.getConfigLong("memoryFreeAfterInitAGC", 0L); + final long memoryFreeAfterStartup = env.getConfigLong("memoryFreeAfterStartup", 0L); final long memoryTotalNow = MemoryControl.total(); - final long memoryTotalAfterInitBGC = Long.parseLong(env.getConfig("memoryTotalAfterInitBGC", "0")); - final long memoryTotalAfterInitAGC = Long.parseLong(env.getConfig("memoryTotalAfterInitAGC", "0")); - final long memoryTotalAfterStartup = Long.parseLong(env.getConfig("memoryTotalAfterStartup", "0")); + final long memoryTotalAfterInitBGC = env.getConfigLong("memoryTotalAfterInitBGC", 0L); + final long memoryTotalAfterInitAGC = env.getConfigLong("memoryTotalAfterInitAGC", 0L); + final long memoryTotalAfterStartup = env.getConfigLong("memoryTotalAfterStartup", 0L); prop.putNum("memoryMax", MemoryControl.maxMemory / MB); prop.putNum("memoryAvailAfterStartup", (MemoryControl.maxMemory - memoryTotalAfterStartup + memoryFreeAfterStartup) / MB); diff --git a/htroot/PerformanceQueues_p.java b/htroot/PerformanceQueues_p.java index 2201e0c04..f33c37f7b 100644 --- a/htroot/PerformanceQueues_p.java +++ b/htroot/PerformanceQueues_p.java @@ -92,19 +92,13 @@ public class PerformanceQueues_p { prop.put("setStartupCommit", "1"); } if(post.containsKey("diskFree")) { - int diskFree = 3000; // default - try { diskFree = Integer.parseInt(post.get("diskFree", Integer.toString(diskFree))); } catch (final NumberFormatException e){} - sb.setConfig(SwitchboardConstants.DISK_FREE, diskFree); + sb.setConfig(SwitchboardConstants.DISK_FREE, post.getInt("diskFree", 3000)); } if(post.containsKey("diskFreeHardlimit")) { - int diskFreeHardlimit = 1000; // default - try { diskFreeHardlimit = Integer.parseInt(post.get("diskFreeHardlimit", Integer.toString(diskFreeHardlimit))); } catch (final NumberFormatException e){} - sb.setConfig(SwitchboardConstants.DISK_FREE_HARDLIMIT, diskFreeHardlimit); + sb.setConfig(SwitchboardConstants.DISK_FREE_HARDLIMIT, post.getInt("diskFreeHardlimit", 1000)); } if(post.containsKey("memoryAcceptDHT")) { - int memoryAcceptDHT = 50; // default - try { memoryAcceptDHT = Integer.parseInt(post.get("memoryAcceptDHT", Integer.toString(memoryAcceptDHT))); } catch (final NumberFormatException e){} - sb.setConfig(SwitchboardConstants.MEMORY_ACCEPTDHT, memoryAcceptDHT); + sb.setConfig(SwitchboardConstants.MEMORY_ACCEPTDHT, post.getInt("memoryAcceptDHT", 50)); } if(post.containsKey("resetObserver")) { MemoryControl.setDHTallowed(); @@ -248,7 +242,7 @@ public class PerformanceQueues_p { c = 0; final int[] speedValues = {200,150,100,50,25,10}; - final int usedspeed = Integer.parseInt(sb.getConfig("performanceSpeed", "100")); + final int usedspeed = sb.getConfigInt("performanceSpeed", 100); for(final int speed: speedValues){ prop.put("speed_" + c + "_value", speed); prop.put("speed_" + c + "_label", speed + " %"); @@ -269,7 +263,7 @@ public class PerformanceQueues_p { * configuring the crawler pool */ // get the current crawler pool configuration - int maxBusy = Integer.parseInt(post.get("Crawler Pool_maxActive","8")); + int maxBusy = post.getInt("Crawler Pool_maxActive", 8); // storing the new values into configfile sb.setConfig(SwitchboardConstants.CRAWLER_THREADS_ACTIVE_MAX,maxBusy); @@ -280,7 +274,7 @@ public class PerformanceQueues_p { */ final WorkflowThread httpd = sb.getThread("10_httpd"); try { - maxBusy = Integer.parseInt(post.get("httpd Session Pool_maxActive","8")); + maxBusy = post.getInt("httpd Session Pool_maxActive", 8); } catch (final NumberFormatException e) { maxBusy = 8; } @@ -330,22 +324,22 @@ public class PerformanceQueues_p { prop.putNum("crawlPauseLocalsearchCurrent", (System.currentTimeMillis() - sb.localSearchLastAccess) / 1000); prop.putNum("crawlPauseRemotesearchCurrent", (System.currentTimeMillis() - sb.remoteSearchLastAccess) / 1000); - // table thread pool settings + // table thread pool settings prop.put("pool_0_name","Crawler Pool"); prop.put("pool_0_maxActive", sb.getConfigLong("crawler.MaxActiveThreads", 0)); - prop.put("pool_0_numActive",sb.crawlQueues.workerSize()); + prop.put("pool_0_numActive",sb.crawlQueues.workerSize()); final WorkflowThread httpd = sb.getThread("10_httpd"); prop.put("pool_1_name", "httpd Session Pool"); prop.put("pool_1_maxActive", ((serverCore)httpd).getMaxSessionCount()); prop.put("pool_1_numActive", ((serverCore)httpd).getJobCount()); - - prop.put("pool", "2"); + + prop.put("pool", "2"); final long curr_prio = sb.getConfigLong("javastart_priority",0); - prop.put("priority_normal",(curr_prio==0) ? "1" : "0"); - prop.put("priority_below",(curr_prio==10) ? "1" : "0"); - prop.put("priority_low",(curr_prio==20) ? "1" : "0"); + prop.put("priority_normal",(curr_prio == 0) ? "1" : "0"); + prop.put("priority_below",(curr_prio == 10) ? "1" : "0"); + prop.put("priority_low",(curr_prio == 20) ? "1" : "0"); // parse initialization memory settings final String Xmx = sb.getConfig("javastart_Xmx", "Xmx500m").substring(3); @@ -353,9 +347,9 @@ public class PerformanceQueues_p { final String Xms = sb.getConfig("javastart_Xms", "Xms500m").substring(3); prop.put("Xms", Xms.substring(0, Xms.length() - 1)); - final String diskFree = sb.getConfig(SwitchboardConstants.DISK_FREE, "3000"); - final String diskFreeHardlimit = sb.getConfig(SwitchboardConstants.DISK_FREE_HARDLIMIT, "1000"); - final String memoryAcceptDHT = sb.getConfig(SwitchboardConstants.MEMORY_ACCEPTDHT, "50000"); + final long diskFree = sb.getConfigLong(SwitchboardConstants.DISK_FREE, 3000L); + final long diskFreeHardlimit = sb.getConfigLong(SwitchboardConstants.DISK_FREE_HARDLIMIT, 1000L); + final long memoryAcceptDHT = sb.getConfigLong(SwitchboardConstants.MEMORY_ACCEPTDHT, 50000L); final boolean observerTrigger = !MemoryControl.getDHTallowed(); prop.put("diskFree", diskFree); prop.put("diskFreeHardlimit", diskFreeHardlimit); diff --git a/htroot/ProxyIndexingMonitor_p.java b/htroot/ProxyIndexingMonitor_p.java index f4bcca6a2..1f2d41bb5 100644 --- a/htroot/ProxyIndexingMonitor_p.java +++ b/htroot/ProxyIndexingMonitor_p.java @@ -54,7 +54,7 @@ public class ProxyIndexingMonitor_p { // boolean se = false; String oldProxyCachePath, newProxyCachePath; - String oldProxyCacheSize, newProxyCacheSize; + long oldProxyCacheSize, newProxyCacheSize; prop.put("info", "0"); prop.put("info_message", ""); @@ -64,19 +64,19 @@ public class ProxyIndexingMonitor_p { if (post.containsKey("proxyprofileset")) try { // read values and put them in global settings final boolean proxyYaCyOnly = post.containsKey("proxyYacyOnly"); - env.setConfig(SwitchboardConstants.PROXY_YACY_ONLY, (proxyYaCyOnly) ? "true" : "false"); + env.setConfig(SwitchboardConstants.PROXY_YACY_ONLY, (proxyYaCyOnly) ? true : false); int newProxyPrefetchDepth = post.getInt("proxyPrefetchDepth", 0); if (newProxyPrefetchDepth < 0) newProxyPrefetchDepth = 0; if (newProxyPrefetchDepth > 20) newProxyPrefetchDepth = 20; // self protection ? env.setConfig("proxyPrefetchDepth", Integer.toString(newProxyPrefetchDepth)); final boolean proxyStoreHTCache = post.containsKey("proxyStoreHTCache"); - env.setConfig("proxyStoreHTCache", (proxyStoreHTCache) ? "true" : "false"); + env.setConfig("proxyStoreHTCache", (proxyStoreHTCache) ? true : false); final boolean proxyIndexingRemote = post.containsKey("proxyIndexingRemote"); - env.setConfig("proxyIndexingRemote", proxyIndexingRemote ? "true" : "false"); + env.setConfig("proxyIndexingRemote", proxyIndexingRemote ? true : false); final boolean proxyIndexingLocalText = post.containsKey("proxyIndexingLocalText"); - env.setConfig("proxyIndexingLocalText", proxyIndexingLocalText ? "true" : "false"); + env.setConfig("proxyIndexingLocalText", proxyIndexingLocalText ? true : false); final boolean proxyIndexingLocalMedia = post.containsKey("proxyIndexingLocalMedia"); - env.setConfig("proxyIndexingLocalMedia", proxyIndexingLocalMedia ? "true" : "false"); + env.setConfig("proxyIndexingLocalMedia", proxyIndexingLocalMedia ? true : false); // added proxyCache, proxyCacheSize - Borg-0300 // proxyCache - check and create the directory @@ -91,11 +91,11 @@ public class ProxyIndexingMonitor_p { if (!cache.isDirectory() && !cache.isFile()) cache.mkdirs(); // proxyCacheSize - oldProxyCacheSize = getStringLong(env.getConfig(SwitchboardConstants.PROXY_CACHE_SIZE, "64")); - newProxyCacheSize = getStringLong(post.get(SwitchboardConstants.PROXY_CACHE_SIZE, "64")); - if (getLong(newProxyCacheSize) < 4) { newProxyCacheSize = "4"; } + oldProxyCacheSize = env.getConfigLong(SwitchboardConstants.PROXY_CACHE_SIZE, 64L); + newProxyCacheSize = post.getLong(SwitchboardConstants.PROXY_CACHE_SIZE, 64L); + if (newProxyCacheSize < 4) { newProxyCacheSize = 4; } env.setConfig(SwitchboardConstants.PROXY_CACHE_SIZE, newProxyCacheSize); - Cache.setMaxCacheSize(Long.parseLong(newProxyCacheSize) * 1024 * 1024); + Cache.setMaxCacheSize(newProxyCacheSize * 1024 * 1024); // implant these settings also into the crawling profile for the proxy if (sb.crawler.defaultProxyProfile == null) { @@ -103,10 +103,10 @@ public class ProxyIndexingMonitor_p { } else { assert sb.crawler.defaultProxyProfile.handle() != null; sb.crawler.defaultProxyProfile.put("generalDepth", Integer.toString(newProxyPrefetchDepth)); - sb.crawler.defaultProxyProfile.put("storeHTCache", (proxyStoreHTCache) ? "true": "false"); - sb.crawler.defaultProxyProfile.put("remoteIndexing",proxyIndexingRemote ? "true":"false"); - sb.crawler.defaultProxyProfile.put("indexText",proxyIndexingLocalText ? "true":"false"); - sb.crawler.defaultProxyProfile.put("indexMedia",proxyIndexingLocalMedia ? "true":"false"); + sb.crawler.defaultProxyProfile.put("storeHTCache", proxyStoreHTCache); + sb.crawler.defaultProxyProfile.put("remoteIndexing", proxyIndexingRemote); + sb.crawler.defaultProxyProfile.put("indexText", proxyIndexingLocalText); + sb.crawler.defaultProxyProfile.put("indexMedia", proxyIndexingLocalMedia); sb.crawler.putActive(sb.crawler.defaultProxyProfile.handle().getBytes(), sb.crawler.defaultProxyProfile); prop.put("info", "2");//new proxyPrefetchdepth @@ -125,7 +125,7 @@ public class ProxyIndexingMonitor_p { prop.putHTML("info_path_return", newProxyCachePath); } // proxyCacheSize - only display on change - if (oldProxyCacheSize.equals(newProxyCacheSize)) { + if (oldProxyCacheSize == newProxyCacheSize) { prop.put("info_size", "0"); prop.put("info_size_return", oldProxyCacheSize); } else { @@ -148,30 +148,14 @@ public class ProxyIndexingMonitor_p { final boolean yacyonly = env.getConfigBool(SwitchboardConstants.PROXY_YACY_ONLY, false); prop.put("proxyYacyOnly", yacyonly ? "1" : "0"); prop.put("proxyPrefetchDepth", env.getConfigLong("proxyPrefetchDepth", 0)); - prop.put("proxyStoreHTCacheChecked", env.getConfig("proxyStoreHTCache", "").equals("true") ? "1" : "0"); - prop.put("proxyIndexingRemote", env.getConfig("proxyIndexingRemote", "").equals("true") ? "1" : "0"); - prop.put("proxyIndexingLocalText", env.getConfig("proxyIndexingLocalText", "").equals("true") ? "1" : "0"); - prop.put("proxyIndexingLocalMedia", env.getConfig("proxyIndexingLocalMedia", "").equals("true") ? "1" : "0"); + prop.put("proxyStoreHTCacheChecked", env.getConfigBool("proxyStoreHTCache", false) ? "1" : "0"); + prop.put("proxyIndexingRemote", env.getConfigBool("proxyIndexingRemote", false) ? "1" : "0"); + prop.put("proxyIndexingLocalText", env.getConfigBool("proxyIndexingLocalText", false) ? "1" : "0"); + prop.put("proxyIndexingLocalMedia", env.getConfigBool("proxyIndexingLocalMedia", false) ? "1" : "0"); prop.put("proxyCache", env.getConfig(SwitchboardConstants.HTCACHE_PATH, SwitchboardConstants.HTCACHE_PATH_DEFAULT)); prop.put("proxyCacheSize", env.getConfigLong(SwitchboardConstants.PROXY_CACHE_SIZE, 64)); // return rewrite properties return prop; } - public static long getLong(final String value) { - try { - return Long.parseLong(value); - } catch (final Exception e) { - return 0; - } - } - - public static String getStringLong(final String value) { - try { - return Long.toString(Long.parseLong(value)); - } catch (final Exception e) { - return "0"; - } - } - } \ No newline at end of file diff --git a/htroot/QuickCrawlLink_p.java b/htroot/QuickCrawlLink_p.java index 332882b7b..500a6ecf0 100644 --- a/htroot/QuickCrawlLink_p.java +++ b/htroot/QuickCrawlLink_p.java @@ -110,10 +110,10 @@ public class QuickCrawlLink_p { // get other parameters if set final String crawlingMustMatch = post.get("mustmatch", CrawlProfile.MATCH_ALL); final String crawlingMustNotMatch = post.get("mustnotmatch", CrawlProfile.MATCH_NEVER); - final int CrawlingDepth = Integer.parseInt(post.get("crawlingDepth", "0")); + final int CrawlingDepth = post.getInt("crawlingDepth", 0); final boolean crawlDynamic = post.get("crawlingQ", "").equals("on"); final boolean indexText = post.get("indexText", "on").equals("on"); - final boolean indexMedia = post.get("indexMedia", "on").equals("on"); + final boolean indexMedia = post.get("indexMedia", "on").equals("on"); final boolean storeHTCache = post.get("storeHTCache", "").equals("on"); final boolean remoteIndexing = post.get("crawlOrder", "").equals("on"); final boolean xsstopw = post.get("xsstopw", "").equals("on"); diff --git a/htroot/RemoteCrawl_p.java b/htroot/RemoteCrawl_p.java index 2bc0a741c..59e96e0fd 100644 --- a/htroot/RemoteCrawl_p.java +++ b/htroot/RemoteCrawl_p.java @@ -57,14 +57,14 @@ public class RemoteCrawl_p { boolean crawlResponse = post.get("crawlResponse", "off").equals("on"); // read remote crawl request settings - sb.setConfig("crawlResponse", (crawlResponse) ? "true" : "false"); + sb.setConfig("crawlResponse", crawlResponse); } if (post.containsKey("acceptCrawlLimit")) { // read remote crawl request settings int newppm = 1; try { - newppm = Math.max(1, Integer.parseInt(post.get("acceptCrawlLimit", "1"))); + newppm = Math.max(1, post.getInt("acceptCrawlLimit", 1)); } catch (final NumberFormatException e) {} sb.setRemotecrawlPPM(newppm); } @@ -119,7 +119,7 @@ public class RemoteCrawl_p { prop.putHTML(STR_TABLE_LIST + conCount + "_version", yacyVersion.combined2prettyVersion(seed.get(yacySeed.VERSION, "0.1"), shortname)); prop.putNum(STR_TABLE_LIST + conCount + "_lastSeen", /*seed.getLastSeenString() + " " +*/ lastseen); prop.put(STR_TABLE_LIST + conCount + "_utc", seed.get(yacySeed.UTC, "-")); - prop.putHTML(STR_TABLE_LIST + conCount + "_uptime", yacyPeerActions.formatInterval(60000 * Long.parseLong(seed.get(yacySeed.UPTIME, "0")))); + prop.putHTML(STR_TABLE_LIST + conCount + "_uptime", yacyPeerActions.formatInterval(60000 * seed.getLong(yacySeed.UPTIME, 0L))); prop.putNum(STR_TABLE_LIST + conCount + "_LCount", seed.getLinkCount()); prop.putNum(STR_TABLE_LIST + conCount + "_ICount", seed.getWordCount()); prop.putNum(STR_TABLE_LIST + conCount + "_RCount", rcount); diff --git a/htroot/SettingsAck_p.java b/htroot/SettingsAck_p.java index 5aeeee6f6..020e7f8f2 100644 --- a/htroot/SettingsAck_p.java +++ b/htroot/SettingsAck_p.java @@ -130,15 +130,9 @@ public class SettingsAck_p { // read and process data String filter = (post.get("proxyfilter")).trim(); - String use_proxyAccounts=""; - if(post.containsKey("use_proxyaccounts")){ - //needed? or set to true by default? - use_proxyAccounts = ((post.get("use_proxyaccounts")).equals("on") ? "true" : "false" ); - }else{ - use_proxyAccounts = "false"; - } + final boolean useProxyAccounts = post.containsKey("use_proxyaccounts") && post.get("use_proxyaccounts").equals("on"); // do checks - if ((filter == null) || (use_proxyAccounts == null)) { + if ((filter == null) || (!post.containsKey("use_proxyaccounts"))) { prop.put("info", "1");//error with submitted information return prop; } @@ -175,8 +169,8 @@ public class SettingsAck_p { // check passed. set account: env.setConfig("proxyClient", filter); - env.setConfig("use_proxyAccounts", use_proxyAccounts);//"true" or "false" - if (use_proxyAccounts.equals("false")){ + env.setConfig("use_proxyAccounts", useProxyAccounts); + if (!useProxyAccounts){ prop.put("info", "6");//proxy account has changed(no pw) prop.putHTML("info_filter", filter); } else { @@ -192,20 +186,20 @@ public class SettingsAck_p { // set transparent proxy flag HTTPDProxyHandler.isTransparentProxy = post.containsKey("isTransparentProxy"); - env.setConfig("isTransparentProxy", HTTPDProxyHandler.isTransparentProxy ? "true" : "false"); + env.setConfig("isTransparentProxy", HTTPDProxyHandler.isTransparentProxy); prop.put("info_isTransparentProxy", HTTPDProxyHandler.isTransparentProxy ? "on" : "off"); // setting the keep alive property HTTPDemon.keepAliveSupport = post.containsKey("connectionKeepAliveSupport"); - env.setConfig("connectionKeepAliveSupport", HTTPDemon.keepAliveSupport ? "true" : "false"); + env.setConfig("connectionKeepAliveSupport", HTTPDemon.keepAliveSupport); prop.put("info_connectionKeepAliveSupport", HTTPDemon.keepAliveSupport ? "on" : "off"); // setting via header property - env.setConfig("proxy.sendViaHeader", post.containsKey("proxy.sendViaHeader")?"true":"false"); + env.setConfig("proxy.sendViaHeader", post.containsKey("proxy.sendViaHeader")); prop.put("info_proxy.sendViaHeader", post.containsKey("proxy.sendViaHeader")? "on" : "off"); // setting X-Forwarded-for header property - env.setConfig("proxy.sendXForwardedForHeader", post.containsKey("proxy.sendXForwardedForHeader")?"true":"false"); + env.setConfig("proxy.sendXForwardedForHeader", post.containsKey("proxy.sendXForwardedForHeader")); prop.put("info_proxy.sendXForwardedForHeader", post.containsKey("proxy.sendXForwardedForHeader")? "on" : "off"); prop.put("info", "20"); @@ -294,13 +288,7 @@ public class SettingsAck_p { final boolean useRemoteProxy4SSL = post.containsKey("remoteProxyUse4SSL"); final String remoteProxyHost = post.get("remoteProxyHost", ""); - final String remoteProxyPortStr = post.get("remoteProxyPort", ""); - int remoteProxyPort = 0; - try { - remoteProxyPort = Integer.parseInt(remoteProxyPortStr); - } catch (final NumberFormatException e) { - remoteProxyPort = 3128; - } + final int remoteProxyPort = post.getInt("remoteProxyPort", 3128); final String remoteProxyUser = post.get("remoteProxyUser", ""); final String remoteProxyPwd = post.get("remoteProxyPwd", ""); @@ -316,9 +304,9 @@ public class SettingsAck_p { env.setConfig("remoteProxyUser", remoteProxyUser); env.setConfig("remoteProxyPwd", remoteProxyPwd); env.setConfig("remoteProxyNoProxy", remoteProxyNoProxyStr); - env.setConfig("remoteProxyUse", (useRemoteProxy) ? "true" : "false"); - env.setConfig("remoteProxyUse4Yacy", (useRemoteProxy4Yacy) ? "true" : "false"); - env.setConfig("remoteProxyUse4SSL", (useRemoteProxy4SSL) ? "true" : "false"); + env.setConfig("remoteProxyUse", useRemoteProxy); + env.setConfig("remoteProxyUse4Yacy", useRemoteProxy4Yacy); + env.setConfig("remoteProxyUse4SSL", useRemoteProxy4SSL); /* ==================================================================== * Enabling settings @@ -436,9 +424,9 @@ public class SettingsAck_p { * Message forwarding configuration */ if (post.containsKey("msgForwarding")) { - env.setConfig("msgForwardingEnabled",post.containsKey("msgForwardingEnabled")?"true":"false"); - env.setConfig("msgForwardingCmd",post.get("msgForwardingCmd")); - env.setConfig("msgForwardingTo",post.get("msgForwardingTo")); + env.setConfig("msgForwardingEnabled", post.containsKey("msgForwardingEnabled")); + env.setConfig("msgForwardingCmd", post.get("msgForwardingCmd")); + env.setConfig("msgForwardingTo", post.get("msgForwardingTo")); prop.put("info", "21"); prop.put("info_msgForwardingEnabled", post.containsKey("msgForwardingEnabled") ? "on" : "off"); diff --git a/htroot/Settings_p.java b/htroot/Settings_p.java index 0980cb1ee..0e6fd50d5 100644 --- a/htroot/Settings_p.java +++ b/htroot/Settings_p.java @@ -85,10 +85,10 @@ public final class Settings_p { prop.putHTML("peerLang", peerLang); // http networking settings - prop.put("isTransparentProxy", env.getConfig("isTransparentProxy", "false").equals("true") ? "1" : "0"); - prop.put("connectionKeepAliveSupport", env.getConfig("connectionKeepAliveSupport", "false").equals("true") ? "1" : "0"); - prop.put("proxy.sendViaHeader", env.getConfig("proxy.sendViaHeader", "false").equals("true") ? "1" : "0"); - prop.put("proxy.sendXForwardedForHeader", env.getConfig("proxy.sendXForwardedForHeader", "true").equals("true") ? "1" : "0"); + prop.put("isTransparentProxy", env.getConfigBool("isTransparentProxy", false) ? "1" : "0"); + prop.put("connectionKeepAliveSupport", env.getConfigBool("connectionKeepAliveSupport", false) ? "1" : "0"); + prop.put("proxy.sendViaHeader", env.getConfigBool("proxy.sendViaHeader", false) ? "1" : "0"); + prop.put("proxy.sendXForwardedForHeader", env.getConfigBool("proxy.sendXForwardedForHeader", true) ? "1" : "0"); // set values String s; @@ -109,9 +109,9 @@ public final class Settings_p { } // remote proxy - prop.put("remoteProxyUseChecked", env.getConfig("remoteProxyUse", "false").equals("true") ? 1 : 0); - prop.put("remoteProxyUse4Yacy", env.getConfig("remoteProxyUse4Yacy", "true").equals("true") ? 1 : 0); - prop.put("remoteProxyUse4SSL", env.getConfig("remoteProxyUse4SSL", "true").equals("true") ? 1 : 0); + prop.put("remoteProxyUseChecked", env.getConfigBool("remoteProxyUse", false) ? 1 : 0); + prop.put("remoteProxyUse4Yacy", env.getConfigBool("remoteProxyUse4Yacy", true) ? 1 : 0); + prop.put("remoteProxyUse4SSL", env.getConfigBool("remoteProxyUse4SSL", true) ? 1 : 0); prop.putHTML("remoteProxyHost", env.getConfig("remoteProxyHost", "")); prop.putHTML("remoteProxyPort", env.getConfig("remoteProxyPort", "")); @@ -125,7 +125,7 @@ public final class Settings_p { prop.putHTML("proxyfilter", env.getConfig("proxyClient", "*")); // proxy password - if ( env.getConfig("use_proxyAccounts", "false").equals("false") ) { + if (!env.getConfigBool("use_proxyAccounts", false)) { // no password has been specified prop.put("use_proxyAccounts", "0"); //unchecked } else { @@ -194,7 +194,7 @@ public final class Settings_p { /* * Message forwarding configuration */ - prop.put("msgForwardingEnabled",env.getConfig("msgForwardingEnabled","false").equals("true") ? "1" : "0"); + prop.put("msgForwardingEnabled",env.getConfigBool("msgForwardingEnabled",false) ? "1" : "0"); prop.putHTML("msgForwardingCmd",env.getConfig("msgForwardingCmd", "")); prop.putHTML("msgForwardingTo",env.getConfig("msgForwardingTo", "")); diff --git a/htroot/Status.java b/htroot/Status.java index 60dd20f4f..7e6e456ec 100644 --- a/htroot/Status.java +++ b/htroot/Status.java @@ -99,20 +99,12 @@ public class Status { ByteCount.resetCount(); redirect = true; } else if (post.containsKey("popup")) { - final String trigger_enabled = post.get("popup"); - if ("false".equals(trigger_enabled)) { - sb.setConfig("browserPopUpTrigger", "false"); - } else if ("true".equals(trigger_enabled)){ - sb.setConfig("browserPopUpTrigger", "true"); - } + final boolean trigger_enabled = post.getBoolean("popup", false); + sb.setConfig("browserPopUpTrigger", trigger_enabled); redirect = true; } else if (post.containsKey("tray")) { - final String trigger_enabled = post.get("tray"); - if ("false".equals(trigger_enabled)) { - sb.setConfig("trayIcon", "false"); - } else if ("true".equals(trigger_enabled)){ - sb.setConfig("trayIcon", "true"); - } + final boolean trigger_enabled = post.getBoolean("tray", false); + sb.setConfig("trayIcon", trigger_enabled); redirect = true; } @@ -192,11 +184,11 @@ public class Status { // ssl support prop.put("sslSupport",sb.getConfig("keyStore", "").length() == 0 ? "0" : "1"); - if ("true".equals(sb.getConfig("remoteProxyUse", "false"))) { + if (sb.getConfigBool("remoteProxyUse", false)) { prop.put("remoteProxy", "1"); prop.putXML("remoteProxy_host", sb.getConfig("remoteProxyHost", "")); prop.putXML("remoteProxy_port", sb.getConfig("remoteProxyPort", "")); - prop.put("remoteProxy_4Yacy", "true".equalsIgnoreCase(sb.getConfig("remoteProxyUse4Yacy", "true")) ? "0" : "1"); + prop.put("remoteProxy_4Yacy", sb.getConfigBool("remoteProxyUse4Yacy", true) ? "0" : "1"); } else { prop.put("remoteProxy", "0"); // not used } @@ -209,7 +201,7 @@ public class Status { prop.put("peerAddress", "0"); // not assigned prop.put("peerStatistics", "0"); // unknown } else { - final long uptime = 60000 * Long.parseLong(sb.peers.mySeed().get(yacySeed.UPTIME, "0")); + final long uptime = 60000 * sb.peers.mySeed().getLong(yacySeed.UPTIME, 0L); prop.put("peerStatistics", "1"); prop.put("peerStatistics_uptime", yacyPeerActions.formatInterval(uptime)); prop.putNum("peerStatistics_pagesperminute", sb.peers.mySeed().getPPM()); @@ -282,7 +274,7 @@ public class Status { prop.put("otherPeers", "0"); // not online } - if ("false".equals(sb.getConfig("browserPopUpTrigger", "false"))) { + if (!sb.getConfigBool("browserPopUpTrigger", false)) { prop.put("popup", "0"); } else { prop.put("popup", "1"); @@ -290,7 +282,7 @@ public class Status { if (!OS.isWindows) { prop.put("tray", "2"); - } else if ("false".equals(sb.getConfig("trayIcon", "false"))) { + } else if (!sb.getConfigBool("trayIcon", false)) { prop.put("tray", "0"); } else { prop.put("tray", "1"); @@ -314,8 +306,8 @@ public class Status { // Queue information final int loaderJobCount = sb.crawlQueues.workerSize(); - final int loaderMaxCount = Integer.parseInt(sb.getConfig(SwitchboardConstants.CRAWLER_THREADS_ACTIVE_MAX, "10")); - final int loaderPercent = (loaderMaxCount==0)?0:loaderJobCount*100/loaderMaxCount; + final int loaderMaxCount = sb.getConfigInt(SwitchboardConstants.CRAWLER_THREADS_ACTIVE_MAX, 10); + final int loaderPercent = (loaderMaxCount == 0) ? 0 : loaderJobCount * 100 / loaderMaxCount; prop.putNum("loaderQueueSize", loaderJobCount); prop.putNum("loaderQueueMax", loaderMaxCount); prop.put("loaderQueuePercent", (loaderPercent>100) ? 100 : loaderPercent); diff --git a/htroot/Table_API_p.java b/htroot/Table_API_p.java index 49e9311d8..4f553bb2b 100644 --- a/htroot/Table_API_p.java +++ b/htroot/Table_API_p.java @@ -24,6 +24,7 @@ import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.TreeSet; import java.util.regex.Pattern; @@ -50,16 +51,15 @@ public class Table_API_p { int startRecord = 0; int maximumRecords = 25; - boolean inline = false; Pattern query = Pattern.compile(".*"); if (post != null && post.containsKey("startRecord")) startRecord = post.getInt("startRecord", 0); if (post != null && post.containsKey("maximumRecords")) maximumRecords = post.getInt("maximumRecords", 0); - if (post != null && post.containsKey("query") && post.get("query", "").length() > 0) { + if (post != null && post.containsKey("query") && !post.get("query", "").isEmpty()) { query = Pattern.compile(".*" + post.get("query", "") + ".*"); startRecord = 0; maximumRecords = 1000; } - if (post != null && post.get("inline","false").equals("true")) inline = true; + final boolean inline = (post != null && post.getBoolean("inline",false)); prop.put("inline", (inline) ? 1 : 0); @@ -70,7 +70,7 @@ public class Table_API_p { String pk; if (post != null && post.containsKey("repeat_select") && ((pk = post.get("pk")) != null)) try { - String action = post.get("repeat_select", "off"); + final String action = post.get("repeat_select", "off"); if (action.equals("on")) { Tables.Row row = sb.tables.select(WorkTables.TABLE_API_NAME, pk.getBytes()); if (row != null) { @@ -87,10 +87,10 @@ public class Table_API_p { } if (post != null && post.containsKey("repeat_time") && ((pk = post.get("pk")) != null)) try { - String action = post.get("repeat_time", "off"); - Tables.Row row = sb.tables.select(WorkTables.TABLE_API_NAME, pk.getBytes()); + final String action = post.get("repeat_time", "off"); + final Tables.Row row = sb.tables.select(WorkTables.TABLE_API_NAME, pk.getBytes()); if (row != null) { - if (action.equals("off")) { + if ("off".equals(action)) { row.put(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_TIME, 0); } else { row.put(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_TIME, Integer.parseInt(action)); @@ -105,8 +105,8 @@ public class Table_API_p { } if (post != null && post.containsKey("repeat_unit") && ((pk = post.get("pk")) != null)) try { - String action = post.get("repeat_unit", "seldays"); - Tables.Row row = sb.tables.select(WorkTables.TABLE_API_NAME, pk.getBytes()); + final String action = post.get("repeat_unit", "seldays"); + final Tables.Row row = sb.tables.select(WorkTables.TABLE_API_NAME, pk.getBytes()); if (row != null) { int time = row.get(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_TIME, 1); row.put(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_UNIT, action.substring(3)); @@ -123,8 +123,8 @@ public class Table_API_p { Log.logException(e); } - if (post != null && post.get("deleterows", "").length() > 0) { - for (Map.Entry entry: post.entrySet()) { + if (post != null && !post.get("deleterows", "").isEmpty()) { + for (final Map.Entry entry: post.entrySet()) { if (entry.getValue().startsWith("mark_")) { try { sb.tables.delete(WorkTables.TABLE_API_NAME, entry.getValue().substring(5).getBytes()); @@ -135,17 +135,17 @@ public class Table_API_p { } } - if (post != null && post.get("execrows", "").length() > 0) { + if (post != null && !post.get("execrows", "").isEmpty()) { // create a time-ordered list of events to execute - TreeSet pks = new TreeSet(); - for (Map.Entry entry: post.entrySet()) { + final Set pks = new TreeSet(); + for (final Map.Entry entry: post.entrySet()) { if (entry.getValue().startsWith("mark_")) { pks.add(entry.getValue().substring(5)); } } // now call the api URLs and store the result status - Map l = sb.tables.execAPICalls("localhost", (int) sb.getConfigLong("port", 8090), sb.getConfig("adminAccountBase64MD5", ""), pks); + final Map l = sb.tables.execAPICalls("localhost", (int) sb.getConfigLong("port", 8090), sb.getConfig("adminAccountBase64MD5", ""), pks); // construct result table prop.put("showexec", l.size() > 0 ? 1 : 0); @@ -170,7 +170,7 @@ public class Table_API_p { prop.put("showtable_inline", inline ? 1 : 0); // insert rows - List table = new ArrayList(maximumRecords); + final List table = new ArrayList(maximumRecords); int count = 0; int tablesize = 0; try { @@ -195,15 +195,15 @@ public class Table_API_p { if (table.size() >= maximumRecords) break; } // then work on the list - for (Tables.Row row: table) { - Date now = new Date(); - Date date = row.containsKey(WorkTables.TABLE_API_COL_DATE) ? row.get(WorkTables.TABLE_API_COL_DATE, now) : null; - Date date_recording = row.get(WorkTables.TABLE_API_COL_DATE_RECORDING, date); - Date date_last_exec = row.get(WorkTables.TABLE_API_COL_DATE_LAST_EXEC, date); - Date date_next_exec = row.get(WorkTables.TABLE_API_COL_DATE_NEXT_EXEC, (Date) null); - int callcount = row.get(WorkTables.TABLE_API_COL_APICALL_COUNT, 1); - String unit = row.get(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_UNIT, "days"); - int time = row.get(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_TIME, 0); + for (final Tables.Row row: table) { + final Date now = new Date(); + final Date date = row.containsKey(WorkTables.TABLE_API_COL_DATE) ? row.get(WorkTables.TABLE_API_COL_DATE, now) : null; + final Date date_recording = row.get(WorkTables.TABLE_API_COL_DATE_RECORDING, date); + final Date date_last_exec = row.get(WorkTables.TABLE_API_COL_DATE_LAST_EXEC, date); + final Date date_next_exec = row.get(WorkTables.TABLE_API_COL_DATE_NEXT_EXEC, (Date) null); + final int callcount = row.get(WorkTables.TABLE_API_COL_APICALL_COUNT, 1); + final String unit = row.get(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_UNIT, "days"); + final int time = row.get(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_TIME, 0); prop.put("showtable_list_" + count + "_inline", inline ? 1 : 0); prop.put("showtable_list_" + count + "_dark", dark ? 1 : 0); dark=!dark; prop.put("showtable_list_" + count + "_pk", UTF8.String(row.getPK())); diff --git a/htroot/Table_YMark_p.java b/htroot/Table_YMark_p.java index d066c9a16..d2627580d 100644 --- a/htroot/Table_YMark_p.java +++ b/htroot/Table_YMark_p.java @@ -87,15 +87,14 @@ public class Table_YMark_p { Log.logException(e); } - String counts = post.get("count", null); - int maxcount = (counts == null || counts.equals("all")) ? Integer.MAX_VALUE : Integer.parseInt(counts); + final String counts = post.get("count", null); + int maxcount = (counts == null || counts.equals("all")) ? Integer.MAX_VALUE : post.getInt("count", 10); String pattern = post.get("search", ""); - Pattern matcher = (pattern.length() == 0 || pattern.equals(".*")) ? null : Pattern.compile(".*" + pattern + ".*"); + Pattern matcher = (pattern.isEmpty() || pattern.equals(".*")) ? null : Pattern.compile(".*" + pattern + ".*"); prop.put("pattern", pattern); - List columns = null; - columns = new ArrayList(); - for (Map.Entry entry: post.entrySet()) { + List columns = new ArrayList(); + for (final Map.Entry entry: post.entrySet()) { if (entry.getKey().startsWith("col_")) { columns.add(entry.getKey().substring(4)); } @@ -111,62 +110,62 @@ public class Table_YMark_p { Iterator cit; String col; try { - cit = sb.tables.columns(table).iterator(); + cit = sb.tables.columns(table).iterator(); while(cit.hasNext()) { - col = cit.next(); - prop.put("showselection_columns_" + count + "_col", col); - prop.put("showselection_columns_" + count + "_checked", columns.contains(col) ? 1 : 0); - count++; + col = cit.next(); + prop.put("showselection_columns_" + count + "_col", col); + prop.put("showselection_columns_" + count + "_checked", columns.contains(col) ? 1 : 0); + count++; } - } catch (IOException e) { + } catch (IOException e) { Log.logException(e); - } + } } prop.put("showselection_columns", count); // apply deletion requests - if (post.get("deletetable", "").length() > 0) try { - sb.tables.clear(table); - sb.tables.clear(YMarkTables.TABLES.FOLDERS.tablename(bmk_user)); - sb.tables.clear(YMarkTables.TABLES.TAGS.tablename(bmk_user)); + if (!post.get("deletetable", "").isEmpty()) try { + sb.tables.clear(table); + sb.tables.clear(YMarkTables.TABLES.FOLDERS.tablename(bmk_user)); + sb.tables.clear(YMarkTables.TABLES.TAGS.tablename(bmk_user)); } catch (IOException e) { Log.logException(e); } // apply rebuildIndex request - if (post.get("rebuildindex", "").length() > 0) try { - sb.tables.bookmarks.folders.rebuildIndex(bmk_user); - sb.tables.bookmarks.tags.rebuildIndex(bmk_user); + if (!post.get("rebuildindex", "").isEmpty()) try { + sb.tables.bookmarks.folders.rebuildIndex(bmk_user); + sb.tables.bookmarks.tags.rebuildIndex(bmk_user); } catch (IOException e) { Log.logException(e); } - if (post.get("deleterows", "").length() > 0) { - for (Map.Entry entry: post.entrySet()) { + if (!post.get("deleterows", "").isEmpty()) { + for (final Map.Entry entry: post.entrySet()) { if (entry.getValue().startsWith("mark_")) try { - sb.tables.bookmarks.deleteBookmark(bmk_user, entry.getValue().substring(5).getBytes()); + sb.tables.bookmarks.deleteBookmark(bmk_user, entry.getValue().substring(5).getBytes()); } catch (IOException e) { Log.logException(e); } catch (RowSpaceExceededException e) { Log.logException(e); - } + } } } - if (post.get("commitrow", "").length() > 0) { - final HashMap bmk = new HashMap(); - for (Map.Entry entry: post.entrySet()) { + if (!post.get("commitrow", "").isEmpty()) { + final HashMap bmk = new HashMap(); + for (final Map.Entry entry: post.entrySet()) { if (entry.getKey().startsWith("col_")) { bmk.put(entry.getKey().substring(4), entry.getValue()); } } try { - sb.tables.bookmarks.addBookmark(bmk_user, bmk, false); - } catch (IOException e) { + sb.tables.bookmarks.addBookmark(bmk_user, bmk, false); + } catch (IOException e) { Log.logException(e); - } catch (RowSpaceExceededException e) { + } catch (RowSpaceExceededException e) { Log.logException(e); - } + } } // generate table @@ -178,7 +177,7 @@ public class Table_YMark_p { if (post.containsKey("editrow")) { // check if we can find a key String pk = null; - for (Map.Entry entry: post.entrySet()) { + for (final Map.Entry entry: post.entrySet()) { if (entry.getValue().startsWith("mark_")) { pk = entry.getValue().substring(5); break; @@ -195,7 +194,7 @@ public class Table_YMark_p { } } else if (post.containsKey("addrow")) try { // get a new key - String pk = UTF8.String(sb.tables.createRow(table)); + final String pk = UTF8.String(sb.tables.createRow(table)); setEdit(sb, prop, table, pk, columns); } catch (IOException e) { Log.logException(e); @@ -207,15 +206,15 @@ public class Table_YMark_p { try { - prop.put("showtable_bmksize", sb.tables.size(table)); - prop.put("showtable_tagsize", sb.tables.size(YMarkTables.TABLES.TAGS.tablename(bmk_user))); - prop.put("showtable_foldersize", sb.tables.size(YMarkTables.TABLES.FOLDERS.tablename(bmk_user))); - } catch (IOException e) { + prop.put("showtable_bmksize", sb.tables.size(table)); + prop.put("showtable_tagsize", sb.tables.size(YMarkTables.TABLES.TAGS.tablename(bmk_user))); + prop.put("showtable_foldersize", sb.tables.size(YMarkTables.TABLES.FOLDERS.tablename(bmk_user))); + } catch (IOException e) { Log.logException(e); - prop.put("showtable_bmksize", 0); - prop.put("showtable_tagsize", 0); - prop.put("showtable_foldersize", 0); - } + prop.put("showtable_bmksize", 0); + prop.put("showtable_tagsize", 0); + prop.put("showtable_foldersize", 0); + } // insert the columns @@ -233,9 +232,9 @@ public class Table_YMark_p { } count = 0; try { - Iterator mapIterator; - if(post.containsKey("folders") && !post.get("folders").isEmpty()) { - mapIterator = sb.tables.orderByPK(sb.tables.bookmarks.folders.getBookmarks(bmk_user, post.get("folders")), maxcount).iterator(); + Iterator mapIterator; + if (post.containsKey("folders") && !post.get("folders").isEmpty()) { + mapIterator = sb.tables.orderByPK(sb.tables.bookmarks.folders.getBookmarks(bmk_user, post.get("folders")), maxcount).iterator(); } else if(post.containsKey("tags") && !post.get("tags").isEmpty()) { mapIterator = sb.tables.orderByPK(sb.tables.bookmarks.tags.getBookmarks(bmk_user, post.get("tags")), maxcount).iterator(); } else { @@ -286,7 +285,7 @@ public class Table_YMark_p { if (row == null) return; int count = 0; byte[] cell; - for (String col: columns) { + for (final String col: columns) { cell = row.get(col); prop.put("showedit_list_" + count + "_key", col); prop.put("showedit_list_" + count + "_value", cell == null ? "" : UTF8.String(cell)); diff --git a/htroot/Tables_p.java b/htroot/Tables_p.java index b88e918e6..6d67559a3 100644 --- a/htroot/Tables_p.java +++ b/htroot/Tables_p.java @@ -50,7 +50,7 @@ public class Tables_p { // show table selection int count = 0; - Iterator ti = sb.tables.tables(); + final Iterator ti = sb.tables.tables(); String tablename; prop.put("showselection", 1); while (ti.hasNext()) { @@ -64,10 +64,10 @@ public class Tables_p { if (post == null) return prop; // return rewrite properties - String counts = post.get("count", null); - int maxcount = (counts == null || counts.equals("all")) ? Integer.MAX_VALUE : Integer.parseInt(counts); - String pattern = post.get("search", ""); - Pattern matcher = (pattern.length() == 0 || pattern.equals(".*")) ? null : Pattern.compile(".*" + pattern + ".*"); + final String counts = post.get("count", null); + int maxcount = (counts == null || counts.equals("all")) ? Integer.MAX_VALUE : post.getInt("count", 10); + final String pattern = post.get("search", ""); + final Pattern matcher = (pattern.length() == 0 || pattern.equals(".*")) ? null : Pattern.compile(".*" + pattern + ".*"); prop.put("pattern", pattern); List columns = null; @@ -86,7 +86,7 @@ public class Tables_p { } if (post.get("deleterows", "").length() > 0) { - for (Map.Entry entry: post.entrySet()) { + for (final Map.Entry entry: post.entrySet()) { if (entry.getValue().startsWith("mark_")) try { sb.tables.delete(table, entry.getValue().substring(5).getBytes()); } catch (IOException e) { @@ -96,9 +96,9 @@ public class Tables_p { } if (post.get("commitrow", "").length() > 0) { - String pk = post.get("pk"); - Map map = new HashMap(); - for (Map.Entry entry: post.entrySet()) { + final String pk = post.get("pk"); + final Map map = new HashMap(); + for (final Map.Entry entry: post.entrySet()) { if (entry.getKey().startsWith("col_")) { map.put(entry.getKey().substring(4), entry.getValue().getBytes()); } @@ -119,7 +119,7 @@ public class Tables_p { if (post.containsKey("editrow")) { // check if we can find a key String pk = null; - for (Map.Entry entry: post.entrySet()) { + for (final Map.Entry entry: post.entrySet()) { if (entry.getValue().startsWith("mark_")) { pk = entry.getValue().substring(5); break; @@ -136,7 +136,7 @@ public class Tables_p { } } else if (post.containsKey("addrow")) try { // get a new key - String pk = UTF8.String(sb.tables.createRow(table)); + final String pk = UTF8.String(sb.tables.createRow(table)); setEdit(sb, prop, table, pk, columns); } catch (IOException e) { Log.logException(e); @@ -202,11 +202,11 @@ public class Tables_p { prop.put("showedit", 1); prop.put("showedit_table", table); prop.put("showedit_pk", pk); - Tables.Row row = sb.tables.select(table, pk.getBytes()); + final Tables.Row row = sb.tables.select(table, pk.getBytes()); if (row == null) return; int count = 0; byte[] cell; - for (String col: columns) { + for (final String col: columns) { cell = row.get(col); prop.put("showedit_list_" + count + "_key", col); prop.put("showedit_list_" + count + "_value", cell == null ? "" : UTF8.String(cell)); diff --git a/htroot/Threaddump_p.java b/htroot/Threaddump_p.java index c6ca134c7..ca9b36dc8 100644 --- a/htroot/Threaddump_p.java +++ b/htroot/Threaddump_p.java @@ -49,7 +49,7 @@ public class Threaddump_p { final StringBuilder buffer = new StringBuilder(1000); - final boolean plain = post != null && post.get("plain", "false").equals("true"); + final boolean plain = post != null && post.getBoolean("plain", false); final int sleep = (post == null) ? 0 : post.getInt("sleep", 0); // a sleep before creation of a thread dump can be used for profiling if (sleep > 0) try {Thread.sleep(sleep);} catch (final InterruptedException e) {} prop.put("dump", "1"); @@ -89,10 +89,10 @@ public class Threaddump_p { } */ try { - new ThreadDump().appendBlockTraces(buffer, plain); - } catch (IOException e) { - e.printStackTrace(); - } + new ThreadDump().appendBlockTraces(buffer, plain); + } catch (IOException e) { + e.printStackTrace(); + } // generate a single thread dump final Map stackTraces = ThreadDump.getAllStackTraces(); diff --git a/htroot/ViewFile.java b/htroot/ViewFile.java index 25c029e7f..ea06fca62 100644 --- a/htroot/ViewFile.java +++ b/htroot/ViewFile.java @@ -154,7 +154,7 @@ public class ViewFile { // define an url by post parameter url = new DigestURI(MultiProtocolURI.unescape(urlString)); urlHash = UTF8.String(url.hash()); - pre = post.get("pre", "false").equals("true"); + pre = post.getBoolean("pre", false); } catch (final MalformedURLException e) {} diff --git a/htroot/api/bookmarks/get_bookmarks.java b/htroot/api/bookmarks/get_bookmarks.java index d337733f1..6215389b4 100644 --- a/htroot/api/bookmarks/get_bookmarks.java +++ b/htroot/api/bookmarks/get_bookmarks.java @@ -81,8 +81,8 @@ public class get_bookmarks { // check for GET parameters if (post != null){ - itemsPerPage = (post.containsKey("rp")) ? Integer.parseInt(post.get("rp"), MAXRESULTS) : MAXRESULTS; - page = (post.containsKey("page")) ? Integer.parseInt(post.get("page", "1")): 1; + itemsPerPage = (post.containsKey("rp")) ? post.getInt("rp", MAXRESULTS) : MAXRESULTS; + page = (post.containsKey("page")) ? post.getInt("page", 1): 1; query = (post.containsKey("query")) ? post.get("query", "") : ""; qtype = (post.containsKey("qtype")) ? post.get("qtype", "") : ""; // if (post.containsKey("sortorder")) sortorder = post.get("sortorder"); diff --git a/htroot/api/bookmarks/tags/getTag.java b/htroot/api/bookmarks/tags/getTag.java index 792be511f..c25e9a5d0 100755 --- a/htroot/api/bookmarks/tags/getTag.java +++ b/htroot/api/bookmarks/tags/getTag.java @@ -16,7 +16,7 @@ public class getTag { public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { // return variable that accumulates replacements final Switchboard switchboard = (Switchboard) env; - final boolean isAdmin=switchboard.verifyAuthentication(header, true); + final boolean isAdmin = switchboard.verifyAuthentication(header, true); final serverObjects prop = new serverObjects(); Iterator it = null; String tagName = ""; @@ -24,27 +24,27 @@ public class getTag { int comp = SORT_ALPHA; - if(post != null){ - if(!isAdmin){ - // force authentication if desired - if(post.containsKey("login")){ - prop.put("AUTHENTICATE","admin log-in"); - } - } - - if(post.containsKey("top")) { - final String s_top = post.get("top"); - top = Integer.parseInt(s_top); - } - if(post.containsKey("sort")) { - final String sort = post.get("sort"); - if (sort.equals("size")) - comp = SORT_SIZE; - } + if (post != null) { + if (!isAdmin) { + // force authentication if desired + if(post.containsKey("login")){ + prop.put("AUTHENTICATE","admin log-in"); + } + } + + if (post.containsKey("top")) { + top = post.getInt("top", SHOW_ALL); + } + if (post.containsKey("sort")) { + if ("size".equals(post.get("sort"))) { + comp = SORT_SIZE; + } + } } - if(post != null && post.containsKey("tag")) { + + if (post != null && post.containsKey("tag")) { tagName=post.get("tag"); - if (!tagName.equals("")) { + if (!tagName.isEmpty()) { it = switchboard.bookmarksDB.getTagIterator(tagName, isAdmin, comp, top); } } else { @@ -53,15 +53,15 @@ public class getTag { // Iterator it = switchboard.bookmarksDB.getTagIterator(isAdmin); - int count=0; - if(it != null) { + int count = 0; + if (it != null) { BookmarksDB.Tag tag; while (it.hasNext()) { tag = it.next(); - if(!tag.getTagName().startsWith("/")) { // ignore folder tags - prop.putXML("tags_"+count+"_name", tag.getTagName()); - prop.put("tags_"+count+"_count", tag.size()); - count++; + if(!tag.getTagName().startsWith("/")) { // ignore folder tags + prop.putXML("tags_" + count + "_name", tag.getTagName()); + prop.put("tags_" + count + "_count", tag.size()); + count++; } } } diff --git a/htroot/index.java b/htroot/index.java index 821eca613..d94b41239 100644 --- a/htroot/index.java +++ b/htroot/index.java @@ -68,7 +68,7 @@ public class index { if (!sb.getConfigBool("search.options", true)) searchoptions = 0; final String former = (post == null) ? "" : post.get("former", ""); final int count = Math.min(100, (post == null) ? 10 : post.getInt("count", 10)); - final int maximumRecords = Integer.parseInt((sb.getConfig(SwitchboardConstants.SEARCH_ITEMS, "10"))); + final int maximumRecords = sb.getConfigInt(SwitchboardConstants.SEARCH_ITEMS, 10); final String urlmaskfilter = (post == null) ? ".*" : post.get("urlmaskfilter", ".*"); final String prefermaskfilter = (post == null) ? "" : post.get("prefermaskfilter", ""); final String constraint = (post == null) ? "" : post.get("constraint", ""); diff --git a/htroot/opensearchdescription.java b/htroot/opensearchdescription.java index 6e674231d..50c2fa90e 100644 --- a/htroot/opensearchdescription.java +++ b/htroot/opensearchdescription.java @@ -43,7 +43,7 @@ public class opensearchdescription { if (thisaddress.indexOf(':') == -1) thisaddress += ":" + serverCore.getPortNr(env.getConfig("port", "8090")); int compareyacy = 0; - if (post != null && post.get("compare_yacy", "false").equals("true")) + if (post != null && post.getBoolean("compare_yacy", false)) compareyacy = 1; final serverObjects prop = new serverObjects(); diff --git a/htroot/sharedBlacklist_p.java b/htroot/sharedBlacklist_p.java index bdf80a288..b34d182a5 100644 --- a/htroot/sharedBlacklist_p.java +++ b/htroot/sharedBlacklist_p.java @@ -38,6 +38,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; import de.anomic.data.ListManager; import de.anomic.data.list.ListAccumulator; @@ -115,12 +116,12 @@ public class sharedBlacklist_p { * ====================================================== */ // get the source peer hash - final String Hash = post.get("hash"); + final String hash = post.get("hash"); // generate the download URL String downloadURLOld = null; if( sb.peers != null ){ //no nullpointer error.. - final yacySeed seed = sb.peers.getConnected(Hash); + final yacySeed seed = sb.peers.getConnected(hash); if (seed != null) { final String IP = seed.getIP(); final String Port = seed.get(yacySeed.PORT, "8090"); @@ -129,12 +130,12 @@ public class sharedBlacklist_p { downloadURLOld = "http://" + IP + ":" + Port + "/yacy/list.html?col=black"; } else { prop.put("status", STATUS_PEER_UNKNOWN);//YaCy-Peer not found - prop.putHTML("status_name", Hash); + prop.putHTML("status_name", hash); prop.put("page", "1"); } } else { prop.put("status", STATUS_PEER_UNKNOWN);//YaCy-Peer not found - prop.putHTML("status_name", Hash); + prop.putHTML("status_name", hash); prop.put("page", "1"); } @@ -147,7 +148,7 @@ public class sharedBlacklist_p { otherBlacklist = FileUtils.strings(u.get(MultiProtocolURI.yacybotUserAgent, 10000)); } catch (final Exception e) { prop.put("status", STATUS_PEER_UNKNOWN); - prop.putHTML("status_name", Hash); + prop.putHTML("status_name", hash); prop.put("page", "1"); } } @@ -215,8 +216,8 @@ public class sharedBlacklist_p { pw = new PrintWriter(new FileWriter(new File(ListManager.listsPath, selectedBlacklistName), true)); // loop through the received entry list - final int num = Integer.parseInt( post.get("num") ); - for(int i=0;i < num; i++){ + final int num = post.getInt("num", 0); + for(int i = 0; i < num; i++){ if( post.containsKey("item" + i) ){ String newItem = post.get("item" + i); @@ -268,7 +269,7 @@ public class sharedBlacklist_p { // generate the html list if (otherBlacklist != null) { // loading the current blacklist content - final HashSet Blacklist = new HashSet(FileUtils.getListArray(new File(ListManager.listsPath, selectedBlacklistName))); + final Set Blacklist = new HashSet(FileUtils.getListArray(new File(ListManager.listsPath, selectedBlacklistName))); int count = 0; while (otherBlacklist.hasNext()) { diff --git a/htroot/yacy/hello.java b/htroot/yacy/hello.java index 08e542806..a16a604ec 100644 --- a/htroot/yacy/hello.java +++ b/htroot/yacy/hello.java @@ -72,9 +72,7 @@ public final class hello { // final String mytime = (String) post.get(MYTIME, ""); // final String key = post.get("key", ""); // transmission key for response final String seed = post.get("seed", ""); - final String countStr = post.get("count", "0"); - int count = 0; - try {count = (countStr == null) ? 0 : Integer.parseInt(countStr);} catch (final NumberFormatException e) {count = 0;} + int count = post.getInt("count", 0); // final Date remoteTime = yacyCore.parseUniversalDate(post.get(MYTIME)); // read remote time final String clientip = header.get(HeaderFramework.CONNECTION_PROP_CLIENTIP, ""); // read an artificial header addendum long time = System.currentTimeMillis(); @@ -147,21 +145,22 @@ public final class hello { // if the previous attempt (using the reported ip address) was not successful, // then try the ip where the request came from if (urls < 0) { - boolean isNotLocal = true; - - // we are only allowed to connect to the client IP address if it's not our own address - if (serverCore.useStaticIP) { - isNotLocal = !ias.isSiteLocalAddress(); + boolean isNotLocal = true; + + // we are only allowed to connect to the client IP address if it's not our own address + if (serverCore.useStaticIP) { + isNotLocal = !ias.isSiteLocalAddress(); } - if (isNotLocal) { - serverCore.checkInterruption(); + + if (isNotLocal) { + serverCore.checkInterruption(); prop.put("yourip", clientip); remoteSeed.setIP(clientip); urls = yacyClient.queryUrlCount(remoteSeed); time_backping = System.currentTimeMillis() - time; backping_method = "clientip=" + clientip; - } + } } // System.out.println("YACYHELLO: YOUR IP=" + clientip); diff --git a/htroot/yacy/message.java b/htroot/yacy/message.java index c6a70c7f2..849d52e9d 100644 --- a/htroot/yacy/message.java +++ b/htroot/yacy/message.java @@ -169,7 +169,7 @@ public final class message { */ private static void messageForwardingViaEmail(final Switchboard sb, final MessageBoard.entry msgEntry) { try { - if (!Boolean.parseBoolean(sb.getConfig("msgForwardingEnabled","false"))) return; + if (!sb.getConfigBool("msgForwardingEnabled", false)) return; // get the recipient address final String sendMailTo = sb.getConfig("msgForwardingTo","root@localhost").trim(); diff --git a/htroot/yacy/search.java b/htroot/yacy/search.java index a7c5e8bd3..0669e373c 100644 --- a/htroot/yacy/search.java +++ b/htroot/yacy/search.java @@ -254,7 +254,11 @@ public final class search { wordhash = entry.getKey(); final ReferenceContainer container = entry.getValue(); indexabstractContainercount += container.size(); - indexabstract.append("indexabstract." + UTF8.String(wordhash) + "=").append(ReferenceContainer.compressIndex(container, null, 1000).toString()).append(serverCore.CRLF_STRING); + indexabstract.append("indexabstract."); + indexabstract.append(UTF8.String(wordhash)); + indexabstract.append("="); + indexabstract.append(ReferenceContainer.compressIndex(container, null, 1000).toString()); + indexabstract.append(serverCore.CRLF_STRING); } } @@ -323,7 +327,7 @@ public final class search { while (j.hasNext()) { wordhash = j.next(); indexabstractContainercount += theSearch.abstractsCount(wordhash); - indexabstract.append("indexabstract." + UTF8.String(wordhash) + "=").append(theSearch.abstractsString(wordhash)).append(serverCore.CRLF_STRING); + indexabstract.append("indexabstract.").append(UTF8.String(wordhash)).append("=").append(theSearch.abstractsString(wordhash)).append(serverCore.CRLF_STRING); } } prop.put("indexcount", indexcount.toString()); @@ -336,11 +340,11 @@ public final class search { } else if (abstracts.equals("auto")) { // automatically attach the index abstract for the index that has the most references. This should be our target dht position indexabstractContainercount += theSearch.abstractsCount(theSearch.getAbstractsMaxCountHash()); - indexabstract.append("indexabstract." + UTF8.String(theSearch.getAbstractsMaxCountHash()) + "=").append(theSearch.abstractsString(theSearch.getAbstractsMaxCountHash())).append(serverCore.CRLF_STRING); + indexabstract.append("indexabstract.").append(UTF8.String(theSearch.getAbstractsMaxCountHash())).append("=").append(theSearch.abstractsString(theSearch.getAbstractsMaxCountHash())).append(serverCore.CRLF_STRING); if ((theSearch.getAbstractsNearDHTHash() != null) && (!(UTF8.String(theSearch.getAbstractsNearDHTHash()).equals(UTF8.String(theSearch.getAbstractsMaxCountHash()))))) { // in case that the neardhthash is different from the maxcounthash attach also the neardhthash-container indexabstractContainercount += theSearch.abstractsCount(theSearch.getAbstractsNearDHTHash()); - indexabstract.append("indexabstract." + UTF8.String(theSearch.getAbstractsNearDHTHash()) + "=").append(theSearch.abstractsString(theSearch.getAbstractsNearDHTHash())).append(serverCore.CRLF_STRING); + indexabstract.append("indexabstract.").append(UTF8.String(theSearch.getAbstractsNearDHTHash())).append("=").append(theSearch.abstractsString(theSearch.getAbstractsNearDHTHash())).append(serverCore.CRLF_STRING); } //System.out.println("DEBUG-ABSTRACTGENERATION: maxcounthash = " + maxcounthash); //System.out.println("DEBUG-ABSTRACTGENERATION: neardhthash = "+ neardhthash); @@ -367,7 +371,7 @@ public final class search { prop.put("indexabstract", indexabstract.toString()); // prepare result - if (joincount == 0 || accu == null || accu.size() == 0) { + if (joincount == 0 || accu == null || accu.isEmpty()) { // no results prop.put("links", ""); @@ -423,7 +427,7 @@ public final class search { prop.put("searchtime", System.currentTimeMillis() - timestamp); - final int links = Integer.parseInt(prop.get("linkcount","0")); + final int links = prop.getInt("linkcount",0); sb.peers.mySeed().incSI(links); sb.peers.mySeed().incSU(links); return prop; diff --git a/htroot/yacy/transferRWI.java b/htroot/yacy/transferRWI.java index 3191000e1..de81fbc5f 100644 --- a/htroot/yacy/transferRWI.java +++ b/htroot/yacy/transferRWI.java @@ -84,8 +84,8 @@ public final class transferRWI { final int wordc = post.getInt("wordc", 0); // number of different words final int entryc = post.getInt("entryc", 0); // number of entries in indexes byte[] indexes = post.get("indexes", "").getBytes(); // the indexes, as list of word entries - boolean granted = sb.getConfig("allowReceiveIndex", "false").equals("true"); - final boolean blockBlacklist = sb.getConfig("indexReceiveBlockBlacklist", "false").equals("true"); + boolean granted = sb.getConfigBool("allowReceiveIndex", false); + final boolean blockBlacklist = sb.getConfigBool("indexReceiveBlockBlacklist", false); final long cachelimit = sb.getConfigLong(SwitchboardConstants.WORDCACHE_MAX_COUNT, 100000); final yacySeed otherPeer = sb.peers.get(iam); final String otherPeerName = iam + ":" + ((otherPeer == null) ? "NULL" : (otherPeer.getName() + "/" + otherPeer.getVersion())); diff --git a/htroot/yacy/transferURL.java b/htroot/yacy/transferURL.java index 19a470e92..a291e958d 100644 --- a/htroot/yacy/transferURL.java +++ b/htroot/yacy/transferURL.java @@ -66,8 +66,8 @@ public final class transferURL { final String youare = post.get("youare", ""); // seed hash of the target peer, needed for network stability // final String key = post.get("key", ""); // transmission key final int urlc = post.getInt("urlc", 0); // number of transported urls - final boolean granted = sb.getConfig("allowReceiveIndex", "false").equals("true"); - final boolean blockBlacklist = sb.getConfig("indexReceiveBlockBlacklist", "false").equals("true"); + final boolean granted = sb.getConfigBool("allowReceiveIndex", false); + final boolean blockBlacklist = sb.getConfigBool("indexReceiveBlockBlacklist", false); // response values String result = ""; diff --git a/htroot/yacysearch.java b/htroot/yacysearch.java index 712f5d06c..845ccdd7d 100644 --- a/htroot/yacysearch.java +++ b/htroot/yacysearch.java @@ -553,19 +553,15 @@ public class yacysearch { AccessTracker.add(AccessTracker.Location.local, theQuery); // check suggestions - int meanMax = 0; - if (post != null && post.containsKey("meanCount")) { - try { - meanMax = Integer.parseInt(post.get("meanCount")); - } catch (NumberFormatException e) {} - } + final int meanMax = (post != null) ? post.getInt("meanCount", 0) : 0; + prop.put("meanCount", meanMax); if (meanMax > 0) { final DidYouMean didYouMean = new DidYouMean(indexSegment.termIndex(), querystring); final Iterator meanIt = didYouMean.getSuggestions(100, 5).iterator(); int meanCount = 0; String suggestion; - while(meanCount coordinates = LibraryProvider.geoLoc.find(originalquerystring, false); + final SortedSet coordinates = LibraryProvider.geoLoc.find(originalquerystring, false); if (coordinates == null || coordinates.isEmpty() || offset > 0) { prop.put("geoinfo", "0"); } else { int i = 0; - for (Location c: coordinates) { + for (final Location c: coordinates) { prop.put("geoinfo_loc_" + i + "_lon", Math.round(c.lon() * 10000.0f) / 10000.0f); prop.put("geoinfo_loc_" + i + "_lat", Math.round(c.lat() * 10000.0f) / 10000.0f); prop.put("geoinfo_loc_" + i + "_name", c.getName()); diff --git a/source/de/anomic/server/serverObjects.java b/source/de/anomic/server/serverObjects.java index 3237c5494..e5f97d01d 100644 --- a/source/de/anomic/server/serverObjects.java +++ b/source/de/anomic/server/serverObjects.java @@ -50,6 +50,7 @@ import java.io.UnsupportedEncodingException; import java.net.InetAddress; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.regex.Pattern; @@ -87,7 +88,7 @@ public class serverObjects extends HashMap implements Cloneable super(input); } - private static final String removeBOM(String s) { + private static final String removeByteOrderMark(final String s) { if (s == null || s.length() == 0) return s; if (s.charAt(0) == BOM) return s.substring(1); return s; @@ -133,10 +134,7 @@ public class serverObjects extends HashMap implements Cloneable * @return value as it was added to the map or NaN if an error occured. */ public double put(final String key, final float value) { - if (null == this.put(key, Float.toString(value))) { - return Float.NaN; - } - return value; + return (null == this.put(key, Float.toString(value))) ? Float.NaN : value; } /** @@ -144,10 +142,7 @@ public class serverObjects extends HashMap implements Cloneable * @return Returns 0 for the error case. */ public long put(final String key, final long value) { - if (null == this.put(key, Long.toString(value))) { - return 0; - } - return value; + return (null == this.put(key, Long.toString(value))) ? 0 : value; } public String put(final String key, final java.util.Date value) { @@ -157,6 +152,7 @@ public class serverObjects extends HashMap implements Cloneable public String put(final String key, final InetAddress value) { return this.put(key, value.toString()); } + /** * Add a String to the map. The content of the String is escaped to be usable in JSON output. * @param key key name as String. @@ -174,6 +170,7 @@ public class serverObjects extends HashMap implements Cloneable value = patternT.matcher(value).replaceAll("\\t"); return put(key, value); } + public String putJSON(final String key, final byte[] value) { return putJSON(key, UTF8.String(value)); } @@ -188,6 +185,7 @@ public class serverObjects extends HashMap implements Cloneable public String putHTML(final String key, final String value) { return put(key, CharacterCoding.unicode2html(value, true)); } + public String putHTML(final String key, final byte[] value) { return putHTML(key, UTF8.String(value)); } @@ -234,6 +232,7 @@ public class serverObjects extends HashMap implements Cloneable public String putWiki(final String key, final String wikiCode){ return this.put(key, Switchboard.wikiParser.transform(wikiCode)); } + public String putWiki(final String key, final byte[] wikiCode) { try { return this.put(key, Switchboard.wikiParser.transform(wikiCode)); @@ -254,19 +253,17 @@ public class serverObjects extends HashMap implements Cloneable // new get with default objects public Object get(final String key, final Object dflt) { final Object result = super.get(key); - if (result == null) return dflt; - return result; + return (result == null) ? dflt : result; } // string variant public String get(final String key, final String dflt) { - final String result = removeBOM(super.get(key)); - if (result == null) return dflt; - return result; + final String result = removeByteOrderMark(super.get(key)); + return (result == null) ? dflt : result; } public int getInt(final String key, final int dflt) { - final String s = removeBOM(super.get(key)); + final String s = removeByteOrderMark(super.get(key)); if (s == null) return dflt; try { return Integer.parseInt(s); @@ -276,7 +273,7 @@ public class serverObjects extends HashMap implements Cloneable } public long getLong(final String key, final long dflt) { - final String s = removeBOM(super.get(key)); + final String s = removeByteOrderMark(super.get(key)); if (s == null) return dflt; try { return Long.parseLong(s); @@ -286,7 +283,7 @@ public class serverObjects extends HashMap implements Cloneable } public float getFloat(final String key, final float dflt) { - final String s = removeBOM(super.get(key)); + final String s = removeByteOrderMark(super.get(key)); if (s == null) return dflt; try { return Float.parseFloat(s); @@ -296,7 +293,7 @@ public class serverObjects extends HashMap implements Cloneable } public boolean getBoolean(final String key, final boolean dflt) { - String s = removeBOM(super.get(key)); + String s = removeByteOrderMark(super.get(key)); if (s == null) return dflt; s = s.toLowerCase(); return s.equals("true") || s.equals("on") || s.equals("1"); @@ -304,24 +301,21 @@ public class serverObjects extends HashMap implements Cloneable public boolean hasValue(final String key) { final String s = super.get(key); - if (s == null || s.length() < 1) return false; - return true; + return (s != null && !s.isEmpty()); } // returns a set of all values where their key mappes the keyMapper public String[] getAll(final String keyMapper) { // the keyMapper may contain regular expressions as defined in String.matches // this method is particulary useful when parsing the result of checkbox forms - final ArrayList v = new ArrayList(); - String key; - for (Map.Entry entry: entrySet()) { - key = entry.getKey(); - if (key.matches(keyMapper)) v.add(entry.getValue()); + final List v = new ArrayList(); + for (final Map.Entry entry: entrySet()) { + if (entry.getKey().matches(keyMapper)) { + v.add(entry.getValue()); + } } - // make a String[] - final String[] result = new String[v.size()]; - for (int i = 0; i < v.size(); i++) result[i] = v.get(i); - return result; + + return v.toArray(new String[0]); } // put all elements of another hashtable into the own table @@ -336,11 +330,15 @@ public class serverObjects extends HashMap implements Cloneable BufferedOutputStream fos = null; try { fos = new BufferedOutputStream(new FileOutputStream(f)); - String key, value; - for (Map.Entry entry: entrySet()) { - key = entry.getKey(); - value = patternNewline.matcher(entry.getValue()).replaceAll("\\\\n"); - fos.write(UTF8.getBytes(key + "=" + value + "\r\n")); + final StringBuilder line = new StringBuilder(64); + for (final Map.Entry entry : entrySet()) { + line.delete(0, line.length()); + line.append(entry.getKey()); + line.append("="); + line.append(patternNewline.matcher(entry.getValue()).replaceAll("\\\\n")); + line.append("\r\n"); + + fos.write(UTF8.getBytes(line.toString())); } } finally { if (fos != null) { @@ -371,10 +369,11 @@ public class serverObjects extends HashMap implements Cloneable /** * output the objects in a HTTP GET syntax */ + @Override public String toString() { - if (this.size() == 0) return ""; - StringBuilder param = new StringBuilder(this.size() * 40); - for (Map.Entry entry: this.entrySet()) { + if (this.isEmpty()) return ""; + final StringBuilder param = new StringBuilder(this.size() * 40); + for (final Map.Entry entry: this.entrySet()) { param.append(MultiProtocolURI.escape(entry.getKey())); param.append('='); param.append(MultiProtocolURI.escape(entry.getValue())); diff --git a/source/de/anomic/server/serverSwitch.java b/source/de/anomic/server/serverSwitch.java index 98d639ad6..fd45634ba 100644 --- a/source/de/anomic/server/serverSwitch.java +++ b/source/de/anomic/server/serverSwitch.java @@ -34,9 +34,12 @@ import java.net.InetAddress; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.List; import java.util.Map; +import java.util.NavigableMap; import java.util.Random; import java.util.TreeMap; +import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentHashMap; import net.yacy.cora.document.MultiProtocolURI; @@ -63,11 +66,11 @@ public class serverSwitch { protected boolean firstInit; protected Log log; protected int serverJobs; - private ConcurrentHashMap configProps; - private final ConcurrentHashMap configRemoved; - private final ConcurrentHashMap authorization; - private final TreeMap workerThreads; - private final serverAccessTracker accessTracker; + private ConcurrentMap configProps; + private final ConcurrentMap configRemoved; + private final ConcurrentMap authorization; + private final NavigableMap workerThreads; + private final serverAccessTracker accessTracker; public serverSwitch(final File dataPath, final File appPath, final String initPath, final String configPath) { // we initialize the switchboard with a property file, @@ -85,7 +88,7 @@ public class serverSwitch { new File(configFile.getParent()).mkdir(); // predefine init's - ConcurrentHashMap initProps; + final ConcurrentMap initProps; if (initFile.exists()) initProps = FileUtils.loadMap(initFile); else @@ -98,10 +101,10 @@ public class serverSwitch { // delete the 'pro' init settings i = initProps.keySet().iterator(); while (i.hasNext()) { - prop = i.next(); - if (prop.endsWith("__pro")) { - i.remove(); - } + prop = i.next(); + if (prop.endsWith("__pro")) { + i.remove(); + } } // load config's from last save @@ -207,8 +210,12 @@ public class serverSwitch { configProps.remove(key); } - /* (non-Javadoc) - * @see de.anomic.server.serverSwitch#getConfig(java.lang.String, java.lang.String) + /** + * Gets a configuration parameter from the properties. + * @param key name of the configuration parameter + * @param dflt default value which will be used in case parameter can not be + * found or if it is invalid + * @return value if the parameter or default value */ public String getConfig(final String key, final String dflt) { // get the value @@ -218,7 +225,14 @@ public class serverSwitch { if (s == null) return dflt; return s; } - + + /** + * Gets a configuration parameter from the properties. + * @param key name of the configuration parameter + * @param dflt default value which will be used in case parameter can not be + * found or if it is invalid + * @return value if the parameter or default value + */ public long getConfigLong(final String key, final long dflt) { try { return Long.parseLong(getConfig(key, Long.toString(dflt))); @@ -226,7 +240,14 @@ public class serverSwitch { return dflt; } } - + + /** + * Gets a configuration parameter from the properties. + * @param key name of the configuration parameter + * @param dflt default value which will be used in case parameter can not be + * found or if it is invalid + * @return value if the parameter or default value + */ public double getConfigFloat(final String key, final float dflt) { try { return Float.parseFloat(getConfig(key, Float.toString(dflt))); @@ -234,7 +255,29 @@ public class serverSwitch { return dflt; } } - + + /** + * Gets a configuration parameter from the properties. + * @param key name of the configuration parameter + * @param dflt default value which will be used in case parameter can not be + * found or if it is invalid + * @return value if the parameter or default value + */ + public int getConfigInt(final String key, final int dflt) { + try { + return Integer.parseInt(getConfig(key, Integer.toString(dflt))); + } catch (final NumberFormatException e) { + return dflt; + } + } + + /** + * Gets a configuration parameter from the properties. + * @param key name of the configuration parameter + * @param dflt default value which will be used in case parameter can not be + * found or if it is invalid + * @return value if the parameter or default value + */ public boolean getConfigBool(final String key, final boolean dflt) { return Boolean.parseBoolean(getConfig(key, Boolean.toString(dflt))); } @@ -270,7 +313,7 @@ public class serverSwitch { private void saveConfig() { try { - ConcurrentHashMap configPropsCopy = new ConcurrentHashMap(); + ConcurrentMap configPropsCopy = new ConcurrentHashMap(); configPropsCopy.putAll(configProps); // avoid concurrency problems FileUtils.saveMap(configFile, configPropsCopy, configComment); } catch (final IOException e) { @@ -279,8 +322,11 @@ public class serverSwitch { } } - public ConcurrentHashMap getRemoved() { - // returns configuration that had been removed during initialization + /** + * Gets configuration parameters which have been removed during initialization. + * @return contains parameter name as key and parameter value as value + */ + public ConcurrentMap getRemoved() { return configRemoved; } @@ -381,10 +427,10 @@ public class serverSwitch { } public String[] sessionsOlderThan(String threadName, long timeout) { - ArrayList list = new ArrayList(); + final List list = new ArrayList(); final WorkflowThread st = getThread(threadName); - for (Session s: ((serverCore) st).getJobList()) { + for (final Session s: ((serverCore) st).getJobList()) { if (!s.isAlive()) continue; if (s.getTime() > timeout) { list.add(s.getName()); @@ -397,7 +443,7 @@ public class serverSwitch { if (sessionName == null) return; final WorkflowThread st = getThread(threadName); - for (Session s: ((serverCore) st).getJobList()) { + for (final Session s: ((serverCore) st).getJobList()) { if ( (s.isAlive()) && (s.getName().equals(sessionName)) @@ -483,6 +529,7 @@ public class serverSwitch { return this.appPath; } + @Override public String toString() { return configProps.toString(); } @@ -491,15 +538,15 @@ public class serverSwitch { serverJobs = jobs; } - public void track(String host, String accessPath) { + public void track(final String host, final String accessPath) { this.accessTracker.track(host, accessPath); } - public Collection accessTrack(String host) { + public Collection accessTrack(final String host) { return this.accessTracker.accessTrack(host); } - public int latestAccessCount(final String host, long timedelta) { + public int latestAccessCount(final String host, final long timedelta) { return this.accessTracker.latestAccessCount(host, timedelta); } @@ -515,9 +562,10 @@ public class serverSwitch { * @param rootPath searchpath for file * @param file file to use when remote fetching fails (null if unused) */ - public Reader getConfigFileFromWebOrLocally(String uri, String rootPath, File file) throws IOException, FileNotFoundException { + public Reader getConfigFileFromWebOrLocally(final String uri, + final String rootPath, final File file) throws IOException, FileNotFoundException { if (uri.startsWith("http://") || uri.startsWith("https://")) { - String[] uris = uri.split(","); + final String[] uris = uri.split(","); for (String netdef: uris) { netdef = netdef.trim(); try { @@ -544,7 +592,7 @@ public class serverSwitch { throw new FileNotFoundException(); } } else { - final File f = (uri.length() > 0 && uri.charAt(0) == '/') ? new File(uri) : new File(rootPath, uri); + final File f = (uri.length() > 0 && uri.startsWith("/")) ? new File(uri) : new File(rootPath, uri); if (f.exists()) { return new FileReader(f); } else { @@ -554,14 +602,21 @@ public class serverSwitch { } private static Random pwGenerator = new Random(); - + /** - * generates a random password + * Generates a random password. + * @return random password which is 20 characters long. */ public String genRandomPassword() { return genRandomPassword(20); } - public String genRandomPassword(int length) { + + /** + * Generates a random password of a given length. + * @param length length o password + * @return password of given length + */ + public String genRandomPassword(final int length) { byte[] bytes = new byte[length]; pwGenerator.nextBytes(bytes); return Digest.encodeMD5Hex(bytes); diff --git a/source/de/anomic/yacy/yacySeed.java b/source/de/anomic/yacy/yacySeed.java index e7a42149c..7f28dda5b 100644 --- a/source/de/anomic/yacy/yacySeed.java +++ b/source/de/anomic/yacy/yacySeed.java @@ -57,6 +57,7 @@ import java.util.Random; import java.util.Set; import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import java.util.regex.Pattern; import net.yacy.cora.date.AbstractFormatter; @@ -173,14 +174,14 @@ public class yacySeed implements Cloneable, Comparable, Comparator dna; + private final ConcurrentMap dna; private String alternativeIP = null; private final long birthdate; // keep this value in ram since it is often used and may cause lockings in concurrent situations. // use our own formatter to prevent concurrency locks with other processes private final static GenericFormatter my_SHORT_SECOND_FORMATTER = new GenericFormatter(GenericFormatter.FORMAT_SHORT_SECOND, GenericFormatter.time_second); - public yacySeed(final String theHash, final ConcurrentHashMap theDna) { + public yacySeed(final String theHash, final ConcurrentMap theDna) { // create a seed with a pre-defined hash map assert theHash != null; this.hash = theHash; @@ -332,6 +333,18 @@ public class yacySeed implements Cloneable, Comparable, Comparator, Comparator copymap = new HashMap(); copymap.putAll(this.dna); @@ -872,6 +886,7 @@ public class yacySeed implements Cloneable, Comparable, Comparator ndna = new ConcurrentHashMap(); ndna.putAll(this.dna); @@ -888,6 +903,7 @@ public class yacySeed implements Cloneable, Comparable, Comparator