Skip to content

Commit

Permalink
always use a default value for boolean options to have transparency for
Browse files Browse the repository at this point in the history
the outcome if the attribute is missing in servlets
  • Loading branch information
Orbiter committed Jul 25, 2013
1 parent 61e0152 commit 4c242f9
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 59 deletions.
2 changes: 1 addition & 1 deletion htroot/AccessPicture_p.java
Expand Up @@ -65,7 +65,7 @@ public static RasterPlotter respond(@SuppressWarnings("unused") final RequestHea
color_grid = post.get("colorgrid", color_grid);
color_dot = post.get("colordot", color_dot);
color_line = post.get("colorline", color_line);
corona = !post.containsKey("corona") || post.getBoolean("corona");
corona = !post.containsKey("corona") || post.getBoolean("corona", false);
coronaangle = (corona) ? post.getInt("coronaangle", 0) : -1;
}
if (coronaangle < 0) corona = false;
Expand Down
12 changes: 6 additions & 6 deletions htroot/ConfigPortal.java
Expand Up @@ -83,15 +83,15 @@ public static serverObjects respond(final RequestHeader header, final serverObje
sb.setConfig(SwitchboardConstants.SEARCH_ITEMS, post.getInt("maximumRecords", 10));
sb.setConfig(SwitchboardConstants.INDEX_FORWARD, post.get(SwitchboardConstants.INDEX_FORWARD, ""));
HTTPDFileHandler.indexForward = post.get(SwitchboardConstants.INDEX_FORWARD, "");
sb.setConfig("publicTopmenu", !post.containsKey("publicTopmenu") || post.getBoolean("publicTopmenu"));
sb.setConfig("publicSearchpage", !post.containsKey("publicSearchpage") || post.getBoolean("publicSearchpage"));
sb.setConfig("search.options", post.getBoolean("search.options"));
sb.setConfig("publicTopmenu", !post.containsKey("publicTopmenu") || post.getBoolean("publicTopmenu", true));
sb.setConfig("publicSearchpage", !post.containsKey("publicSearchpage") || post.getBoolean("publicSearchpage", true));
sb.setConfig("search.options", post.getBoolean("search.options", false));

sb.setConfig("interaction.userlogon.enabled", post.getBoolean("interaction.userlogon"));
sb.setConfig(SwitchboardConstants.GREEDYLEARNING_ACTIVE, post.getBoolean(SwitchboardConstants.GREEDYLEARNING_ACTIVE));
sb.setConfig("interaction.userlogon.enabled", post.getBoolean("interaction.userlogon", false));
sb.setConfig(SwitchboardConstants.GREEDYLEARNING_ACTIVE, post.getBoolean(SwitchboardConstants.GREEDYLEARNING_ACTIVE, true));

sb.setConfig(SwitchboardConstants.SEARCH_VERIFY, post.get("search.verify", "ifexist"));
sb.setConfig(SwitchboardConstants.SEARCH_VERIFY_DELETE, post.getBoolean("search.verify.delete"));
sb.setConfig(SwitchboardConstants.SEARCH_VERIFY_DELETE, post.getBoolean("search.verify.delete", false));

sb.setConfig("about.headline", post.get("about.headline", ""));
sb.setConfig("about.body", post.get("about.body", ""));
Expand Down
46 changes: 23 additions & 23 deletions htroot/ConfigSearchPage_p.java
Expand Up @@ -59,34 +59,34 @@ public static serverObjects respond(final RequestHeader header, final serverObje
// store this call as api call
sb.tables.recordAPICall(post, "ConfigPortal.html", WorkTables.TABLE_API_TYPE_CONFIGURATION, "new portal design. greeting: " + newGreeting);

sb.setConfig("publicTopmenu", post.getBoolean("publicTopmenu"));
sb.setConfig("search.options", post.getBoolean("search.options"));
sb.setConfig("publicTopmenu", post.getBoolean("publicTopmenu", false));
sb.setConfig("search.options", post.getBoolean("search.options", false));

sb.setConfig("search.text", post.getBoolean("search.text"));
sb.setConfig("search.image", post.getBoolean("search.image"));
sb.setConfig("search.audio", post.getBoolean("search.audio"));
sb.setConfig("search.video", post.getBoolean("search.video"));
sb.setConfig("search.app", post.getBoolean("search.app"));
sb.setConfig("search.text", post.getBoolean("search.text", false));
sb.setConfig("search.image", post.getBoolean("search.image", false));
sb.setConfig("search.audio", post.getBoolean("search.audio", false));
sb.setConfig("search.video", post.getBoolean("search.video", false));
sb.setConfig("search.app", post.getBoolean("search.app", false));

sb.setConfig("search.result.show.date", post.getBoolean("search.result.show.date"));
sb.setConfig("search.result.show.size", post.getBoolean("search.result.show.size"));
sb.setConfig("search.result.show.metadata", post.getBoolean("search.result.show.metadata"));
sb.setConfig("search.result.show.parser", post.getBoolean("search.result.show.parser"));
sb.setConfig("search.result.show.citation", post.getBoolean("search.result.show.citation"));
sb.setConfig("search.result.show.pictures", post.getBoolean("search.result.show.pictures"));
sb.setConfig("search.result.show.cache", post.getBoolean("search.result.show.cache"));
sb.setConfig("search.result.show.proxy", post.getBoolean("search.result.show.proxy"));
sb.setConfig("search.result.show.hostbrowser", post.getBoolean("search.result.show.hostbrowser"));
sb.setConfig("search.result.show.tags", post.getBoolean("search.result.show.tags"));
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.citation", post.getBoolean("search.result.show.citation", false));
sb.setConfig("search.result.show.pictures", post.getBoolean("search.result.show.pictures", false));
sb.setConfig("search.result.show.cache", post.getBoolean("search.result.show.cache", false));
sb.setConfig("search.result.show.proxy", post.getBoolean("search.result.show.proxy", false));
sb.setConfig("search.result.show.hostbrowser", post.getBoolean("search.result.show.hostbrowser", false));
sb.setConfig("search.result.show.tags", post.getBoolean("search.result.show.tags", false));

// construct navigation String
String nav = "";
if (post.getBoolean("search.navigation.filetype")) nav += "filetype,";
if (post.getBoolean("search.navigation.protocol")) nav += "protocol,";
if (post.getBoolean("search.navigation.hosts")) nav += "hosts,";
if (post.getBoolean("search.navigation.authors")) nav += "authors,";
if (post.getBoolean("search.navigation.namespace")) nav += "namespace,";
if (post.getBoolean("search.navigation.topics")) nav += "topics,";
if (post.getBoolean("search.navigation.filetype", false)) nav += "filetype,";
if (post.getBoolean("search.navigation.protocol", false)) nav += "protocol,";
if (post.getBoolean("search.navigation.hosts", false)) nav += "hosts,";
if (post.getBoolean("search.navigation.authors", false)) nav += "authors,";
if (post.getBoolean("search.navigation.namespace", false)) nav += "namespace,";
if (post.getBoolean("search.navigation.topics", false)) nav += "topics,";
if (nav.endsWith(",")) nav = nav.substring(0, nav.length() - 1);
sb.setConfig("search.navigation", nav);
}
Expand Down
2 changes: 1 addition & 1 deletion htroot/ConfigUpdate_p.java
Expand Up @@ -157,7 +157,7 @@ public static serverObjects respond(@SuppressWarnings("unused") final RequestHea
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", (post.getBoolean("onlySignedFiles")) ? "1" : "0");
sb.setConfig("update.onlySignedFiles", (post.getBoolean("onlySignedFiles", true)) ? "1" : "0");
}
}

Expand Down
2 changes: 1 addition & 1 deletion htroot/Connections_p.java
Expand Up @@ -61,7 +61,7 @@ public static serverObjects respond(@SuppressWarnings("unused") final RequestHea
// determines if name lookup should be done or not
final boolean doNameLookup;
if (post != null) {
doNameLookup = post.getBoolean("nameLookup");
doNameLookup = post.getBoolean("nameLookup", false);
if (post.containsKey("closeServerSession")) {
final String sessionName = post.get("closeServerSession", null);
sb.closeSessions(sessionName);
Expand Down
4 changes: 2 additions & 2 deletions htroot/Crawler_p.java
Expand Up @@ -171,7 +171,7 @@ public static serverObjects respond(final RequestHeader header, final serverObje
long t = timeParser(true, post.getInt("deleteIfOlderNumber", -1), post.get("deleteIfOlderUnit","year")); // year, month, day, hour
if (t > 0) deleteageDate = new Date(t);
}
final boolean deleteold = (deleteage && deleteageDate != null) || (restrictedcrawl && post.getBoolean("deleteold"));
final boolean deleteold = (deleteage && deleteageDate != null) || (restrictedcrawl && post.getBoolean("deleteold", false));

String crawlingStart0 = post.get("crawlingURL","").trim(); // the crawljob start url
String[] rootURLs0 = crawlingStart0.indexOf('\n') > 0 || crawlingStart0.indexOf('\r') > 0 ? crawlingStart0.split("[\\r\\n]+") : crawlingStart0.split(Pattern.quote("|"));
Expand Down Expand Up @@ -207,7 +207,7 @@ public static serverObjects respond(final RequestHeader header, final serverObje
String ipMustMatch = post.get("ipMustmatch", CrawlProfile.MATCH_ALL_STRING);
final String ipMustNotMatch = post.get("ipMustnotmatch", CrawlProfile.MATCH_NEVER_STRING);
if (ipMustMatch.length() < 2) ipMustMatch = CrawlProfile.MATCH_ALL_STRING;
final String countryMustMatch = post.getBoolean("countryMustMatchSwitch") ? post.get("countryMustMatchList", "") : "";
final String countryMustMatch = post.getBoolean("countryMustMatchSwitch", false) ? post.get("countryMustMatchList", "") : "";
sb.setConfig("crawlingIPMustMatch", ipMustMatch);
sb.setConfig("crawlingIPMustNotMatch", ipMustNotMatch);
if (countryMustMatch.length() > 0) sb.setConfig("crawlingCountryMustMatch", countryMustMatch);
Expand Down
2 changes: 1 addition & 1 deletion htroot/HostBrowser.java
Expand Up @@ -228,7 +228,7 @@ url, null, load, new Date(),
delete = true;
}
int facetcount=post.getInt("facetcount", 0);
boolean complete = post.getBoolean("complete");
boolean complete = post.getBoolean("complete", false);
if (complete) { // we want only root paths for complete lists
p = path.indexOf('/', 10);
if (p > 0) path = path.substring(0, p + 1);
Expand Down
14 changes: 7 additions & 7 deletions htroot/IndexFederated_p.java
Expand Up @@ -48,7 +48,7 @@ public static serverObjects respond(@SuppressWarnings("unused") final RequestHea

if (post != null && post.containsKey("set")) {
//yacy
boolean post_core_rwi = post.getBoolean(SwitchboardConstants.CORE_SERVICE_RWI);
boolean post_core_rwi = post.getBoolean(SwitchboardConstants.CORE_SERVICE_RWI, false);
final boolean previous_core_rwi = sb.index.connectedRWI() && env.getConfigBool(SwitchboardConstants.CORE_SERVICE_RWI, false);
env.setConfig(SwitchboardConstants.CORE_SERVICE_RWI, post_core_rwi);
if (previous_core_rwi && !post_core_rwi) sb.index.disconnectRWI(); // switch off
Expand All @@ -58,7 +58,7 @@ public static serverObjects respond(@SuppressWarnings("unused") final RequestHea
sb.index.connectRWI(wordCacheMaxCount, fileSizeMax);
} catch (final IOException e) { ConcurrentLog.logException(e); } // switch on

boolean post_core_citation = post.getBoolean(SwitchboardConstants.CORE_SERVICE_CITATION);
boolean post_core_citation = post.getBoolean(SwitchboardConstants.CORE_SERVICE_CITATION, false);
final boolean previous_core_citation = sb.index.connectedCitation() && env.getConfigBool(SwitchboardConstants.CORE_SERVICE_CITATION, false);
env.setConfig(SwitchboardConstants.CORE_SERVICE_CITATION, post_core_citation);
if (previous_core_citation && !post_core_citation) sb.index.disconnectCitation(); // switch off
Expand All @@ -68,7 +68,7 @@ public static serverObjects respond(@SuppressWarnings("unused") final RequestHea
sb.index.connectCitation(wordCacheMaxCount, fileSizeMax);
} catch (final IOException e) { ConcurrentLog.logException(e); } // switch on

boolean post_core_fulltext = post.getBoolean(SwitchboardConstants.CORE_SERVICE_FULLTEXT);
boolean post_core_fulltext = post.getBoolean(SwitchboardConstants.CORE_SERVICE_FULLTEXT, true);
final boolean previous_core_fulltext = sb.index.fulltext().connectedLocalSolr() && env.getConfigBool(SwitchboardConstants.CORE_SERVICE_FULLTEXT, false);
env.setConfig(SwitchboardConstants.CORE_SERVICE_FULLTEXT, post_core_fulltext);

Expand All @@ -83,17 +83,17 @@ public static serverObjects respond(@SuppressWarnings("unused") final RequestHea
try { sb.index.fulltext().connectLocalSolr(); } catch (final IOException e) { ConcurrentLog.logException(e); }
}

boolean webgraph = post.getBoolean(SwitchboardConstants.CORE_SERVICE_WEBGRAPH);
boolean webgraph = post.getBoolean(SwitchboardConstants.CORE_SERVICE_WEBGRAPH, false);
sb.index.fulltext().writeWebgraph(webgraph);
env.setConfig(SwitchboardConstants.CORE_SERVICE_WEBGRAPH, webgraph);

boolean jena = post.getBoolean(SwitchboardConstants.CORE_SERVICE_JENA);
boolean jena = post.getBoolean(SwitchboardConstants.CORE_SERVICE_JENA, false);
env.setConfig(SwitchboardConstants.CORE_SERVICE_JENA, jena);

// solr
final boolean solrRemoteWasOn = sb.index.fulltext().connectedRemoteSolr() && env.getConfigBool(SwitchboardConstants.FEDERATED_SERVICE_SOLR_INDEXING_ENABLED, true);
String solrurls = post.get("solr.indexing.url", env.getConfig(SwitchboardConstants.FEDERATED_SERVICE_SOLR_INDEXING_URL, "http://127.0.0.1:8983/solr"));
final boolean solrRemoteIsOnAfterwards = post.getBoolean("solr.indexing.solrremote") & solrurls.length() > 0;
final boolean solrRemoteIsOnAfterwards = post.getBoolean("solr.indexing.solrremote", false) & solrurls.length() > 0;
env.setConfig(SwitchboardConstants.FEDERATED_SERVICE_SOLR_INDEXING_ENABLED, solrRemoteIsOnAfterwards);
final BufferedReader r = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(UTF8.getBytes(solrurls))));
final StringBuilder s = new StringBuilder();
Expand Down Expand Up @@ -148,7 +148,7 @@ public static serverObjects respond(@SuppressWarnings("unused") final RequestHea
ConcurrentLog.severe("IndexFederated_p", "change of solr connection failed", e);
}

boolean lazy = post.getBoolean("solr.indexing.lazy");
boolean lazy = post.getBoolean("solr.indexing.lazy", true);
env.setConfig(SwitchboardConstants.FEDERATED_SERVICE_SOLR_INDEXING_LAZY, lazy);
}

Expand Down
2 changes: 1 addition & 1 deletion htroot/NetworkPicture.java
Expand Up @@ -90,7 +90,7 @@ public static EncodedImage respond(
passiveLimit = post.getInt("pal", passiveLimit);
potentialLimit = post.getInt("pol", potentialLimit);
maxCount = post.getInt("max", maxCount);
corona = !post.containsKey("corona") || post.getBoolean("corona");
corona = post.getBoolean("corona", true);
coronaangle = (corona) ? post.getInt("coronaangle", 0) : -1;
communicationTimeout = post.getLong("ct", -1);
bgcolor = post.get("bgcolor", bgcolor);
Expand Down
2 changes: 1 addition & 1 deletion htroot/PeerLoadPicture.java
Expand Up @@ -22,7 +22,7 @@ public static Image respond(@SuppressWarnings("unused") final RequestHeader head
if (post != null) {
width = post.getInt("width", 800);
height = post.getInt("height", 600);
showidle = post.getBoolean("showidle");
showidle = post.getBoolean("showidle", false);
}

final CircleThreadPiece idle = new CircleThreadPiece("Idle", new Color(170, 255, 170));
Expand Down
4 changes: 2 additions & 2 deletions htroot/Status.java
Expand Up @@ -102,11 +102,11 @@ public static serverObjects respond(
ByteCount.resetCount();
redirect = true;
} else if ( post.containsKey("popup") ) {
final boolean trigger_enabled = post.getBoolean("popup");
final boolean trigger_enabled = post.getBoolean("popup", false);
sb.setConfig("browserPopUpTrigger", trigger_enabled);
redirect = true;
} else if ( post.containsKey("tray") ) {
final boolean trigger_enabled = post.getBoolean("tray");
final boolean trigger_enabled = post.getBoolean("tray", false);
sb.setConfig("trayIcon", trigger_enabled);
redirect = true;
}
Expand Down
2 changes: 1 addition & 1 deletion htroot/Table_API_p.java
Expand Up @@ -65,7 +65,7 @@ public static serverObjects respond(@SuppressWarnings("unused") final RequestHea
startRecord = 0;
maximumRecords = 1000;
}
final boolean inline = (post != null && post.getBoolean("inline"));
final boolean inline = (post != null && post.getBoolean("inline", false));

prop.put("inline", (inline) ? 1 : 0);

Expand Down
2 changes: 1 addition & 1 deletion htroot/Threaddump_p.java
Expand Up @@ -49,7 +49,7 @@ public static serverObjects respond(@SuppressWarnings("unused") final RequestHea

final StringBuilder buffer = new StringBuilder(1000);

final boolean plain = post != null && post.getBoolean("plain");
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");
Expand Down
2 changes: 1 addition & 1 deletion htroot/ViewFile.java
Expand Up @@ -129,7 +129,7 @@ public static serverObjects respond(final RequestHeader header, final serverObje
// define an url by post parameter
url = new DigestURI(MultiProtocolURI.unescape(urlString));
urlHash = ASCII.String(url.hash());
pre = post.getBoolean("pre");
pre = post.getBoolean("pre", false);
} catch (final MalformedURLException e) {}

URIMetadataNode urlEntry = null;
Expand Down
2 changes: 1 addition & 1 deletion htroot/api/ymarks/import_ymark.java
Expand Up @@ -62,7 +62,7 @@ public static serverObjects respond(final RequestHeader header, final serverObje
boolean merge = false;
boolean empty = false;
final String indexing = post.get("indexing", "off");
final boolean medialink = post.getBoolean("medialink");
final boolean medialink = post.getBoolean("medialink", false);

if(post.containsKey("autotag") && !post.get("autotag", "off").equals("off")) {
autotag = true;
Expand Down
3 changes: 1 addition & 2 deletions htroot/opensearchdescription.java
Expand Up @@ -44,8 +44,7 @@ public static serverObjects respond(final RequestHeader header, final serverObje
if (thisaddress.indexOf(':',0) == -1) thisaddress += ":" + serverCore.getPortNr(env.getConfig("port", "8090"));

int compareyacy = 0;
if (post != null && post.getBoolean("compare_yacy"))
compareyacy = 1;
if (post != null && post.getBoolean("compare_yacy", false)) compareyacy = 1;

final serverObjects prop = new serverObjects();
prop.put("compareyacy", compareyacy);
Expand Down
7 changes: 0 additions & 7 deletions source/net/yacy/server/serverObjects.java
Expand Up @@ -444,13 +444,6 @@ public double getDouble(final String key, final double dflt) {
}
}

public boolean getBoolean(final String key) {
String s = removeByteOrderMark(get(key));
if (s == null) return false;
s = s.toLowerCase();
return s.equals("true") || s.equals("on") || s.equals("1");
}

public boolean getBoolean(final String key, final boolean dflt) {
String s = removeByteOrderMark(get(key));
if (s == null) return dflt;
Expand Down

0 comments on commit 4c242f9

Please sign in to comment.