View Javadoc
1   /*
2    * $Header: /cvsroot/sinon/sinon/src/java/eteg/sinon/core/PositioningStep.java,v 1.2 2005/06/21 14:25:07 thiagohp Exp $
3    * $Revision: 1.2 $
4    * $Date: 2005/06/21 14:25:07 $
5    * $Author: thiagohp $
6    *
7    * =============================================================================
8    *
9    * Copyright 2004-2005 Eteg Internet Ltda. (http://www.eteg.com.br)
10   *
11   * Licensed under the Apache License, Version 2.0 (the "License");
12   * you may not use this file except in compliance with the License.
13   * You may obtain a copy of the License at
14   *
15   *     http://www.apache.org/licenses/LICENSE-2.0
16   *
17   * Unless required by applicable law or agreed to in writing, software
18   * distributed under the License is distributed on an "AS IS" BASIS,
19   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   * See the License for the specific language governing permissions and
21   * limitations under the License.
22   */
23  package eteg.sinon.core;
24  
25  /***
26   * <p>
27   *     Class that represents positioning steps inside a page in Sinon.
28   * </p>
29   *
30   * <p>
31   *     The properties of instances of this class are:
32   * </p>
33   *
34   * <ul>
35   *     <li>
36   *         <code>type</code>: a <code>String</code> containing the
37   *         positioning step. The current set of positioning step types are:
38   *         {@link #JUMP}, {@link #FROM}, and {@link #TO}.
39   *     </li>
40   *     <li>
41   *         <code>reference</code>: string used as reference to this
42   *         positioning step. It is searched inside the page text.
43   *         Loop positioning steps does not have a reference.
44   *     </li>
45   *     <li>
46   *         <code>direction</code>: search direction. The possible values
47   *         are {@link #FORWARD} and {@link #BACKWARD}.
48   *         Default: {@link #FORWARD}.
49   *     </li>
50   *     <li>
51   *         <code>before</code>: string used to specify a position after which
52   *         the reference cannot be found. If the reference is found after
53   *         the <code>before</code> string, a failure happens.
54   *     </li>
55   *     <li>
56   *         <code>failIfFound</code>: if <code>true</code>, this positioning
57   *         steps is considered a failure if the reference is found.
58   *         Default: false.
59   *     </li>
60   *     <li>
61   *         <code>mustTrimReference</code>:
62   *         Tells if the reference must be trimmed (methodo
63   *         <code>String.trim</code> before used. Default: true.
64   *     </li>
65   * </ul>
66   *
67   * @author <a href="mailto:thiagohp at users.sourceforge.net">Thiago H. de Paula Figueiredo</a>
68   * @author Last modified by $Author: thiagohp $
69   * @version $Revision: 1.2 $
70   */
71  public class PositioningStep implements Step {
72  
73      /***
74       * Constant that defines the jump positioning step type.
75       */
76      final public static String JUMP = "jump";
77  
78      /***
79       * Constant that defines the from positioning step type.
80       */
81      final public static String FROM = "from";
82  
83      /***
84       * Constant that defines the to positioning step type.
85       */
86  
87      final public static String TO = "to";
88  
89      /***
90       * Constant that defines the loop positioning step type.
91       */
92      final public static String LOOP = "loop";
93  
94      /***
95       * <code>String</code> que define o tipo de passo de extração loop.
96       */
97  //    final public static String REGEX = "regex";
98  
99      /***
100      * Constants used to specify a forward search.
101      */
102     final public static boolean FORWARD = true;
103 
104     /***
105      * Constants used to specify a backward search.
106      */
107     final public static boolean BACKWARD = false;
108 
109     /***
110      * Positioning step type.
111      */
112     private String type;
113 
114     /***
115      * String used as reference to this positioning step.
116      */
117     private String reference;
118 
119     /***
120      * String que marca uma posição a partir da qual ocorrências da
121      * referências serão consideradas inválidas.
122      */
123     private String before;
124 
125     /***
126      * Se <code>true</code>, este passo falha caso a referência
127      * seja encontrada.
128      * Default : false
129      */
130     private boolean failIfFound;
131 
132     /***
133      * Direção da procura. Deve-se utilizar as constantes {@link #FORWARD} e
134      * {@link #BACKWARD}.
135      */
136     private boolean direction;
137 
138     /***
139      * Tells if the reference must be trimmed (methodo <code>String.trim</code>
140      * before used. Default: true.
141      */
142     private boolean mustTrimReference;
143 
144     /***
145      * Constructor without parameters.
146      */
147     public PositioningStep() {
148 
149         type = null;
150         reference = null;
151         direction = FORWARD;
152         before = null;
153         failIfFound = false;
154         mustTrimReference = true;
155 
156     }
157 
158     /***
159      * Returns the value of the <code>before</code> property.
160      * @return a <code>String</code>.
161      */
162     public String getBefore() {
163         return before;
164     }
165 
166     /***
167      * Sets the value of the <code>before</code> property.
168      * @param before the new <code>before</code> value.
169      */
170     public void setBefore(String before) {
171         this.before = before;
172     }
173 
174     /***
175      * Returns the value of the <code>type</code> property.
176      * @return a <code>String</code>.
177      */
178     public String getType() {
179         return type;
180     }
181 
182     /***
183      * Sets the value of the <code>type</code> property.
184      * @param type the new <code>type</code> value.
185      */
186     public void setType(String type) {
187         this.type = type;
188     }
189 
190     /***
191      * Returns the value of the <code>reference</code> property.
192      * @return a <code>String</code>.
193      */
194     public String getReference() {
195         return reference;
196     }
197 
198     /***
199      * Sets the value of the <code>reference</code> property.
200      * @param reference the new <code>reference</code> value.
201      */
202     public void setReference(String reference) {
203         this.reference = reference;
204     }
205 
206     /***
207      * Returns the value of the <code>direction</code> property.
208      * @return {@link #FORWARD} or {@link #BACKWARD}.
209      */
210     public boolean getDirection() {
211         return direction;
212     }
213 
214     /***
215      * Sets the value of the <code>direction</code> property.
216      * @param {@link #FORWARD} or {@link #BACKWARD}.
217      */
218     public void setDirection(boolean direction) {
219         this.direction = direction;
220     }
221 
222     /***
223      * Returns the value of the <code>failIfFound</code> property.
224      * @return a <code>boolean</code>.
225      */
226     public boolean isFailIfFound() {
227         return failIfFound;
228     }
229 
230     /***
231      * Sets the value of the <code>failIfFound</code> property.
232      * @param failIfFound the new <code>failIfFound</code> value.
233      */
234     public void setFailIfFound(boolean failIfFound) {
235         this.failIfFound = failIfFound;
236     }
237 
238     /***
239      * Returns the value of the <code>mustTrimReference</code> property.
240      * @return a <code>String</code>.
241      */
242     public boolean isMustTrimReference() {
243         return mustTrimReference;
244     }
245 
246     /***
247      * Sets the value of the <code>mustTrimReference</code> property.
248      * @param mustTrimReference the new <code>mustTrimReference</code> value.
249      */
250     public void setMustTrimReference(boolean mustTrimReference) {
251         this.mustTrimReference = mustTrimReference;
252     }
253 
254     /***
255      * Returns <code>false</code>.
256      * @return <code>false</code>
257      */
258     public boolean isDataExtraction() {
259         return false;
260     }
261 
262     /***
263      * Returns <code>true</code>.
264      * @return <code>true</code>
265      */
266     public boolean isPositioningStep() {
267         return true;
268     }
269 
270     /***
271      * Diz se este passo é um loop.
272      * @return <code>true</code> se este passo é um loop,
273      * <code>false</code> caso contrário.
274      */
275     public boolean isLoop() {
276         return false;
277     }
278 
279     /***
280      * Returns <code>false</code>.
281      * @return false.
282      */
283     public boolean isAction() {
284         return false;
285     }
286 
287     /***
288      * Tells if the type of this positioning step is <code>from</code>.
289      * @return <code>true</code> if the type of this positioning step is
290      * <code>from</code>, <code>false</code> otherwise.
291      */
292     public boolean isFrom() {
293         return type.equals(FROM);
294     }
295 
296     /***
297      * Tells if the type of this positioning step is <code>to</code>.
298      * @return <code>true</code> if the type of this positioning step is
299      * <code>to</code>, <code>false</code> otherwise.
300      */
301     public boolean isTo() {
302         return type.equals(TO);
303     }
304 
305     /***
306      * Tells if the type of this positioning step is <code>jump</code>.
307      * @return <code>true</code> if the type of this positioning step is
308      * <code>jump</code>, <code>false</code> otherwise.
309      */
310     public boolean isJump() {
311         return type.equals(JUMP);
312     }
313 
314 }