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: PersonTreeNodeRenderer.java,v $
031: * Revision 1.4 2005/10/11 18:53:06 colinmacleod
032: * Fixed some checkstyle and javadoc issues.
033: *
034: * Revision 1.3 2005/10/02 14:08:55 colinmacleod
035: * Added/improved log4j logging.
036: *
037: * Revision 1.2 2005/04/09 17:19:10 colinmacleod
038: * Changed copyright text to GPL v2 explicitly.
039: *
040: * Revision 1.1.1.1 2005/03/10 17:50:36 colinmacleod
041: * Restructured ivata op around Hibernate/PicoContainer.
042: * Renamed ivata groupware.
043: *
044: * Revision 1.5 2004/12/23 21:01:26 colinmacleod
045: * Updated Struts to v1.2.4.
046: * Changed base classes to use ivata masks.
047: *
048: * Revision 1.4 2004/11/12 15:57:07 colinmacleod
049: * Removed dependencies on SSLEXT.
050: * Moved Persistence classes to ivata masks.
051: *
052: * Revision 1.3 2004/07/13 19:41:16 colinmacleod
053: * Moved project to POJOs from EJBs.
054: * Applied PicoContainer to services layer (replacing session EJBs).
055: * Applied Hibernate to persistence layer (replacing entity EJBs).
056: *
057: * Revision 1.2 2004/03/21 21:16:18 colinmacleod
058: * Shortened name to ivata op.
059: *
060: * Revision 1.1.1.1 2004/01/27 20:57:58 colinmacleod
061: * Moved ivata openportal to SourceForge..
062: *
063: * Revision 1.2 2004/01/20 15:11:46 jano
064: * fixing problems with new sslext
065: *
066: * Revision 1.1.1.1 2003/10/13 20:50:09 colin
067: * Restructured portal into subprojects
068: *
069: * Revision 1.1 2003/02/24 19:33:33 colin
070: * moved to jsp
071: *
072: * Revision 1.8 2003/02/04 17:43:47 colin
073: * copyright notice
074: *
075: * Revision 1.7 2003/01/31 16:20:01 colin
076: * bugfixes for /addressBook/group.jsp
077: *
078: * Revision 1.6 2003/01/24 19:30:27 peter
079: * added pageContext to initialize parameters, URL rewriting
080: *
081: * Revision 1.5 2002/09/16 15:57:56 colin
082: * resolved
083: *
084: * Revision 1.4 2002/09/16 15:54:31 jano
085: * changed opening and closing folder and added
086: * initializePersonTree section in theme
087: *
088: * Revision 1.3 2002/09/03 08:05:47 jano
089: * corecting of seting property value
090: *
091: * Revision 1.2 2002/08/28 15:13:49 jano
092: * new code cenerated by rose, I was missing imports
093: * -----------------------------------------------------------------------------
094: */
095: package com.ivata.groupware.web.tree.person;
096:
097: import org.apache.log4j.Logger;
098:
099: import java.net.MalformedURLException;
100: import java.util.HashMap;
101: import java.util.List;
102: import java.util.Properties;
103:
104: import javax.servlet.http.HttpServletRequest;
105: import javax.servlet.http.HttpSession;
106: import javax.servlet.jsp.JspException;
107: import javax.servlet.jsp.JspWriter;
108: import javax.servlet.jsp.PageContext;
109:
110: import org.apache.struts.taglib.TagUtils;
111:
112: import com.ivata.groupware.business.addressbook.person.PersonDO;
113: import com.ivata.groupware.business.addressbook.person.group.tree.PersonTreeNode;
114: import com.ivata.groupware.web.tree.DefaultTreeNodeRenderer;
115: import com.ivata.groupware.web.tree.TreeNode;
116: import com.ivata.mask.util.StringHandling;
117:
118: /**
119: * <p>Overrides methods <code>setAdditionalProperties</code> and
120: * <code>initialize</code>. We need to know which check box is checked
121: * and which is not.</p>
122: *
123: * @since 2002-05-27
124: * @author jano
125: * @version $Revision: 1.4 $
126: * @see DefaultTreeNodeRenderer
127: */
128: public class PersonTreeNodeRenderer extends DefaultTreeNodeRenderer {
129: /**
130: * Logger for this class.
131: */
132: private static final Logger logger = Logger
133: .getLogger(PersonTreeNodeRenderer.class);
134:
135: /**
136: * Stores the unique identifiers of all people who are checked in the tree.
137: */
138: private List checked = null;
139: /**
140: * Current page context of the page we are processing.
141: */
142: private PageContext pageContext = null;
143:
144: /**
145: * <p>Overridden method to set up <code>check</code> property of the
146: * check box in the leaf node.</p>
147: *
148: * @param treeNode the current node in the tree being drawn.
149: * @param level the depth of this node within the tree, with 0 being
150: * root.
151: * @param properties all the properties are already defined. New
152: * properties
153: * should be added to this instance and returned.
154: * @return all of the properties which should be evaluated in the
155: * client theme
156: * section.
157: * @throws JspException thrown by subclasses if there is a formatting
158: * error.
159: */
160: public java.util.Properties setAdditionalProperties(
161: final TreeNode treeNode, final int level,
162: final java.util.Properties properties) throws JspException {
163: if (logger.isDebugEnabled()) {
164: logger.debug("setAdditionalProperties(TreeNode treeNode = "
165: + treeNode + ", int level = " + level
166: + ", java.util.Properties properties = "
167: + properties + ") - start");
168: }
169:
170: PersonDO person = (PersonDO) ((PersonTreeNode) treeNode)
171: .getPerson();
172:
173: if (person != null) {
174: // see if person Id is in checked vector
175: if ((checked != null) && (person != null)
176: && (checked.indexOf(person.getId()) != -1)) {
177: properties.setProperty("checked", "checked");
178: }
179: properties.setProperty("value", person.getId().toString());
180: properties.setProperty("email", StringHandling.getNotNull(
181: person.getEmailAddress(), "[none]"));
182: properties.setProperty("fileAs", StringHandling
183: .getNotNull(person.getFileAs()));
184: } else {
185: HashMap map = new HashMap();
186: map
187: .put(
188: "page",
189: "/mask/find.action?deleteKey=group.alert.delete"
190: + "&menuFrameURI=%2FaddressBook%2FgroupTree.action"
191: + "%3FgroupTreeRefresh%3Dtrue%26mode%3Dgroup&"
192: + "idString="
193: + treeNode.getId().toString()
194: + "&inputMask=imGroupInputMaskAction"
195: + "&baseClass=com.ivata.groupware.business.addressbook"
196: + ".person.group.GroupDO&bundle=addressBook"
197: + "&resourceFieldPath=group&menuFrameName=ivataGroupList");
198: try {
199: String uRL = TagUtils.getInstance().computeURL(
200: pageContext, "utilLoading", null, null, null,
201: null, map, null, true);
202: properties.setProperty("groupFindAction", uRL);
203: } catch (MalformedURLException e) {
204: logger.error(
205: "setAdditionalProperties - exception computing url for "
206: + "forward 'utilLoading', parameters '"
207: + map + "'", e);
208: throw new JspException(e);
209: }
210: }
211:
212: if (logger.isDebugEnabled()) {
213: logger
214: .debug("setAdditionalProperties - end - return value = "
215: + properties);
216: }
217: return properties;
218: }
219:
220: /**
221: * <p>This method is called by the tree tag during
222: * <code>doStartTag</code> to allow the renderer to open or close
223: * folders as appropriate.</p>
224: *
225: * <p>It gets <code>Vector checkedAttendee</code> from the
226: * session.</p>
227: *
228: * @param session the current session which can be used to retrieve
229: * settings.
230: * @param request the current servlet request which can be used to
231: * retrieve settings.
232: * @param out jsp writer which can be used to output HTML.
233: * @param pageContextParam the current <code>PageContext</code>
234: * @throws JspException not thrown by this class but can be thrown by
235: * subclasses
236: * who experience an error on initialization.
237: */
238: public void initialize(final HttpSession session,
239: final HttpServletRequest request, final JspWriter out,
240: final PageContext pageContextParam) throws JspException {
241: if (logger.isDebugEnabled()) {
242: logger.debug("initialize(HttpSession session = " + session
243: + ", HttpServletRequest request = " + request
244: + ", JspWriter out = " + out
245: + ", PageContext pageContext = " + pageContextParam
246: + ") - start");
247: }
248:
249: this .pageContext = pageContextParam;
250: try {
251: out.print(getTreeTag().getTheme().parseSection(
252: "initializePersonTree", new Properties()));
253: } catch (java.io.IOException e) {
254: logger.error(
255: "initialize - exception writing out the theme section '"
256: + "initializePersonTree'.", e);
257: throw new JspException(e);
258: }
259:
260: super .initialize(session, request, out, pageContextParam);
261: checked = (java.util.List) session
262: .getAttribute("checkedAttendees");
263:
264: if (logger.isDebugEnabled()) {
265: logger.debug("initialize - end");
266: }
267: }
268:
269: /**
270: * Get the unique identifiers of all people who are checked in the tree.
271: *
272: * @return <code>List</code> of instances of <code>Integer</code>.
273: */
274: public final List getChecked() {
275: if (logger.isDebugEnabled()) {
276: logger.debug("getChecked() - start");
277: }
278:
279: if (logger.isDebugEnabled()) {
280: logger.debug("getChecked() - end - return value = "
281: + checked);
282: }
283: return checked;
284: }
285:
286: /**
287: * <copyDoc>Refer to {@link #getChecked}.</copyDoc>
288: * @param checkedParam
289: * <copyDoc>Refer to {@link #getChecked}.</copyDoc>
290: */
291: public final void setChecked(final List checkedParam) {
292: if (logger.isDebugEnabled()) {
293: logger.debug("setChecked(java.util.Vector checked = "
294: + checkedParam + ") - start");
295: }
296:
297: this .checked = checkedParam;
298:
299: if (logger.isDebugEnabled()) {
300: logger.debug("setChecked(java.util.Vector) - end");
301: }
302: }
303: }
|