KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > custom > fileupload > HtmlInputFileUpload


1 /*
2  * Copyright 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.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 /**
26  * @author Manfred Geiler (latest modification by $Author: matze $)
27  * @version $Revision: 1.6 $ $Date: 2004/10/13 11:50:57 $
28  */

29 public class HtmlInputFileUpload
30         extends HtmlInputText
31         implements UserRoleAware
32 {
33     public static final String JavaDoc COMPONENT_TYPE = "org.apache.myfaces.HtmlInputFileUpload";
34     public static final String JavaDoc COMPONENT_FAMILY = "javax.faces.Input";
35     private static final String JavaDoc DEFAULT_RENDERER_TYPE = "org.apache.myfaces.FileUpload";
36
37     private String JavaDoc _accept = null;
38     private String JavaDoc _enabledOnUserRole = null;
39     private String JavaDoc _visibleOnUserRole = null;
40
41     private String JavaDoc _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 JavaDoc getStorage() {
59         if (_storage != null) return _storage;
60         ValueBinding vb = getValueBinding("storage");
61         return vb != null ? (String JavaDoc)vb.getValue(getFacesContext()) : null;
62
63     }
64
65     public void setStorage(String JavaDoc string) {
66         _storage = string;
67     }
68
69     public String JavaDoc getFamily()
70     {
71         return COMPONENT_FAMILY;
72     }
73
74     public void setAccept(String JavaDoc accept)
75     {
76         _accept = accept;
77     }
78
79     public String JavaDoc getAccept()
80     {
81         if (_accept != null) return _accept;
82         ValueBinding vb = getValueBinding("accept");
83         return vb != null ? (String JavaDoc)vb.getValue(getFacesContext()) : null;
84     }
85
86     public void setEnabledOnUserRole(String JavaDoc enabledOnUserRole)
87     {
88         _enabledOnUserRole = enabledOnUserRole;
89     }
90
91     public String JavaDoc getEnabledOnUserRole()
92     {
93         if (_enabledOnUserRole != null) return _enabledOnUserRole;
94         ValueBinding vb = getValueBinding("enabledOnUserRole");
95         return vb != null ? (String JavaDoc)vb.getValue(getFacesContext()) : null;
96     }
97
98     public void setVisibleOnUserRole(String JavaDoc visibleOnUserRole)
99     {
100         _visibleOnUserRole = visibleOnUserRole;
101     }
102
103     public String JavaDoc getVisibleOnUserRole()
104     {
105         if (_visibleOnUserRole != null) return _visibleOnUserRole;
106         ValueBinding vb = getValueBinding("visibleOnUserRole");
107         return vb != null ? (String JavaDoc)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 JavaDoc saveState(FacesContext context)
118     {
119         Object JavaDoc values[] = new Object JavaDoc[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 JavaDoc) (values));
126     }
127
128     public void restoreState(FacesContext context, Object JavaDoc state)
129     {
130         Object JavaDoc values[] = (Object JavaDoc[])state;
131         super.restoreState(context, values[0]);
132         _accept = (String JavaDoc)values[1];
133         _enabledOnUserRole = (String JavaDoc)values[2];
134         _visibleOnUserRole = (String JavaDoc)values[3];
135         _storage = (String JavaDoc)values[4];
136     }
137 }
138
Popular Tags