Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/sitemesh/taglib/decorator/PropertyTag.java


1   package com.sitemesh.taglib.decorator;
2   
3   import com.sitemesh.HTMLPage;
4   import com.sitemesh.taglib.AbstractTag;
5   import javax.servlet.jsp.JspException;
6   
7   /**
8    * Write property of Page to out.
9    *
10   * @author <a href="joe@truemesh.com">Joe Walnes</a>
11   * @version $Revision: 1.2 $
12   *
13   * @see com.sitemesh.Page#getProperty(java.lang.String)
14   */
15  public class PropertyTag extends AbstractTag {
16  
17    private String propertyName, defaultValue;
18  
19    /**
20     * Key of property to write.
21     */
22    public void setProperty( String propertyName ) {
23      this.propertyName = propertyName;
24    }
25  
26    /**
27     * Value to write if no property matching key is found (optional).
28     */
29    public void setDefault( String defaultValue ) {
30      this.defaultValue = defaultValue;
31    }
32  
33    public int doEndTag() throws JspException {
34      try {
35        HTMLPage htmlPage = ( HTMLPage )getPage();
36        String result = htmlPage.getProperty(propertyName);
37        if ( result == null || result.length() == 0 ) result=defaultValue;
38        pageContext.getOut().print( result );
39      }
40      catch ( Exception e ) {
41        trace( e );
42      }
43      return EVAL_PAGE;
44    }
45  
46    public void release() {
47      defaultValue = null;
48      propertyName = null;
49      super.release();
50    }
51  
52  }