KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > component > inputfile > InputFile


1 /*
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * "The contents of this file are subject to the Mozilla Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11  * License for the specific language governing rights and limitations under
12  * the License.
13  *
14  * The Original Code is ICEfaces 1.5 open source software code, released
15  * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
16  * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
17  * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
18  *
19  * Contributor(s): _____________________.
20  *
21  * Alternatively, the contents of this file may be used under the terms of
22  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
23  * License), in which case the provisions of the LGPL License are
24  * applicable instead of those above. If you wish to allow use of your
25  * version of this file only under the terms of the LGPL License and not to
26  * allow others to use your version of this file under the MPL, indicate
27  * your decision by deleting the provisions above and replace them with
28  * the notice and other provisions required by the LGPL License. If you do
29  * not delete the provisions above, a recipient may use your version of
30  * this file under either the MPL or the LGPL License."
31  *
32  */

33
34 package com.icesoft.faces.component.inputfile;
35
36 import com.icesoft.faces.component.CSS_DEFAULT;
37 import com.icesoft.faces.component.ext.taglib.Util;
38 import com.icesoft.faces.component.style.OutputStyle;
39 import com.icesoft.faces.context.BridgeFacesContext;
40 import com.icesoft.faces.util.CoreUtils;
41 import com.icesoft.faces.utils.MessageUtils;
42 import com.icesoft.faces.webapp.http.servlet.FileUploadComponent;
43 import com.icesoft.faces.webapp.xmlhttp.PersistentFacesState;
44 import org.apache.commons.fileupload.FileItemStream;
45 import org.apache.commons.fileupload.FileUploadBase;
46 import org.apache.commons.fileupload.util.Streams;
47 import org.apache.commons.logging.Log;
48 import org.apache.commons.logging.LogFactory;
49
50 import javax.faces.component.UICommand;
51 import javax.faces.component.UIComponent;
52 import javax.faces.context.FacesContext;
53 import javax.faces.context.ExternalContext;
54 import javax.faces.el.MethodBinding;
55 import javax.faces.el.ValueBinding;
56 import javax.faces.event.ActionEvent;
57 import javax.faces.event.ActionListener;
58 import javax.servlet.ServletContext JavaDoc;
59
60 import java.io.File JavaDoc;
61 import java.io.FileOutputStream JavaDoc;
62 import java.io.IOException JavaDoc;
63 import java.io.OutputStream JavaDoc;
64 import java.io.Serializable JavaDoc;
65 import java.io.Writer JavaDoc;
66 import java.util.ArrayList JavaDoc;
67 import java.util.EventObject JavaDoc;
68 import java.util.Iterator JavaDoc;
69
70
71 /**
72  * InputFile is a JSF component class representing an ICEfaces inputFile.
73  */

74 public class InputFile extends UICommand implements Serializable JavaDoc, FileUploadComponent {
75     private static final Log log = LogFactory.getLog(InputFile.class);
76     
77     public static final int DEFAULT = 0;
78     public static final int UPLOADING = 1;
79     public static final int SAVED = 2;
80     public static final int INVALID = 3;
81     public static final int SIZE_LIMIT_EXCEEDED = 4;
82     public static final int UNKNOWN_SIZE = 5;
83     public static final int INVALID_NAME_PATTERN = 6;
84
85     public static final String JavaDoc INVALID_FILE_MESSAGE_ID = "com.icesoft.faces.component.inputfile.INVALID_FILE";
86     public static final String JavaDoc INVALID_NAME_PATTERN_MESSAGE_ID = "com.icesoft.faces.component.inputfile.INVALID_NAME_PATTERN";
87     public static final String JavaDoc SIZE_LIMIT_EXCEEDED_MESSAGE_ID = "com.icesoft.faces.component.inputfile.SIZE_LIMIT_EXCEEDED";
88     public static final String JavaDoc UNKNOWN_SIZE_MESSAGE_ID = "com.icesoft.faces.component.inputfile.UNKNOWN_SIZE";
89
90     public static final String JavaDoc FILE_UPLOAD_PREFIX = "fileUpload";
91     private Boolean JavaDoc disabled;
92     private String JavaDoc style;
93     private String JavaDoc styleClass;
94     private String JavaDoc label;
95     private String JavaDoc enabledOnUserRole;
96     private String JavaDoc renderedOnUserRole;
97     private String JavaDoc title;
98     private int height = 30;
99     private int width = 500;
100     private int inputTextSize = 35;
101     private String JavaDoc inputTextClass;
102     private String JavaDoc fileNamePattern;
103     private boolean uniqueFolder = true;
104     private boolean uniqueFolderSet = false;
105     private String JavaDoc uploadDirectory;
106     private Boolean JavaDoc uploadDirectoryAbsolute;
107     private Throwable JavaDoc uploadException;
108     private int status = DEFAULT;
109     private FileInfo fileInfo = new FileInfo();
110     private int progress = 0;
111     private File JavaDoc file;
112     private long sizeMax;
113     private MethodBinding progressListener;
114
115     /**
116      * <p>Return the value of the <code>COMPONENT_TYPE</code> of this
117      * component.</p>
118      */

119     public String JavaDoc getComponentType() {
120         return "com.icesoft.faces.File";
121     }
122
123     /**
124      * <p>Return the value of the <code>RENDERER_TYPE</code> of this
125      * component.</p>
126      */

127     public String JavaDoc getRendererType() {
128         return "com.icesoft.faces.Upload";
129     }
130
131     /**
132      * <p>Return the value of the <code>COMPONENT_FAMILY</code> of this
133      * component.</p>
134      */

135     public String JavaDoc getFamily() {
136         return "com.icesoft.faces.File";
137     }
138
139     public void upload(
140             FileItemStream stream,
141             String JavaDoc uploadDirectory,
142             boolean uploadDirectoryAbsolute,
143             long maxSize,
144             BridgeFacesContext bfc,
145             ServletContext JavaDoc servletContext,
146             String JavaDoc sessionId)
147             throws IOException JavaDoc
148     {
149         this.uploadException = null;
150         this.status = UPLOADING;
151         this.sizeMax = maxSize;
152         FacesContext context = FacesContext.getCurrentInstance();
153         // InputFile uploadDirectory attribute takes precedence,
154
// but if it's not given, then default to the
155
// com.icesoft.faces.uploadDirectory context-param
156
String JavaDoc folder = getUploadDirectory();
157         if(folder == null) {
158             folder = uploadDirectory;
159         }
160         // InputFile uploadDirectoryAbsolute attribute takes precedence,
161
// but if it's not given, then default to the
162
// com.icesoft.faces.uploadDirectoryAbsolute context-param
163
Boolean JavaDoc folderAbs = getUploadDirectoryAbsolute();
164         if(folderAbs == null) {
165             folderAbs = uploadDirectoryAbsolute ? Boolean.TRUE : Boolean.FALSE;
166         }
167         if(!folderAbs.booleanValue()) {
168             folder = servletContext.getRealPath(folder);
169         }
170         if(isUniqueFolder()) {
171             String JavaDoc FILE_SEPARATOR = System.getProperty("file.separator");
172             folder = folder + FILE_SEPARATOR + sessionId;
173         }
174         
175         String JavaDoc namePattern = getFileNamePattern().trim();
176         String JavaDoc fileName = stream.getName();
177         try {
178             if(fileName != null && fileName.length() > 0) {
179                 // IE gives us the whole path on the client, but we just
180
// want the client end file name, not the path
181
File JavaDoc tempFileName = new File JavaDoc(fileName);
182                 fileName = tempFileName.getName();
183             } else {
184                 throw new FileUploadBase.FileUploadIOException(
185                         new FileUploadBase.InvalidContentTypeException());
186             }
187             
188             fileInfo.setFileName(fileName);
189             fileInfo.setContentType(stream.getContentType());
190             if (fileName != null && fileName.trim().matches(namePattern)) {
191                 File JavaDoc folderFile = new File JavaDoc(folder);
192                 if(!folderFile.exists())
193                     folderFile.mkdirs();
194                 file = new File JavaDoc(folder, fileName);
195                 OutputStream JavaDoc output = new FileOutputStream JavaDoc(file);
196                 Streams.copy(stream.openStream(), output, true);
197                 if (file.length() == 0 ) {
198                     setProgress(0);
199                     file.delete();
200                     throw new FileUploadBase.FileUploadIOException(
201                             new FileUploadBase.InvalidContentTypeException());
202                 }
203                 status = SAVED;
204                 fileInfo.setPhysicalPath(file.getAbsolutePath());
205                 updateFileValueBinding(context);
206                 notifyDone(bfc);
207             } else {
208                 fileInfo.reset();
209                 file = null;
210                 status = INVALID_NAME_PATTERN;
211                 context.addMessage(null, MessageUtils.getMessage(context, INVALID_NAME_PATTERN_MESSAGE_ID, new Object JavaDoc[] { fileName, namePattern }));
212                 notifyDone(bfc);
213             }
214         } catch (FileUploadBase.FileUploadIOException uploadException) {
215             this.uploadException = uploadException.getCause();
216             try {
217                 throw this.uploadException;
218             } catch (FileUploadBase.FileSizeLimitExceededException e) {
219                 status = SIZE_LIMIT_EXCEEDED;
220             } catch (FileUploadBase.UnknownSizeException e) {
221                 status = UNKNOWN_SIZE;
222             } catch (FileUploadBase.InvalidContentTypeException e) {
223                 status = INVALID;
224             } catch (Throwable JavaDoc t) {
225                 status = INVALID;
226             }
227             fileInfo.setException(uploadException);
228             if(file != null)
229                 file.delete();
230             notifyDone(bfc);
231             throw uploadException;
232         }
233         catch(IOException JavaDoc e) { // Eg: If creating the saved file fails
234
this.uploadException = e;
235             status = INVALID;
236             fileInfo.setException(e);
237             if(file != null)
238                 file.delete();
239             notifyDone(bfc);
240             throw e;
241         }
242         
243         PersistentFacesState.getInstance().renderLater();
244     }
245     
246     protected void notifyDone(BridgeFacesContext bfc) {
247         ActionEvent event = new ActionEvent(this);
248
249         bfc.setCurrentInstance();
250
251         //this is true for JSF 1.1 only
252
MethodBinding actionListener = getActionListener();
253         if(actionListener != null) {
254             actionListener.invoke(
255                 FacesContext.getCurrentInstance(),
256                 new Object JavaDoc[] {event} );
257         }
258         
259         //this is true for JSF 1.2 only
260
ActionListener[] actionListeners = getActionListeners();
261         for (int i=0; i< actionListeners.length; i++) {
262             actionListeners[i].processAction(event);
263         }
264         MethodBinding action = getAction();
265         if(action != null) {
266             action.invoke(FacesContext.getCurrentInstance(), null);
267         }
268         
269         if(fileInfo != null)
270             fileInfo.reset();
271     }
272     
273     public void renderIFrame(Writer JavaDoc writer, BridgeFacesContext context) throws IOException JavaDoc {
274         writer.write("<html style=\"overflow:hidden;\">");
275         ArrayList JavaDoc outputStyleComponents = findOutputStyleComponents(context.getViewRoot());
276         if (outputStyleComponents != null)
277         {
278             writer.write("<head>");
279             for (int i = 0; i < outputStyleComponents.size(); i++)
280             {
281                 OutputStyle outputStyle = (OutputStyle) outputStyleComponents.get(i);
282                 String JavaDoc href = outputStyle.getHref();
283                 if ((href != null) && (href.length() > 0))
284                 {
285                     href = CoreUtils.resolveResourceURL(context, href);
286                     writer.write("<link rel=\"stylesheet\" type=\"text/css\" HREF=\"" + href + "\">");
287                 }
288             }
289             writer.write("</head>");
290         }
291         String JavaDoc srv = getUploadServletPath(context);
292         writer.write("<body style=\"background-color:transparent; overflow:hidden\"><form method=\"post\" action=\""+srv+"\" enctype=\"multipart/form-data\" id=\"fileUploadForm\">");
293         writer.write("<input type=\"hidden\" name=\"componentID\" value=\"");
294         writer.write(this.getClientId(context));
295         writer.write("\"/>");
296         writer.write("<input type=\"hidden\" name=\"viewNumber\"");
297         writer.write(" value=\"" + context.getViewNumber() + "\"/>");
298         writer.write("<input type=\"file\" name=\"upload\"");
299         writer.write(" size=\"" + getInputTextSize() + "\"");
300         String JavaDoc inputTextClass = getInputTextClass();
301         if (inputTextClass != null) writer.write(" class=\"" + inputTextClass + "\"");
302         String JavaDoc title = getTitle();
303         if (title != null) writer.write(" title=\"" + title +"\"");
304         writer.write("/>");
305         writer.write("<input type=\"submit\" value=\"" + getLabel() + "\"");
306         String JavaDoc buttonClass = getButtonClass();
307         if (buttonClass != null) writer.write(" class=\"" + buttonClass + "\"");
308         if (isDisabled()) writer.write(" disabled=\"disabled\"");
309         writer.write("/>");
310         writer.write("</form>");
311         writer.write("</body></html>");
312     }
313     
314     private String JavaDoc getUploadServletPath(BridgeFacesContext context) {
315         String JavaDoc requestContextPath = null;
316         if(context != null) {
317             ExternalContext externalContext = context.getExternalContext();
318             if(externalContext != null) {
319                 requestContextPath = externalContext.getRequestContextPath();
320             }
321         }
322         if(requestContextPath == null || requestContextPath.length() == 0)
323             return "./uploadHtml";
324         else
325             return requestContextPath + "/uploadHtml";
326     }
327
328     public Throwable JavaDoc getUploadException() {
329         return uploadException;
330     }
331
332     /**
333      * <p/>
334      * Set the value of the <code>label</code> property. </p>
335      */

336     public void setLabel(String JavaDoc label) {
337         this.label = label;
338     }
339
340     /**
341      * <p/>
342      * Set the value of the <code>uniqueFolder</code> property. </p>
343      */

344     public void setUniqueFolder(boolean uniqueFolder) {
345         if (uniqueFolder != this.uniqueFolder) {
346             this.uniqueFolder = uniqueFolder;
347         }
348         this.uniqueFolderSet = true;
349     }
350
351     /**
352      * <p/>
353      * Return the value of the <code>uniqueFolder</code> property. </p>
354      */

355     public boolean isUniqueFolder() {
356         if (this.uniqueFolderSet) {
357             return (this.uniqueFolder);
358         }
359         ValueBinding vb = getValueBinding("uniqueFolder");
360         if (vb != null) {
361             return (Boolean.TRUE.equals(vb.getValue(getFacesContext())));
362         }
363         return true;
364     }
365     
366     /**
367      * <p/>
368      * Return the value of the <code>label</code> property. </p>
369      */

370     public String JavaDoc getLabel() {
371         if (label != null) {
372             return label;
373         }
374         ValueBinding vb = getValueBinding("label");
375         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : "Upload";
376     }
377
378     /**
379      * <p>Return the value of the <code>disabled</code> property.</p>
380      */

381     public boolean isDisabled() {
382         if (!Util.isEnabledOnUserRole(this)) {
383             return true;
384         } else {
385             if (disabled != null) {
386                 return disabled.booleanValue();
387             }
388             ValueBinding vb = getValueBinding("disabled");
389             Boolean JavaDoc boolVal = vb != null ?
390                               (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
391             return boolVal != null ? boolVal.booleanValue() : false;
392
393         }
394
395     }
396
397     /**
398      * <p>Set the value of the <code>disabled</code> property.</p>
399      */

400     public void setDisabled(boolean disabled) {
401         this.disabled = Boolean.valueOf(disabled);
402     }
403
404     /**
405      * <p>Set the value of the <code>enabledOnUserRole</code> property.</p>
406      */

407     public void setEnabledOnUserRole(String JavaDoc enabledOnUserRole) {
408         this.enabledOnUserRole = enabledOnUserRole;
409     }
410
411     /**
412      * <p>Return the value of the <code>enabledOnUserRole</code> property.</p>
413      */

414     public String JavaDoc getEnabledOnUserRole() {
415         if (enabledOnUserRole != null) {
416             return enabledOnUserRole;
417         }
418         ValueBinding vb = getValueBinding("enabledOnUserRole");
419         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
420     }
421
422
423     public void setUploadDirectory(String JavaDoc uploadDirectory) {
424         this.uploadDirectory = uploadDirectory;
425     }
426
427     public String JavaDoc getUploadDirectory() {
428         if (uploadDirectory != null) {
429             return uploadDirectory;
430         }
431         ValueBinding vb = getValueBinding("uploadDirectory");
432         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
433     }
434     
435     public void setUploadDirectoryAbsolute(Boolean JavaDoc uploadDirectoryAbsolute) {
436         this.uploadDirectoryAbsolute = uploadDirectoryAbsolute;
437     }
438     
439     public Boolean JavaDoc getUploadDirectoryAbsolute() {
440         if (uploadDirectoryAbsolute != null) {
441             return uploadDirectoryAbsolute;
442         }
443         ValueBinding vb = getValueBinding("uploadDirectoryAbsolute");
444         return vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
445     }
446
447     /**
448      * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
449      */

450     public void setRenderedOnUserRole(String JavaDoc renderedOnUserRole) {
451         this.renderedOnUserRole = renderedOnUserRole;
452     }
453
454     /**
455      * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
456      */

457     public String JavaDoc getRenderedOnUserRole() {
458         if (renderedOnUserRole != null) {
459             return renderedOnUserRole;
460         }
461         ValueBinding vb = getValueBinding("renderedOnUserRole");
462         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
463     }
464
465     /**
466      * <p>Return the value of the <code>rendered</code> property.</p>
467      */

468     public boolean isRendered() {
469         if (!Util.isRenderedOnUserRole(this)) {
470             return false;
471         }
472         return super.isRendered();
473     }
474
475     /**
476      * <p>Set the value of the <code>style</code> property.</p>
477      */

478     public void setStyle(String JavaDoc style) {
479         this.style = style;
480     }
481
482     /**
483      * <p>Return the value of the <code>style</code> property.</p>
484      */

485     public String JavaDoc getStyle() {
486         if (style != null) {
487             return style;
488         }
489         ValueBinding vb = getValueBinding("style");
490         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) :
491                "border-collapse:collapse; border-spacing:0px; padding:0px;";
492     }
493
494     /**
495      * <p>Set the value of the <code>styleClass</code> property.</p>
496      */

497     public void setStyleClass(String JavaDoc styleClass) {
498         this.styleClass = styleClass;
499     }
500
501     /**
502      * <p>Return the value of the <code>styleClass</code> property.</p>
503      */

504     public String JavaDoc getStyleClass() {
505         return Util.getQualifiedStyleClass(this,
506                             styleClass,
507                             CSS_DEFAULT.ICE_FILE_UPLOAD_BASE_CLASS,
508                             "styleClass",
509                             isDisabled());
510     }
511
512     /**
513      * <p>Gets the state of the instance as a <code>Serializable</code>
514      * Object.</p>
515      */

516     public Object JavaDoc saveState(FacesContext context) {
517         Object JavaDoc values[] = new Object JavaDoc[24];
518         values[0] = super.saveState(context);
519         values[1] = disabled;
520         values[2] = style;
521         values[3] = styleClass;
522         values[4] = label;
523         values[5] = enabledOnUserRole;
524         values[6] = renderedOnUserRole;
525         values[7] = title;
526         values[8] = new Integer JavaDoc(height);
527         values[9] = new Integer JavaDoc(width);
528         values[10] = new Integer JavaDoc(inputTextSize);
529         values[11] = inputTextClass;
530         values[12] = fileNamePattern;
531         values[13] = uniqueFolder ? Boolean.TRUE : Boolean.FALSE;
532         values[14] = uniqueFolderSet ? Boolean.TRUE : Boolean.FALSE;
533         values[15] = uploadDirectory;
534         values[16] = uploadDirectoryAbsolute;
535         values[17] = uploadException;
536         values[18] = new Integer JavaDoc(status);
537         values[19] = fileInfo;
538         values[20] = new Integer JavaDoc(progress);
539         values[21] = file;
540         values[22] = new Long JavaDoc(sizeMax);
541         values[23] = saveAttachedState(context, progressListener);
542         return ((Object JavaDoc) (values));
543     }
544
545     /**
546      * <p>Perform any processing required to restore the state from the entries
547      * in the state Object.</p>
548      */

549     public void restoreState(FacesContext context, Object JavaDoc state) {
550         Object JavaDoc values[] = (Object JavaDoc[]) state;
551         super.restoreState(context, values[0]);
552         disabled = (Boolean JavaDoc) values[1];
553         style = (String JavaDoc) values[2];
554         styleClass = (String JavaDoc) values[3];
555         label = (String JavaDoc) values[4];
556         enabledOnUserRole = (String JavaDoc) values[5];
557         renderedOnUserRole = (String JavaDoc) values[6];
558         title = (String JavaDoc) values[7];
559         height = ((Integer JavaDoc) values[8]).intValue();
560         width = ((Integer JavaDoc) values[9]).intValue();
561         inputTextSize = ((Integer JavaDoc) values[10]).intValue();
562         inputTextClass = (String JavaDoc) values[11];
563         fileNamePattern = (String JavaDoc) values[12];
564         uniqueFolder = ((Boolean JavaDoc) values[13]).booleanValue();
565         uniqueFolderSet = ((Boolean JavaDoc) values[14]).booleanValue();
566         uploadDirectory = (String JavaDoc) values[15];
567         uploadDirectoryAbsolute = (Boolean JavaDoc) values[16];
568         uploadException = (Throwable JavaDoc) values[17];
569         status = ((Integer JavaDoc) values[18]).intValue();
570         fileInfo = (FileInfo) values[19];
571         progress = ((Integer JavaDoc) values[20]).intValue();
572         file = (File JavaDoc) values[21];
573         sizeMax = ((Long JavaDoc) values[22]).longValue();
574         progressListener = (MethodBinding) restoreAttachedState(context, values[23]);
575     }
576
577     /**
578      * <p>Set the value of the <code>title</code> property.</p>
579      */

580     public void setTitle(String JavaDoc title) {
581         this.title = title;
582     }
583
584     /**
585      * <p>Return the value of the <code>title</code> property.</p>
586      */

587     public String JavaDoc getTitle() {
588         if (title != null) {
589             return title;
590         }
591         ValueBinding vb = getValueBinding("title");
592         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
593     }
594     
595     // size
596
private String JavaDoc size = null;
597
598     /**
599      * <p>Set the value of the <code>size</code> property.</p>
600      */

601     public void setSize(String JavaDoc size) {
602         this.size = size;
603     }
604
605     /**
606      * <p>Return the value of the <code>size</code> property.</p>
607      */

608     public String JavaDoc getSize() {
609         if (size != null) {
610             return size;
611         }
612         ValueBinding vb = getValueBinding("size");
613         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
614     }
615
616
617     public int getHeight() {
618         ValueBinding vb = getValueBinding("height");
619         if (vb != null) {
620             Integer JavaDoc value = (Integer JavaDoc) vb.getValue(getFacesContext());
621             if (null == value) {
622             return height;
623             }
624             return (value.intValue());
625         } else {
626             return (this.height);
627         }
628     }
629
630     public void setHeight(int height) {
631         this.height = height;
632     }
633
634     public int getWidth() {
635         ValueBinding vb = getValueBinding("width");
636         if (vb != null) {
637             Integer JavaDoc value = (Integer JavaDoc) vb.getValue(getFacesContext());
638             if (null == value) {
639             return width;
640             }
641             return (value.intValue());
642         } else {
643             return (this.width);
644         }
645     }
646
647     public void setWidth(int width) {
648         this.width = width;
649     }
650
651     public int getInputTextSize() {
652         ValueBinding vb = getValueBinding("inputTextSize");
653         if (vb != null) {
654             Integer JavaDoc value = (Integer JavaDoc) vb.getValue(getFacesContext());
655             if (null == value) {
656             return inputTextSize;
657             }
658             return (value.intValue());
659         } else {
660             return (this.inputTextSize);
661         }
662     }
663
664     public void setInputTextSize(int inputTextSize) {
665         this.inputTextSize = inputTextSize;
666     }
667
668     public String JavaDoc getFileNamePattern() {
669         if (fileNamePattern != null) {
670             return fileNamePattern;
671         }
672         ValueBinding vb = getValueBinding("fileNamePattern");
673         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : ".+";
674     }
675
676     public void setFileNamePattern(String JavaDoc fileNamePattern) {
677         this.fileNamePattern = fileNamePattern;
678     }
679
680
681     public void setInputTextClass(String JavaDoc inputTextClass) {
682         this.inputTextClass = inputTextClass;
683     }
684     
685     public String JavaDoc getInputTextClass() {
686         return Util.getQualifiedStyleClass(this,
687                 inputTextClass,
688                 CSS_DEFAULT.ICE_FILE_UPLOAD_DEFAULT_INPUT_TEXT_CLASS,
689                 "inputTextClass",
690                 isDisabled());
691     }
692
693     private String JavaDoc buttonClass = null;
694
695     public void setButtonClass(String JavaDoc buttonClass) {
696         this.buttonClass = buttonClass;
697     }
698
699     public String JavaDoc getButtonClass() {
700         return Util.getQualifiedStyleClass(this,
701                 buttonClass,
702                 CSS_DEFAULT.ICE_FILE_UPLOAD_DEFAULT_BUTTON_CLASS,
703                 "buttonClass",
704                 isDisabled());
705     }
706
707     boolean isRegister() {
708         return false;
709     }
710
711     public void setRegister(FacesContext facesContext) {
712         //do nothing
713
}
714
715     /**
716      * <p/>
717      * Return the value of the <code>fileInfo</code> property. </p>
718      */

719     public FileInfo getFileInfo() {
720         return fileInfo;
721     }
722
723     void setFileInfo(FileInfo fileInfo) {
724         //do nothing
725
}
726
727     /**
728      * <p/>
729      * Return the value of the <code>file</code> property. </p>
730      */

731     public File JavaDoc getFile() {
732         return file;
733     }
734
735     /**
736      * <p/>
737      * Set the value of the <code>file<code> property. </p>
738      */

739     public void setFile(File JavaDoc file) {
740         //do nothing
741
}
742
743     /**
744      * In the 1.5.3 codebase, there was a writeable ValueBinding named "file"
745      * that would be updated when a new file was saved. This provides
746      * backwards compatibility with that.
747      */

748     protected void updateFileValueBinding(FacesContext context) {
749         try {
750             ValueBinding vb = getValueBinding("file");
751             if(vb != null)
752                 vb.setValue(context, getFile());
753         }
754         catch(Exception JavaDoc e) {
755             log.warn("The InputFile's file attribute has a ValueBinding, whose value could not be set",e);
756         }
757     }
758     
759     public int getStatus() {
760         return status;
761     }
762
763     /**
764      * <p>Return the value of the <code>fileName</code> property.</p>
765      *
766      * @deprecated use getFileInfo().getFileName() instead.
767      */

768     public String JavaDoc getFilename() {
769         return fileInfo.getFileName();
770     }
771
772     /**
773      * <p>Set the value of the <code>fileName</code> property.</p>
774      *
775      * @deprecated use getFileInfo().setFileName() instead.
776      */

777     public void setFilename(String JavaDoc filename) {
778        fileInfo.setFileName(filename);
779     }
780
781     /**
782      * <p>Return the value of the <code>size</code> property.</p>
783      *
784      * @deprecated use getFileInfo().getSize() instead.
785      */

786     public long getFilesize() {
787         return fileInfo.getSize();
788     }
789
790     /**
791      * <p>Set the value of the <code>size</code> property.</p>
792      *
793      */

794     public void setFilesize(long filesize) {
795         fileInfo.setSize(filesize);
796     }
797
798     public long getSizeMax() {
799        return sizeMax;
800     }
801
802     public MethodBinding getProgressListener() {
803         return progressListener;
804     }
805
806     public void setProgressListener(MethodBinding binding) {
807         progressListener = binding;
808     }
809
810     public int getProgress(){
811         return progress;
812     }
813
814     public void setProgress(int i){
815
816         progress = i;
817         fileInfo.setPercent(i);
818         if( getProgressListener() != null )
819             getProgressListener().invoke(FacesContext.getCurrentInstance(), new Object JavaDoc[] {new EventObject JavaDoc(this)});
820     }
821
822     public String JavaDoc getCssFile() {
823       return null;
824     }
825
826     private String JavaDoc getDisabled() {
827         return null;
828     }
829   
830     private String JavaDoc getStyleClassString() {
831         return null;
832     }
833     
834     private String JavaDoc getStyleString() {
835         return null;
836     }
837     
838     private String JavaDoc getStyleInfo() {
839         return null;
840     }
841     private String JavaDoc getInputTextClassString() {
842         return null;
843     }
844
845     private String JavaDoc getButtonClassString() {
846         return null;
847     }
848     
849     private String JavaDoc getTitleAsString(){
850         return null;
851     }
852     
853     private static ArrayList JavaDoc findOutputStyleComponents(UIComponent parent) {
854         ArrayList JavaDoc returnValue = null;
855         Iterator JavaDoc children = parent.getChildren().iterator();
856         UIComponent childComponent = null;
857         while (children.hasNext()) {
858             childComponent = (UIComponent) children.next();
859             if (childComponent instanceof OutputStyle) {
860                 if (returnValue == null) {
861                     returnValue = new ArrayList JavaDoc();
862                 }
863                 returnValue.add(childComponent);
864             }
865             else {
866                 ArrayList JavaDoc outputStyleComponents = findOutputStyleComponents(childComponent);
867                 if (outputStyleComponents != null) {
868                     if (returnValue == null) {
869                         returnValue = outputStyleComponents;
870                     }
871                     else {
872                         returnValue.add(outputStyleComponents);
873                     }
874                 }
875             }
876         }
877         return returnValue;
878     }
879     
880     private String JavaDoc onfocus;
881     
882     public void setOnfocus(String JavaDoc onfocus) {
883         this.onfocus = onfocus;
884     }
885     
886     public String JavaDoc getOnfocus() {
887         if (onfocus != null) {
888             return onfocus;
889         }
890         ValueBinding vb = getValueBinding("onfocus");
891         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
892     }
893     
894     private String JavaDoc onchange;
895     
896     public void setOnchange(String JavaDoc onchange) {
897         this.onchange = onchange;
898     }
899     
900     public String JavaDoc getOnchange() {
901         if (onchange != null) {
902             return onchange;
903         }
904         ValueBinding vb = getValueBinding("onchange");
905         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
906     }
907     
908     private String JavaDoc accept;
909     
910     public void setAccept(String JavaDoc accept) {
911         this.accept = accept;
912     }
913     
914     public String JavaDoc getAccept() {
915         if (accept != null) {
916             return accept;
917         }
918         ValueBinding vb = getValueBinding("accept");
919         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
920     }
921     
922     private String JavaDoc accesskey;
923     
924     public void setAccesskey(String JavaDoc accesskey) {
925         this.accesskey = accesskey;
926     }
927     
928     public String JavaDoc getAccesskey() {
929         if (accesskey != null) {
930             return accesskey;
931         }
932         ValueBinding vb = getValueBinding("accesskey");
933         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
934     }
935     
936     private String JavaDoc onblur;
937     
938     public void setOnblur(String JavaDoc onblur) {
939         this.onblur = onblur;
940     }
941     
942     public String JavaDoc getOnblur() {
943         if (onblur != null) {
944             return onblur;
945         }
946         ValueBinding vb = getValueBinding("onblur");
947         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
948     }
949     
950     private String JavaDoc tabindex;
951     
952     public void setTabindex(String JavaDoc tabindex) {
953         this.tabindex = tabindex;
954     }
955     
956     public String JavaDoc getTabindex() {
957         if (tabindex != null) {
958             return tabindex;
959         }
960         ValueBinding vb = getValueBinding("tabindex");
961         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
962     }
963 }
964
Popular Tags