From abb67500909b928c7506f42ae21d7216e025f510 Mon Sep 17 00:00:00 2001 From: allo Date: Tue, 10 May 2005 16:55:18 +0000 Subject: [PATCH] added Include Funktion. #%include.inc%# includes other Templates git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@102 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/http/httpTemplate.java | 30 ++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/source/de/anomic/http/httpTemplate.java b/source/de/anomic/http/httpTemplate.java index bdbd10c9a..ad5a37cd3 100644 --- a/source/de/anomic/http/httpTemplate.java +++ b/source/de/anomic/http/httpTemplate.java @@ -48,6 +48,10 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PushbackInputStream; +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.File; import java.util.Hashtable; import de.anomic.server.serverFileUtils; @@ -72,6 +76,10 @@ final class httpTemplate { private static final byte[] aOpen = {hash, lrbr}; private static final byte[] aClose = {rrbr, hash}; + private static final byte ps = (byte)'%'; + private static final byte[] iOpen = {hash, ps}; + private static final byte[] iClose = {ps, hash}; + private static boolean transferUntil(PushbackInputStream i, OutputStream o, byte[] pattern) throws IOException { // returns true if pattern was found; everything but the pattern has then be transfered so far int ppos = 0; @@ -269,7 +277,27 @@ final class httpTemplate { serverFileUtils.copy(pis, out); return; } - }else{ //no match, but a single hash (output # + bb) + }else if( (bb & 0xFF) == ps){ //include + String include = ""; + String line = ""; + keyStream = new ByteArrayOutputStream(); //reset stream + if(transferUntil(pis, keyStream, iClose)){ + try{ + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream( new File("htroot", keyStream.toString()) ))); + //Read the Include + while( (line = br.readLine()) != null ){ + include+=line+de.anomic.server.serverCore.crlfString; + } + }catch(IOException e){ + //file not found? + System.err.println("Include Error with file: "+keyStream.toString()); + e.printStackTrace(); + } + PushbackInputStream pis2 = new PushbackInputStream(new ByteArrayInputStream(include.getBytes())); + writeTemplate(pis2, out, pattern, dflt, prefix); + } + + }else{ //no match, but a single hash (output # + bb) byte[] tmp=new byte[2]; tmp[0]=hash; tmp[1]=(byte)bb;