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

Quick Search    Search Deep

Source code: com/aendvari/tethys/tag/message/ParameterTag.java


1   /*
2    * ParameterTag.java
3    *
4    * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved.
5    *
6    * See the file LICENSE for terms of use.
7    *
8    */
9   
10  package com.aendvari.tethys.tag.message;
11  
12  import java.io.IOException;
13  
14  import javax.servlet.http.*;
15  import javax.servlet.jsp.*;
16  import javax.servlet.jsp.tagext.*;
17  
18  import com.aendvari.common.model.*;
19  
20  import com.aendvari.tethys.*;
21  import com.aendvari.tethys.tag.*;
22  import com.aendvari.tethys.tag.model.*;
23  import com.aendvari.tethys.context.*;
24  
25  
26  /**
27   * <p>Parameter value for a particular {@link MessageTag}.</p>
28   *
29   * @author  Scott Milne
30   *
31   */
32  
33  public class ParameterTag extends ModelTreeTag
34  {
35    /* Variables */
36  
37    /** The type of the define (path or value). */
38    public String type;
39  
40    /** The value of this parameter. */
41    protected String value;
42  
43  
44    /* Constructor */
45  
46    public ParameterTag()
47    {
48      super();
49  
50      value = null;
51      type = null;
52    }
53  
54  
55    /* Attributes */
56  
57    public String getValue() { return value; }
58    public void setValue(String value) { this.value = value; }
59  
60    public String getType() { return type; }
61    public void setType( String type ) { this.type = type; }
62  
63  
64    /* Methods */
65  
66    public int doStartTag() throws JspTagException
67    {
68      try
69      {
70        // make sure this tag is within a "MatchTag"
71        MessageTag messageTag = (MessageTag)findAncestorWithClass(this, MessageTag.class);
72  
73        if (messageTag == null)
74        {
75          throw new JspTagException("ParameterTag: without MessageTag");
76        }
77  
78        // check for the type tag. It's not required, but must be valid
79        if (type != null)
80        {
81          if (!type.equals("path") && !type.equals("value"))
82          {
83            throw new JspTagException("ParameterTag: \"type\" (not required) must be either \"value\" or \"path\"");
84          }
85        }
86        else
87        {
88          type = "value";
89        }
90  
91  
92        // if path was provided, use it
93        if (getPath() != null)
94        {
95          // establish tag context
96          establishModelContext();
97  
98          // get the value from the path
99          ModelNode modelNode = getModelNode(path, true);
100 
101         String attributeValue = "";
102 
103         if (modelNode != null)
104         {
105           if (type.equals("value"))
106           {
107             // set the tag value to return
108             attributeValue = modelNode.getNodeValue();
109           }
110           else
111           {
112             // set the tag value to return
113             attributeValue = modelContext.extendModelPath(getPath());
114 
115             // for visual purposes, convert all "." into "/"
116             // OSM supports both, but it looks better to have all the same
117             attributeValue = attributeValue.replace('.', '/');
118 
119             // trim it just in case
120             attributeValue = attributeValue.trim();
121           }
122         }
123 
124         // set this parameter into the list of params for the message tag
125         messageTag.setParameter( getName(), attributeValue );
126       }
127       // otherwise use the value
128       else if (getValue() != null)
129       {
130         // set this parameter into the list of params for the message tag
131         messageTag.setParameter( getName(), getValue() );
132       }
133       // if neither was found, report an error
134       else
135       {
136         throw new JspTagException("ParameterTag: you must define either \"value\" or \"path\"");
137       }
138     }
139     catch (Exception e)
140     {
141       throw new JspTagException("ParameterTag:" + e.toString());
142     }
143 
144     // nothing matched, so don't display the body
145     return SKIP_BODY;
146   }
147 
148     /**
149      * Release all allocated resources.
150    *
151      */
152 
153     public void release()
154     {
155         super.release();
156 
157     value = null;
158     type = null;
159     }
160 }
161