alternatives By Name

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@498 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
allo 20 years ago
parent 86305f051d
commit 3762acde6e

@ -252,12 +252,20 @@ public final class httpTemplate {
keyStream=new ByteArrayOutputStream(); //clear keyStream=new ByteArrayOutputStream(); //clear
boolean byName=false;
int whichPattern=0; int whichPattern=0;
String patternName="";
if(pattern.containsKey(prefix + key) && pattern.get(prefix + key) != null){ if(pattern.containsKey(prefix + key) && pattern.get(prefix + key) != null){
try{ 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){ }catch(NumberFormatException e){
whichPattern=0; whichPattern=0;
} }
}else{ }else{
//System.out.println("Pattern \""+new String(prefix + key)+"\" is not set"); //DEBUG //System.out.println("Pattern \""+new String(prefix + key)+"\" is not set"); //DEBUG
@ -266,59 +274,76 @@ public final class httpTemplate {
int currentPattern=0; int currentPattern=0;
boolean found=false; boolean found=false;
keyStream = new ByteArrayOutputStream(); //reset stream keyStream = new ByteArrayOutputStream(); //reset stream
while(!found){ if(byName){
bb=pis.read(); //TODO: better Error Handling
if( (bb & 0xFF) == hash){ transferUntil(pis, keyStream, (new String("%%"+patternName)).getBytes());
bb=pis.read(); if(pis.available()==0){
if( (bb & 0xFF) == lrbr){ serverLog.logError("TEMPLATE", "No such Template: %%"+patternName);
transferUntil(pis, keyStream, aClose); return;
}
//reached the end. output last string. keyStream=new ByteArrayOutputStream();
if(keyStream.toString().equals("/" + key)){ transferUntil(pis, keyStream, "::".getBytes());
pis2 = new PushbackInputStream(new ByteArrayInputStream(text.getBytes())); pis2 = new PushbackInputStream(new ByteArrayInputStream(keyStream.toString().getBytes()));
//this maybe the wrong, but its the last writeTemplate(pis2, out, pattern, dflt, prefix + key + "_");
writeTemplate(pis2, out, pattern, dflt, prefix + key + "_"); transferUntil(pis, keyStream, (new String("#(/"+key+")#")).getBytes());
found=true; if(pis.available()==0){
}else if(others >0 && keyStream.toString().startsWith("/")){ //close nested serverLog.logError("TEMPLATE", "No Close Key found for #("+key+")# (by Name)");
others--; }
text += "#("+keyStream.toString()+")#"; }else{
}else{ //nested while(!found){
others++; bb=pis.read();
text += "#("+keyStream.toString()+")#"; if( (bb & 0xFF) == hash){
} bb=pis.read();
keyStream = new ByteArrayOutputStream(); //reset stream if( (bb & 0xFF) == lrbr){
continue; transferUntil(pis, keyStream, aClose);
}else{ //is not #(
pis.unread(bb);//is processed in next loop //reached the end. output last string.
bb = (hash);//will be added to text this loop if(keyStream.toString().equals("/" + key)){
//text += "#"; pis2 = new PushbackInputStream(new ByteArrayInputStream(text.getBytes()));
} //this maybe the wrong, but its the last
}else if( (bb & 0xFF) == ':' && others==0){//ignore :: in nested Expressions writeTemplate(pis2, out, pattern, dflt, prefix + key + "_");
bb=pis.read(); found=true;
if( (bb & 0xFF) == ':'){ }else if(others >0 && keyStream.toString().startsWith("/")){ //close nested
if(currentPattern == whichPattern){ //found the pattern others--;
pis2 = new PushbackInputStream(new ByteArrayInputStream(text.getBytes())); text += "#("+keyStream.toString()+")#";
writeTemplate(pis2, out, pattern, dflt, prefix + key + "_"); }else{ //nested
others++;
transferUntil(pis, keyStream, (new String("#(/"+key+")#")).getBytes());//to #(/key)#. text += "#("+keyStream.toString()+")#";
}
found=true; keyStream = new ByteArrayOutputStream(); //reset stream
} continue;
currentPattern++; }else{ //is not #(
text=""; pis.unread(bb);//is processed in next loop
continue; bb = (hash);//will be added to text this loop
}else{ //text += "#";
text += ":"; }
} }else if( (bb & 0xFF) == ':' && others==0){//ignore :: in nested Expressions
} bb=pis.read();
if(!found){ if( (bb & 0xFF) == ':'){
text += (char)bb; if(currentPattern == whichPattern){ //found the pattern
if(pis.available()==0){ pis2 = new PushbackInputStream(new ByteArrayInputStream(text.getBytes()));
serverLog.logError("TEMPLATE", "No Close Key found for #("+key+")#"); writeTemplate(pis2, out, pattern, dflt, prefix + key + "_");
found=true;
} transferUntil(pis, keyStream, (new String("#(/"+key+")#")).getBytes());//to #(/key)#.
}
}//while found=true;
}
currentPattern++;
text="";
continue;
}else{
text += ":";
}
}
if(!found){
text += (char)bb;
if(pis.available()==0){
serverLog.logError("TEMPLATE", "No Close Key found for #("+key+")# (by Index)");
found=true;
}
}
}//while
}//if(byName) (else branch)
}else if( (bb & 0xFF) == lbr ){ //normal }else if( (bb & 0xFF) == lbr ){ //normal
if (transferUntil(pis, keyStream, pClose)) { if (transferUntil(pis, keyStream, pClose)) {
// pattern detected, write replacement // pattern detected, write replacement

Loading…
Cancel
Save