KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > invicta > template > TemplateHelper


1 package net.sf.invicta.template;
2
3 import net.sf.invicta.api.InvictaComponent;
4 import net.sf.invicta.api.InvictaProject;
5
6 /**
7  *
8  */

9 public class TemplateHelper {
10
11     /**
12      *
13      * @param project
14      * @param component
15      * @return Object[][]
16      */

17     protected static Object JavaDoc[][] getParams(InvictaProject project, InvictaComponent component) {
18         String JavaDoc componentName = "";
19         String JavaDoc componentDir = "";
20         String JavaDoc componentType = "";
21         if (component != null) {
22             componentName = component.getName();
23             componentDir = component.getDir();
24             componentType = component.getTypeName();
25         }
26         
27         return new Object JavaDoc[][]
28                     {
29                      { "componentName", componentName },
30                      { "componentDir", componentDir },
31                      { "componentType", componentType },
32                      { "projectName", project.getName() },
33                      { "projectDir", project.getDir() }
34                     };
35     }
36     
37     /**
38      *
39      * @param template
40      * @param project
41      * @param component
42      * @return String
43      * @throws InvictaTemplateException
44      */

45     public static String JavaDoc format(String JavaDoc template, InvictaProject project, InvictaComponent component) throws InvictaTemplateException {
46         StringBuffer JavaDoc dump = new StringBuffer JavaDoc();
47         format(template, project, component, dump);
48         return dump.toString();
49     }
50     
51     /**
52      *
53      * @param template
54      * @param project
55      * @param component
56      * @param moreParams
57      * @return String
58      * @throws InvictaTemplateException
59      */

60     public static String JavaDoc format(String JavaDoc template, InvictaProject project, InvictaComponent component, Object JavaDoc[][] moreParams) throws InvictaTemplateException {
61         StringBuffer JavaDoc dump = new StringBuffer JavaDoc();
62         format(template, project, component, dump, moreParams);
63         return dump.toString();
64     }
65     
66     /**
67      *
68      * @param template
69      * @param params
70      * @param component
71      * @param dump
72      * @throws InvictaTemplateException
73      */

74     public static void format(String JavaDoc template, Object JavaDoc[][] params, InvictaComponent component, StringBuffer JavaDoc dump) throws InvictaTemplateException {
75                             
76         TemplateProcessor templateProcessor = new TemplateProcessor(template, component);
77         templateProcessor.format(params, dump);
78     }
79     
80     /**
81      *
82      * @param template
83      * @param project
84      * @param component
85      * @param dump
86      * @throws InvictaTemplateException
87      */

88     public static void format(String JavaDoc template, InvictaProject project, InvictaComponent component, StringBuffer JavaDoc dump) throws InvictaTemplateException {
89         
90         format(template, getParams(project,component), component, dump);
91     }
92     
93     /**
94      *
95      * @param template
96      * @param project
97      * @param component
98      * @param dump
99      * @param moreParams
100      * @throws InvictaTemplateException
101      */

102     public static void format(String JavaDoc template, InvictaProject project, InvictaComponent component, StringBuffer JavaDoc dump, Object JavaDoc[][] moreParams) throws InvictaTemplateException {
103         Object JavaDoc[][] params = getParams(project, component);
104         Object JavaDoc[][] allParams = new Object JavaDoc[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     /**
116      *
117      * @param template
118      * @param project
119      * @param dump
120      * @throws InvictaTemplateException
121      */

122     public static void format(String JavaDoc template, InvictaProject project, StringBuffer JavaDoc dump) throws InvictaTemplateException {
123         format(template, project, null, dump);
124     }
125 }
126
Popular Tags