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
pull/1/head
allo 20 years ago
parent 6f4d2e5272
commit abb6750090

@ -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;

Loading…
Cancel
Save