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.
98 lines
3.6 KiB
98 lines
3.6 KiB
17 years ago
|
// plasmaProtocolLoader.java
|
||
|
// (C) 2007 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||
|
// first published 24.10.2007 on http://yacy.net
|
||
|
//
|
||
|
// This is a part of YaCy, a peer-to-peer based web search engine
|
||
|
//
|
||
|
// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $
|
||
|
// $LastChangedRevision: 1986 $
|
||
|
// $LastChangedBy: orbiter $
|
||
|
//
|
||
|
// LICENSE
|
||
|
//
|
||
|
// 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
|
||
|
|
||
17 years ago
|
package de.anomic.crawler;
|
||
17 years ago
|
|
||
|
import java.util.Arrays;
|
||
|
import java.util.HashSet;
|
||
|
|
||
|
import de.anomic.plasma.plasmaHTCache;
|
||
|
import de.anomic.plasma.plasmaSwitchboard;
|
||
|
import de.anomic.server.logging.serverLog;
|
||
|
|
||
17 years ago
|
public final class ProtocolLoader {
|
||
17 years ago
|
|
||
|
private plasmaSwitchboard sb;
|
||
|
private serverLog log;
|
||
17 years ago
|
private HashSet<String> supportedProtocols;
|
||
17 years ago
|
private HTTPLoader httpLoader;
|
||
|
private FTPLoader ftpLoader;
|
||
17 years ago
|
|
||
17 years ago
|
public ProtocolLoader(plasmaSwitchboard sb, serverLog log) {
|
||
17 years ago
|
this.sb = sb;
|
||
|
this.log = log;
|
||
17 years ago
|
this.supportedProtocols = new HashSet<String>(Arrays.asList(new String[]{"http","https","ftp"}));
|
||
17 years ago
|
|
||
|
// initiate loader objects
|
||
17 years ago
|
httpLoader = new HTTPLoader(sb, log);
|
||
|
ftpLoader = new FTPLoader(sb, log);
|
||
17 years ago
|
}
|
||
|
|
||
|
public boolean isSupportedProtocol(String protocol) {
|
||
|
if ((protocol == null) || (protocol.length() == 0)) return false;
|
||
|
return this.supportedProtocols.contains(protocol.trim().toLowerCase());
|
||
|
}
|
||
|
|
||
17 years ago
|
@SuppressWarnings("unchecked")
|
||
|
public HashSet<String> getSupportedProtocols() {
|
||
|
return (HashSet<String>) this.supportedProtocols.clone();
|
||
17 years ago
|
}
|
||
|
|
||
17 years ago
|
public plasmaHTCache.Entry load(CrawlEntry entry, String parserMode) {
|
||
17 years ago
|
// getting the protocol of the next URL
|
||
|
String protocol = entry.url().getProtocol();
|
||
|
|
||
17 years ago
|
if ((protocol.equals("http") || (protocol.equals("https")))) return httpLoader.load(entry, parserMode);
|
||
17 years ago
|
if (protocol.equals("ftp")) return ftpLoader.load(entry);
|
||
|
|
||
|
this.log.logWarning("Unsupported protocol '" + protocol + "' in url " + entry.url());
|
||
|
return null;
|
||
|
}
|
||
|
|
||
17 years ago
|
public String process(CrawlEntry entry, String parserMode) {
|
||
17 years ago
|
// load a resource, store it to htcache and push queue entry to switchboard queue
|
||
|
// returns null if everything went fine, a fail reason string if a problem occurred
|
||
|
plasmaHTCache.Entry h;
|
||
|
try {
|
||
17 years ago
|
h = load(entry, parserMode);
|
||
17 years ago
|
entry.setStatus("loaded");
|
||
|
if (h == null) return "load failed";
|
||
|
boolean stored = sb.htEntryStoreProcess(h);
|
||
|
entry.setStatus("stored-" + ((stored) ? "ok" : "fail"));
|
||
|
return (stored) ? null : "not stored";
|
||
|
} catch (Exception e) {
|
||
|
log.logWarning("problem loading " + entry.url().toString(), e);
|
||
|
return "load error - " + e.getMessage();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|