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

Quick Search    Search Deep

Source code: com/aendvari/tethys/tag/logic/OperatorTag.java


1   /*
2    * OperatorTag.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.logic;
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.context.*;
23  
24  
25  /**
26   * <p>Base class for operator tags.</p>
27   *
28   * @author  Scott Milne
29   *
30   */
31  
32  public abstract class OperatorTag extends LogicTag
33  {
34    /* Variables */
35  
36    /** value to compare with */
37    private String value;
38  
39    /** value derived from the "path" */
40    private String actualValue;
41  
42    /** type of the operator string/number */
43    private String type;
44  
45    /** true/false to represent the operator response */
46    private boolean operatorResponse;
47  
48    public interface Type
49    {
50      final static String StringType  = "string";  // compare using strings
51      final static String NumberType  = "number";  // compare using numbers
52    }
53  
54  
55    /* Constructor */
56  
57    public OperatorTag()
58    {
59      super();
60  
61      value = "";
62      actualValue = "";
63      type = Type.StringType;
64    }
65  
66    /* Attributes */
67  
68    public String getValue() { return value; }
69    public void setValue(String value) { this.value = value; }
70  
71    public String getActualValue() { return actualValue; }
72    public void setActualValue(String actualValue) { this.actualValue = actualValue; }
73  
74    public String getType() { return type; }
75    public void setType(String type) { this.type = type; }
76  
77    public boolean getOperatorResponse()
78    {
79      return operatorResponse;
80    }
81  
82    public void setOperatorResponse(boolean operatorResponse)
83      throws JspTagException
84    {
85      this.operatorResponse = operatorResponse;
86  
87      // set this value into the response
88      if (getName() != null)
89      {
90        response.setMatched(operatorResponse);
91      }
92    }
93  
94    public boolean isStringType() { return type.equals(Type.StringType); }
95    public boolean isNumberType() { return type.equals(Type.NumberType); }
96  
97  
98    public int doStartTag() throws JspTagException
99    {
100     try
101     {
102       // check the "type" parameter
103       if( type.equals("") )
104       {
105         if(
106           (type.compareToIgnoreCase(Type.StringType)==0) &&
107           (type.compareToIgnoreCase(Type.NumberType)==0)
108         )
109         {
110           throw new JspTagException("OperatorTag: \"type\" must be either \"number\" or \"string\"");
111         }
112       }
113 
114       // establish tag context
115       establishModelContext();
116 
117       // get the value from the path
118       ModelNode modelNode = getModelNode(path, true);
119 
120       if (modelNode != null)
121       {
122         // set the actual value
123         actualValue = modelNode.getNodeValue();
124       }
125 
126       // if refer name supplied, then create a response object
127       if (getName() != null)
128       {
129         createResponse();
130 
131         // set operator value
132         response.setValue(getActualValue());
133       }
134 
135       // keep context of parent tag (pass through)
136       modelContext = getParentModelContext();
137     }
138     catch (Exception exception)
139     {
140       throw new JspTagException("OperatorTag:" + exception.toString());
141     }
142 
143     return EVAL_BODY_INCLUDE;
144   }
145 
146     /**
147      * Release all allocated resources.
148    *
149      */
150 
151     public void release()
152     {
153         super.release();
154 
155     value = "";
156     actualValue = "";
157     type = Type.StringType;
158     }
159 }
160