KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.cocoon.forms.event.ValueChangedListener;
19 import org.apache.cocoon.forms.event.WidgetEventMulticaster;
20
21 /**
22  * The definition of an upload widget.
23  *
24  * @author <a HREF="mailto:uv@upaya.co.uk">Upayavira</a>
25  * @author <a HREF="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
26  * @version $Id: UploadDefinition.java 327208 2005-10-21 15:30:51Z sylvain $
27  */

28 public class UploadDefinition extends AbstractWidgetDefinition {
29     private ValueChangedListener listener;
30     private boolean required;
31     private String JavaDoc mimeTypes;
32     
33     public UploadDefinition() {
34         this.mimeTypes = null;
35         this.required = false;
36     }
37     
38     public UploadDefinition(boolean required, String JavaDoc mimeTypes) {
39         this.required = required;
40         this.mimeTypes = mimeTypes;
41     }
42     
43     /**
44      * initialize this definition with the other, sort of like a copy constructor
45      */

46     public void initializeFrom(WidgetDefinition definition) throws Exception JavaDoc {
47         super.initializeFrom(definition);
48         
49         if(definition instanceof UploadDefinition) {
50             UploadDefinition other = (UploadDefinition)definition;
51             
52             this.required = other.required;
53             this.mimeTypes = other.mimeTypes.substring(0); // deep copy
54
this.listener = WidgetEventMulticaster.add(this.listener, other.listener);
55             
56         } else {
57             throw new Exception JavaDoc("Definition to inherit from is not of the right type! (at "+getLocation()+")");
58         }
59     }
60     
61     public void addMimeTypes(String JavaDoc types) {
62         if(types != null) {
63             if(mimeTypes == null)
64                 mimeTypes = types;
65             else {
66                 if(mimeTypes.length()>0)
67                     mimeTypes += ", ";
68                 mimeTypes += types;
69             }
70         }
71     }
72     
73     public void setRequired(boolean required) {
74         checkMutable();
75         this.required = required;
76     }
77
78     public Widget createInstance() {
79         Upload upload = new Upload(this);
80         return upload;
81     }
82
83     public boolean isRequired() {
84         return required;
85     }
86     
87     public String JavaDoc getMimeTypes() {
88         return this.mimeTypes;
89     }
90
91     public void addValueChangedListener(ValueChangedListener listener) {
92         checkMutable();
93         this.listener = WidgetEventMulticaster.add(this.listener, listener);
94     }
95     
96     public ValueChangedListener getValueChangedListener() {
97         return this.listener;
98     }
99     
100     public boolean hasValueChangedListeners() {
101         return listener != null;
102     }
103 }
104
Popular Tags