← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3235: Centralization in GridUtils

 

------------------------------------------------------------
revno: 3235
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-03-31 15:38:43 +0200
message:
  Centralization in GridUtils
modified:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== 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;
     }
 }