From: <sa...@us...> - 2004-03-08 13:38:58
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10511/org/jrobin/core Modified Files: RpnCalculator.java XmlTemplate.java XmlWriter.java Log Message: XML templates improved Index: RpnCalculator.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RpnCalculator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RpnCalculator.java 10 Nov 2003 08:52:27 -0000 1.2 --- RpnCalculator.java 8 Mar 2004 13:14:39 -0000 1.3 *************** *** 397,400 **** --- 397,401 ---- } + /* public static void main(String[] args) throws RrdException { RpnCalculator c = new RpnCalculator("2,3,/,value,+"); *************** *** 402,404 **** --- 403,406 ---- System.out.println(c.calculate()); } + */ } Index: XmlTemplate.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/XmlTemplate.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** XmlTemplate.java 26 Feb 2004 13:15:54 -0000 1.4 --- XmlTemplate.java 8 Mar 2004 13:14:39 -0000 1.5 *************** *** 35,38 **** --- 35,40 ---- import java.util.Date; import java.util.GregorianCalendar; + import java.util.regex.Pattern; + import java.util.regex.Matcher; import java.awt.*; *************** *** 46,49 **** --- 48,54 ---- */ public abstract class XmlTemplate { + private static final String PATTERN_STRING = "\\$\\{(\\w+)\\}"; + private static final Pattern PATTERN = Pattern.compile(PATTERN_STRING); + protected Element root; private HashMap valueMap = new HashMap(); *************** *** 183,201 **** } ! private String resolveMappings(String value) { ! if(value != null && value.startsWith("${") && value.endsWith("}")) { ! // template variable found, remove leading "${" and trailing "}" ! String var = value.substring(2, value.length() - 1); if(valueMap.containsKey(var)) { // mapping found ! value = valueMap.get(var).toString(); } else { // no mapping found - this is illegal throw new IllegalArgumentException( ! "No mapping found for template variable " + value); } } ! return value; } --- 188,209 ---- } ! private String resolveMappings(String templateValue) { ! Matcher matcher = PATTERN.matcher(templateValue); ! StringBuffer result = new StringBuffer(); ! while(matcher.find()) { ! String var = matcher.group(1); if(valueMap.containsKey(var)) { // mapping found ! matcher.appendReplacement(result, valueMap.get(var).toString()); } else { // no mapping found - this is illegal + // throw runtime exception throw new IllegalArgumentException( ! "No mapping found for template variable ${" + var + "}"); } } ! matcher.appendTail(result); ! return result.toString(); } Index: XmlWriter.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/XmlWriter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** XmlWriter.java 1 Mar 2004 08:50:24 -0000 1.5 --- XmlWriter.java 8 Mar 2004 13:14:39 -0000 1.6 *************** *** 195,201 **** return s.replaceAll("<", "<").replaceAll(">", ">"); } - - public static void main(String[] args) { - System.out.println(escape("<->")); - } } --- 195,197 ---- |