01: /*
02: * XCustomJavaTemplateEngine.java
03: *
04: * Created on 21 May 2007, 18:09
05: *
06: * To change this template, choose Tools | Template Manager
07: * and open the template in the editor.
08: */
09:
10: package com.xoetrope.carousel.catalog;
11:
12: import com.xoetrope.template.XTemplateEngine;
13: import net.xoetrope.xui.XProject;
14:
15: /**
16: * @author kingsley.elmes
17: */
18: public class XCustomJavaTemplateEngine extends XTemplateEngine {
19: /**
20: * Creates a new instance of XCustomTemplateEngine
21: * @param proj <CODE>XProject</CODE> instance passed to this class
22: * @param source <CODE>String</CODE>
23: * @param target <CODE>String</CODE>
24: */
25: public XCustomJavaTemplateEngine(XProject proj, String source,
26: String target) {
27: super (proj, source, target);
28: }
29:
30: /**
31: * Check whether an code block is to be included in the java class
32: * @param elementName <CODE>String</CODE> specifying the element name or tag
33: * @return <CODE>boolean</CODE> specifying whether the code bloack is to be included
34: */
35: public boolean includes(String elementName) {
36: if (includes.containsKey(elementName)) {
37: Object o = includes.get(elementName);
38: return ((Boolean) o).booleanValue();
39: }
40: return false;
41: }
42:
43: /**
44: * Returns content to be included in the template based on a key
45: * @param elementName <CODE>String</CODE> specifying the key
46: */
47: public String getContent(String elementName) {
48: if (contents.containsKey(elementName)) {
49: return contents.get(elementName).toString();
50: }
51: return "";
52: }
53:
54: /**
55: * Sets the package name of the java class being processed
56: * @param s <CODE>String</CODE> specifying the package name
57: */
58: public void setPackageName(String s) {
59: contents.put("PACKAGE", s);
60: }
61:
62: /**
63: * Sets an import name in the java class being processed
64: * @param s <CODE>String</CODE> specifying the import name
65: */
66: public void setImportName1(String s) {
67: contents.put("IMPORT_NAME_1", s);
68: }
69:
70: /**
71: * Set whether a code block is to be included or not
72: * @param s <CODE>String</CODE> specifying the tag name
73: * @param b <CODE>boolean</CODE> specifying whether the code bloask is to be included or not
74: */
75: public void addInclude(String s, boolean b) {
76: includes.put(s, b);
77: }
78:
79: /**
80: * Sets how many sample products are to be used within the catalogue
81: * @param a <CODE>int</CODE> specifying the amount of products to be included
82: */
83: public void useSampleProducts(int a) {
84: if (a == 4) {
85: includes.put("PROD4", true);
86: } else if (a == 8) {
87: includes.put("PROD4", true);
88: includes.put("PROD8", true);
89: } else if (a == 12) {
90: includes.put("PROD4", true);
91: includes.put("PROD8", true);
92: includes.put("PROD12", true);
93: }
94: }
95: }
|