1 package org.apache.maven.jelly.tags.maven;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import org.apache.commons.jelly.JellyTagException;
22 import org.apache.commons.jelly.XMLOutput;
23 import org.apache.maven.jelly.tags.BaseTagSupport;
24
25 /**
26 * A tag to check parameters are being passed correctly
27 */
28 public class ParamCheck
29 extends BaseTagSupport
30 {
31 /** the value to check */
32 private String value;
33
34 /** the message to display when value is empty */
35 private String message;
36
37 /** whether to fail or not */
38 private boolean fail;
39
40
41
42
43 public void doTag( XMLOutput output )
44 throws JellyTagException
45 {
46 if ( ( value == null ) || "".equals( value.trim() ) )
47 {
48 if ( fail )
49 {
50 throw new JellyTagException( getMessage() );
51 }
52 else
53 {
54 System.out.println( getMessage() );
55 }
56 }
57 }
58
59 /**
60 * @param failOrNot whether this tag should throw an exception if the value is empty
61 */
62 public void setFail( boolean failOrNot )
63 {
64 fail = failOrNot;
65 }
66
67 /**
68 * @return the message field if not null, or the body of the tag if it is
69 */
70 public String getMessage()
71 throws JellyTagException
72 {
73 if ( message == null )
74 {
75 return getBodyText();
76 }
77 else
78 {
79 return message;
80 }
81
82 }
83
84 /**
85 * @param string the message to display when the value is empty
86 */
87 public void setMessage( String string )
88 {
89 message = string;
90 }
91
92 /**
93 * @param string the value to check
94 */
95 public void setValue( String string )
96 {
97 value = string;
98 }
99
100 }