KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > taglib > DbLabelTag


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbLabelTag.java,v 1.22 2004/08/24 00:32:35 javajunkie Exp $
3  * $Revision: 1.22 $
4  * $Date: 2004/08/24 00:32:35 $
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.util.Util;
30
31 import javax.servlet.jsp.JspException JavaDoc;
32
33
34
35 /**
36  * this tag renders a dabase-datadriven LABEL, which is apassive element (it
37  * can't be changed by the user) - it is predestinated for use with read-only
38  * data (i.e. primary keys you don't want the user to change, etc)
39  *
40  * @author Joachim Peer
41  *
42  */

43 public class DbLabelTag extends DbBaseHandlerTag
44    implements javax.servlet.jsp.tagext.TryCatchFinally JavaDoc {
45    // logging category for this class
46
static Log logCat = LogFactory.getLog(DbLabelTag.class.getName());
47
48    /**
49     * @see javax.servlet.jsp.tagext.TryCatchFinally#doCatch(java.lang.Throwable)
50     */

51    public void doCatch(Throwable JavaDoc t) throws Throwable JavaDoc {
52       throw t;
53    }
54
55
56    /**
57     * Description of the Method
58     *
59     * @return Description of the Return Value
60     *
61     * @exception javax.servlet.jsp.JspException Description of the Exception
62     */

63    public int doEndTag() throws javax.servlet.jsp.JspException JavaDoc {
64       try {
65          String JavaDoc fieldValue = getFormattedFieldValue();
66
67          // PG, 2001-12-14
68
// If maxlength was input, trim display
69
String JavaDoc size = null;
70
71          if (((size = this.getMaxlength()) != null)
72                    && (size.trim()
73                                  .length() > 0)) {
74             //convert to int
75
int count = Integer.parseInt(size);
76
77             // Trim and add trim indicator (...)
78
if (count < fieldValue.length()) {
79                fieldValue = fieldValue.substring(0, count);
80                fieldValue += "...";
81             }
82          }
83
84          // SM 2003-08-05
85
// if styleClass is present, render a SPAN with text included
86
String JavaDoc s = prepareStyles();
87          fieldValue = escapeHTML(fieldValue);
88
89          if (Util.isNull(s)) {
90             pageContext.getOut()
91                        .write(fieldValue);
92          } else {
93             pageContext.getOut()
94                        .write("<span " + s +">" + fieldValue + "</span>");
95          }
96       } catch (java.io.IOException JavaDoc ioe) {
97          // better to KNOW what happended !
98
logCat.error("::doEndTag - IO Error", ioe);
99          throw new JspException JavaDoc("IO Error: " + ioe.getMessage());
100       } catch (Exception JavaDoc e) {
101          // better to KNOW what happended !
102
logCat.error("::doEndTag - general exception", e);
103          throw new JspException JavaDoc("Error: " + e.getMessage());
104       }
105
106       return EVAL_PAGE;
107    }
108
109
110    /**
111     * DOCUMENT ME!
112     */

113    public void doFinally() {
114       super.doFinally();
115    }
116 }
117
Popular Tags