001: /*
002: * Copyright (c) 2001 - 2005 ivata limited.
003: * All rights reserved.
004: * -----------------------------------------------------------------------------
005: * ivata groupware may be redistributed under the GNU General Public
006: * License as published by the Free Software Foundation;
007: * version 2 of the License.
008: *
009: * These programs are free software; you can redistribute them and/or
010: * modify them under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; version 2 of the License.
012: *
013: * These programs are distributed in the hope that they will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: *
017: * See the GNU General Public License in the file LICENSE.txt for more
018: * details.
019: *
020: * If you would like a copy of the GNU General Public License write to
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place - Suite 330
024: * Boston, MA 02111-1307, USA.
025: *
026: *
027: * To arrange commercial support and licensing, contact ivata at
028: * http://www.ivata.com/contact.jsp
029: * -----------------------------------------------------------------------------
030: * $Log: TreeNodeRenderer.java,v $
031: * Revision 1.3 2005/10/11 18:51:39 colinmacleod
032: * Fixed some checkstyle and javadoc issues.
033: *
034: * Revision 1.2 2005/10/02 14:08:57 colinmacleod
035: * Added/improved log4j logging.
036: *
037: * Revision 1.1 2005/09/29 13:44:03 colinmacleod
038: * Moved to core subproject.
039: *
040: * Revision 1.2 2005/04/09 17:19:10 colinmacleod
041: * Changed copyright text to GPL v2 explicitly.
042: *
043: * Revision 1.1.1.1 2005/03/10 17:50:36 colinmacleod
044: * Restructured ivata op around Hibernate/PicoContainer.
045: * Renamed ivata groupware.
046: *
047: * Revision 1.1 2004/09/30 15:16:03 colinmacleod
048: * Split off addressbook elements into security subproject.
049: *
050: * Revision 1.3 2004/07/13 19:41:16 colinmacleod
051: * Moved project to POJOs from EJBs.
052: * Applied PicoContainer to services layer (replacing session EJBs).
053: * Applied Hibernate to persistence layer (replacing entity EJBs).
054: *
055: * Revision 1.2 2004/03/21 21:16:18 colinmacleod
056: * Shortened name to ivata op.
057: *
058: * Revision 1.1.1.1 2004/01/27 20:57:58 colinmacleod
059: * Moved ivata openportal to SourceForge..
060: *
061: * Revision 1.1.1.1 2003/10/13 20:50:09 colin
062: * Restructured portal into subprojects
063: *
064: * Revision 1.1 2003/02/24 19:33:33 colin
065: * moved to jsp
066: *
067: * Revision 1.4 2003/02/04 17:43:46 colin
068: * copyright notice
069: *
070: * Revision 1.3 2003/01/24 19:30:27 peter
071: * added pageContext to initialize parameters, URL rewriting
072: *
073: * Revision 1.2 2002/08/10 21:17:48 colin
074: * first version of HTML sanitizer/parser to clean up HTML code
075: *
076: * Revision 1.1 2002/06/21 11:58:37 colin
077: * restructured com.ivata.groupware.web into seperate
078: * subcategories:
079: * fornat, javascript, theme and tree.
080: * -----------------------------------------------------------------------------
081: */
082: package com.ivata.groupware.web.tree;
083:
084: import java.util.Properties;
085:
086: import org.apache.log4j.Logger;
087:
088: import javax.servlet.http.HttpServletRequest;
089: import javax.servlet.http.HttpSession;
090: import javax.servlet.jsp.JspException;
091: import javax.servlet.jsp.JspWriter;
092: import javax.servlet.jsp.PageContext;
093: import javax.swing.tree.TreeModel;
094:
095: import com.ivata.groupware.web.tag.webgui.tree.TreeTag;
096: import com.ivata.mask.web.theme.Theme;
097:
098: /**
099: * <p>This interface defines the methods of an HTML tree renderer as
100: * used in
101: * the ivata groupware {@link com.ivata.groupware.web.tag.webgui.TreeTag
102: * tree
103: * tag}.</p>
104: *
105: * @since 2002-05-16
106: * @author Colin MacLeod
107: * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
108: * @version $Revision: 1.3 $
109: */
110: public abstract class TreeNodeRenderer {
111: /**
112: * Logger for this class.
113: */
114: private static final Logger logger = Logger
115: .getLogger(TreeNodeRenderer.class);
116:
117: /**
118: * <p>This tree tag reference is used to open and close folders.</p>
119: */
120: private TreeTag treeTag;
121:
122: /**
123: * <p>Get a string which will be used in the tree representation of
124: * the tree node. This can contain caption information and image
125: * paths, for
126: * example, as properties which are evaluated by {@link
127: * com.ivata.groupware.web.theme.Theme#parseSection(String
128: * name,
129: * java.util.Properties properties)
130: * Theme.parseSection(String name, java.util.Properties
131: * properties)}.</p>
132: * @param model <code>TreeModel</code> representing the data of the
133: * tree.
134: * @param node <code>Object</code> representing a node in the tree.
135: * The
136: * <code>toString( )</code> of this node will be used as the
137: * 'caption'
138: * properties when parsing.
139: * @param expanded <code>true</code> if this node is 'open', otherwise
140: * <code>false</code>.
141: * @param level the depth of this node within the tree, with 0 being
142: * root.
143: * @param last <code>true</code> if this node is the last in the
144: * current branch,
145: * otherwise <code>false</code>.
146: * @param theme this theme does the parsing.
147: * @param properties existing properties to parse.
148: * @return the parsed string.
149: * @throws JspException if the theme sections required by the
150: * renderer have not been defined.
151: */
152: public abstract String render(final TreeModel model,
153: final Object node, final boolean expanded, final int level,
154: final boolean last, final Theme theme,
155: final Properties properties) throws JspException;
156:
157: /**
158: * <p>This method initializes the internal reference to the tree
159: * tag.</p>
160: *
161: * @param treeTagParam internal reference to the treetag which owns this
162: * renderer.
163: */
164: public void setTreeTag(final TreeTag treeTagParam) {
165: if (logger.isDebugEnabled()) {
166: logger.debug("setTreeTag(TreeTag treeTag = " + treeTagParam
167: + ") - start");
168: }
169:
170: this .treeTag = treeTagParam;
171:
172: if (logger.isDebugEnabled()) {
173: logger.debug("setTreeTag(TreeTag) - end");
174: }
175: }
176:
177: /**
178: * <p>This method is called by the tree tag during
179: * <code>doStartTag</code> to
180: * allow the renderer to open or close folders as apropriate.</p>
181: *
182: * @param session the current session which can be used to retrieve
183: * settings.
184: * @param request the current servlet request which can be used to
185: * retrieve
186: * settings.
187: * @param out jsp writer which can be used to output HTML.
188: * @param pageContext the current PageContext
189: * @throws JspException not thrown by this class but can be thrown by
190: * subclasses
191: * who experience an error on initialization.
192: */
193: public abstract void initialize(final HttpSession session,
194: final HttpServletRequest request, final JspWriter out,
195: final PageContext pageContext) throws JspException;
196:
197: /**
198: * <p>Is called by the tree tag after the tree has been drawn. Can be
199: * overridden
200: * by subclasses to provide finalization.</p>
201: *
202: * <p>This default implementation does nothing.</p>
203: *
204: * @param session the current session which can be used to retrieve
205: * settings.
206: * @param request the current servlet request which can be used to
207: * retrieve
208: * settings.
209: * @param out jsp writer which can be used to output HTML.
210: * @throws JspException not thrown by this class but can be thrown by
211: * subclasses
212: * who experience an error on finalization.
213: */
214: public void finalize(final HttpSession session,
215: final HttpServletRequest request, final JspWriter out)
216: throws JspException {
217: if (logger.isDebugEnabled()) {
218: logger.debug("finalize(HttpSession session = " + session
219: + ", HttpServletRequest request = " + request
220: + ", JspWriter out = " + out + ") - start");
221: }
222:
223: if (logger.isDebugEnabled()) {
224: logger.debug("finalize- end");
225: }
226: }
227:
228: /**
229: * <p>Get the internal reference to the tree tag.</p>
230: *
231: * @return internal reference to the treetag which owns this renderer.
232: */
233: public TreeTag getTreeTag() {
234: if (logger.isDebugEnabled()) {
235: logger.debug("getTreeTag() - start");
236: }
237:
238: if (logger.isDebugEnabled()) {
239: logger.debug("getTreeTag() - end - return value = "
240: + treeTag);
241: }
242: return treeTag;
243: }
244: }
|