/DictionaryLoader_p.html Will also be used for more dictionary files in the future git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6872 6c8d7289-2bf4-0310-a012-ef5d649a1542pull/1/head
parent
90fa8fd4d4
commit
3661cb692c
@ -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>
|
@ -0,0 +1,107 @@
|
||||
// DictionaryLoader_p.java
|
||||
// -----------------------
|
||||
// part of YaCy
|
||||
// (C) by Michael Peter Christen; mc@yacy.net
|
||||
// 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
|
||||
}
|
||||
}
|
Loading…
Reference in new issue