Coverage details for org.chwf.taglib.jutil.PrintTag

LineHitsSource
1 /*
2 Chrysalis Web Framework [http://chrysalis.sourceforge.net]
3 Copyright (c) 2002, 2003, 2004, Paul Strack
4  
5 All rights reserved.
6  
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9  
10 1. Redistributions of source code must retain the above copyright notice, this
11 list of conditions and the following disclaimer.
12  
13 2. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16  
17 3. Neither the name of the copyright holder nor the names of its contributors
18 may be used to endorse or promote products derived from this software without
19 specific prior written permission.
20  
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
25 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32  
33 package org.chwf.taglib.jutil;
34  
35 import java.io.IOException;
36 import java.util.Locale;
37  
38 import javax.servlet.jsp.JspException;
39  
40 import org.chwf.converter.Converter;
41 import org.chwf.filter.BeanFilter;
42 import org.chwf.filter.PropertyFilter;
43 import org.chwf.i18n.UserLocale;
44 import org.chwf.taglib.base.ObjectTagSupport;
45  
46 /**
47  * Tag handler for the <code>&lt;print&gt;</code> tag.
48  *
49  * @author <a href="mailto:pfstrack@users.sourceforge.net">Paul Strack</a>
50  */
5116public class PrintTag extends ObjectTagSupport {
52  
53   /** Logical datatype. */
54   private String datatype;
55  
56   /** Property attribute. */
57   private String attribute;
58  
59   /**
60    * Clean up data for tag handler reuse and pooling. Should be overridden in
61    * tag handler. Subclasses should always invoke their superclass's cleanup
62    * method: <code>super.cleanup()</code>
63    */
64   public void cleanup() {
651    super.cleanup();
661    this.datatype = null;
671    this.attribute = null;
681  }
69  
70   /**
71    * Calls superclass method. Is present here because of a bug in some servlet
72    * engines that requires tag attibute setters to be defined in the tag class
73    * itself.
74    *
75    * @param objectName The object name.
76    * @throws JspException For errors.
77    */
78   public void setObject(String objectName) throws JspException {
797    super.setObject(objectName);
807  }
81  
82   /**
83    * Calls superclass method. Is present here because of a bug in some servlet
84    * engines that requires tag attibute setters to be defined in the tag class
85    * itself.
86    *
87    * @param property The property name.
88    * @throws JspException For errors.
89    */
90   public void setProperty(String property) throws JspException {
915    super.setProperty(property);
925  }
93  
94   /**
95    * Calls superclass method. Is present here because of a bug in some servlet
96    * engines that requires tag attibute setters to be defined in the tag class
97    * itself.
98    *
99    * @param el The JSTL Expression Language statement.
100    */
101   public void setEl(String el) {
1023    super.setEl(el);
1033  }
104  
105   /**
106    * Logical datatype.
107    *
108    * @param datatype Logical datatype.
109    */
110   public void setDatatype(String datatype) {
1116    this.datatype = datatype;
1126  }
113  
114   /**
115    * Logical datatype.
116    *
117    * @return Logical datatype.
118    */
119   public String getDatatype() {
1209    return datatype;
121   }
122  
123   /**
124    * Property attribute to print (if any).
125    *
126    * @param attribute Property attribute to print (if any).
127    */
128   public void setAttribute(String attribute) {
1292    this.attribute = attribute;
1302  }
131  
132   /**
133    * Property attribute to print (if any).
134    *
135    * @return Property attribute to print (if any).
136    */
137   public String getAttribute() {
13811    return attribute;
139   }
140  
141   /**
142    * Prints the tag value.
143    *
144    * @return SKIP_BODY
145    * @throws IOException For IO exceptions.
146    * @throws JspException For parsiing errors.
147    */
148   public int doStart() throws IOException, JspException {
1498    String value = null;
1508    if (getAttribute() != null) {
1511      BeanFilter filter = BeanFilter.findFilter(findObject());
1521      PropertyFilter propertyFilter = filter.getPropertyFilter(getProperty());
1531      Locale locale = UserLocale.getLocale();
1541      value = propertyFilter.getLocalizedAttribute(getAttribute(), locale);
155     } else {
1567      String datatype = getDatatype();
1577      String property = getProperty();
1587      if ((property != null) && datatype == null) {
1592        Object object = findObject();
1602        BeanFilter filter = BeanFilter.findFilter(object);
1612        value = filter.get(object, property);
162       } else {
1635        Object result = getTagResult();
1645        if (result != null) {
1655          if (datatype == null) {
1662            datatype = result.getClass().getName();
167           }
1685          value = Converter.getConverter(datatype).format(result);
169         }
170       }
171     }
1728    if (value != null) {
1737      pageContext.getOut().print(value);
174     }
1758    return SKIP_BODY;
176   }
177 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.