1 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 28 public class UploadDefinition extends AbstractWidgetDefinition { 29 private ValueChangedListener listener; 30 private boolean required; 31 private String mimeTypes; 32 33 public UploadDefinition() { 34 this.mimeTypes = null; 35 this.required = false; 36 } 37 38 public UploadDefinition(boolean required, String mimeTypes) { 39 this.required = required; 40 this.mimeTypes = mimeTypes; 41 } 42 43 46 public void initializeFrom(WidgetDefinition definition) throws Exception { 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); this.listener = WidgetEventMulticaster.add(this.listener, other.listener); 55 56 } else { 57 throw new Exception ("Definition to inherit from is not of the right type! (at "+getLocation()+")"); 58 } 59 } 60 61 public void addMimeTypes(String 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 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 |