KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > condition > IsNotWhitespace


1 /**
2  * $Id: IsNotWhitespace.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2002-2005 iDare Media, Inc. All rights reserved.
4  *
5  * Originally written by iDare Media, Inc. for release into the public domain. This
6  * library, source form and binary form, is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2.1 of the License, or (at your option) any
9  * later version.<p>
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU LGPL (GNU Lesser General Public License) for more details.<p>
14  *
15  * You should have received a copy of the GNU Lesser General Public License along with this
16  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
17  * 330, Boston, MA 02111-1307 USA. The LGPL can be found online at
18  * http://www.fsf.org/copyleft/lesser.html<p>
19  *
20  * This product has been influenced by several projects within the open-source community.
21  * The JWare developers wish to acknowledge the open-source community's support. For more
22  * information regarding the open-source products used within JWare, please visit the
23  * JWare website.
24  *----------------------------------------------------------------------------------------*
25  * WEBSITE- http://www.jware.info EMAIL- inquiries@jware.info
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx.condition;
30
31 import com.idaremedia.antx.FlexString;
32 import com.idaremedia.antx.helpers.Tk;
33 import com.idaremedia.antx.parameters.Handling;
34 import com.idaremedia.antx.parameters.MalformedCheckEnabled;
35
36 /**
37  * Simple Is-Not-Whitespace condition check. Example usage:
38  * <pre>
39  * &lt;isnotwhitespace value="${module.title}"/&gt;
40  * &lt;isnotwhitespace property="_loop.module.title"/&gt;
41  * &lt;isnotwhitespace value="${project.id}" malformed="reject"/&gt;
42  *</pre>
43  *
44  * @since JWare/AntX 0.1
45  * @author ssmc, &copy;2002-2005 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
46  * @version 0.5
47  * @.safety single
48  * @.group api,infra
49  **/

50
51 public class IsNotWhitespace extends SimpleFlexCondition
52     implements MalformedCheckEnabled
53 {
54     /**
55      * Initializes new IsNotWhitespace condition.
56      **/

57     public IsNotWhitespace()
58     {
59     }
60
61
62     /**
63      * Creates defined IsNotWhitespace condition.
64      * @param value the value against which condition checks
65      **/

66     public IsNotWhitespace(String JavaDoc value)
67     {
68         setValue(value);
69     }
70
71
72
73     /**
74      * Sets condition string used by evaluation method.
75      * @param value the value (non-null)
76      **/

77     public void setValue(String JavaDoc value)
78     {
79         require_(value!=null,"setValu- nonzro");
80         setLiteral(value);
81     }
82
83
84
85     /**
86      * Tells this condition to check for failed property
87      * substitution. When property substitution fails, the default
88      * Ant behavior is to leave the property reference as the
89      * value. This option allows the condition user to specify
90      * how to interpret this situation.
91      * @param response how to handle unresolved references
92      * @since JWare/AntX 0.4
93      **/

94     public void setMalformed(Handling response)
95     {
96         m_testFailedSubst = !Handling.isYes(response,Handling.REJECT);
97     }
98
99
100     /**
101      * Returns how this condition will handle unresolved
102      * properties. Returnes either "accept" or "reject".
103      * @since JWare/AntX 0.4
104      **/

105     public Handling getMalformedHandling()
106     {
107         return m_testFailedSubst ? Handling.REJECT : Handling.ACCEPT;
108     }
109
110
111     /**
112      * Returns <i>true</i> if the condition value is not
113      * all whitespace.
114      **/

115     public boolean eval()
116     {
117         verifyCanEvaluate_("eval");
118
119         FlexString xv = getValueHelper();
120         String JavaDoc value = xv.getValue();
121         boolean notWS = !Tk.isWhitespace(value);
122
123         if (notWS && m_testFailedSubst) {
124             if (xv.isProperty()) {
125                 if (!LocalPropertyExaminer.verifyProperty
126                     (getProject(), xv)) {
127                     notWS=false;
128                 }
129             } else {
130                 if (!LocalPropertyExaminer.verifyLiteral
131                     (getProject(), xv)) {
132                     notWS=false;
133                 }
134             }
135         }
136         return notWS;
137     }
138
139
140     private boolean m_testFailedSubst= true;//NB:reject unresolved
141
}
142
143 /* end-of-IsNotWhitespace.java */
144
Popular Tags