KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cayenne > tutorial > tapestry > pages > EditorPage


1 package cayenne.tutorial.tapestry.pages;
2
3
4 /**
5  * @author Eric Schneider
6  *
7  * A wedge class that handles and displays all user input
8  * validation errors.
9  */

10 public class EditorPage extends ApplicationPage {
11
12     /** A human presentable error message. Should never be null. */
13     protected String JavaDoc errorMessage;
14
15     public void initialize() {
16         super.initialize();
17
18         setErrorMessage("");
19     }
20
21     public String JavaDoc getErrorMessage() {
22         return errorMessage;
23     }
24
25     /** Sets the error message. If the argument is null,
26      * it will set the error message to the empty string.
27      *
28      * @param The new error message. Should not be null.
29      */

30     public void setErrorMessage(String JavaDoc errorMessage) {
31         if (errorMessage == null) {
32             this.errorMessage = "";
33         }
34         else {
35             this.errorMessage = errorMessage;
36         }
37     }
38
39     /** Appends the argument to the error message. Ensures that
40       * the argument does not already exist in the error message.
41       *
42       * @param The string to be appended to the error message.
43       */

44     public void appendToErrorMessage(String JavaDoc appendix) {
45         if ((appendix != null) && (errorMessageContainsString(appendix) == false)) {
46             setErrorMessage(getErrorMessage().concat(appendix));
47         }
48     }
49
50     /** Appends the argument to the error message. Assumes it is HTML
51       * and prepends an HTML break tag to the appendix.
52       *
53       * @param The string to be appended to the error message, assumed to be HTML.
54       */

55     public void appendHtmlToErrorMessage(String JavaDoc htmlAppendix) {
56         if ((htmlAppendix != null)
57             && (errorMessageContainsString(htmlAppendix) == false)) {
58             StringBuffer JavaDoc newAppendix;
59
60             newAppendix = new StringBuffer JavaDoc();
61             if (getErrorMessage().length() != 0) {
62                 newAppendix.append("<BR>");
63             }
64
65             newAppendix.append(htmlAppendix);
66
67             appendToErrorMessage(newAppendix.toString());
68         }
69     }
70
71     /** Checks to see if the argument is already in the error message.
72       * If the argument is null, returns true. Trims the argument for
73       * matching purposes.
74       *
75       * @param The String to check the error message to see if it contains it.
76       * @return true if the string is already in the error message, false otherwise.
77       */

78     public boolean errorMessageContainsString(String JavaDoc text) {
79         if (text == null) {
80             return true;
81         }
82
83         if (getErrorMessage().indexOf(text.trim()) == -1) {
84             return false;
85         }
86         else {
87             return true;
88         }
89     }
90
91     /** Returns true if the error message is non-empty (i.e., length > 0).
92       *
93       * @return true if the error message is not empty.
94       */

95     public boolean getHasErrorMessage() {
96         if (getErrorMessage().length() > 0) {
97             return true;
98         }
99         else {
100             return false;
101         }
102     }
103
104     public boolean assertNotNull(Object JavaDoc anObject) {
105         if (anObject == null) {
106             return false;
107         }
108
109         if ((anObject instanceof String JavaDoc) && ("".equals(anObject))) {
110             return false;
111         }
112
113         return true;
114     }
115 }
116
Popular Tags