1 /*
2 * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbLabelTag.java,v 1.26 2006/01/13 13:38:51 hkollmann Exp $
3 * $Revision: 1.26 $
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.util.Util;
30
31 import javax.servlet.jsp.JspException;
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 AbstractDbBaseHandlerTag
44 implements javax.servlet.jsp.tagext.TryCatchFinally {
45 // logging category for this class
46 static Log logCat = LogFactory.getLog(DbLabelTag.class.getName());
47
48 /***
49 * Description of the Method
50 *
51 * @return Description of the Return Value
52 *
53 * @exception javax.servlet.jsp.JspException Description of the Exception
54 */
55 public int doEndTag() throws javax.servlet.jsp.JspException {
56 try {
57 String fieldValue = getFormattedFieldValue();
58
59 // PG, 2001-12-14
60 // If maxlength was input, trim display
61 String size = null;
62
63 if (((size = this.getMaxlength()) != null)
64 && (size.trim()
65 .length() > 0)) {
66 //convert to int
67 int count = Integer.parseInt(size);
68
69 // Trim and add trim indicator (...)
70 if (count < fieldValue.length()) {
71 fieldValue = fieldValue.substring(0, count);
72 fieldValue += "...";
73 }
74 }
75
76 // SM 2003-08-05
77 // if styleClass is present, render a SPAN with text included
78 String s = prepareStyles();
79 fieldValue = escapeHTML(fieldValue);
80
81 if (Util.isNull(s)) {
82 pageContext.getOut()
83 .write(fieldValue);
84 } else {
85 pageContext.getOut()
86 .write("<span " + s +">" + fieldValue + "</span>");
87 }
88 } catch (java.io.IOException ioe) {
89 // better to KNOW what happended !
90 logCat.error("::doEndTag - IO Error", ioe);
91 throw new JspException("IO Error: " + ioe.getMessage());
92 } catch (Exception e) {
93 // better to KNOW what happended !
94 logCat.error("::doEndTag - general exception", e);
95 throw new JspException("Error: " + e.getMessage());
96 }
97
98 return EVAL_PAGE;
99 }
100
101
102 /***
103 * DOCUMENT ME!
104 */
105 public void doFinally() {
106 super.doFinally();
107 }
108 }