=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java' --- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java 2011-03-31 11:10:04 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java 2011-03-31 13:38:43 +0000 @@ -231,11 +231,7 @@ { final StringWriter writer = new StringWriter(); - final VelocityEngine velocity = new VelocityEngine(); - - velocity.setProperty( Velocity.RESOURCE_LOADER, RESOURCE_LOADER_NAME ); - velocity.setProperty( RESOURCE_LOADER_NAME + ".resource.loader.class", ClasspathResourceLoader.class.getName() ); - velocity.init(); + final VelocityEngine velocity = getVelocityEngine(); final VelocityContext context = new VelocityContext(); @@ -258,16 +254,27 @@ public static void toJrxml( Grid grid, Writer writer ) throws Exception { + final VelocityEngine velocity = getVelocityEngine(); + + final VelocityContext context = new VelocityContext(); + + context.put( KEY_GRID, grid ); + + velocity.getTemplate( TEMPLATE ).merge( context, writer ); + } + + /** + * Creates a VelocityEngine instance. + */ + private static VelocityEngine getVelocityEngine() + throws Exception + { final VelocityEngine velocity = new VelocityEngine(); velocity.setProperty( Velocity.RESOURCE_LOADER, RESOURCE_LOADER_NAME ); velocity.setProperty( RESOURCE_LOADER_NAME + ".resource.loader.class", ClasspathResourceLoader.class.getName() ); velocity.init(); - final VelocityContext context = new VelocityContext(); - - context.put( KEY_GRID, grid ); - - velocity.getTemplate( TEMPLATE ).merge( context, writer ); + return velocity; } }