2005-12-29 18:45:50 +01:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.MalformedURLException;
|
2008-09-20 00:19:11 +02:00
|
|
|
import java.util.Set;
|
2005-12-29 18:45:50 +01:00
|
|
|
|
2009-10-11 02:12:19 +02:00
|
|
|
import net.yacy.kelondro.data.meta.DigestURI;
|
|
|
|
|
2009-07-24 16:52:27 +02:00
|
|
|
import de.anomic.crawler.CrawlProfile;
|
2009-07-08 23:48:08 +02:00
|
|
|
import de.anomic.document.parser.html.ContentScraper;
|
2009-07-19 22:37:44 +02:00
|
|
|
import de.anomic.http.metadata.RequestHeader;
|
|
|
|
import de.anomic.search.Switchboard;
|
2005-12-29 18:45:50 +01:00
|
|
|
import de.anomic.server.serverObjects;
|
|
|
|
import de.anomic.server.serverSwitch;
|
|
|
|
|
2006-02-17 21:55:31 +01:00
|
|
|
public class getpageinfo_p {
|
2008-07-04 13:03:03 +02:00
|
|
|
|
2009-07-19 22:37:44 +02:00
|
|
|
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
|
|
|
|
final Switchboard sb = (Switchboard) env;
|
2008-08-02 14:12:04 +02:00
|
|
|
final serverObjects prop = new serverObjects();
|
2008-09-19 16:27:44 +02:00
|
|
|
|
|
|
|
// avoid UNRESOLVED PATTERN
|
|
|
|
prop.put("title", "");
|
|
|
|
prop.put("desc", "");
|
|
|
|
prop.put("lang", "");
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("robots-allowed", "3"); //unknown
|
2008-09-19 16:27:44 +02:00
|
|
|
prop.put("sitemap", "");
|
|
|
|
prop.put("favicon","");
|
|
|
|
|
|
|
|
// default actions
|
|
|
|
String actions="title,robots";
|
|
|
|
|
2005-12-29 18:45:50 +01:00
|
|
|
if(post!=null && post.containsKey("url")){
|
2006-02-17 21:55:31 +01:00
|
|
|
if(post.containsKey("actions"))
|
2008-06-06 18:01:27 +02:00
|
|
|
actions=post.get("actions");
|
|
|
|
String url=post.get("url");
|
2006-09-09 14:28:28 +02:00
|
|
|
if(url.toLowerCase().startsWith("ftp://")){
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("robots-allowed", "1");
|
2008-10-22 20:59:04 +02:00
|
|
|
prop.putXML("title", "FTP: "+url);
|
2006-09-09 14:34:24 +02:00
|
|
|
return prop;
|
|
|
|
} else if (!(url.toLowerCase().startsWith("http://") || url.toLowerCase().startsWith("https://"))) {
|
2006-02-17 21:55:31 +01:00
|
|
|
url = "http://" + url;
|
|
|
|
}
|
|
|
|
if (actions.indexOf("title")>=0) {
|
2009-10-11 02:12:19 +02:00
|
|
|
DigestURI u = null;
|
2006-02-17 21:55:31 +01:00
|
|
|
try {
|
2009-10-11 02:12:19 +02:00
|
|
|
u = new DigestURI(url, null);
|
2009-07-25 23:38:57 +02:00
|
|
|
} catch (final MalformedURLException e) {
|
|
|
|
// fail, do nothing
|
|
|
|
}
|
|
|
|
ContentScraper scraper = null;
|
|
|
|
if (u != null) try {
|
|
|
|
scraper = ContentScraper.parseResource(sb.loader, u, CrawlProfile.CACHE_STRATEGY_IFFRESH);
|
|
|
|
} catch (final IOException e) {
|
|
|
|
// try again, try harder
|
|
|
|
try {
|
|
|
|
scraper = ContentScraper.parseResource(sb.loader, u, CrawlProfile.CACHE_STRATEGY_IFEXIST);
|
|
|
|
} catch (final IOException ee) {
|
|
|
|
// now thats a fail, do nothing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (scraper != null) {
|
2007-06-09 17:22:37 +02:00
|
|
|
// put the document title
|
2008-10-22 20:59:04 +02:00
|
|
|
prop.putXML("title", scraper.getTitle());
|
2007-06-09 17:22:37 +02:00
|
|
|
|
|
|
|
// put the favicon that belongs to the document
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("favicon", (scraper.getFavicon()==null) ? "" : scraper.getFavicon().toString());
|
2007-06-09 17:22:37 +02:00
|
|
|
|
|
|
|
// put keywords
|
2008-08-02 14:12:04 +02:00
|
|
|
final String list[]=scraper.getKeywords();
|
2008-05-18 14:48:57 +02:00
|
|
|
int count = 0;
|
2007-06-01 16:44:46 +02:00
|
|
|
for(int i=0;i<list.length;i++){
|
2009-07-25 23:38:57 +02:00
|
|
|
String tag = list[i];
|
|
|
|
if (!tag.equals("")) {
|
|
|
|
prop.putXML("tags_"+count+"_tag", tag);
|
|
|
|
count++;
|
|
|
|
}
|
2006-02-17 21:55:31 +01:00
|
|
|
}
|
2008-05-18 14:48:57 +02:00
|
|
|
prop.put("tags", count);
|
2008-09-18 23:01:23 +02:00
|
|
|
// put description
|
2008-10-22 20:59:04 +02:00
|
|
|
prop.putXML("desc", scraper.getDescription());
|
2008-09-20 00:19:11 +02:00
|
|
|
// put language
|
|
|
|
Set<String> languages = scraper.getContentLanguages();
|
2008-10-22 20:59:04 +02:00
|
|
|
prop.putXML("lang", (languages == null) ? "unknown" : languages.iterator().next());
|
2005-12-29 18:45:50 +01:00
|
|
|
}
|
2006-02-17 21:55:31 +01:00
|
|
|
}
|
|
|
|
if(actions.indexOf("robots")>=0){
|
|
|
|
try {
|
2009-10-11 02:12:19 +02:00
|
|
|
final DigestURI theURL = new DigestURI(url, null);
|
2008-09-18 23:01:23 +02:00
|
|
|
|
2007-05-06 11:52:04 +02:00
|
|
|
// determine if crawling of the current URL is allowed
|
2008-07-05 02:35:20 +02:00
|
|
|
prop.put("robots-allowed", sb.robots.isDisallowed(theURL) ? "0" : "1");
|
2007-05-06 11:52:04 +02:00
|
|
|
|
|
|
|
// get the sitemap URL of the domain
|
2009-10-11 02:12:19 +02:00
|
|
|
final DigestURI sitemapURL = sb.robots.getSitemapURL(theURL);
|
2008-10-22 20:59:04 +02:00
|
|
|
prop.putXML("sitemap", (sitemapURL==null)?"":sitemapURL.toString());
|
2008-08-02 14:12:04 +02:00
|
|
|
} catch (final MalformedURLException e) {}
|
2006-02-17 21:55:31 +01:00
|
|
|
}
|
|
|
|
|
2005-12-29 18:45:50 +01:00
|
|
|
}
|
|
|
|
// return rewrite properties
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|