001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.jsp;
021:
022: /////////////////////////
023: //$Archive: /SOFIA/SourceCode/com/salmonllc/jsp/JspCookieCrumble.java $
024: //$Author: Srufle $
025: //$Revision: 14 $
026: //$Modtime: 7/22/04 6:13p $
027: /////////////////////////
028: import com.salmonllc.html.*;
029:
030: import com.salmonllc.util.MessageLog;
031: import com.salmonllc.util.Util;
032:
033: import java.io.PrintWriter;
034: import java.util.ArrayList;
035: import java.util.Hashtable;
036:
037: /**
038: * This type create a group of text components that shows the history of where you have been in the site.
039: *
040: * @see com.salmonllc.jsp.tags.CookieCrumbleTag
041: * @see com.salmonllc.jsp.tags.CrumbleTag
042: */
043: public class JspCookieCrumble extends HtmlComponent {
044: private ArrayList _arrCrumble = new ArrayList();
045: private Hashtable _hashCrumble = new Hashtable();
046: private HtmlContainer _cont;
047: private String _fCrumbleFont = "CrumbleFont";
048: private String _fCrumbleLinkFont = "CrumbleLinkFont";
049: private String _fSeparator;
050: private String _fTheme;
051: private boolean _fFixSpecialHtmlCharacters;
052:
053: /**
054: * JspCookieCrumble constructor comment.
055: *
056: * @param name java.lang.String
057: * @param p com.salmonllc.html.HtmlPage
058: */
059: public JspCookieCrumble(String name, HtmlPage p) {
060: super ("CookieCrumbleComp" + name, p);
061:
062: try {
063: _cont = new HtmlContainer("crumble_cont", p);
064: _fSeparator = " : ";
065: } catch (Exception e) {
066: MessageLog.writeErrorMessage("CookieCrumbleComp", e, this );
067: }
068: }
069:
070: /**
071: * This method gets a crumble object from the cookie crumble.
072: *
073: * @param key - name of crumble you are looking for
074: *
075: * @return JspCrumbleObject
076: */
077: public JspCrumbleObject getCrumble(String key) {
078: if (key == null) {
079: return null;
080: } else {
081: return (JspCrumbleObject) _hashCrumble.get(key);
082: }
083: }
084:
085: /**
086: * Sets the crumbles text portion font type.
087: *
088: * @param newCrumbleFont - font to use for the crumbles
089: */
090: public void setCrumbleFont(java.lang.String newCrumbleFont) {
091: _fCrumbleFont = newCrumbleFont;
092: }
093:
094: /**
095: * Gets the crumbles text portion font type.
096: *
097: * @return java.lang.String
098: */
099: public java.lang.String getCrumbleFont() {
100: return _fCrumbleFont;
101: }
102:
103: /**
104: * Sets the crumbles link portion font type.
105: *
106: * @param newCrumbleLinkFont java.lang.String
107: */
108: public void setCrumbleLinkFont(java.lang.String newCrumbleLinkFont) {
109: _fCrumbleLinkFont = newCrumbleLinkFont;
110: }
111:
112: /**
113: * Gets the crumbles link portion font type.
114: *
115: * @return java.lang.String
116: */
117: public java.lang.String getCrumbleLinkFont() {
118: return _fCrumbleLinkFont;
119: }
120:
121: /**
122: * Sets the cookie crumble to fix html characters in each crumble object
123: *
124: * @param b - flag value
125: */
126: public void setFixSpecialHtmlCharacters(boolean b) {
127: _fFixSpecialHtmlCharacters = b;
128: }
129:
130: /**
131: * Gets whether the cookie crumble should fix html characters in each crumble object
132: *
133: * @return boolean
134: */
135: public boolean isFixSpecialHtmlCharacters() {
136: return _fFixSpecialHtmlCharacters;
137: }
138:
139: /**
140: * Sets the seperator character to use between crumbles
141: *
142: * @param string
143: */
144: public void setSeparator(String string) {
145: _fSeparator = string;
146: }
147:
148: /**
149: * Gets the seperator character to use between crumbles
150: *
151: * @return
152: */
153: public String getSeparator() {
154: return _fSeparator;
155: }
156:
157: /**
158: * Sets the crumble theme.
159: *
160: * @param newTheme java.lang.String
161: */
162: public void setTheme(java.lang.String newTheme) {
163: _fTheme = newTheme;
164: }
165:
166: /**
167: * Gets the theme of the Crumble component.
168: *
169: * @return java.lang.String
170: */
171: public java.lang.String getTheme() {
172: return _fTheme;
173: }
174:
175: /**
176: * This method adds a crumble object to the cookie crumble.
177: *
178: * @param key - name used for looking up the crumble
179: * @param textDesc - text of teh crumble
180: * @param href - (Optional) href or the crumble
181: */
182: public void addCrumble(String key, String textDesc, String href) {
183: JspCrumbleObject cro = new JspCrumbleObject(key, textDesc, href);
184: addCrumble(cro);
185: }
186:
187: /**
188: * This method adds a crumble object to the cookie crumble.
189: *
190: * @param cro
191: */
192: public void addCrumble(JspCrumbleObject cro) {
193: _arrCrumble.add(cro);
194: _hashCrumble.put(cro.getName(), cro);
195: }
196:
197: /**
198: * This method will generate the html for each component in the page
199: *
200: * @param p - PrintWriter
201: * @param rowNo - rowNo
202: *
203: * @throws Exception
204: */
205: public void generateHTML(PrintWriter p, int rowNo) throws Exception {
206: if (!_visible) {
207: return;
208: }
209:
210: // for each item in list
211: JspCrumbleObject cro = null;
212: HtmlText htText = null;
213: HtmlText separatorText = null;
214: HtmlLink hlLink = null;
215:
216: _cont.removeAll();
217:
218: int arrSize = _arrCrumble.size();
219:
220: if (arrSize <= 0) {
221: return;
222: }
223:
224: // MessageLog.writeDebugMessage(" 1 generateHTML arrSize=" + arrSize, this);
225: String croText = null;
226: String croHref = null;
227:
228: for (int i = 0; i < arrSize; i++) {
229: // MessageLog.writeDebugMessage(" 1 generateHTML i=" + i, this);
230: // create a link with text in it
231: cro = (JspCrumbleObject) _arrCrumble.get(i);
232: htText = null;
233: croHref = cro.getHref();
234: croText = cro.getText();
235:
236: if (Util.isFilled(croHref)) {
237: htText = new HtmlText(croText, getCrumbleLinkFont(),
238: getPage());
239: htText
240: .setFixSpecialHtmlCharacters(isFixSpecialHtmlCharacters());
241: hlLink = new HtmlLink("hlLink" + i, croHref, getPage());
242: hlLink.add(htText);
243: } else {
244: htText = new HtmlText(croText, getCrumbleFont(),
245: getPage());
246: htText
247: .setFixSpecialHtmlCharacters(isFixSpecialHtmlCharacters());
248: }
249:
250: // add link
251: // add :
252: String separator = getSeparator();
253:
254: if (!Util.isFilled(separator)) {
255: separator = " : ";
256: }
257:
258: separatorText = new HtmlText(separator,
259: getCrumbleLinkFont(), getPage());
260: separatorText
261: .setFixSpecialHtmlCharacters(isFixSpecialHtmlCharacters());
262:
263: if (Util.isFilled(croHref)) {
264: _cont.add(hlLink);
265: } else {
266: _cont.add(htText);
267: }
268:
269: if (i < (arrSize - 1)) {
270: _cont.add(separatorText);
271: }
272: }
273:
274: _cont.generateHTML(p, rowNo);
275: }
276:
277: /**
278: * This method removes all crumble objects from the cookie crumble.
279: *
280: * @return boolean
281: */
282: public boolean removeAllCrumble() {
283: boolean ret = false;
284: _hashCrumble.clear();
285: _arrCrumble.clear();
286:
287: if ((_hashCrumble.size() == 0) && (_arrCrumble.size() == 0)) {
288: ret = true;
289: }
290:
291: return ret;
292: }
293:
294: /**
295: * This method removes a single crumble object from the cookie crumble.
296: *
297: * @param key - name of crumble you are looking for
298: *
299: * @return boolean
300: */
301: public boolean removeCrumble(String key) {
302: boolean ret = false;
303:
304: if (key == null) {
305: ret = false;
306: } else {
307: JspCrumbleObject cro = (JspCrumbleObject) _hashCrumble
308: .get(key);
309: ret = _arrCrumble.remove(cro);
310: _hashCrumble.remove(key);
311: }
312:
313: return ret;
314: }
315:
316: /**
317: * This method removes a crumble object from the cookie crumble. And all ones that follow.
318: *
319: * @param key - name of crumble you are looking for
320: */
321: public void trimCrumble(String key) {
322: if (key == null) {
323: return;
324: } else {
325: JspCrumbleObject cro = (JspCrumbleObject) _hashCrumble
326: .get(key);
327:
328: if (cro == null) {
329: return;
330: }
331:
332: int i = _arrCrumble.size() - 1;
333: int stopIndex = _arrCrumble.indexOf(cro);
334:
335: for (; i >= stopIndex; i--) {
336: cro = (JspCrumbleObject) _arrCrumble.remove(i);
337: _hashCrumble.remove(cro.getName());
338: }
339: }
340: }
341: }
|