Index: magnolia-core/src/main/java/info/magnolia/content2bean/impl/Content2BeanTransformerImpl.java =================================================================== --- magnolia-core/src/main/java/info/magnolia/content2bean/impl/Content2BeanTransformerImpl.java (revision 50091) +++ magnolia-core/src/main/java/info/magnolia/content2bean/impl/Content2BeanTransformerImpl.java (working copy) @@ -35,6 +35,7 @@ import info.magnolia.cms.core.Content; import info.magnolia.cms.util.ContentUtil; +import info.magnolia.cms.util.SimpleUrlPattern; import info.magnolia.cms.util.SystemContentWrapper; import info.magnolia.content2bean.Content2BeanException; import info.magnolia.content2bean.Content2BeanTransformer; @@ -45,6 +46,7 @@ import info.magnolia.objectfactory.Classes; import info.magnolia.objectfactory.ComponentProvider; import org.apache.commons.beanutils.BeanUtilsBean; +import org.apache.commons.beanutils.Converter; import org.apache.commons.beanutils.MethodUtils; import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.beanutils.PropertyUtilsBean; @@ -94,6 +96,11 @@ // de-register the converter for Class, we do our own conversion in convertPropertyValue() convertUtilsBean.deregister(Class.class); + convertUtilsBean.register(new Converter() { + public Object convert(Class type, Object value) { + return new SimpleUrlPattern((String) value); + } + }, SimpleUrlPattern.class); this.beanUtilsBean = new BeanUtilsBean(convertUtilsBean, new PropertyUtilsBean()); } @@ -341,7 +348,7 @@ try { return Classes.getClassFactory().forName(value.toString()); } catch (ClassNotFoundException e) { - log.error(e.getMessage()); + log.error("Can convert {} to class: {}", value, e.toString()); throw new Content2BeanException(e); } } Index: magnolia-core/src/test/java/info/magnolia/content2bean/Content2BeanTest.java =================================================================== --- magnolia-core/src/test/java/info/magnolia/content2bean/Content2BeanTest.java (revision 50091) +++ magnolia-core/src/test/java/info/magnolia/content2bean/Content2BeanTest.java (working copy) @@ -35,6 +35,7 @@ import static org.junit.Assert.*; import info.magnolia.cms.core.Content; +import info.magnolia.cms.util.SimpleUrlPattern; import info.magnolia.content2bean.impl.Content2BeanProcessorImpl; import info.magnolia.test.MgnlTestCase; import info.magnolia.test.mock.MockComponentProvider; @@ -330,6 +331,22 @@ } @Test + public void testSimpleUrlPatternIsConvertedAutomagically() throws Exception { + Content node = MockUtil.createContent("myNode", new String[][]{ + {"class", "info.magnolia.content2bean.Content2BeanTest$BeanWithSimpleUrlPattern"}, + {"myPattern", "H?llo*"} + }, new Content[0]); + final BeanWithSimpleUrlPattern res = (BeanWithSimpleUrlPattern) Content2BeanUtil.toBean(node, true); + assertNotNull(res); + assertNotNull(res.getMyPattern()); + assertTrue(res.getMyPattern() instanceof SimpleUrlPattern); + assertTrue(res.matches("Hello world")); + assertTrue(res.matches("Hallo weld")); + assertFalse(res.matches("Haaaallo weeeeeld")); + assertFalse(res.matches("Bonjour monde")); + } + + @Test public void testCanSpecifySpecificMapImplementation() throws Exception { final Content node = MockUtil.createNode("/foo/bar", "/foo/bar.class=" + BeanWithMap.class.getName(), @@ -407,6 +424,22 @@ } } + public static final class BeanWithSimpleUrlPattern { + private SimpleUrlPattern myPattern; + + public SimpleUrlPattern getMyPattern() { + return myPattern; + } + + public void setMyPattern(SimpleUrlPattern myPattern) { + this.myPattern = myPattern; + } + + public boolean matches(String in) { + return myPattern.match(in); + } + } + public static class MyMap extends HashMap { }