- Revision
- 776
- Author
- mauro
- Date
- 2008-08-20 16:06:19 -0500 (Wed, 20 Aug 2008)
Log Message
Added asProperties function to covert a map to key/value pairs. Made classloader injectable in sitemesh decorator.
Modified Paths
Diff
Modified: trunk/waffle-resources/src/main/resources/ftl/waffle/form.ftl (775 => 776)
--- trunk/waffle-resources/src/main/resources/ftl/waffle/form.ftl 2008-08-20 02:48:05 UTC (rev 775) +++ trunk/waffle-resources/src/main/resources/ftl/waffle/form.ftl 2008-08-20 21:06:19 UTC (rev 776) @@ -70,6 +70,23 @@ </#function> <#-- + * Converts a map of elements to key=values properties, where the values are joined if a sequence. + * + * @param map the map + * @param propertySeparator (defaults to "=") + * @param valueSeparator (defaults to ",") + * @param newlineSeparator (defaults to "\n") + * @return The String with joined values +--> +<#function asProperties map propertySeparator="=" valueSeparator="," newlineSeparator="\n"> + <#assign result = ''/> + <#list map.keySet() as key><#assign values=map.get(key)> + <#assign result = result + "${key}" + propertySeparator + join(values,valueSeparator) + newlineSeparator /> + </#list> + <#return result> +</#function> + +<#-- * Shows values as CSV * * @param values the sequence of values
Modified: trunk/waffle-testing/src/main/java/org/codehaus/waffle/testing/view/ViewHarness.java (775 => 776)
--- trunk/waffle-testing/src/main/java/org/codehaus/waffle/testing/view/ViewHarness.java 2008-08-20 02:48:05 UTC (rev 775) +++ trunk/waffle-testing/src/main/java/org/codehaus/waffle/testing/view/ViewHarness.java 2008-08-20 21:06:19 UTC (rev 776) @@ -88,7 +88,7 @@ * Processes a view with custom configuration * * @param resource the template resource path - * @param configuration the view processor configuration + * @param configuration the view processor configuration * @param controller the controller instance * @param debug the debug boolean flag * @return The processed resource @@ -113,24 +113,26 @@ */ public static String decorateView(String resource, Object controller, String decoratorsResource, String decoratorName, Map<String, Object> decoratorDataModel) { - return decorateView(resource, new Properties(), controller, decoratorsResource, decoratorName, - decoratorDataModel); + return decorateView(resource, new Properties(), Thread.currentThread().getContextClassLoader(), controller, + decoratorsResource, decoratorName, decoratorDataModel); } /** * Decorates a view with Sitemesh and custom processor configuration * * @param resource the template resource path - * @param configuration the view processor configuration + * @param configuration the view processor configuration + * @param classLaoder the ClassLoader used to load the decorator * @param controller the controller instance * @param decoratorsResource the Sitemesh decorators resource * @param decoratorName the decorator name * @param decoratorDataModel the decorator data model that can be used to override the processor data model * @return The decorated resource */ - public static String decorateView(String resource, Properties configuration, Object controller, - String decoratorsResource, String decoratorName, Map<String, Object> decoratorDataModel) { - SitemeshDecorator decorator = new SitemeshDecorator(new ViewHarness(configuration).processorFor(resource)); + public static String decorateView(String resource, Properties configuration, ClassLoader classLoader, + Object controller, String decoratorsResource, String decoratorName, Map<String, Object> decoratorDataModel) { + SitemeshDecorator decorator = new SitemeshDecorator(new ViewHarness(configuration).processorFor(resource), + classLoader); return decorator.decorate(resource, controller, decoratorsResource, decoratorName, decoratorDataModel); }
Modified: trunk/waffle-testing/src/main/java/org/codehaus/waffle/testing/view/sitemesh/SitemeshDecorator.java (775 => 776)
--- trunk/waffle-testing/src/main/java/org/codehaus/waffle/testing/view/sitemesh/SitemeshDecorator.java 2008-08-20 02:48:05 UTC (rev 775) +++ trunk/waffle-testing/src/main/java/org/codehaus/waffle/testing/view/sitemesh/SitemeshDecorator.java 2008-08-20 21:06:19 UTC (rev 776) @@ -4,6 +4,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.io.InputStream; import java.util.Map; import org.apache.commons.io.IOUtils; @@ -21,11 +22,13 @@ * @author Mauro Talevi */ public class SitemeshDecorator { - + private final ViewProcessor processor; + private final ClassLoader classLoader; - public SitemeshDecorator(ViewProcessor processor) { + public SitemeshDecorator(ViewProcessor processor, ClassLoader classLoader) { this.processor = processor; + this.classLoader = classLoader; } /** @@ -55,7 +58,7 @@ dataModel.put("body", page.getBody()); return processor.process(decorator.getPage(), dataModel); } catch (Exception e) { - throw new RuntimeException("Failed to decorate resource", e); + throw new RuntimeException("Failed to decorate resource "+resource+" with decorators "+decoratorsResource, e); } } @@ -69,6 +72,10 @@ } private String loadContent(String resource) throws IOException { - return IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream(resource)); + InputStream stream = classLoader.getResourceAsStream(resource); + if ( stream == null ){ + throw new IOException("Resource "+resource+" not found in classloader "+classLoader); + } + return IOUtils.toString(stream); } }
To unsubscribe from this list please visit:
