| Line | Hits | Source |
|---|---|---|
| 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><print></code> tag. | |
| 48 | * | |
| 49 | * @author <a href="mailto:pfstrack@users.sourceforge.net">Paul Strack</a> | |
| 50 | */ | |
| 51 | 16 | public 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() { | |
| 65 | 1 | super.cleanup(); |
| 66 | 1 | this.datatype = null; |
| 67 | 1 | this.attribute = null; |
| 68 | 1 | } |
| 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 { | |
| 79 | 7 | super.setObject(objectName); |
| 80 | 7 | } |
| 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 { | |
| 91 | 5 | super.setProperty(property); |
| 92 | 5 | } |
| 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) { | |
| 102 | 3 | super.setEl(el); |
| 103 | 3 | } |
| 104 | ||
| 105 | /** | |
| 106 | * Logical datatype. | |
| 107 | * | |
| 108 | * @param datatype Logical datatype. | |
| 109 | */ | |
| 110 | public void setDatatype(String datatype) { | |
| 111 | 6 | this.datatype = datatype; |
| 112 | 6 | } |
| 113 | ||
| 114 | /** | |
| 115 | * Logical datatype. | |
| 116 | * | |
| 117 | * @return Logical datatype. | |
| 118 | */ | |
| 119 | public String getDatatype() { | |
| 120 | 9 | 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) { | |
| 129 | 2 | this.attribute = attribute; |
| 130 | 2 | } |
| 131 | ||
| 132 | /** | |
| 133 | * Property attribute to print (if any). | |
| 134 | * | |
| 135 | * @return Property attribute to print (if any). | |
| 136 | */ | |
| 137 | public String getAttribute() { | |
| 138 | 11 | 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 { | |
| 149 | 8 | String value = null; |
| 150 | 8 | if (getAttribute() != null) { |
| 151 | 1 | BeanFilter filter = BeanFilter.findFilter(findObject()); |
| 152 | 1 | PropertyFilter propertyFilter = filter.getPropertyFilter(getProperty()); |
| 153 | 1 | Locale locale = UserLocale.getLocale(); |
| 154 | 1 | value = propertyFilter.getLocalizedAttribute(getAttribute(), locale); |
| 155 | } else { | |
| 156 | 7 | String datatype = getDatatype(); |
| 157 | 7 | String property = getProperty(); |
| 158 | 7 | if ((property != null) && datatype == null) { |
| 159 | 2 | Object object = findObject(); |
| 160 | 2 | BeanFilter filter = BeanFilter.findFilter(object); |
| 161 | 2 | value = filter.get(object, property); |
| 162 | } else { | |
| 163 | 5 | Object result = getTagResult(); |
| 164 | 5 | if (result != null) { |
| 165 | 5 | if (datatype == null) { |
| 166 | 2 | datatype = result.getClass().getName(); |
| 167 | } | |
| 168 | 5 | value = Converter.getConverter(datatype).format(result); |
| 169 | } | |
| 170 | } | |
| 171 | } | |
| 172 | 8 | if (value != null) { |
| 173 | 7 | pageContext.getOut().print(value); |
| 174 | } | |
| 175 | 8 | return SKIP_BODY; |
| 176 | } | |
| 177 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |