From fe77fc3d62e1c2a86354de1d42ac771edfddb7cd Mon Sep 17 00:00:00 2001 From: orbiter Date: Fri, 30 Jan 2009 13:30:36 +0000 Subject: [PATCH] - added new property setting 'repositoryPath' which can be used to map any path to http://localhost:8080/repository/ This can be used to do an intranet-indexing without the setting of symbolic links - which does not work in Windows environment. Now also Windows users can index their file system easily using the intranet use case. - fixed some problems with the identification of the alternative path in DATA/HTDOCS in the httpd file server git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5538 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- defaults/yacy.init | 12 ++++- source/de/anomic/http/httpdFileHandler.java | 49 ++++++++------------- 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/defaults/yacy.init b/defaults/yacy.init index 591790fc5..bec584163 100644 --- a/defaults/yacy.init +++ b/defaults/yacy.init @@ -162,15 +162,23 @@ htTemplatePath = htroot/env/templates htDefaultPath=htroot # individual htroot folder -# every user may publicise her/his own web pages +# every user may publicize her/his own web pages # these pages shall be placed in the path defined here # the htdocs path shares its content with the htroot path htDocsPath = DATA/HTDOCS +# alternative path for the repository path of the web server: the URL +# http://localhost:8080/repository +# points to DATA/HTDOCS/repository, but can be altered with this repository path +# hint: the repository path is the default path for intranet indexing. The easiest ways +# to do a indexing of the local storage system is to set a path here for the repository +# that points to the root path of the files that shall be indexed +repositoryPath=DATA/HTDOCS/repository + # the default files (typically index.html), if no file name is given # The complete path to this file is created by combination with the rootPath # you can set a list of defaults, separated by comma -# the first one is priorized +# the first one is preferred defaultFiles = ConfigBasic.html,index.html,index.htm,default.html,search.html,console.html,control.html,welcome.html,wiki.html,forum.html,blog.html,email.html,content.html,monitor.html,share.html,dir.html,readme.txt # locale-options: YaCy supports localization. diff --git a/source/de/anomic/http/httpdFileHandler.java b/source/de/anomic/http/httpdFileHandler.java index 1b60fe289..49ea7e677 100644 --- a/source/de/anomic/http/httpdFileHandler.java +++ b/source/de/anomic/http/httpdFileHandler.java @@ -202,35 +202,22 @@ public final class httpdFileHandler { * @param path relative from htroot * @param localeSelection language of localized file; locale.language from switchboard is used if localeSelection.equals("") */ public static File getLocalizedFile(final String path, final String localeSelection){ - if (htDefaultPath == null) htDefaultPath = switchboard.getConfigPath("htDefaultPath","htroot"); - if (htLocalePath == null) htLocalePath = switchboard.getConfigPath("locale.translated_html","DATA/LOCALE/htroot"); + //if (htDefaultPath == null) htDefaultPath = switchboard.getConfigPath("htDefaultPath", "htroot"); + //if (htLocalePath == null) htLocalePath = switchboard.getConfigPath("locale.translated_html", "DATA/LOCALE/htroot"); + //if (htDocsPath == null) htDocsPath = switchboard.getConfigPath(plasmaSwitchboardConstants.HTDOCS_PATH, plasmaSwitchboardConstants.HTDOCS_PATH_DEFAULT); + if (path.startsWith("/repository/")) + return new File(switchboard.getConfig("repositoryPath", "DATA/HTDOCS/repository"), path.substring(11)); if (!(localeSelection.equals("default"))) { final File localePath = new File(htLocalePath, localeSelection + '/' + path); - if (localePath.exists()) // avoid "NoSuchFile" troubles if the "localeSelection" is misspelled - return localePath; + if (localePath.exists()) return localePath; // avoid "NoSuchFile" troubles if the "localeSelection" is misspelled } + + File docsPath = new File(htDocsPath, path); + if (docsPath.exists()) return docsPath; return new File(htDefaultPath, path); } -// private void textMessage(OutputStream out, int retcode, String body) throws IOException { -// httpd.sendRespondHeader( -// this.connectionProperties, // the connection properties -// out, // the output stream -// "HTTP/1.1", // the http version that should be used -// retcode, // the http status code -// null, // the http status message -// "text/plain", // the mimetype -// body.length(), // the content length -// httpc.nowDate(), // the modification date -// null, // the expires date -// null, // cookies -// null, // content encoding -// null); // transfer encoding -// out.write(body.getBytes()); -// out.flush(); -// } - private static final httpResponseHeader getDefaultHeaders(final String path) { final httpResponseHeader headers = new httpResponseHeader(); String ext; @@ -412,7 +399,7 @@ public final class httpdFileHandler { File targetClass=null; // locate the file - if (!(path.startsWith("/"))) path = "/" + path; // attach leading slash + if (!path.startsWith("/") && !path.startsWith("\\")) path = "/" + path; // attach leading slash // a different language can be desired (by i.e. ConfigBasic.html) than the one stored in the locale.language String localeSelection = switchboard.getConfig("locale.language","default"); @@ -426,9 +413,9 @@ public final class httpdFileHandler { } File targetFile = getLocalizedFile(path, localeSelection); - final String targetExt = conProp.getProperty("EXT",""); + final String targetExt = conProp.getProperty("EXT",""); targetClass = rewriteClassFile(new File(htDefaultPath, path)); - if (path.endsWith("/")) { + if (path.endsWith("/") || path.endsWith("\\")) { String testpath; // attach default file name for (int i = 0; i < defaultFiles.length; i++) { @@ -440,13 +427,13 @@ public final class httpdFileHandler { break; } } + targetFile = getLocalizedFile(path, localeSelection); //no defaultfile, send a dirlisting - if (targetFile == null || !targetFile.exists()) { + if (targetFile == null || !targetFile.exists() || (targetFile.exists() && targetFile.isDirectory())) { final StringBuilder aBuffer = new StringBuilder(); aBuffer.append("\n\n\n\n

Index of " + path + "

\n \n\n\n"); // write the list to the client - httpd.sendRespondHeader(conProp, out, httpVersion, 200, null, "text/html; charset=UTF-8", aBuffer.length(), new Date(dir.lastModified()), null, new httpResponseHeader(), null, null, true); + httpd.sendRespondHeader(conProp, out, httpVersion, 200, null, "text/html; charset=UTF-8", aBuffer.length(), new Date(targetFile.lastModified()), null, new httpResponseHeader(), null, null, true); if (!method.equals(httpHeader.METHOD_HEAD)) { out.write(aBuffer.toString().getBytes("UTF-8")); } @@ -724,7 +711,7 @@ public final class httpdFileHandler { /* servletProperties tp = (servlerObjects) */ invokeServlet(targetClass, requestHeader, args); forceConnectionClose(conProp); return; - } else if ((targetFile.exists()) && (targetFile.canRead())) { + } else if (targetFile.exists() && targetFile.isFile() && targetFile.canRead()) { // we have found a file that can be written to the client // if this file uses templates, then we use the template // re-write - method to create an result