yacy_search_server/htroot/robots.java
orbiter 1d8d51075c refactoring:
- removed the plasma package. The name of that package came from a very early pre-version of YaCy, even before YaCy was named AnomicHTTPProxy. The Proxy project introduced search for cache contents using class files that had been developed during the plasma project. Information from 2002 about plasma can be found here:
http://web.archive.org/web/20020802110827/http://anomic.de/AnomicPlasma/index.html
We stil have one class that comes mostly unchanged from the plasma project, the Condenser class. But this is now part of the document package and all other classes in the plasma package can be assigned to other packages.
- cleaned up the http package: better structure of that class and clean isolation of server and client classes. The old HTCache becomes part of the client sub-package of http.
- because the plasmaSwitchboard is now part of the search package all servlets had to be touched to declare a different package source.

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6232 6c8d7289-2bf4-0310-a012-ef5d649a1542
2009-07-19 20:37:44 +00:00

76 lines
3.8 KiB
Java

import java.io.File;
import java.util.ArrayList;
import de.anomic.http.metadata.RequestHeader;
import de.anomic.http.server.RobotsTxtConfig;
import de.anomic.search.Switchboard;
import de.anomic.search.SwitchboardConstants;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.server.servletProperties;
public class robots {
public static servletProperties respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
final servletProperties prop = new servletProperties();
final RobotsTxtConfig rbc = ((Switchboard)env).robotstxtConfig;
if (rbc.isAllDisallowed()) {
prop.put(RobotsTxtConfig.ALL, 1);
} else {
if (rbc.isBlogDisallowed()) prop.put(RobotsTxtConfig.ALL + "_" + RobotsTxtConfig.BLOG, "1");
if (rbc.isBookmarksDisallowed()) prop.put(RobotsTxtConfig.ALL + "_" + RobotsTxtConfig.BOOKMARKS, "1");
if (rbc.isFileshareDisallowed()) prop.put(RobotsTxtConfig.ALL + "_" + RobotsTxtConfig.FILESHARE, "1");
if (rbc.isHomepageDisallowed()) prop.put(RobotsTxtConfig.ALL + "_" + RobotsTxtConfig.HOMEPAGE, "1");
if (rbc.isNetworkDisallowed()) prop.put(RobotsTxtConfig.ALL + "_" + RobotsTxtConfig.NETWORK, "1");
if (rbc.isNewsDisallowed()) prop.put(RobotsTxtConfig.ALL + "_" + RobotsTxtConfig.NEWS, "1");
if (rbc.isStatusDisallowed()) prop.put(RobotsTxtConfig.ALL + "_" + RobotsTxtConfig.STATUS, "1");
if (rbc.isSurftipsDisallowed()) prop.put(RobotsTxtConfig.ALL + "_" + RobotsTxtConfig.SURFTIPS, "1");
if (rbc.isWikiDisallowed()) prop.put(RobotsTxtConfig.ALL + "_" + RobotsTxtConfig.WIKI, "1");
if (rbc.isProfileDisallowed()) prop.put(RobotsTxtConfig.ALL + "_" + RobotsTxtConfig.PROFILE, "1");
if (rbc.isLockedDisallowed() || rbc.isDirsDisallowed()) {
final ArrayList<String>[] p = getFiles(env.getConfig(SwitchboardConstants.HTROOT_PATH, SwitchboardConstants.HTROOT_PATH_DEFAULT));
if (rbc.isLockedDisallowed()) {
prop.put(RobotsTxtConfig.ALL + "_" + RobotsTxtConfig.LOCKED, p[0].size());
for (int i=0; i<p[0].size(); i++)
prop.put(RobotsTxtConfig.ALL + "_" + RobotsTxtConfig.LOCKED + "_" + i + "_page", p[0].get(i));
}
if (rbc.isDirsDisallowed()) {
prop.put(RobotsTxtConfig.ALL + "_" + RobotsTxtConfig.DIRS, p[1].size());
for (int i=0; i<p[1].size(); i++)
prop.put(RobotsTxtConfig.ALL + "_" + RobotsTxtConfig.DIRS + "_" + i + "_dir", p[1].get(i));
}
}
}
return prop;
}
@SuppressWarnings("unchecked")
private static ArrayList<String>[] getFiles(final String htrootPath) {
final File htroot = new File(htrootPath);
if (!htroot.exists()) return null;
final ArrayList<String> htrootFiles = new ArrayList<String>();
final ArrayList<String> htrootDirs = new ArrayList<String>();
final String[] htroots = htroot.list();
File file;
for (int i=0, dot; i<htroots.length; i++) {
if (htroots[i].equals("www")) continue;
file = new File(htroot, htroots[i]);
if (file.isDirectory()) {
htrootDirs.add(htroots[i]);
} else if (
((dot = htroots[i].lastIndexOf('.')) < 2 ||
htroots[i].charAt(dot - 2) == '_' && htroots[i].charAt(dot - 1) == 'p') &&
!(htroots[i].endsWith("java") || htroots[i].endsWith("class"))
) {
htrootFiles.add(htroots[i]);
}
}
return new ArrayList[] { htrootFiles, htrootDirs };
}
}