Thanks again David. I've made those changes and attached them to the issue. All tests pass and it seems to work ok.
I've just remembered that I forgot to swap to use StringBuilder - I'll do that before committing. Let me know if there's any other comments! Cheers Jon On Mon, Aug 31, 2009 at 11:56 PM, David Blevins <[email protected]>wrote: > > On Aug 31, 2009, at 2:44 PM, Jonathan Gallimore wrote: > > This seems to work well, although I did break the JndiNameTest. I've fixed >> this by using the StringTemplate that is used normally, and grabbing the >> format string from there. This seems a bit nasty but all the openejb-core >> tests pass now (and I'll run the rest tonight). >> > > > That does seem a bit nasty. What if we created a complete replacement > StringTemplate class, something like this (refactored version of the code > from your patch): > > public class StringTemplate { > > private static final Pattern PATTERN = > Pattern.compile("(\\{)((\\.|\\w)+)(})"); > > private Matcher matcher; > > public StringTemplate(String template) { > matcher = PATTERN.matcher(template); > } > > public String format(Map<String, String> map) { > StringBuffer buf = new StringBuffer(); > > while (matcher.find()) { > String key = matcher.group(2); > String value = map.get(key); > > if (key.toLowerCase().endsWith(".lc")) { > value = map.get(key.substring(0, key.length() - > 3)).toLowerCase(); > } else if (key.toLowerCase().endsWith(".uc")) { > value = map.get(key.substring(0, key.length() - > 3)).toUpperCase(); > } else if (key.toLowerCase().endsWith(".cc")) { > value = Strings.camelCase(map.get(key.substring(0, > key.length() - 3))); > } > > matcher.appendReplacement(buf, value); > } > > matcher.appendTail(buf); > return buf.toString(); > } > > } > > > We could throw that in the util package then just do a find/replace on > org.codehaus.swizzle.stream.StringTemplate -> > org.apache.openejb.util.StringTemplate > > Thoughts? > > On a side note we should use StringBuilder instead of StringBuffer. > > -David > >
