001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.forms.formmodel;
018:
019: import org.apache.cocoon.forms.FormsException;
020: import org.apache.cocoon.forms.event.ValueChangedListener;
021: import org.apache.cocoon.forms.event.WidgetEventMulticaster;
022:
023: /**
024: * The definition of an upload widget.
025: *
026: * @version $Id: UploadDefinition.java 449149 2006-09-23 03:58:05Z crossley $
027: */
028: public class UploadDefinition extends AbstractWidgetDefinition {
029: private ValueChangedListener listener;
030: private boolean required;
031: private String mimeTypes;
032:
033: public UploadDefinition() {
034: this .mimeTypes = null;
035: this .required = false;
036: }
037:
038: public UploadDefinition(boolean required, String mimeTypes) {
039: this .required = required;
040: this .mimeTypes = mimeTypes;
041: }
042:
043: /**
044: * initialize this definition with the other, sort of like a copy constructor
045: */
046: public void initializeFrom(WidgetDefinition definition)
047: throws Exception {
048: super .initializeFrom(definition);
049:
050: if (!(definition instanceof UploadDefinition)) {
051: throw new FormsException("Ancestor definition "
052: + definition.getClass().getName()
053: + " is not an UploadDefinition.", getLocation());
054: }
055:
056: UploadDefinition other = (UploadDefinition) definition;
057:
058: this .required = other.required;
059: this .mimeTypes = other.mimeTypes;
060: this .listener = WidgetEventMulticaster.add(this .listener,
061: other.listener);
062: }
063:
064: public void addMimeTypes(String types) {
065: if (types != null) {
066: if (mimeTypes == null)
067: mimeTypes = types;
068: else {
069: if (mimeTypes.length() > 0)
070: mimeTypes += ", ";
071: mimeTypes += types;
072: }
073: }
074: }
075:
076: public void setRequired(boolean required) {
077: checkMutable();
078: this .required = required;
079: }
080:
081: public Widget createInstance() {
082: return new Upload(this );
083: }
084:
085: public boolean isRequired() {
086: return required;
087: }
088:
089: public String getMimeTypes() {
090: return this .mimeTypes;
091: }
092:
093: public void addValueChangedListener(ValueChangedListener listener) {
094: checkMutable();
095: this .listener = WidgetEventMulticaster.add(this .listener,
096: listener);
097: }
098:
099: public ValueChangedListener getValueChangedListener() {
100: return this .listener;
101: }
102:
103: public boolean hasValueChangedListeners() {
104: return listener != null;
105: }
106: }
|