1 16 package org.apache.myfaces.custom.fileupload; 17 18 import org.apache.myfaces.component.UserRoleAware; 19 import org.apache.myfaces.component.UserRoleUtils; 20 21 import javax.faces.component.html.HtmlInputText; 22 import javax.faces.context.FacesContext; 23 import javax.faces.el.ValueBinding; 24 25 29 public class HtmlInputFileUpload 30 extends HtmlInputText 31 implements UserRoleAware 32 { 33 public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlInputFileUpload"; 34 public static final String COMPONENT_FAMILY = "javax.faces.Input"; 35 private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.FileUpload"; 36 37 private String _accept = null; 38 private String _enabledOnUserRole = null; 39 private String _visibleOnUserRole = null; 40 41 private String _storage = null; 42 43 public HtmlInputFileUpload() 44 { 45 setRendererType(DEFAULT_RENDERER_TYPE); 46 } 47 48 public void setUploadedFile(UploadedFile upFile) 49 { 50 setValue(upFile); 51 } 52 53 public UploadedFile getUploadedFile() 54 { 55 return (UploadedFile)getValue(); 56 } 57 58 public String getStorage() { 59 if (_storage != null) return _storage; 60 ValueBinding vb = getValueBinding("storage"); 61 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 62 63 } 64 65 public void setStorage(String string) { 66 _storage = string; 67 } 68 69 public String getFamily() 70 { 71 return COMPONENT_FAMILY; 72 } 73 74 public void setAccept(String accept) 75 { 76 _accept = accept; 77 } 78 79 public String getAccept() 80 { 81 if (_accept != null) return _accept; 82 ValueBinding vb = getValueBinding("accept"); 83 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 84 } 85 86 public void setEnabledOnUserRole(String enabledOnUserRole) 87 { 88 _enabledOnUserRole = enabledOnUserRole; 89 } 90 91 public String getEnabledOnUserRole() 92 { 93 if (_enabledOnUserRole != null) return _enabledOnUserRole; 94 ValueBinding vb = getValueBinding("enabledOnUserRole"); 95 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 96 } 97 98 public void setVisibleOnUserRole(String visibleOnUserRole) 99 { 100 _visibleOnUserRole = visibleOnUserRole; 101 } 102 103 public String getVisibleOnUserRole() 104 { 105 if (_visibleOnUserRole != null) return _visibleOnUserRole; 106 ValueBinding vb = getValueBinding("visibleOnUserRole"); 107 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 108 } 109 110 111 public boolean isRendered() 112 { 113 if (!UserRoleUtils.isVisibleOnUserRole(this)) return false; 114 return super.isRendered(); 115 } 116 117 public Object saveState(FacesContext context) 118 { 119 Object values[] = new Object [5]; 120 values[0] = super.saveState(context); 121 values[1] = _accept; 122 values[2] = _enabledOnUserRole; 123 values[3] = _visibleOnUserRole; 124 values[4] = _storage; 125 return ((Object ) (values)); 126 } 127 128 public void restoreState(FacesContext context, Object state) 129 { 130 Object values[] = (Object [])state; 131 super.restoreState(context, values[0]); 132 _accept = (String )values[1]; 133 _enabledOnUserRole = (String )values[2]; 134 _visibleOnUserRole = (String )values[3]; 135 _storage = (String )values[4]; 136 } 137 } 138 | Popular Tags |