KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > 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.woody.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.woody.formmodel.WidgetDefinition;
23 import org.apache.cocoon.woody.util.JavaScriptHelper;
24 import org.apache.cocoon.woody.validation.WidgetValidator;
25 import org.apache.cocoon.woody.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.woody.validation.impl.JavaScriptValidator
33  * @author <a HREF="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
34  * @version CVS $Id: JavaScriptValidatorBuilder.java 30932 2004-07-29 17:35:38Z vgritsenko $
35  */

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

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

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