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: PasswordTag.java,v $
31   * Revision 1.3  2005/04/11 15:28:32  colinmacleod
32   * Re-ordered members.
33   *
34   * Revision 1.2  2005/04/09 18:04:20  colinmacleod
35   * Changed copyright text to GPL v2 explicitly.
36   *
37   * Revision 1.1  2005/01/06 23:10:06  colinmacleod
38   * Moved up a version number.
39   * Changed copyright notices to 2005.
40   * Updated the documentation:
41   *   - started working on multiproject:site docu.
42   *   - changed the logo.
43   * Added checkstyle and fixed LOADS of style issues.
44   * Added separate thirdparty subproject.
45   * Added struts (in web), util and webgui (in webtheme) from ivata op.
46   *
47   * Revision 1.4  2004/11/03 16:12:09  colinmacleod
48   * Changed fieldPath to resourceFieldPath.
49   *
50   * Revision 1.3  2004/07/13 19:48:10  colinmacleod
51   * Moved project to POJOs from EJBs.
52   * Applied PicoContainer to services layer (replacing session EJBs).
53   * Applied Hibernate to persistence layer (replacing entity EJBs).
54   *
55   * Revision 1.2  2004/03/21 21:16:35  colinmacleod
56   * Shortened name to ivata op.
57   *
58   * Revision 1.1.1.1  2004/01/27 20:59:40  colinmacleod
59   * Moved ivata op to SourceForge.
60   *
61   * Revision 1.2  2003/10/16 15:43:03  jano
62   * Fixes problems with building and some problems with splitting to subprojects
63   *
64   * Revision 1.1.1.1  2003/10/13 20:49:26  colin
65   * Restructured portal into subprojects
66   *
67   * Revision 1.2  2003/03/03 16:57:12  colin
68   * converted localization to automatic paths
69   * added labels
70   * added mandatory fieldName attribute
71   *
72   * Revision 1.1  2003/02/24 19:33:33  colin
73   * Moved to new subproject.
74   *
75   * Revision 1.3  2003/02/13 08:51:32  colin
76   * moved initialization from doStartTag to MaskProperties.doStartTag
77   *
78   * Revision 1.2  2003/01/30 07:52:44  colin
79   * bugfixes in mandatory handling
80   *
81   * Revision 1.1  2003/01/18 20:32:08  colin
82   * added html struts override tags and help
83   * -----------------------------------------------------------------------------
84   */
85  package com.ivata.mask.web.tag.html;
86  import java.io.IOException;
87  import javax.servlet.jsp.JspException;
88  import javax.servlet.jsp.JspWriter;
89  /***
90   * <p>
91   * Overrides an HTML <code>&lt;input type=password&gt;</code> tag, by
92   * overriding the class from <strong>Struts </strong>.
93   * </p>
94   *
95   * <p>
96   * <b>Tag attributes: </b> <br/><table cellpadding='2' cellspacing='5'
97   * border='0' align='center' width='85%'>
98   * <tr class='TableHeadingColor'>
99   * <th>attribute</th>
100  * <th>reqd.</th>
101  * <th>param. class</th>
102  * <th width='100%'>description</th>
103  * </tr>
104  * <tr>
105  * <td>fieldName</td>
106  * <td>true</td>
107  * <td><code>java.lang.String</code></td>
108  * <td>The field name is used to default the following attributes of the tag:
109  * <br/>
110  * <ul>
111  * <li><code>styleId</code></li>
112  * <li><code>titleKey</code></li>
113  * <li><code>valueKey</code></li>
114  * </ul>.</td>
115  * </tr>
116  * <tr>
117  * <td>mandatory</td>
118  * <td>false</td>
119  * <td><code>boolean</code></td>
120  * <td>Specifies data for this tag must be entered when the form is submitted.
121  * </td>
122  * </tr>
123  * <tr>
124  * <td>readOnly</td>
125  * <td>false</td>
126  * <td><code>boolean</code></td>
127  * <td>Specifies the form elements should be displayed only and cannot be
128  * altered.</td>
129  * </tr>
130  * </table>
131  * </p>
132  *
133  * <p>
134  * <b>Note: </b> all the tag attributes from {@link
135  * org.apache.struts.taglib.PasswordTag Stuts} are also included.
136  * </p>
137  *
138  * @since ivata masks 0.4 (2003-01-15)
139  * @author Colin MacLeod
140  * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
141  * @version $Revision: 1.3 $
142  */
143 public class PasswordTag extends org.apache.struts.taglib.html.PasswordTag {
144     /***
145      * <p>
146      * Stores and maintains <strong>ivata op </strong> specific mask properties.
147      * </p>
148      */
149     private MaskProperties maskProperties = new MaskProperties();
150     /***
151      * <p>
152      * Overridden to set <code>title</code> and <code>value</code>
153      * attributes from keys.
154      * </p>
155      *
156      * @return value returned by superclass method.
157      *
158      * @throws JspException
159      *             if there is an error wrting to <code>out.print()</code>
160      */
161     public int doEndTag() throws JspException {
162         if (maskProperties.getReadOnly()) {
163             try {
164                 // passwords get a hard-coded string - no guessing what the
165                 // value is :-)
166                 JspWriter out = pageContext.getOut();
167                 out.print("********");
168                 return EVAL_PAGE;
169             } catch (IOException e) {
170                 throw new JspException("ERROR in PasswordTag: IOException: "
171                         + e.getMessage());
172             }
173         }
174         int returnValue = super.doEndTag();
175         maskProperties.reset(this);
176         return returnValue;
177     }
178     /***
179      * <p>
180      * Overridden to remove any value from the password.
181      * </p>
182      *
183      * @return value returned by superclass method, or <code>SKIP_BODY</code>
184      *         if this tag is read-only.
185      *
186      * @throws JspException
187      *             if either <code>valueKey</code> or <code>titleKey</code>
188      *             have not been set, or as thrown by superclass method.
189      */
190     public int doStartTag() throws JspException {
191         maskProperties.doStartTag(this, pageContext);
192         // all password fields are always initially empty in ivata op
193         this.setValue("");
194         if (maskProperties.getReadOnly()) {
195             return SKIP_BODY;
196         } else {
197             // if it is not read-only, use the standard struts implementation
198             return super.doStartTag();
199         }
200     }
201     /***
202      * <p>
203      * Stores and maintains <strong>ivata op </strong> specific mask properties.
204      * </p>
205      *
206      * @return the current value of maskProperties.
207      */
208     public MaskProperties getMaskProperties() {
209         return maskProperties;
210     }
211     /***
212      * <p>
213      * >Name of the field to which this label refers. This is used in
214      * conjunction with the <code>resourceFieldPath</code> to retrieve the
215      * correct message resources path.
216      * </p>
217      *
218      * @param fieldName
219      *            the new value of fieldName.
220      */
221     public void setFieldName(final String fieldName) {
222         maskProperties.setFieldName(fieldName);
223     }
224     /***
225      * <p>
226      * Set whether or not the value this control must be entered.
227      * </p>
228      *
229      * @param mandatory
230      *            <code>true</code> if this field must be entered, otherwise
231      *            <code>false</code> if the field is optional.
232      */
233     public void setMandatory(final boolean mandatory) {
234         maskProperties.setMandatory(mandatory);
235     }
236     /***
237      * <p>
238      * Stores and maintains <strong>ivata op </strong> specific mask properties.
239      * </p>
240      *
241      * @param maskPropertiesParam
242      *            the new value of maskProperties.
243      */
244     public void setMaskProperties(final MaskProperties maskPropertiesParam) {
245         this.maskProperties = maskPropertiesParam;
246     }
247     /***
248      * <p>
249      * Specifies whether or not the input values can be altered.
250      * </p>
251      *
252      * @param readOnly
253      *            <code>true</code> if the input of this field can be changed,
254      *            otherwise <code>false</code> to only display the current
255      *            value.
256      */
257     public void setReadOnly(final boolean readOnly) {
258         maskProperties.setReadOnly(readOnly);
259     }
260 }
261