View Javadoc

1   package org.apache.maven.jelly.tags.maven;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
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      /* (non-Javadoc)
41       * @see org.apache.commons.jelly.Tag#doTag(org.apache.commons.jelly.XMLOutput)
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 }