You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
175 lines
7.5 KiB
175 lines
7.5 KiB
18 years ago
|
// CrawlProfileEditor_p.java
|
||
17 years ago
|
// (C) 2005, by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||
|
// first published 04.07.2005 on http://yacy.net
|
||
18 years ago
|
//
|
||
17 years ago
|
// This is a part of YaCy, a peer-to-peer based web search engine
|
||
|
//
|
||
15 years ago
|
// $LastChangedDate$
|
||
|
// $LastChangedRevision$
|
||
|
// $LastChangedBy$
|
||
17 years ago
|
//
|
||
|
// LICENSE
|
||
13 years ago
|
//
|
||
18 years ago
|
// 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
|
||
|
|
||
2 years ago
|
package net.yacy.htroot;
|
||
|
|
||
14 years ago
|
import java.util.Map;
|
||
14 years ago
|
import java.util.TreeMap;
|
||
18 years ago
|
|
||
14 years ago
|
import net.yacy.cora.protocol.RequestHeader;
|
||
12 years ago
|
import net.yacy.cora.util.ConcurrentLog;
|
||
12 years ago
|
import net.yacy.cora.util.SpaceExceededException;
|
||
12 years ago
|
import net.yacy.crawler.CrawlSwitchboard;
|
||
12 years ago
|
import net.yacy.crawler.data.CrawlProfile;
|
||
13 years ago
|
import net.yacy.search.Switchboard;
|
||
12 years ago
|
import net.yacy.server.serverObjects;
|
||
|
import net.yacy.server.serverSwitch;
|
||
|
import net.yacy.server.servletProperties;
|
||
18 years ago
|
|
||
|
public class CrawlProfileEditor_p {
|
||
15 years ago
|
|
||
|
private final static String CRAWL_PROFILE_PREFIX = "crawlProfiles_";
|
||
|
private static final String EDIT_ENTRIES_PREFIX = "edit_entries_";
|
||
|
|
||
7 years ago
|
public static serverObjects respond(final RequestHeader header,
|
||
14 years ago
|
final serverObjects post,
|
||
|
final serverSwitch env) {
|
||
18 years ago
|
final servletProperties prop = new servletProperties();
|
||
16 years ago
|
final Switchboard sb = (Switchboard)env;
|
||
13 years ago
|
|
||
18 years ago
|
// read post for handle
|
||
17 years ago
|
final String handle = (post == null) ? "" : post.get("handle", "");
|
||
17 years ago
|
if (post != null) {
|
||
14 years ago
|
if (post.containsKey("terminate")) try {
|
||
17 years ago
|
// termination of a crawl: shift the crawl from active to passive
|
||
14 years ago
|
final CrawlProfile p = sb.crawler.getActive(handle.getBytes());
|
||
|
if (p != null) sb.crawler.putPassive(handle.getBytes(), p);
|
||
17 years ago
|
// delete all entries from the crawl queue that are deleted here
|
||
14 years ago
|
sb.crawler.removeActive(handle.getBytes());
|
||
11 years ago
|
sb.crawler.removePassive(handle.getBytes());
|
||
13 years ago
|
sb.crawlQueues.noticeURL.removeByProfileHandle(handle, 10000);
|
||
12 years ago
|
} catch (final SpaceExceededException e) {
|
||
12 years ago
|
ConcurrentLog.logException(e);
|
||
17 years ago
|
}
|
||
|
if (post.containsKey("delete")) {
|
||
|
// deletion of a terminated crawl profile
|
||
14 years ago
|
sb.crawler.removePassive(handle.getBytes());
|
||
17 years ago
|
}
|
||
17 years ago
|
if (post.containsKey("deleteTerminatedProfiles")) {
|
||
14 years ago
|
for (final byte[] h: sb.crawler.getPassive()) {
|
||
|
sb.crawler.removePassive(h);
|
||
17 years ago
|
}
|
||
|
}
|
||
18 years ago
|
}
|
||
13 years ago
|
|
||
14 years ago
|
// generate handle list: first sort by handle name
|
||
14 years ago
|
CrawlProfile selentry;
|
||
14 years ago
|
final Map<String, String> orderdHandles = new TreeMap<String, String>();
|
||
14 years ago
|
for (final byte[] h : sb.crawler.getActive()) {
|
||
|
selentry = sb.crawler.getActive(h);
|
||
12 years ago
|
if (selentry != null && !CrawlSwitchboard.DEFAULT_PROFILES.contains(selentry.name())) {
|
||
12 years ago
|
orderdHandles.put(selentry.collectionName(), selentry.handle());
|
||
14 years ago
|
}
|
||
14 years ago
|
}
|
||
13 years ago
|
|
||
14 years ago
|
// then write into pop-up menu list
|
||
|
int count = 0;
|
||
14 years ago
|
for (final Map.Entry<String, String> NameHandle: orderdHandles.entrySet()) {
|
||
14 years ago
|
prop.put("profiles_" + count + "_name", NameHandle.getKey());
|
||
|
prop.put("profiles_" + count + "_handle", NameHandle.getValue());
|
||
|
if (handle.equals(NameHandle.getValue())) {
|
||
17 years ago
|
prop.put("profiles_" + count + "_selected", "1");
|
||
15 years ago
|
}
|
||
18 years ago
|
count++;
|
||
|
}
|
||
|
prop.put("profiles", count);
|
||
14 years ago
|
selentry = sb.crawler.getActive(handle.getBytes());
|
||
15 years ago
|
assert selentry == null || selentry.handle() != null;
|
||
18 years ago
|
// read post for change submit
|
||
|
if ((post != null) && (selentry != null)) {
|
||
15 years ago
|
if (post.containsKey("submit")) {
|
||
|
try {
|
||
2 years ago
|
for (final CrawlProfile.CrawlAttribute attribute: CrawlProfile.CrawlAttribute.values()) {
|
||
10 years ago
|
final String cval = selentry.get(attribute.key);
|
||
|
final String val = (attribute.type == CrawlProfile.CrawlAttribute.BOOLEAN) ? Boolean.toString(post.containsKey(attribute.key)) : post.get(attribute.key, cval);
|
||
15 years ago
|
if (!cval.equals(val)) {
|
||
10 years ago
|
selentry.put(attribute.key, val);
|
||
14 years ago
|
sb.crawler.putActive(selentry.handle().getBytes(), selentry);
|
||
15 years ago
|
}
|
||
|
}
|
||
|
} catch (final Exception ex) {
|
||
12 years ago
|
ConcurrentLog.logException(ex);
|
||
15 years ago
|
prop.put("error", "1");
|
||
|
prop.putHTML("error_message", ex.getMessage());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
13 years ago
|
|
||
18 years ago
|
// generate crawl profile table
|
||
18 years ago
|
count = 0;
|
||
17 years ago
|
boolean dark = true;
|
||
17 years ago
|
final int domlistlength = (post == null) ? 160 : post.getInt("domlistlength", 160);
|
||
14 years ago
|
CrawlProfile profile;
|
||
17 years ago
|
// put active crawls into list
|
||
14 years ago
|
for (final byte[] h: sb.crawler.getActive()) {
|
||
|
profile = sb.crawler.getActive(h);
|
||
13 years ago
|
profile.putProfileEntry(CRAWL_PROFILE_PREFIX, prop, true, dark, count, domlistlength);
|
||
17 years ago
|
dark = !dark;
|
||
|
count++;
|
||
|
}
|
||
|
// put passive crawls into list
|
||
17 years ago
|
boolean existPassiveCrawls = false;
|
||
14 years ago
|
for (final byte[] h: sb.crawler.getPassive()) {
|
||
|
profile = sb.crawler.getPassive(h);
|
||
13 years ago
|
profile.putProfileEntry(CRAWL_PROFILE_PREFIX, prop, false, dark, count, domlistlength);
|
||
18 years ago
|
dark = !dark;
|
||
18 years ago
|
count++;
|
||
17 years ago
|
existPassiveCrawls = true;
|
||
18 years ago
|
}
|
||
18 years ago
|
prop.put("crawlProfiles", count);
|
||
14 years ago
|
|
||
|
prop.put("existPassiveCrawls", existPassiveCrawls ? "1" : "0");
|
||
|
|
||
18 years ago
|
// generate edit field
|
||
|
if (selentry == null) {
|
||
17 years ago
|
prop.put("edit", "0");
|
||
18 years ago
|
} else {
|
||
15 years ago
|
prop.put("edit", "1");
|
||
12 years ago
|
prop.put("edit_name", selentry.collectionName());
|
||
15 years ago
|
prop.put("edit_handle", selentry.handle());
|
||
|
count = 0;
|
||
2 years ago
|
for (final CrawlProfile.CrawlAttribute attribute: CrawlProfile.CrawlAttribute.values()) {
|
||
10 years ago
|
final String val = selentry.get(attribute.key);
|
||
|
prop.put(EDIT_ENTRIES_PREFIX + count + "_readonly", attribute.readonly ? "1" : "0");
|
||
|
prop.put(EDIT_ENTRIES_PREFIX + count + "_readonly_name", attribute.key);
|
||
|
prop.put(EDIT_ENTRIES_PREFIX + count + "_readonly_label", attribute.label);
|
||
|
prop.put(EDIT_ENTRIES_PREFIX + count + "_readonly_type", attribute.type);
|
||
|
if (attribute.type == CrawlProfile.CrawlAttribute.BOOLEAN) {
|
||
14 years ago
|
prop.put(EDIT_ENTRIES_PREFIX + count + "_readonly_type_checked",
|
||
10 years ago
|
val == null ? "0" : Boolean.parseBoolean(val) ? "1" : "0");
|
||
15 years ago
|
} else {
|
||
7 years ago
|
prop.put(header.fileType(), EDIT_ENTRIES_PREFIX + count + "_readonly_type_value", val == null ? "" : val);
|
||
15 years ago
|
}
|
||
|
count++;
|
||
|
}
|
||
|
prop.put("edit_entries", count);
|
||
|
}
|
||
13 years ago
|
|
||
18 years ago
|
return prop;
|
||
|
}
|
||
13 years ago
|
|
||
18 years ago
|
}
|