From 7ca60f97bf9494601e018a132c8e00a29ea2a71b Mon Sep 17 00:00:00 2001 From: allo Date: Wed, 12 Oct 2005 12:44:05 +0000 Subject: [PATCH] localization Support for Includes git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@923 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/Status.java | 2 +- source/de/anomic/http/httpTemplate.java | 3 ++- source/de/anomic/http/httpdFileHandler.java | 30 ++++++++++++++++----- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/htroot/Status.java b/htroot/Status.java index 7c44c6705..03b9cd5c4 100644 --- a/htroot/Status.java +++ b/htroot/Status.java @@ -79,7 +79,7 @@ public class Status { yacyCore.peerActions.updateMySeed(); if (((plasmaSwitchboard) env).adminAuthenticated(header) >= 2) { - prop.put("privateStatusTable", new File(env.getRootPath(), "htroot/Status_p.inc").toString()); + prop.put("privateStatusTable", "Status_p.inc"); } else { prop.put("privateStatusTable", ""); } diff --git a/source/de/anomic/http/httpTemplate.java b/source/de/anomic/http/httpTemplate.java index b07c6dd33..69d45e0f1 100644 --- a/source/de/anomic/http/httpTemplate.java +++ b/source/de/anomic/http/httpTemplate.java @@ -373,7 +373,8 @@ public final class httpTemplate { if ((!filename.equals("")) && (!filename.equals(dflt))) { BufferedReader br = null; try{ - br = new BufferedReader(new InputStreamReader(new FileInputStream( filename ))); + //br = new BufferedReader(new InputStreamReader(new FileInputStream( filename ))); //Simple Include + br = new BufferedReader( new InputStreamReader(new FileInputStream( httpdFileHandler.getLocalizedFile(filename) )) ); //YaCy (with Locales) //Read the Include while( (line = br.readLine()) != null ){ include+=line+de.anomic.server.serverCore.crlfString; diff --git a/source/de/anomic/http/httpdFileHandler.java b/source/de/anomic/http/httpdFileHandler.java index 9e24adce0..0c4f54f19 100644 --- a/source/de/anomic/http/httpdFileHandler.java +++ b/source/de/anomic/http/httpdFileHandler.java @@ -212,6 +212,28 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http serverLog.logWarning("HTTPDFileHandler", "Content-MD5 support not availabel ..."); } } + /* + * Returns the path of a (existing) localized File, or the english one, if not availible. + * @param path is relative from htroot + * @return the function returns a Filehandle to the translated file, or if not availitble to the english one. + */ + public static File getLocalizedFile(String path){ + plasmaSwitchboard switchboard=plasmaSwitchboard.getSwitchboard(); + // create htLocaleDefault, htLocalePath + if (htDefaultPath == null) htDefaultPath = new File(switchboard.getRootPath(), switchboard.getConfig("htDefaultPath","htroot")); + if (htLocalePath == null) htLocalePath = new File(switchboard.getRootPath(), switchboard.getConfig("htLocalePath","htroot/locale")); + //htLocaleSelection = switchboard.getConfig("htLocaleSelection","default"); + + // find locales or alternatives in htDocsPath + String htLocaleSelection = switchboard.getConfig("htLocaleSelection","default"); + // look if we have a localization of that file + if (!(htLocaleSelection.equals("default"))) { + File localePath = new File(htLocalePath, htLocaleSelection + "/" + path); + if (localePath.exists()) + return localePath; + } + return new File(htDefaultPath, path); + } // private void textMessage(OutputStream out, int retcode, String body) throws IOException { // httpd.sendRespondHeader( @@ -455,13 +477,7 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http path.endsWith("csv") || path.endsWith("pac")) { - // find locales or alternatives in htDocsPath - String htLocaleSelection = switchboard.getConfig("htLocaleSelection","default"); - // look if we have a localization of that file - if (!(htLocaleSelection.equals("default"))) { - File localePath = new File(htLocalePath, htLocaleSelection + "/" + path); - if (localePath.exists()) targetFile = localePath; - } + targetFile = getLocalizedFile(path); // call rewrite-class serverObjects tp = new serverObjects();