KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > validation > impl > JavaScriptValidatorBuilder


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.forms.validation.impl;
17
18 import org.apache.avalon.framework.context.Context;
19 import org.apache.avalon.framework.context.ContextException;
20 import org.apache.avalon.framework.context.Contextualizable;
21 import org.apache.avalon.framework.thread.ThreadSafe;
22 import org.apache.cocoon.forms.formmodel.WidgetDefinition;
23 import org.apache.cocoon.forms.util.JavaScriptHelper;
24 import org.apache.cocoon.forms.validation.WidgetValidator;
25 import org.apache.cocoon.forms.validation.WidgetValidatorBuilder;
26 import org.mozilla.javascript.Function;
27 import org.w3c.dom.Element JavaDoc;
28
29 /**
30  * Builds a JavaScript validator.
31  *
32  * @see org.apache.cocoon.forms.validation.impl.JavaScriptValidator
33  * @author <a HREF="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
34  * @version $Id: JavaScriptValidatorBuilder.java 289538 2005-09-16 13:46:22Z sylvain $
35  */

36 public class JavaScriptValidatorBuilder
37     implements WidgetValidatorBuilder, Contextualizable, ThreadSafe {
38
39     private Context avalonContext;
40     
41     private static final String JavaDoc[] ARG_NAMES = {"widget"};
42
43     /* (non-Javadoc)
44      * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
45      */

46     public void contextualize(Context context) throws ContextException {
47         this.avalonContext = context;
48     }
49
50     /* (non-Javadoc)
51      * @see org.apache.cocoon.forms.validation.ValidatorBuilder#build(org.apache.cocoon.forms.formmodel.WidgetDefinition, org.w3c.dom.Element)
52      */

53     public WidgetValidator build(Element JavaDoc element, WidgetDefinition definition) throws Exception JavaDoc {
54             Function function = JavaScriptHelper.buildFunction(element, "validate", ARG_NAMES);
55
56             return new JavaScriptValidator(this.avalonContext, function);
57     }
58 }
59
Popular Tags