1 5 package com.opensymphony.workflow.loader; 6 7 import org.apache.velocity.Template; 8 import org.apache.velocity.VelocityContext; 9 import org.apache.velocity.app.VelocityEngine; 10 11 import java.io.ByteArrayOutputStream ; 12 import java.io.OutputStreamWriter ; 13 14 15 21 public class WorkflowSerializer { 22 24 private VelocityEngine engine; 25 26 28 public byte[] generateWorkflowXML(WorkflowDescriptor wf) throws Exception { 29 initVelocity(); 30 31 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 32 OutputStreamWriter writer = new OutputStreamWriter (baos); 33 Template template = engine.getTemplate("workflowtemplate.vm"); 34 VelocityContext ctx = new VelocityContext(); 35 ctx.put("workflow", wf); 36 template.merge(ctx, writer); 37 writer.flush(); 38 baos.flush(); 39 40 return baos.toByteArray(); 41 } 42 43 protected void initVelocity() throws Exception { 44 if (engine == null) { 45 engine = new VelocityEngine(); 46 engine.setProperty("resource.loader", "class"); 47 engine.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); 48 engine.init(); 49 } 50 } 51 } 52 | Popular Tags |