001: package com.xoetrope.carousel.catalog;
002:
003: import com.xoetrope.template.XTemplateEngine;
004: import net.xoetrope.xui.XProject;
005:
006: /**
007: * A test application for the template engine
008: *
009: * <p> Copyright (c) Xoetrope Ltd., 2001-2007, This software is licensed under
010: * the GNU Public License (GPL), please see license.txt for more details. If
011: * you make commercial use of this software you must purchase a commercial
012: * license from Xoetrope.</p>
013: * <p> $Revision: 1.2 $</p>
014: */
015: public class XCustomXmlTemplateEngine extends XTemplateEngine {
016: private String welcomeText, subTitle;
017: private int samples;
018:
019: /**
020: *
021: * Creates a new instance of XCustomXmlTemplateEngine
022: */
023: public XCustomXmlTemplateEngine(XProject proj, String source,
024: String target) {
025: super (proj, source, target);
026: samples = -1;
027: }
028:
029: /**
030: * Include a given element
031: * @param s the name of the element.
032: * @param b <CODE>boolean</CODE> specifying whether the element is to be used or not.
033: */
034:
035: public void addInclude(String s, boolean b) {
036: includes.put(s, b);
037: }
038:
039: /**
040: * Returns a boolean when given a key specifying whether the element is to be included or not.
041: * @param elementName <CODE>String</CODE> specifying the element name.
042: * @return true if the element is included, false if it is to be excluded.
043: */
044: public boolean includes(String elementName) {
045: if (includes.containsKey(elementName)) {
046: Object o = includes.get(elementName);
047: return ((Boolean) o).booleanValue();
048: }
049: return false;
050: }
051:
052: /**
053: * Sets the welcome text that will be displayed on the welcome page of the catalogue
054: * @param <CODE>String</CODE> containing the welcome text
055: */
056: public void setWelcomeText(String text) {
057: welcomeText = text;
058: }
059:
060: /**
061: * Sets the sub-title text that will be displayed on the welcome page of the catalogue
062: * @param <CODE>String</CODE> containing the sub-title text
063: */
064: public void setSubTitle(String text) {
065: subTitle = text;
066: }
067:
068: /**
069: * Add content to the xml template
070: * @param key <CODE>String</CODE> containing the key for the content
071: * @param content <CODE>String</CODE> containing the content
072: */
073: public void addContent(String key, String content) {
074: contents.put(key, content);
075: }
076:
077: /**
078: * Returns the content to be used in the xml template
079: * @param elementName <CODE>String</CODE> containing the key for the content
080: * @return <CODE>String</CODE> containing the content
081: */
082: public String getContent(String elementName) {
083: if (contents.containsKey(elementName)) {
084: Object o = contents.get(elementName);
085: return o.toString();
086: }
087:
088: return null;
089: }
090:
091: /**
092: * Sets how many sample products are to be used within the catalogue
093: * @param a <CODE>int</CODE> specifying the amount of products to be included
094: */
095: public void useSampleProducts(int s) {
096: samples = s;
097:
098: if (includes("SimpleView")) {
099: if (samples == 2) {
100: addInclude("Products1", true);
101: } else if (samples == 4) {
102: addInclude("Products1", true);
103: addInclude("Products2", true);
104: } else if (samples == 8) {
105: addInclude("Products1", true);
106: addInclude("Products2", true);
107: addInclude("Products3", true);
108: } else if (samples == 12) {
109: addInclude("Products1", true);
110: addInclude("Products2", true);
111: addInclude("Products3", true);
112: addInclude("Products4", true);
113: }
114: } else if (includes("TreeView")) {
115: if (samples == 2) {
116: addInclude("TreeProducts1", true);
117: } else if (samples == 4) {
118: addInclude("TreeProducts1", true);
119: addInclude("TreeProducts2", true);
120: } else if (samples == 8) {
121: addInclude("TreeProducts1", true);
122: addInclude("TreeProducts2", true);
123: addInclude("TreeProducts3", true);
124: } else if (samples == 12) {
125: addInclude("TreeProducts1", true);
126: addInclude("TreeProducts2", true);
127: addInclude("TreeProducts3", true);
128: addInclude("TreeProducts4", true);
129: }
130: }
131: }
132: }
|