Coverage details for org.chwf.taglib.ji18n.MessageTag

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.ji18n;
34  
35 import java.io.IOException;
36 import java.util.Collection;
37 import java.util.LinkedList;
38  
39 import javax.servlet.ServletException;
40 import javax.servlet.http.HttpServletRequest;
41  
42 import org.chwf.i18n.Message;
43 import org.chwf.servlet.view.PageConfig;
44 import org.chwf.taglib.base.LifeCycleTagSupport;
45  
46 /**
47  * Tag handler for the <code>&lt;message&gt;</code> tag.
48  *
49  * @author <a href="mailto:pfstrack@users.sourceforge.net">Paul Strack</a>
50  */
5134public class MessageTag extends LifeCycleTagSupport {
52  
53   /** Message name. */
54   private String name;
55  
56   /** Message resource. */
57   private String resource;
58  
59   /** Message arguments. */
6017  private Collection arguments = new LinkedList();
61  
62   /**
63    * Clean up data for tag handler reuse and pooling. Should be overridden in
64    * tag handler. Subclasses should always invoke their superclass's cleanup
65    * method: <code>super.cleanup()</code>
66    */
67   public void cleanup() {
681    super.cleanup();
691    this.name = null;
701    this.resource = null;
711    arguments.clear();
721  }
73  
74   /**
75    * The message key.
76    *
77    * @return The message key.
78    * @deprecated
79    */
80   public String getKey() {
812    return this.name;
82   }
83  
84   /**
85    * The message key.
86    *
87    * @param key The message key.
88    * @deprecated
89    */
90   public void setKey(String key) {
912    this.name = key;
922  }
93  
94   /**
95    * The message name.
96    *
97    * @return The message name.
98    */
99   public String getName() {
1007    return this.name;
101   }
102  
103   /**
104    * The message name.
105    *
106    * @param name The message name.
107    */
108   public void setName(String name) {
1097    this.name = name;
1107  }
111  
112   /**
113    * The resource name. Defaults to resource derived from page location.
114    *
115    * @return The resource name.
116    */
117   public String getResource() {
1189    if (this.resource == null) {
1193      this.resource =
120         (String) this.pageContext.getAttribute(ResourceTag.RESOURCE_NAME);
121     }
1229    if (this.resource == null) {
1232      HttpServletRequest request =
124         (HttpServletRequest) this.pageContext.getRequest();
1252      this.resource = PageConfig.getPageConfig(request).getResource();
126     }
1279    return this.resource;
128   }
129  
130   /**
131    * The resource name.
132    *
133    * @param resource The resource name.
134    */
135   public void setResource(String resource) {
1367    this.resource = rewritePath(resource);
1377  }
138  
139   /**
140    * Add a tag attribute. This method is used to manipulate generic or
141    * pass-through attributes.
142    *
143    * @param name The attribute name.
144    * @param value The attribute value.
145    */
146   public void addParameter(String name, String value) {
1472    super.addParameter(name, value);
1482    arguments.add(value);
1492  }
150  
151   /**
152    * Write out the message.
153    *
154    * @return EVAL_PAGE
155    * @throws ServletException For servlet errors.
156    * @throws IOException For write errors.
157    */
158   public int doEnd() throws ServletException, IOException {
1593    Message message =
160       Message.getMessage(getName(), arguments.toArray(), getResource());
1613    pageContext.getOut().print(message.toString());
1623    return EVAL_PAGE;
163   }
164  
165   /**
166    * Rewrite the resource path.
167    *
168    * @param path The original path.
169    * @return The rewritten path.
170    */
171   static String rewritePath(String path) {
1729    if (path.charAt(0) == '/') {
1731      path = path.substring(1);
174     }
1759    return path.replace('/', '.');
176   }
177 }
178  

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.