← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2570: Improved Jasper struts result

 

------------------------------------------------------------
revno: 2570
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-01-14 18:42:33 +0100
message:
  Improved Jasper struts result
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Grid.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJasperResult.java
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml


--
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-api/src/main/java/org/hisp/dhis/common/Grid.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Grid.java	2011-01-14 16:14:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Grid.java	2011-01-14 17:42:33 +0000
@@ -55,6 +55,16 @@
     Grid setSubtitle( String subtitle );
 
     /**
+     * Returns the grid table.
+     */
+    String getTable();
+    
+    /**
+     * Sets the grid table.
+     */
+    Grid setTable( String table );
+    
+    /**
      * Returns all header values.
      */
     List<GridHeader> getHeaders();

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJasperResult.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJasperResult.java	2011-01-13 18:38:38 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJasperResult.java	2011-01-14 17:42:33 +0000
@@ -42,6 +42,8 @@
 import org.apache.struts2.ServletActionContext;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.Velocity;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.system.util.StreamUtils;
 import org.hisp.dhis.util.ContextUtils;
@@ -56,8 +58,8 @@
     implements Result
 {
     private static final String KEY_GRID = "grid";
-    private static final String TEMPLATE = "jrxmlGrid.vm";
-    private static final String ENCODING = "UTF-8";
+    private static final String TEMPLATE = "grid.vm";
+    private static final String RESOURCE_LOADER_NAME = "class";
 
     // -------------------------------------------------------------------------
     // Dependencies
@@ -111,11 +113,17 @@
 
         StringWriter writer = new StringWriter();
         
+        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();
+        
         VelocityContext context = new VelocityContext();
         
         context.put( KEY_GRID, grid );
         
-        Velocity.mergeTemplate( TEMPLATE, ENCODING, context, writer );
+        velocity.getTemplate( TEMPLATE ).merge( context, writer );
         
         String report = writer.toString();
 

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml	2010-12-26 18:47:16 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml	2011-01-14 17:42:33 +0000
@@ -37,6 +37,8 @@
 				class="org.hisp.dhis.result.GridXlsResult" />
 			<result-type name="gridPdfResult"
 				class="org.hisp.dhis.result.GridPdfResult" />
+			<result-type name="gridJasperResult"
+				class="org.hisp.dhis.result.GridJasperResult" />
 		</result-types>
 
 		<interceptors>