Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
added dictionary loader servlet that can be used to get the geolocalization file: /DictionaryLoader_p.html Will also be used for more dictionary files in the future
orbiter3661cb692cae
diff --git a/htroot/DictionaryLoader_p.html b/htroot/DictionaryLoader_p.htmlnew file mode 100644index 000000000..8437a5b7c--- /dev/null+++ b/htroot/DictionaryLoader_p.html@@ -0,0 +1,60 @@+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">+<html xmlns="http://www.w3.org/1999/xhtml">+ <head>+ <title>YaCy '#[clientname]#': Dictionary Loader</title>+ #%env/templates/metas.template%#+ </head>+ <body id="DictionaryLoader">+ #%env/templates/header.template%#+ #%env/templates/submenuConfig.template%#+ <h2>Dictionary Loader</h2>++ <p>+ YaCy can use external libraries to enable or enhance some functions. These libraries are not+ included in the main release of YaCy because they would increase the application file too much.+ You can download additional files here.+ </p>++ <form action="DictionaryLoader_p.html" method="post" enctype="multipart/form-data">+ <fieldset>+ <legend>Geolocalization</legend>+ The geolocalization file will enable YaCy to present locations from OpenStreetMap according to given search words.+ With this file it is possible to find locations using the location (city) name, a zip code, a car sign or a telephone pre-dial number.+ <dl>+ <dt><label>Download from</label></dt>+ <dd>#[geo0URL]#</dd>+ <dt><label>Storage location</label></dt>+ <dd>#[geo0Storage]#</dd>+ <dt><label>Status</label></dt>+ <dd>#(geo0Status)#<div class="info">not loaded</div>::<div class="commit">loaded</div>::de-activated#(/geo0Status)#</dd>+ <dt></dt>+ <dd>#(geo0Status)#+ <input type="submit" name="geo0Load" value="Load" />::+ <input type="submit" name="geo0Deactivate" value="de-Activate" />+ <input type="submit" name="geo0Remove" value="Remove" />::+ <input type="submit" name="geo0Activate" value="Activate" />+ <input type="submit" name="geo0Remove" value="Remove" />+ #(/geo0Status)#</dd>+ #(geo0ActionLoaded)#::+ <dt></dt><dd><div class="commit">loaded and activated dictionary file</div></dd>::+ <dt></dt><dd><div class="error">loading of dictionary file failed: #[error]#</div></dd>+ #(/geo0ActionLoaded)#+ #(geo0ActionRemoved)#::+ <dt></dt><dd><div class="commit">de-activated and removed dictionary file</div></dd>::+ <dt></dt><dd><div class="error">cannot remove dictionary file: #[error]#</div></dd>+ #(/geo0ActionRemoved)#+ #(geo0ActionDeactivated)#::+ <dt></dt><dd><div class="commit">de-activated dictionary file</div></dd>::+ <dt></dt><dd><div class="error">cannot de-activate dictionary file: #[error]#</div></dd>+ #(/geo0ActionDeactivated)#+ #(geo0ActionActivated)#::+ <dt></dt><dd><div class="commit">activated dictionary file</div></dd>::+ <dt></dt><dd><div class="error">cannot activate dictionary file: #[error]#</div></dd>+ #(/geo0ActionActivated)#+ </dl>+ </fieldset>+ </form>++ #%env/templates/footer.template%#+ </body>+</html>diff --git a/htroot/DictionaryLoader_p.java b/htroot/DictionaryLoader_p.javanew file mode 100644index 000000000..2e801e153--- /dev/null+++ b/htroot/DictionaryLoader_p.java@@ -0,0 +1,107 @@+// DictionaryLoader_p.java+// -----------------------+// part of YaCy+// (C) by Michael Peter Christen; [email protected]+// first published 12.05.2010 on http://yacy.net+//+// This program is free software; you can redistribute it and/or modify+// it under the terms of the GNU General Public License as published by+// the Free Software Foundation; either version 2 of the License, or+// (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU General Public License for more details.+//+// You should have received a copy of the GNU General Public License+// along with this program; if not, write to the Free Software+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA++import java.io.IOException;+import java.net.MalformedURLException;++import net.yacy.document.geolocalization.OpenGeoDB;+import net.yacy.kelondro.data.meta.DigestURI;+import net.yacy.kelondro.logging.Log;+import net.yacy.kelondro.util.FileUtils;+import de.anomic.crawler.CrawlProfile;+import de.anomic.crawler.retrieval.Response;+import de.anomic.data.LibraryProvider;+import de.anomic.http.server.RequestHeader;+import de.anomic.search.Switchboard;+import de.anomic.server.serverObjects;+import de.anomic.server.serverSwitch;++public class DictionaryLoader_p {++ public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {+ final Switchboard sb = (Switchboard) env;+ final serverObjects prop = new serverObjects(); // return variable that accumulates replacements++ /*+ * distinguish the following cases:+ * - dictionary file was not loaded -> actions: load the file+ * - dictionary file is loaded and enabled -> actions: disable or remove the file+ * - dictionary file is loaded but disabled -> actions: enable or remove the file+ */++ for (LibraryProvider.Dictionary dictionary: LibraryProvider.Dictionary.values()) {+ prop.put(dictionary.nickname + "URL", dictionary.url);+ prop.put(dictionary.nickname + "Storage", dictionary.file().toString());+ prop.put(dictionary.nickname + "Status", dictionary.file().exists() ? 1 : dictionary.fileDisabled().exists() ? 2 : 0);+ prop.put(dictionary.nickname + "ActionLoaded", 0);+ prop.put(dictionary.nickname + "ActionRemoved", 0);+ prop.put(dictionary.nickname + "ActionActivated", 0);+ prop.put(dictionary.nickname + "ActionDeactivated", 0);+ }++ if (post == null) return prop;++ if (post.containsKey("geo0Load")) {+ // load from the net+ try {+ Response response = sb.loader.load(new DigestURI(LibraryProvider.Dictionary.GEO0.url), false, true, CrawlProfile.CACHE_STRATEGY_NOCACHE);+ byte[] b = response.getContent();+ FileUtils.copy(b, LibraryProvider.Dictionary.GEO0.file());+ LibraryProvider.geoDB = new OpenGeoDB(LibraryProvider.Dictionary.GEO0.file());+ prop.put("geo0Status", LibraryProvider.Dictionary.GEO0.file().exists() ? 1 : 0);+ prop.put("geo0ActionLoaded", 1);+ } catch (MalformedURLException e) {+ Log.logException(e);+ prop.put("geo0ActionLoaded", 2);+ prop.put("geo0ActionLoaded_error", e.getMessage());+ } catch (IOException e) {+ Log.logException(e);+ prop.put("geo0ActionLoaded", 2);+ prop.put("geo0ActionLoaded_error", e.getMessage());+ }+ }++ if (post.containsKey("geo0Remove")) {+ FileUtils.deletedelete(LibraryProvider.Dictionary.GEO0.file());+ FileUtils.deletedelete(LibraryProvider.Dictionary.GEO0.fileDisabled());+ LibraryProvider.geoDB = new OpenGeoDB(null);+ prop.put("geo0ActionRemoved", 1);+ }++ if (post.containsKey("geo0Deactivate")) {+ LibraryProvider.Dictionary.GEO0.file().renameTo(LibraryProvider.Dictionary.GEO0.fileDisabled());+ LibraryProvider.geoDB = new OpenGeoDB(null);+ prop.put("geo0ActionDeactivated", 1);+ }++ if (post.containsKey("geo0Activate")) {+ LibraryProvider.Dictionary.GEO0.fileDisabled().renameTo(LibraryProvider.Dictionary.GEO0.file());+ LibraryProvider.geoDB = new OpenGeoDB(LibraryProvider.Dictionary.GEO0.file());+ prop.put("geo0ActionActivated", 1);+ }++ // check status again+ for (LibraryProvider.Dictionary dictionary: LibraryProvider.Dictionary.values()) {+ prop.put(dictionary.nickname + "Status", dictionary.file().exists() ? 1 : dictionary.fileDisabled().exists() ? 2 : 0);+ }++ return prop; // return rewrite values for templates+ }+}diff --git a/htroot/env/base.css b/htroot/env/base.cssindex 118ec413e..2da09b500 100644--- a/htroot/env/base.css+++ b/htroot/env/base.css@@ -124,6 +124,12 @@ tt, *.tt {.error {font-weight:bold;+ color:red;+}++.info {+ font-weight:bold;+ color:yellow;}.commit {diff --git a/htroot/env/templates/submenuConfig.template b/htroot/env/templates/submenuConfig.templateindex 3560972ad..384d13024 100644--- a/htroot/env/templates/submenuConfig.template+++ b/htroot/env/templates/submenuConfig.template@@ -5,6 +5,7 @@<li><a href="/ConfigBasic.html" class="MenuItemLink lock">Basic Configuration</a></li><li><a href="/ConfigAccounts_p.html" class="MenuItemLink lock">Accounts</a></li><li><a href="/ConfigNetwork_p.html" class="MenuItemLink lock">Network Configuration</a></li>+ <li><a href="/DictionaryLoader_p.html" class="MenuItemLink lock">Dictionary Loader</a></li><li><a href="/ConfigUpdate_p.html" class="MenuItemLink lock">System Update</a></li></ul></div>diff --git a/source/de/anomic/data/LibraryProvider.java b/source/de/anomic/data/LibraryProvider.javaindex 3f71d441d..b45a534c3 100644--- a/source/de/anomic/data/LibraryProvider.java+++ b/source/de/anomic/data/LibraryProvider.java@@ -47,11 +47,33 @@ public class LibraryProvider {private static final String path_to_source_dictionaries = "source";private static final String path_to_did_you_mean_dictionaries = "didyoumean";+ public static final String disabledExtension = ".disabled";+public static DidYouMeanLibrary dymLib = new DidYouMeanLibrary(null);public static OpenGeoDB geoDB = new OpenGeoDB(null);private static File dictSource = null;private static File dictRoot = null;+ public static enum Dictionary {+ GEO0("geo0",+ "http://downloads.sourceforge.net/project/opengeodb/Data/0.2.5a/opengeodb-0.2.5a-UTF8-sql.gz",+ "opengeodb-0.2.5a-UTF8-sql.gz");++ public String nickname, url, filename;+ private Dictionary(String nickname, String url, String filename) {+ this.nickname = nickname;+ this.url = url;+ this.filename = filename;+ }++ public File file() {+ return new File(dictSource, filename);+ }+ public File fileDisabled() {+ return new File(dictSource, filename + disabledExtension);+ }+ }+/*** initialize the LibraryProvider as static class.* This assigns default paths, and initializes the dictionary classes