|
|
|
@ -252,10 +252,18 @@ public final class httpTemplate {
|
|
|
|
|
|
|
|
|
|
keyStream=new ByteArrayOutputStream(); //clear
|
|
|
|
|
|
|
|
|
|
boolean byName=false;
|
|
|
|
|
int whichPattern=0;
|
|
|
|
|
String patternName="";
|
|
|
|
|
if(pattern.containsKey(prefix + key) && pattern.get(prefix + key) != null){
|
|
|
|
|
try{
|
|
|
|
|
whichPattern=(int)Integer.parseInt((String)pattern.get(prefix + key)); //which alternative(index)
|
|
|
|
|
Object tmp=pattern.get(prefix + key); //lookup by index OR Name
|
|
|
|
|
if(tmp instanceof String){
|
|
|
|
|
byName=true;
|
|
|
|
|
patternName=(String)tmp;//Name
|
|
|
|
|
}else{
|
|
|
|
|
whichPattern=(int)Integer.parseInt((String)pattern.get(prefix + key)); //index
|
|
|
|
|
}
|
|
|
|
|
}catch(NumberFormatException e){
|
|
|
|
|
whichPattern=0;
|
|
|
|
|
}
|
|
|
|
@ -266,6 +274,22 @@ public final class httpTemplate {
|
|
|
|
|
int currentPattern=0;
|
|
|
|
|
boolean found=false;
|
|
|
|
|
keyStream = new ByteArrayOutputStream(); //reset stream
|
|
|
|
|
if(byName){
|
|
|
|
|
//TODO: better Error Handling
|
|
|
|
|
transferUntil(pis, keyStream, (new String("%%"+patternName)).getBytes());
|
|
|
|
|
if(pis.available()==0){
|
|
|
|
|
serverLog.logError("TEMPLATE", "No such Template: %%"+patternName);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
keyStream=new ByteArrayOutputStream();
|
|
|
|
|
transferUntil(pis, keyStream, "::".getBytes());
|
|
|
|
|
pis2 = new PushbackInputStream(new ByteArrayInputStream(keyStream.toString().getBytes()));
|
|
|
|
|
writeTemplate(pis2, out, pattern, dflt, prefix + key + "_");
|
|
|
|
|
transferUntil(pis, keyStream, (new String("#(/"+key+")#")).getBytes());
|
|
|
|
|
if(pis.available()==0){
|
|
|
|
|
serverLog.logError("TEMPLATE", "No Close Key found for #("+key+")# (by Name)");
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
while(!found){
|
|
|
|
|
bb=pis.read();
|
|
|
|
|
if( (bb & 0xFF) == hash){
|
|
|
|
@ -314,11 +338,12 @@ public final class httpTemplate {
|
|
|
|
|
if(!found){
|
|
|
|
|
text += (char)bb;
|
|
|
|
|
if(pis.available()==0){
|
|
|
|
|
serverLog.logError("TEMPLATE", "No Close Key found for #("+key+")#");
|
|
|
|
|
serverLog.logError("TEMPLATE", "No Close Key found for #("+key+")# (by Index)");
|
|
|
|
|
found=true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}//while
|
|
|
|
|
}//if(byName) (else branch)
|
|
|
|
|
}else if( (bb & 0xFF) == lbr ){ //normal
|
|
|
|
|
if (transferUntil(pis, keyStream, pClose)) {
|
|
|
|
|
// pattern detected, write replacement
|
|
|
|
|