01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.forms.validation.impl;
18:
19: import org.apache.avalon.framework.configuration.Configurable;
20: import org.apache.avalon.framework.configuration.Configuration;
21: import org.apache.avalon.framework.configuration.ConfigurationException;
22: import org.apache.cocoon.forms.FormsConstants;
23: import org.apache.cocoon.forms.util.DomHelper;
24: import org.apache.cocoon.forms.validation.ValidationError;
25: import org.apache.cocoon.util.ConfigurationUtil;
26: import org.apache.excalibur.xml.sax.XMLizable;
27: import org.w3c.dom.Element;
28:
29: /**
30: * Abstract base class for implementing an own Java validator which gets build by
31: * the {@link JavaClassValidatorBuilder}.
32: *
33: * @version $Id: AbstractJavaValidator.java 449149 2006-09-23 03:58:05Z crossley $
34: */
35: public abstract class AbstractJavaValidator implements Configurable {
36:
37: protected ValidationError validationError;
38:
39: /**
40: * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
41: */
42: public void configure(Configuration config)
43: throws ConfigurationException {
44: final Element element = ConfigurationUtil.toElement(config);
45: this .validationError = this .buildFailMessage(element);
46: }
47:
48: /**
49: * Checks if the validation rule configuration contains a custom failmessage, and if so,
50: * sets it one the ValidationRule.
51: */
52: protected ValidationError buildFailMessage(
53: Element validationRuleElement) {
54: Element failMessageElement = DomHelper.getChildElement(
55: validationRuleElement, FormsConstants.DEFINITION_NS,
56: "failmessage");
57: if (failMessageElement != null) {
58: XMLizable failMessage = DomHelper
59: .compileElementContent(failMessageElement);
60: return new ValidationError(failMessage);
61: }
62: return this .getDefaultFailMessage();
63: }
64:
65: protected abstract ValidationError getDefaultFailMessage();
66: }
|