KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > views > jsp > PropertyTag


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork.views.jsp;
6
7 import com.opensymphony.util.TextUtils;
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10
11 import javax.servlet.jsp.JspException JavaDoc;
12 import java.io.IOException JavaDoc;
13
14
15 /**
16  * @author $Author: plightbo $
17  * @version $Revision: 1.18 $
18  */

19 public class PropertyTag extends WebWorkTagSupport {
20     //~ Static fields/initializers /////////////////////////////////////////////
21

22     private static final Log log = LogFactory.getLog(PropertyTag.class);
23
24     //~ Instance fields ////////////////////////////////////////////////////////
25

26     private String JavaDoc defaultValue;
27     private String JavaDoc value;
28     private boolean escape = true;
29
30     //~ Methods ////////////////////////////////////////////////////////////////
31

32     public void setDefault(String JavaDoc defaultValue) {
33         this.defaultValue = defaultValue;
34     }
35
36     public void setEscape(boolean escape) {
37         this.escape = escape;
38     }
39
40     public void setValue(String JavaDoc value) {
41         this.value = value;
42     }
43
44     public int doStartTag() throws JspException JavaDoc {
45         try {
46             Object JavaDoc actualValue = null;
47
48             if (value == null) {
49                 value = "top";
50             }
51
52             // exception: don't call findString(), since we don't want the
53
// expression parsed in this one case. it really
54
// doesn't make sense, in fact.
55
actualValue = getStack().findValue(value, String JavaDoc.class);
56
57             if (actualValue != null) {
58                 pageContext.getOut().print(prepare(actualValue));
59             } else if (defaultValue != null) {
60                 pageContext.getOut().print(prepare(defaultValue));
61             }
62         } catch (IOException JavaDoc e) {
63             log.info("Could not print out value '" + value + "': " + e.getMessage());
64         }
65
66         return SKIP_BODY;
67     }
68
69     private Object JavaDoc prepare(Object JavaDoc value) {
70         if (escape) {
71             return TextUtils.htmlEncode(value.toString());
72         } else {
73             return value;
74         }
75     }
76 }
77
Popular Tags