dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #14834
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5150: Centralized VelocityManager init
------------------------------------------------------------
revno: 5150
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2011-11-13 16:59:09 +0100
message:
Centralized VelocityManager init
modified:
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/velocity/VelocityManager.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-09-14 12:46:13 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java 2011-11-13 15:59:09 +0000
@@ -62,15 +62,13 @@
import org.apache.commons.lang.StringUtils;
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.common.GridHeader;
import org.hisp.dhis.system.util.CodecUtils;
import org.hisp.dhis.system.util.Encoder;
import org.hisp.dhis.system.util.MathUtils;
import org.hisp.dhis.system.util.StreamUtils;
+import org.hisp.dhis.system.velocity.VelocityManager;
import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfPTable;
@@ -99,7 +97,6 @@
private static final String KEY_ENCODER = "encoder";
private static final String KEY_PARAMS = "params";
private static final String TEMPLATE = "grid.vm";
- private static final String RESOURCE_LOADER_NAME = "class";
/**
* Writes a PDF representation of the given Grid to the given OutputStream.
@@ -318,18 +315,12 @@
private static void render( Grid grid, Map<?, ?> params, Writer writer )
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 );
context.put( KEY_ENCODER, ENCODER );
context.put( KEY_PARAMS, params );
- velocity.getTemplate( TEMPLATE ).merge( context, writer );
+ new VelocityManager().getEngine().getTemplate( TEMPLATE ).merge( context, writer );
}
}
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/velocity/VelocityManager.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/velocity/VelocityManager.java 2011-10-07 10:08:02 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/velocity/VelocityManager.java 2011-11-13 15:59:09 +0000
@@ -50,6 +50,11 @@
velocity.init();
}
+ public VelocityEngine getEngine()
+ {
+ return velocity;
+ }
+
public String render( Object object, String template )
{
try