View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/StaticDataItemTag.java,v 1.2 2006/01/13 13:38:51 hkollmann Exp $
3    * $Revision: 1.2 $
4    * $Date: 2006/01/13 13:38:51 $
5    *
6    * DbForms - a Rapid Application Development Framework
7    * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8    *
9    * This library is free software; you can redistribute it and/or
10   * modify it under the terms of the GNU Lesser General Public
11   * License as published by the Free Software Foundation; either
12   * version 2.1 of the License, or (at your option) any later version.
13   *
14   * This library is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this library; if not, write to the Free Software
21   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22   */
23  
24  package org.dbforms.taglib;
25  
26  import org.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
28  
29  import org.dbforms.interfaces.IStaticDataList;
30  import org.dbforms.interfaces.StaticData;
31  import org.dbforms.util.MessageResources;
32  import org.dbforms.util.Util;
33  
34  import javax.servlet.jsp.JspException;
35  
36  
37  
38  /***
39   * DOCUMENT ME!
40   *
41   * @author $author$
42   * @version $Revision: 1.2 $
43   */
44  public class StaticDataItemTag extends AbstractDbBaseHandlerTag
45     implements javax.servlet.jsp.tagext.TryCatchFinally {
46     private static Log logCat = LogFactory.getLog(StaticDataItemTag.class.getName()); // logging category for this class
47     private String     key;
48     private String     value;
49  
50     /***
51      * DOCUMENT ME!
52      *
53      * @param key DOCUMENT ME!
54      */
55     public void setKey(String key) {
56        this.key = key;
57     }
58  
59  
60     /***
61      * DOCUMENT ME!
62      *
63      * @return DOCUMENT ME!
64      */
65     public String getKey() {
66        return key;
67     }
68  
69  
70     /***
71      * DOCUMENT ME!
72      *
73      * @param string
74      */
75     public void setValue(String string) {
76        value = string;
77     }
78  
79  
80     /***
81      * DOCUMENT ME!
82      *
83      * @return DOCUMENT ME!
84      */
85     public String getValue() {
86        String message = null;
87  
88        if ((value != null)
89                  && (getParent() instanceof StaticDataTag
90                  && (getParentForm() != null)
91                  && getParentForm()
92                              .hasCaptionResourceSet())) {
93           try {
94              message = MessageResources.getMessage(value, getLocale());
95  
96              if (!Util.isNull(message)) {
97                 value = message;
98              }
99           } catch (Exception e) {
100             logCat.debug("getValue(" + value + ") Exception : "
101                          + e.getMessage());
102          }
103       }
104 
105       return value;
106    }
107 
108 
109    /***
110     * DOCUMENT ME!
111     */
112    public void doFinally() {
113       key   = null;
114       value = null;
115       super.doFinally();
116    }
117 
118 
119    /***
120     * DOCUMENT ME!
121     *
122     * @return DOCUMENT ME!
123     *
124     * @throws JspException DOCUMENT ME!
125     */
126    public int doStartTag() throws JspException {
127       if ((getParent() != null)
128                 && getParent() instanceof IStaticDataList) {
129          ((IStaticDataList) getParent()).addElement(new StaticData(key,
130                                                                             getValue()));
131       } else {
132          throw new JspException("StaticDataItem element must be placed inside a AddStaticData element!");
133       }
134 
135       return EVAL_BODY_INCLUDE;
136    }
137 }