| 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.Iterator; | |
| 37 | ||
| 38 | import javax.servlet.jsp.JspWriter; | |
| 39 | import javax.servlet.jsp.tagext.BodyContent; | |
| 40 | ||
| 41 | import org.chwf.taglib.base.LifeCycleBodyTagSupport; | |
| 42 | ||
| 43 | /** | |
| 44 | * Tag handler for the <code><element></code> tag. | |
| 45 | * | |
| 46 | * @author <a href="mailto:pfstrack@users.sourceforge.net">Paul Strack</a> | |
| 47 | */ | |
| 48 | 23 | public class ElementTag extends LifeCycleBodyTagSupport { |
| 49 | ||
| 50 | /** Element name. */ | |
| 51 | private String name; | |
| 52 | ||
| 53 | /** | |
| 54 | * Clean up data for tag handler reuse and pooling. Should be overridden in | |
| 55 | * tag handler. Subclasses should always invoke their superclass's cleanup | |
| 56 | * method: <code>super.cleanup()</code> | |
| 57 | */ | |
| 58 | public void cleanup() { | |
| 59 | 1 | super.cleanup(); |
| 60 | 1 | this.name = null; |
| 61 | 1 | } |
| 62 | ||
| 63 | /** | |
| 64 | * The element name. | |
| 65 | * | |
| 66 | * @param name The element name. | |
| 67 | */ | |
| 68 | public void setName(String name) { | |
| 69 | 5 | this.name = name; |
| 70 | 5 | } |
| 71 | ||
| 72 | /** | |
| 73 | * The element name. | |
| 74 | * | |
| 75 | * @return The element name. | |
| 76 | */ | |
| 77 | public String getName() { | |
| 78 | 5 | return this.name; |
| 79 | } | |
| 80 | ||
| 81 | /** | |
| 82 | * Wraps the (trimmed) tag body with the defined element. | |
| 83 | * | |
| 84 | * @return EVAL_PAGE | |
| 85 | * @throws IOException For write errors. | |
| 86 | */ | |
| 87 | public int doEnd() throws IOException { | |
| 88 | // Begin element start tag: | |
| 89 | 3 | JspWriter out = getPreviousOut(); |
| 90 | 3 | out.print("<"); |
| 91 | 3 | out.print(getName()); |
| 92 | ||
| 93 | 3 | printParameters(); |
| 94 | ||
| 95 | // Finish element start tag: | |
| 96 | 3 | out.print(">"); |
| 97 | ||
| 98 | // Print (trimmed) tag body content: | |
| 99 | 3 | BodyContent bodyContent = getBodyContent(); |
| 100 | 3 | if (bodyContent != null) { |
| 101 | 3 | out.print(bodyContent.getString().trim()); |
| 102 | } | |
| 103 | ||
| 104 | // Print element end tag: | |
| 105 | 3 | out.print("</"); |
| 106 | 3 | out.print(name); |
| 107 | 3 | out.print(">"); |
| 108 | ||
| 109 | 3 | return EVAL_PAGE; |
| 110 | } | |
| 111 | ||
| 112 | /** | |
| 113 | * Print parameters as [name='value'] pairs. | |
| 114 | * | |
| 115 | * @throws IOException For write errors. | |
| 116 | */ | |
| 117 | public void printParameters() throws IOException { | |
| 118 | // Print attributes: | |
| 119 | 4 | JspWriter out = getPreviousOut(); |
| 120 | 4 | Iterator attributes = getParameterNames(); |
| 121 | 10 | while (attributes.hasNext()) { |
| 122 | 2 | String attribute = (String) attributes.next(); |
| 123 | 2 | String value = getParameter(attribute); |
| 124 | 2 | out.print(" "); |
| 125 | 2 | out.print(attribute); |
| 126 | 2 | out.print("='"); |
| 127 | 2 | out.print(value); |
| 128 | 2 | out.print("'"); |
| 129 | } | |
| 130 | 4 | } |
| 131 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |