Source code: org/milligan/eccles/tags/AssertTag.java
1 package org.milligan.eccles.tags;
2
3 import org.milligan.eccles.*;
4 import org.milligan.eccles.AssertionException;
5
6
7 /**
8 * Assert tag. Report an exception if the test value is false
9 * @author Ian Tomey
10 *
11 */
12
13 public class AssertTag extends Tag {
14
15 public AssertTag() {
16 }
17
18 public String getTagName() {
19 return "assert";
20 }
21 /**
22 * Tag properties for output
23 */
24 protected static final String tagSpecificProperties[]= new String[] {"test","type","message","count"};
25 private String test;
26 private String type="error";
27 private String message;
28 private String count;
29 private boolean _continue;
30 /**
31 * Get a list of properties to be output
32 * @return list of properties
33 */
34 public String[] getTagPropertiesForDisplay() {
35 return tagSpecificProperties;
36 }
37 public void setTest(String test) {
38 this.test = test;
39 }
40 public String getTest() {
41 return test;
42 }
43 public void setType(String type) {
44 this.type = type;
45 }
46 public String getType() {
47 return type;
48 }
49 public void setMessage(String message) {
50 this.message = message;
51 }
52 public String getMessage() {
53 return message;
54 }
55 public void setCount(String count) {
56 this.count = count;
57 }
58 public String getCount() {
59 return count;
60 }
61
62 public void setContinue(boolean _continue) {
63 this._continue = _continue;
64 }
65 public boolean isContinue() {
66 return _continue;
67 }
68
69 /**
70 *
71 * @param state
72 * @return
73 * @throws EcclesException
74 */
75 public EcclesReturnValue doStartTag(RunState state) throws org.milligan.eccles.EcclesException {
76 boolean testVal = IfTag.evaluateBoolean(state, test);
77 if (testVal) {
78 // test is valid, possibly set count
79 if (!isEmpty(count))
80 state.addMessage(null,count);
81 return SKIP_CHILDREN;
82 }
83
84 String outMessage;
85 if (message==null)
86 outMessage="";
87 else
88 outMessage=(String)state.evaluate(message, java.lang.String.class);
89
90 state.addMessage( outMessage, type );
91 if (!_continue)
92 throw new AssertionException( state, test+" : "+outMessage );
93 return SKIP_CHILDREN;
94 }
95
96 }