KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > validation > ValidationError


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.woody.validation;
17
18 import org.xml.sax.ContentHandler JavaDoc;
19 import org.xml.sax.SAXException JavaDoc;
20 import org.apache.cocoon.woody.util.I18nMessage;
21 import org.apache.cocoon.woody.util.StringMessage;
22 import org.apache.excalibur.xml.sax.XMLizable;
23
24 /**
25  * An object that holds a validation error message. The error message can
26  * be a simple string or a piece of XML.
27  *
28  * @author <a HREF="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
29  * @version CVS $Id: ValidationError.java 30932 2004-07-29 17:35:38Z vgritsenko $
30  */

31 public class ValidationError {
32
33     /** Holds the error message. */
34     private XMLizable saxFragment;
35
36     /**
37      * @param i18n should the errorMessage be interpreted as an i18n key?
38      */

39     public ValidationError(String JavaDoc errorMessage, boolean i18n) {
40         if (i18n) {
41             saxFragment = new I18nMessage(errorMessage);
42         } else {
43             saxFragment = new StringMessage(errorMessage);
44         }
45     }
46
47     /**
48      * @see I18nMessage#I18nMessage(java.lang.String)
49      */

50     public ValidationError(String JavaDoc errorMessageKey) {
51         this.saxFragment = new I18nMessage(errorMessageKey);
52     }
53
54     /**
55      * @see I18nMessage#I18nMessage(java.lang.String, java.lang.String[])
56      */

57     public ValidationError(String JavaDoc errorMessageKey, String JavaDoc[] parameters) {
58         this.saxFragment = new I18nMessage(errorMessageKey, parameters);
59     }
60
61     /**
62      * @see I18nMessage#I18nMessage(java.lang.String, java.lang.String[], boolean[])
63      */

64     public ValidationError(String JavaDoc errorMessageKey, String JavaDoc[] parameters, boolean[] keys) {
65         this.saxFragment = new I18nMessage(errorMessageKey, parameters, keys);
66     }
67
68     /**
69      * @param errorMessage the errormessages in the form of something that is "XMLizable",
70      * i.e. can produce SAX events. It should however not produce start/endDocument calls,
71      * only a piece of embeddable, stand-alone SAX events. Helpful implementations are
72      * {@link org.apache.cocoon.xml.SaxBuffer SaxBuffer}, {@link I18nMessage} or {@link StringMessage}.
73      */

74     public ValidationError(XMLizable errorMessage) {
75         this.saxFragment = errorMessage;
76     }
77
78     /**
79      * Generates SAX events for this ValidationError. In case of the constructors where
80      * a String error message key was supplied, the necessary I18n tags will be generated.
81      */

82     public void generateSaxFragment(ContentHandler JavaDoc contentHandler) throws SAXException JavaDoc {
83         if (saxFragment != null) {
84             saxFragment.toSAX(contentHandler);
85         }
86     }
87 }
88
Popular Tags