1 5 package org.exoplatform.portlet.exomvc.config; 6 7 import java.io.InputStream ; 8 import java.util.Properties ; 9 import javax.portlet.PortletContext; 10 import org.apache.velocity.Template; 11 import org.apache.velocity.app.Velocity; 12 import org.apache.velocity.app.VelocityEngine; 13 import org.exoplatform.commons.utils.IOUtil; 14 15 20 public class VelocityResourceManager { 21 private String reposistoryPath_ ; 22 private PortletContext context_ ; 23 private VelocityEngine vengine_; 24 25 public VelocityResourceManager(PortletContext context, String repo ) throws Exception { 26 reposistoryPath_ = repo + "/velocity/" ; 27 context_ = context ; 28 String path = context.getRealPath(repo + "/velocity") ; 29 Properties p = new Properties (); 30 p.setProperty( Velocity.FILE_RESOURCE_LOADER_PATH, path); 31 vengine_ = new VelocityEngine(); 32 vengine_.init( p ); 33 } 34 35 public String getVelocityReposistory() { return reposistoryPath_ ; } 36 37 public VelocityEngine getVelocityEngine() { return vengine_ ; } 38 39 public Template getTemplate(String template) throws Exception { 40 return vengine_.getTemplate(template) ; 41 } 42 43 public String getResourceAsText(String resource) throws Exception { 44 String path = reposistoryPath_ + resource ; 45 InputStream is = context_.getResourceAsStream(path) ; 46 if(is == null) return "reosurce : " + resource + " is notfound" ; 47 return IOUtil.getStreamContentAsString(is) ; 48 } 49 } | Popular Tags |