1 package net.sf.invicta.template; 2 3 import net.sf.invicta.api.InvictaComponent; 4 import net.sf.invicta.api.InvictaProject; 5 6 9 public class TemplateHelper { 10 11 17 protected static Object [][] getParams(InvictaProject project, InvictaComponent component) { 18 String componentName = ""; 19 String componentDir = ""; 20 String componentType = ""; 21 if (component != null) { 22 componentName = component.getName(); 23 componentDir = component.getDir(); 24 componentType = component.getTypeName(); 25 } 26 27 return new Object [][] 28 { 29 { "componentName", componentName }, 30 { "componentDir", componentDir }, 31 { "componentType", componentType }, 32 { "projectName", project.getName() }, 33 { "projectDir", project.getDir() } 34 }; 35 } 36 37 45 public static String format(String template, InvictaProject project, InvictaComponent component) throws InvictaTemplateException { 46 StringBuffer dump = new StringBuffer (); 47 format(template, project, component, dump); 48 return dump.toString(); 49 } 50 51 60 public static String format(String template, InvictaProject project, InvictaComponent component, Object [][] moreParams) throws InvictaTemplateException { 61 StringBuffer dump = new StringBuffer (); 62 format(template, project, component, dump, moreParams); 63 return dump.toString(); 64 } 65 66 74 public static void format(String template, Object [][] params, InvictaComponent component, StringBuffer dump) throws InvictaTemplateException { 75 76 TemplateProcessor templateProcessor = new TemplateProcessor(template, component); 77 templateProcessor.format(params, dump); 78 } 79 80 88 public static void format(String template, InvictaProject project, InvictaComponent component, StringBuffer dump) throws InvictaTemplateException { 89 90 format(template, getParams(project,component), component, dump); 91 } 92 93 102 public static void format(String template, InvictaProject project, InvictaComponent component, StringBuffer dump, Object [][] moreParams) throws InvictaTemplateException { 103 Object [][] params = getParams(project, component); 104 Object [][] allParams = new Object [params.length + moreParams.length][]; 105 for (int i = 0; i < params.length; i++) { 106 allParams[i] = params[i]; 107 } 108 for (int i = 0; i < moreParams.length; i++) { 109 allParams[i+params.length] = moreParams[i]; 110 } 111 112 format(template, allParams, component,dump); 113 } 114 115 122 public static void format(String template, InvictaProject project, StringBuffer dump) throws InvictaTemplateException { 123 format(template, project, null, dump); 124 } 125 } 126 | Popular Tags |