1 7 package org.jboss.boot.servlets; 8 9 import javax.xml.transform.TransformerException ; 10 11 import org.apache.xalan.extensions.ExpressionContext; 12 import org.apache.xml.utils.QName; 13 import org.apache.xpath.objects.XObject; 14 15 import gnu.regexp.RE; 16 import gnu.regexp.REException; 17 import gnu.regexp.REMatch; 18 19 26 public class Util 27 { 28 static RE variableRE; 29 30 public static void setVariableRE(RE variableRE) 31 { 32 Util.variableRE = variableRE; 33 } 34 35 39 public static String replaceVariables(ExpressionContext ctx, String text) 40 { 41 String value = text; 42 try 43 { 44 REMatch[] matches = variableRE.getAllMatches(text); 45 if( matches.length > 0 ) 46 { 47 StringBuffer tmp = new StringBuffer (); 48 for(int m = 0; m < matches.length; m ++) 49 { 50 String prefix = matches[m].toString(1); 51 String name = matches[m].toString(2); 52 String suffix = matches[m].toString(3); 53 QName varName = new QName(name); 54 XObject var = ctx.getVariableOrParam(varName); 55 tmp.append(prefix); 56 if( var != null ) 57 tmp.append(var.toString()); 58 tmp.append(suffix); 59 } 60 value = tmp.toString(); 61 } 62 } 63 catch(TransformerException e) 64 { 65 e.printStackTrace(); 66 } 67 return value; 68 } 69 70 } 71 | Popular Tags |