View Javadoc

1   /*
2    * Copyright (c) 2001 - 2005 ivata limited.
3    * All rights reserved.
4    * -----------------------------------------------------------------------------
5    * ivata masks may be redistributed under the GNU General Public
6    * License as published by the Free Software Foundation;
7    * version 2 of the License.
8    *
9    * These programs are free software; you can redistribute them and/or
10   * modify them under the terms of the GNU General Public License
11   * as published by the Free Software Foundation; version 2 of the License.
12   *
13   * These programs are distributed in the hope that they will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16   *
17   * See the GNU General Public License in the file LICENSE.txt for more
18   * details.
19   *
20   * If you would like a copy of the GNU General Public License write to
21   *
22   * Free Software Foundation, Inc.
23   * 59 Temple Place - Suite 330
24   * Boston, MA 02111-1307, USA.
25   *
26   *
27   * To arrange commercial support and licensing, contact ivata at
28   *                  http://www.ivata.com/contact.jsp
29   * -----------------------------------------------------------------------------
30   * $Log: MapTag.java,v $
31   * Revision 1.2  2005/04/09 18:04:20  colinmacleod
32   * Changed copyright text to GPL v2 explicitly.
33   *
34   * Revision 1.1  2005/01/19 12:58:20  colinmacleod
35   * Moved from ivata groupware.
36   *
37   * Revision 1.1  2004/09/30 15:16:03  colinmacleod
38   * Split off addressbook elements into security subproject.
39   *
40   * Revision 1.2  2004/03/21 21:16:18  colinmacleod
41   * Shortened name to ivata op.
42   *
43   * Revision 1.1.1.1  2004/01/27 20:57:58  colinmacleod
44   * Moved ivata openportal to SourceForge..
45   *
46   * Revision 1.1.1.1  2003/10/13 20:50:13  colin
47   * Restructured portal into subprojects
48   *
49   * Revision 1.1  2003/02/25 08:15:50  colin
50   * moved to jsp category
51   *
52   * Revision 1.2  2003/02/04 17:43:51  colin
53   * copyright notice
54   *
55   * Revision 1.1  2003/01/23 17:34:42  colin
56   * first version of map util classes
57   * -----------------------------------------------------------------------------
58   */
59  package com.ivata.mask.web.tag.util;
60  
61  import java.util.HashMap;
62  
63  import javax.servlet.jsp.JspException;
64  import javax.servlet.jsp.tagext.BodyTagSupport;
65  
66  
67  /***
68   * <p>This tag defines a <code>Map</code> in page scope and assigns
69   * the entries to it defined by <code>MapEntryTag</code> instance
70   * within
71   * the tag body.</p>
72   *
73   * <p><b>Tag attributes:</b><br/>
74   * <table cellpadding='2' cellspacing='5' border='0' align='center'
75   * width='85%'>
76   *   <tr class='TableHeadingColor'>
77   *     <th>attribute</th>
78   *     <th>reqd.</th>
79   *     <th>param. class</th>
80   *     <th width='100%'>description</th>
81   *   </tr>
82   *   <tr class='TableRowColor'>
83   *     <td>id</td>
84   *     <td>true</td>
85   *     <td><code>String</code></td>
86   *     <td>Specifies the name of the scripting variable and associated
87   * page scope attribute which will be made available.</td>
88   *   </tr>
89   * </table>
90   * </p>
91   * @since ivata masks 0.5 (2002-01-23)
92   * @author Colin MacLeod
93   * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
94   * @version $Revision: 1.2 $
95   */
96  public class MapTag extends BodyTagSupport {
97      /***
98       * <p>Specifies the name of the scripting variable and associated page
99       * scope attribute which will be made available.</p>
100      */
101     private String id;
102     /***
103      * <p>This internal implementaion actually does all the work :-).</p>
104      */
105     private HashMap map = new HashMap();
106 
107     /***
108      * <p>This method is called when the JSP engine encounters the start
109      * tag, after the attributes are processed.<p>
110      *
111      * <p>Scripting variables (if any) have their values set here.</p>
112      *
113      * @return <code>EVAL_BODY_BUFFERED</code> since we always want to
114      * evaluate the tag body once.
115      * @throws JspException if there is a <code>NamingExcpetion</code>
116      * getting the <code>InitialContext</code>
117      * @throws JspException encapsulates any exception when calling
118      * <code>out.println</code>
119      */
120     public int doStartTag() throws JspException {
121         setMap(map);
122         return EVAL_BODY_BUFFERED;
123     }
124 
125     /***
126      * <p>Specifies the name of the scripting variable and associated page
127      * scope attribute which will be made available.</p>
128      *
129      * @return the current value of id.
130      */
131     public final String getId() {
132         return id;
133     }
134 
135     /***
136      * <p>Specifies the name of the scripting variable and associated page
137      * scope attribute which will be made available.</p>
138      *
139      * @param idParam the new value of id.
140      */
141     public final void setId(final String idParam) {
142         this.id = idParam;
143     }
144 
145     /***
146      * <p>This internal implementaion actually does all the work :-).</p>
147      *
148      * @return the current value of map.
149      */
150     public final HashMap getMap() {
151         return map;
152     }
153 
154     /***
155      * <p>This internal implementaion actually does all the work :-).</p>
156      *
157      * @param mapParam the new value of map.
158      */
159     public final void setMap(final HashMap mapParam) {
160         this.map = mapParam;
161         pageContext.setAttribute(id, mapParam);
162     }
163 }