KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > formmodel > UploadDefinitionBuilder


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.formmodel;
17
18 import java.util.Iterator JavaDoc;
19
20 import org.apache.cocoon.forms.event.ValueChangedListener;
21 import org.apache.cocoon.forms.util.DomHelper;
22 import org.w3c.dom.Element JavaDoc;
23
24 /**
25  * Builds {@link org.apache.cocoon.forms.formmodel.UploadDefinition}s.
26  *
27  * @author <a HREF="mailto:uv@upaya.co.uk">Upayavira</a>
28  * @author <a HREF="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
29  * @version $Id: UploadDefinitionBuilder.java 327208 2005-10-21 15:30:51Z sylvain $
30  */

31 public final class UploadDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
32
33     public WidgetDefinition buildWidgetDefinition(Element JavaDoc widgetElement) throws Exception JavaDoc {
34         String JavaDoc mimeTypes = DomHelper.getAttribute(widgetElement, "mime-types", null);
35         
36         UploadDefinition uploadDefinition = new UploadDefinition();
37         super.setupDefinition(widgetElement, uploadDefinition);
38
39         setDisplayData(widgetElement, uploadDefinition);
40         Iterator JavaDoc iter = buildEventListeners(widgetElement, "on-value-changed", ValueChangedListener.class).iterator();
41         while (iter.hasNext()) {
42             uploadDefinition.addValueChangedListener((ValueChangedListener)iter.next());
43         }
44
45         
46         if(widgetElement.hasAttribute("required"))
47             uploadDefinition.setRequired(DomHelper.getAttributeAsBoolean(widgetElement, "required", false));
48         
49         uploadDefinition.addMimeTypes(mimeTypes);
50
51         uploadDefinition.makeImmutable();
52         return uploadDefinition;
53     }
54 }
55
Popular Tags