Source Code Cross Referenced for InputFile.java in  » J2EE » ICEfaces-1.6.1 » com » icesoft » faces » component » inputfile » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » ICEfaces 1.6.1 » com.icesoft.faces.component.inputfile 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003:         *
004:         * "The contents of this file are subject to the Mozilla Public License
005:         * Version 1.1 (the "License"); you may not use this file except in
006:         * compliance with the License. You may obtain a copy of the License at
007:         * http://www.mozilla.org/MPL/
008:         *
009:         * Software distributed under the License is distributed on an "AS IS"
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011:         * License for the specific language governing rights and limitations under
012:         * the License.
013:         *
014:         * The Original Code is ICEfaces 1.5 open source software code, released
015:         * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016:         * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017:         * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018:         *
019:         * Contributor(s): _____________________.
020:         *
021:         * Alternatively, the contents of this file may be used under the terms of
022:         * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023:         * License), in which case the provisions of the LGPL License are
024:         * applicable instead of those above. If you wish to allow use of your
025:         * version of this file only under the terms of the LGPL License and not to
026:         * allow others to use your version of this file under the MPL, indicate
027:         * your decision by deleting the provisions above and replace them with
028:         * the notice and other provisions required by the LGPL License. If you do
029:         * not delete the provisions above, a recipient may use your version of
030:         * this file under either the MPL or the LGPL License."
031:         *
032:         */
033:
034:        package com.icesoft.faces.component.inputfile;
035:
036:        import com.icesoft.faces.component.CSS_DEFAULT;
037:        import com.icesoft.faces.component.FileUploadComponent;
038:        import com.icesoft.faces.component.ext.taglib.Util;
039:        import com.icesoft.faces.component.style.OutputStyle;
040:        import com.icesoft.faces.context.BridgeFacesContext;
041:        import com.icesoft.faces.util.CoreUtils;
042:        import com.icesoft.faces.utils.MessageUtils;
043:        import com.icesoft.faces.webapp.xmlhttp.PersistentFacesState;
044:        import org.apache.commons.fileupload.FileItemStream;
045:        import org.apache.commons.fileupload.FileUploadBase;
046:        import org.apache.commons.fileupload.util.Streams;
047:        import org.apache.commons.logging.Log;
048:        import org.apache.commons.logging.LogFactory;
049:
050:        import javax.faces.component.UICommand;
051:        import javax.faces.component.UIComponent;
052:        import javax.faces.context.ExternalContext;
053:        import javax.faces.context.FacesContext;
054:        import javax.faces.el.MethodBinding;
055:        import javax.faces.el.ValueBinding;
056:        import javax.faces.event.ActionEvent;
057:        import javax.faces.event.ActionListener;
058:        import javax.servlet.ServletContext;
059:        import java.io.File;
060:        import java.io.FileOutputStream;
061:        import java.io.IOException;
062:        import java.io.OutputStream;
063:        import java.io.Serializable;
064:        import java.io.Writer;
065:        import java.util.ArrayList;
066:        import java.util.EventObject;
067:        import java.util.Iterator;
068:
069:        /**
070:         * InputFile is a JSF component class representing an ICEfaces inputFile.
071:         */
072:        public class InputFile extends UICommand implements  Serializable,
073:                FileUploadComponent {
074:            private static final Log log = LogFactory.getLog(InputFile.class);
075:
076:            public static final int DEFAULT = 0;
077:            public static final int UPLOADING = 1;
078:            public static final int SAVED = 2;
079:            public static final int INVALID = 3;
080:            public static final int SIZE_LIMIT_EXCEEDED = 4;
081:            public static final int UNKNOWN_SIZE = 5;
082:            public static final int INVALID_NAME_PATTERN = 6;
083:
084:            public static final String INVALID_FILE_MESSAGE_ID = "com.icesoft.faces.component.inputfile.INVALID_FILE";
085:            public static final String INVALID_NAME_PATTERN_MESSAGE_ID = "com.icesoft.faces.component.inputfile.INVALID_NAME_PATTERN";
086:            public static final String SIZE_LIMIT_EXCEEDED_MESSAGE_ID = "com.icesoft.faces.component.inputfile.SIZE_LIMIT_EXCEEDED";
087:            public static final String UNKNOWN_SIZE_MESSAGE_ID = "com.icesoft.faces.component.inputfile.UNKNOWN_SIZE";
088:
089:            public static final String FILE_UPLOAD_PREFIX = "fileUpload";
090:            private Boolean disabled;
091:            private String style;
092:            private String styleClass;
093:            private String label;
094:            private String enabledOnUserRole;
095:            private String renderedOnUserRole;
096:            private String title;
097:            private int height = 30;
098:            private int width = 500;
099:            private int inputTextSize = 35;
100:            private String inputTextClass;
101:            private String fileNamePattern;
102:            private boolean uniqueFolder = true;
103:            private boolean uniqueFolderSet = false;
104:            private String uploadDirectory;
105:            private Boolean uploadDirectoryAbsolute;
106:            private Throwable uploadException;
107:            private int status = DEFAULT;
108:            private FileInfo fileInfo = new FileInfo();
109:            private int progress = 0;
110:            private File file;
111:            private long sizeMax;
112:            private MethodBinding progressListener;
113:
114:            /**
115:             * <p>Return the value of the <code>COMPONENT_TYPE</code> of this
116:             * component.</p>
117:             */
118:            public String getComponentType() {
119:                return "com.icesoft.faces.File";
120:            }
121:
122:            /**
123:             * <p>Return the value of the <code>RENDERER_TYPE</code> of this
124:             * component.</p>
125:             */
126:            public String getRendererType() {
127:                return "com.icesoft.faces.Upload";
128:            }
129:
130:            /**
131:             * <p>Return the value of the <code>COMPONENT_FAMILY</code> of this
132:             * component.</p>
133:             */
134:            public String getFamily() {
135:                return "com.icesoft.faces.File";
136:            }
137:
138:            public void upload(FileItemStream stream, String uploadDirectory,
139:                    boolean uploadDirectoryAbsolute, long maxSize,
140:                    BridgeFacesContext bfc, ServletContext servletContext,
141:                    String sessionId) throws IOException {
142:                this .uploadException = null;
143:                this .status = UPLOADING;
144:                this .sizeMax = maxSize;
145:                FacesContext context = FacesContext.getCurrentInstance();
146:                // InputFile uploadDirectory attribute takes precedence,
147:                //  but if it's not given, then default to the
148:                //  com.icesoft.faces.uploadDirectory context-param
149:                String folder = getUploadDirectory();
150:                if (folder == null) {
151:                    folder = uploadDirectory;
152:                }
153:                // InputFile uploadDirectoryAbsolute attribute takes precedence,
154:                //  but if it's not given, then default to the
155:                //  com.icesoft.faces.uploadDirectoryAbsolute context-param
156:                Boolean folderAbs = getUploadDirectoryAbsolute();
157:                if (folderAbs == null) {
158:                    folderAbs = uploadDirectoryAbsolute ? Boolean.TRUE
159:                            : Boolean.FALSE;
160:                }
161:                if (!folderAbs.booleanValue()) {
162:                    folder = servletContext.getRealPath(folder);
163:                }
164:                if (isUniqueFolder()) {
165:                    String FILE_SEPARATOR = System
166:                            .getProperty("file.separator");
167:                    folder = folder + FILE_SEPARATOR + sessionId;
168:                }
169:
170:                String namePattern = getFileNamePattern().trim();
171:                String fileName = stream.getName();
172:                // If server is Unix and file name has full Windows path info. (JIRA ICE-1868)
173:                if (File.separatorChar == '/'
174:                        && fileName.matches("^[a-zA-Z]:\\\\.*?|^\\\\\\\\.*?")) {
175:                    // Strip the path info. Keep the base file name
176:                    fileName = fileName
177:                            .substring(fileName.lastIndexOf("\\") + 1);
178:                }
179:                try {
180:                    if (fileName != null && fileName.length() > 0) {
181:                        // IE gives us the whole path on the client, but we just
182:                        //  want the client end file name, not the path
183:                        File tempFileName = new File(fileName);
184:                        fileName = tempFileName.getName();
185:                    } else {
186:                        throw new FileUploadBase.FileUploadIOException(
187:                                new FileUploadBase.InvalidContentTypeException());
188:                    }
189:
190:                    fileInfo.setFileName(fileName);
191:                    fileInfo.setContentType(stream.getContentType());
192:                    if (fileName != null
193:                            && fileName.trim().matches(namePattern)) {
194:                        File folderFile = new File(folder);
195:                        if (!folderFile.exists())
196:                            folderFile.mkdirs();
197:                        file = new File(folder, fileName);
198:                        OutputStream output = new FileOutputStream(file);
199:                        Streams.copy(stream.openStream(), output, true);
200:                        if (file.length() == 0) {
201:                            setProgress(0);
202:                            file.delete();
203:                            throw new FileUploadBase.FileUploadIOException(
204:                                    new FileUploadBase.InvalidContentTypeException());
205:                        }
206:                        status = SAVED;
207:                        fileInfo.setPhysicalPath(file.getAbsolutePath());
208:                        updateFileValueBinding(context);
209:                        notifyDone(bfc);
210:                    } else {
211:                        fileInfo.reset();
212:                        file = null;
213:                        status = INVALID_NAME_PATTERN;
214:                        context.addMessage(null, MessageUtils.getMessage(
215:                                context, INVALID_NAME_PATTERN_MESSAGE_ID,
216:                                new Object[] { fileName, namePattern }));
217:                        notifyDone(bfc);
218:                    }
219:                } catch (FileUploadBase.FileUploadIOException uploadException) {
220:                    this .uploadException = uploadException.getCause();
221:                    try {
222:                        throw this .uploadException;
223:                    } catch (FileUploadBase.FileSizeLimitExceededException e) {
224:                        status = SIZE_LIMIT_EXCEEDED;
225:                    } catch (FileUploadBase.UnknownSizeException e) {
226:                        status = UNKNOWN_SIZE;
227:                    } catch (FileUploadBase.InvalidContentTypeException e) {
228:                        status = INVALID;
229:                    } catch (Throwable t) {
230:                        status = INVALID;
231:                    }
232:                    fileInfo.setException(uploadException);
233:                    if (file != null)
234:                        file.delete();
235:                    notifyDone(bfc);
236:                    throw uploadException;
237:                } catch (IOException e) { // Eg: If creating the saved file fails
238:                    this .uploadException = e;
239:                    status = INVALID;
240:                    fileInfo.setException(e);
241:                    if (file != null)
242:                        file.delete();
243:                    notifyDone(bfc);
244:                    throw e;
245:                }
246:
247:                PersistentFacesState.getInstance().renderLater();
248:            }
249:
250:            protected void notifyDone(BridgeFacesContext bfc) {
251:                ActionEvent event = new ActionEvent(this );
252:
253:                bfc.setCurrentInstance();
254:
255:                //this is true for JSF 1.1 only
256:                MethodBinding actionListener = getActionListener();
257:                if (actionListener != null) {
258:                    actionListener.invoke(FacesContext.getCurrentInstance(),
259:                            new Object[] { event });
260:                }
261:
262:                //this is true for JSF 1.2 only
263:                ActionListener[] actionListeners = getActionListeners();
264:                for (int i = 0; i < actionListeners.length; i++) {
265:                    actionListeners[i].processAction(event);
266:                }
267:                MethodBinding action = getAction();
268:                if (action != null) {
269:                    action.invoke(FacesContext.getCurrentInstance(), null);
270:                }
271:
272:                if (fileInfo != null)
273:                    fileInfo.reset();
274:            }
275:
276:            public void renderIFrame(Writer writer, BridgeFacesContext context)
277:                    throws IOException {
278:                writer.write("<html style=\"overflow:hidden;\">");
279:                ArrayList outputStyleComponents = findOutputStyleComponents(context
280:                        .getViewRoot());
281:                if (outputStyleComponents != null) {
282:                    writer.write("<head>");
283:                    for (int i = 0; i < outputStyleComponents.size(); i++) {
284:                        OutputStyle outputStyle = (OutputStyle) outputStyleComponents
285:                                .get(i);
286:                        String href = outputStyle.getHref();
287:                        if ((href != null) && (href.length() > 0)) {
288:                            href = CoreUtils.resolveResourceURL(context, href);
289:                            writer
290:                                    .write("<link rel=\"stylesheet\" type=\"text/css\" href=\""
291:                                            + href + "\">");
292:                        }
293:                    }
294:                    writer.write("</head>");
295:                }
296:                String srv = getUploadServletPath(context);
297:                writer
298:                        .write("<body style=\"background-color:transparent; overflow:hidden\"><form method=\"post\" action=\""
299:                                + srv
300:                                + "\" enctype=\"multipart/form-data\" id=\"fileUploadForm\">");
301:                writer
302:                        .write("<input type=\"hidden\" name=\"ice.component\" value=\"");
303:                writer.write(this .getClientId(context));
304:                writer.write("\"/>");
305:                writer.write("<input type=\"hidden\" name=\"ice.view.active\"");
306:                writer.write(" value=\"" + context.getViewNumber() + "\"/>");
307:                writer.write("<input type=\"file\" name=\"upload\"");
308:                writer.write(" size=\"" + getInputTextSize() + "\"");
309:                String inputTextClass = getInputTextClass();
310:                if (inputTextClass != null)
311:                    writer.write(" class=\"" + inputTextClass + "\"");
312:                String title = getTitle();
313:                if (title != null)
314:                    writer.write(" title=\"" + title + "\"");
315:                writer.write("/>");
316:                writer.write("<input type=\"submit\" value=\"" + getLabel()
317:                        + "\"");
318:                String buttonClass = getButtonClass();
319:                if (buttonClass != null)
320:                    writer.write(" class=\"" + buttonClass + "\"");
321:                if (isDisabled())
322:                    writer.write(" disabled=\"disabled\"");
323:                writer.write("/>");
324:                writer.write("</form>");
325:                writer.write("</body></html>");
326:            }
327:
328:            private String getUploadServletPath(BridgeFacesContext context) {
329:                String requestContextPath = null;
330:                if (context != null) {
331:                    ExternalContext externalContext = context
332:                            .getExternalContext();
333:                    if (externalContext != null) {
334:                        requestContextPath = externalContext
335:                                .getRequestContextPath();
336:                    }
337:                }
338:                if (requestContextPath == null
339:                        || requestContextPath.length() == 0)
340:                    return "./uploadHtml";
341:                else
342:                    return requestContextPath + "/uploadHtml";
343:            }
344:
345:            public Throwable getUploadException() {
346:                return uploadException;
347:            }
348:
349:            /**
350:             * <p/>
351:             * Set the value of the <code>label</code> property. </p>
352:             */
353:            public void setLabel(String label) {
354:                this .label = label;
355:            }
356:
357:            /**
358:             * <p/>
359:             * Set the value of the <code>uniqueFolder</code> property. </p>
360:             */
361:            public void setUniqueFolder(boolean uniqueFolder) {
362:                if (uniqueFolder != this .uniqueFolder) {
363:                    this .uniqueFolder = uniqueFolder;
364:                }
365:                this .uniqueFolderSet = true;
366:            }
367:
368:            /**
369:             * <p/>
370:             * Return the value of the <code>uniqueFolder</code> property. </p>
371:             */
372:            public boolean isUniqueFolder() {
373:                if (this .uniqueFolderSet) {
374:                    return (this .uniqueFolder);
375:                }
376:                ValueBinding vb = getValueBinding("uniqueFolder");
377:                if (vb != null) {
378:                    return (Boolean.TRUE.equals(vb.getValue(getFacesContext())));
379:                }
380:                return true;
381:            }
382:
383:            /**
384:             * <p/>
385:             * Return the value of the <code>label</code> property. </p>
386:             */
387:            public String getLabel() {
388:                if (label != null) {
389:                    return label;
390:                }
391:                ValueBinding vb = getValueBinding("label");
392:                return vb != null ? (String) vb.getValue(getFacesContext())
393:                        : "Upload";
394:            }
395:
396:            /**
397:             * <p>Return the value of the <code>disabled</code> property.</p>
398:             */
399:            public boolean isDisabled() {
400:                if (!Util.isEnabledOnUserRole(this )) {
401:                    return true;
402:                } else {
403:                    if (disabled != null) {
404:                        return disabled.booleanValue();
405:                    }
406:                    ValueBinding vb = getValueBinding("disabled");
407:                    Boolean boolVal = vb != null ? (Boolean) vb
408:                            .getValue(getFacesContext()) : null;
409:                    return boolVal != null ? boolVal.booleanValue() : false;
410:
411:                }
412:
413:            }
414:
415:            /**
416:             * <p>Set the value of the <code>disabled</code> property.</p>
417:             */
418:            public void setDisabled(boolean disabled) {
419:                this .disabled = Boolean.valueOf(disabled);
420:            }
421:
422:            /**
423:             * <p>Set the value of the <code>enabledOnUserRole</code> property.</p>
424:             */
425:            public void setEnabledOnUserRole(String enabledOnUserRole) {
426:                this .enabledOnUserRole = enabledOnUserRole;
427:            }
428:
429:            /**
430:             * <p>Return the value of the <code>enabledOnUserRole</code> property.</p>
431:             */
432:            public String getEnabledOnUserRole() {
433:                if (enabledOnUserRole != null) {
434:                    return enabledOnUserRole;
435:                }
436:                ValueBinding vb = getValueBinding("enabledOnUserRole");
437:                return vb != null ? (String) vb.getValue(getFacesContext())
438:                        : null;
439:            }
440:
441:            public void setUploadDirectory(String uploadDirectory) {
442:                this .uploadDirectory = uploadDirectory;
443:            }
444:
445:            public String getUploadDirectory() {
446:                if (uploadDirectory != null) {
447:                    return uploadDirectory;
448:                }
449:                ValueBinding vb = getValueBinding("uploadDirectory");
450:                return vb != null ? (String) vb.getValue(getFacesContext())
451:                        : null;
452:            }
453:
454:            public void setUploadDirectoryAbsolute(
455:                    Boolean uploadDirectoryAbsolute) {
456:                this .uploadDirectoryAbsolute = uploadDirectoryAbsolute;
457:            }
458:
459:            public Boolean getUploadDirectoryAbsolute() {
460:                if (uploadDirectoryAbsolute != null) {
461:                    return uploadDirectoryAbsolute;
462:                }
463:                ValueBinding vb = getValueBinding("uploadDirectoryAbsolute");
464:                return vb != null ? (Boolean) vb.getValue(getFacesContext())
465:                        : null;
466:            }
467:
468:            /**
469:             * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
470:             */
471:            public void setRenderedOnUserRole(String renderedOnUserRole) {
472:                this .renderedOnUserRole = renderedOnUserRole;
473:            }
474:
475:            /**
476:             * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
477:             */
478:            public String getRenderedOnUserRole() {
479:                if (renderedOnUserRole != null) {
480:                    return renderedOnUserRole;
481:                }
482:                ValueBinding vb = getValueBinding("renderedOnUserRole");
483:                return vb != null ? (String) vb.getValue(getFacesContext())
484:                        : null;
485:            }
486:
487:            /**
488:             * <p>Return the value of the <code>rendered</code> property.</p>
489:             */
490:            public boolean isRendered() {
491:                if (!Util.isRenderedOnUserRole(this )) {
492:                    return false;
493:                }
494:                return super .isRendered();
495:            }
496:
497:            /**
498:             * <p>Set the value of the <code>style</code> property.</p>
499:             */
500:            public void setStyle(String style) {
501:                this .style = style;
502:            }
503:
504:            /**
505:             * <p>Return the value of the <code>style</code> property.</p>
506:             */
507:            public String getStyle() {
508:                if (style != null) {
509:                    return style;
510:                }
511:                ValueBinding vb = getValueBinding("style");
512:                return vb != null ? (String) vb.getValue(getFacesContext())
513:                        : "border-collapse:collapse; border-spacing:0px; padding:0px;";
514:            }
515:
516:            /**
517:             * <p>Set the value of the <code>styleClass</code> property.</p>
518:             */
519:            public void setStyleClass(String styleClass) {
520:                this .styleClass = styleClass;
521:            }
522:
523:            /**
524:             * <p>Return the value of the <code>styleClass</code> property.</p>
525:             */
526:            public String getStyleClass() {
527:                return Util.getQualifiedStyleClass(this , styleClass,
528:                        CSS_DEFAULT.ICE_FILE_UPLOAD_BASE_CLASS, "styleClass",
529:                        isDisabled());
530:            }
531:
532:            /**
533:             * <p>Gets the state of the instance as a <code>Serializable</code>
534:             * Object.</p>
535:             */
536:            public Object saveState(FacesContext context) {
537:                Object values[] = new Object[24];
538:                values[0] = super .saveState(context);
539:                values[1] = disabled;
540:                values[2] = style;
541:                values[3] = styleClass;
542:                values[4] = label;
543:                values[5] = enabledOnUserRole;
544:                values[6] = renderedOnUserRole;
545:                values[7] = title;
546:                values[8] = new Integer(height);
547:                values[9] = new Integer(width);
548:                values[10] = new Integer(inputTextSize);
549:                values[11] = inputTextClass;
550:                values[12] = fileNamePattern;
551:                values[13] = uniqueFolder ? Boolean.TRUE : Boolean.FALSE;
552:                values[14] = uniqueFolderSet ? Boolean.TRUE : Boolean.FALSE;
553:                values[15] = uploadDirectory;
554:                values[16] = uploadDirectoryAbsolute;
555:                values[17] = uploadException;
556:                values[18] = new Integer(status);
557:                values[19] = fileInfo;
558:                values[20] = new Integer(progress);
559:                values[21] = file;
560:                values[22] = new Long(sizeMax);
561:                values[23] = saveAttachedState(context, progressListener);
562:                return ((Object) (values));
563:            }
564:
565:            /**
566:             * <p>Perform any processing required to restore the state from the entries
567:             * in the state Object.</p>
568:             */
569:            public void restoreState(FacesContext context, Object state) {
570:                Object values[] = (Object[]) state;
571:                super .restoreState(context, values[0]);
572:                disabled = (Boolean) values[1];
573:                style = (String) values[2];
574:                styleClass = (String) values[3];
575:                label = (String) values[4];
576:                enabledOnUserRole = (String) values[5];
577:                renderedOnUserRole = (String) values[6];
578:                title = (String) values[7];
579:                height = ((Integer) values[8]).intValue();
580:                width = ((Integer) values[9]).intValue();
581:                inputTextSize = ((Integer) values[10]).intValue();
582:                inputTextClass = (String) values[11];
583:                fileNamePattern = (String) values[12];
584:                uniqueFolder = ((Boolean) values[13]).booleanValue();
585:                uniqueFolderSet = ((Boolean) values[14]).booleanValue();
586:                uploadDirectory = (String) values[15];
587:                uploadDirectoryAbsolute = (Boolean) values[16];
588:                uploadException = (Throwable) values[17];
589:                status = ((Integer) values[18]).intValue();
590:                fileInfo = (FileInfo) values[19];
591:                progress = ((Integer) values[20]).intValue();
592:                file = (File) values[21];
593:                sizeMax = ((Long) values[22]).longValue();
594:                progressListener = (MethodBinding) restoreAttachedState(
595:                        context, values[23]);
596:            }
597:
598:            /**
599:             * <p>Set the value of the <code>title</code> property.</p>
600:             */
601:            public void setTitle(String title) {
602:                this .title = title;
603:            }
604:
605:            /**
606:             * <p>Return the value of the <code>title</code> property.</p>
607:             */
608:            public String getTitle() {
609:                if (title != null) {
610:                    return title;
611:                }
612:                ValueBinding vb = getValueBinding("title");
613:                return vb != null ? (String) vb.getValue(getFacesContext())
614:                        : null;
615:            }
616:
617:            // size
618:            private String size = null;
619:
620:            /**
621:             * <p>Set the value of the <code>size</code> property.</p>
622:             */
623:            public void setSize(String size) {
624:                this .size = size;
625:            }
626:
627:            /**
628:             * <p>Return the value of the <code>size</code> property.</p>
629:             */
630:            public String getSize() {
631:                if (size != null) {
632:                    return size;
633:                }
634:                ValueBinding vb = getValueBinding("size");
635:                return vb != null ? (String) vb.getValue(getFacesContext())
636:                        : null;
637:            }
638:
639:            public int getHeight() {
640:                ValueBinding vb = getValueBinding("height");
641:                if (vb != null) {
642:                    Integer value = (Integer) vb.getValue(getFacesContext());
643:                    if (null == value) {
644:                        return height;
645:                    }
646:                    return (value.intValue());
647:                } else {
648:                    return (this .height);
649:                }
650:            }
651:
652:            public void setHeight(int height) {
653:                this .height = height;
654:            }
655:
656:            public int getWidth() {
657:                ValueBinding vb = getValueBinding("width");
658:                if (vb != null) {
659:                    Integer value = (Integer) vb.getValue(getFacesContext());
660:                    if (null == value) {
661:                        return width;
662:                    }
663:                    return (value.intValue());
664:                } else {
665:                    return (this .width);
666:                }
667:            }
668:
669:            public void setWidth(int width) {
670:                this .width = width;
671:            }
672:
673:            public int getInputTextSize() {
674:                ValueBinding vb = getValueBinding("inputTextSize");
675:                if (vb != null) {
676:                    Integer value = (Integer) vb.getValue(getFacesContext());
677:                    if (null == value) {
678:                        return inputTextSize;
679:                    }
680:                    return (value.intValue());
681:                } else {
682:                    return (this .inputTextSize);
683:                }
684:            }
685:
686:            public void setInputTextSize(int inputTextSize) {
687:                this .inputTextSize = inputTextSize;
688:            }
689:
690:            public String getFileNamePattern() {
691:                if (fileNamePattern != null) {
692:                    return fileNamePattern;
693:                }
694:                ValueBinding vb = getValueBinding("fileNamePattern");
695:                return vb != null ? (String) vb.getValue(getFacesContext())
696:                        : ".+";
697:            }
698:
699:            public void setFileNamePattern(String fileNamePattern) {
700:                this .fileNamePattern = fileNamePattern;
701:            }
702:
703:            public void setInputTextClass(String inputTextClass) {
704:                this .inputTextClass = inputTextClass;
705:            }
706:
707:            public String getInputTextClass() {
708:                return Util.getQualifiedStyleClass(this , inputTextClass,
709:                        CSS_DEFAULT.ICE_FILE_UPLOAD_DEFAULT_INPUT_TEXT_CLASS,
710:                        "inputTextClass", isDisabled());
711:            }
712:
713:            private String buttonClass = null;
714:
715:            public void setButtonClass(String buttonClass) {
716:                this .buttonClass = buttonClass;
717:            }
718:
719:            public String getButtonClass() {
720:                return Util.getQualifiedStyleClass(this , buttonClass,
721:                        CSS_DEFAULT.ICE_FILE_UPLOAD_DEFAULT_BUTTON_CLASS,
722:                        "buttonClass", isDisabled());
723:            }
724:
725:            boolean isRegister() {
726:                return false;
727:            }
728:
729:            public void setRegister(FacesContext facesContext) {
730:                //do nothing
731:            }
732:
733:            /**
734:             * <p/>
735:             * Return the value of the <code>fileInfo</code> property. </p>
736:             */
737:            public FileInfo getFileInfo() {
738:                return fileInfo;
739:            }
740:
741:            void setFileInfo(FileInfo fileInfo) {
742:                //do nothing
743:            }
744:
745:            /**
746:             * <p/>
747:             * Return the value of the <code>file</code> property. </p>
748:             */
749:            public File getFile() {
750:                return file;
751:            }
752:
753:            /**
754:             * <p/>
755:             * Set the value of the <code>file<code> property. </p>
756:             */
757:            public void setFile(File file) {
758:                //do nothing
759:            }
760:
761:            /**
762:             * In the 1.5.3 codebase, there was a writeable ValueBinding named "file"
763:             * that would be updated when a new file was saved. This provides
764:             * backwards compatibility with that.
765:             */
766:            protected void updateFileValueBinding(FacesContext context) {
767:                try {
768:                    ValueBinding vb = getValueBinding("file");
769:                    if (vb != null)
770:                        vb.setValue(context, getFile());
771:                } catch (Exception e) {
772:                    log
773:                            .warn(
774:                                    "The InputFile's file attribute has a ValueBinding, whose value could not be set",
775:                                    e);
776:                }
777:            }
778:
779:            public int getStatus() {
780:                return status;
781:            }
782:
783:            /**
784:             * <p>Return the value of the <code>fileName</code> property.</p>
785:             *
786:             * @deprecated use getFileInfo().getFileName() instead.
787:             */
788:            public String getFilename() {
789:                return fileInfo.getFileName();
790:            }
791:
792:            /**
793:             * <p>Set the value of the <code>fileName</code> property.</p>
794:             *
795:             * @deprecated use getFileInfo().setFileName() instead.
796:             */
797:            public void setFilename(String filename) {
798:                fileInfo.setFileName(filename);
799:            }
800:
801:            /**
802:             * <p>Return the value of the <code>size</code> property.</p>
803:             *
804:             * @deprecated use getFileInfo().getSize() instead.
805:             */
806:            public long getFilesize() {
807:                return fileInfo.getSize();
808:            }
809:
810:            /**
811:             * <p>Set the value of the <code>size</code> property.</p>
812:             */
813:            public void setFilesize(long filesize) {
814:                fileInfo.setSize(filesize);
815:            }
816:
817:            public long getSizeMax() {
818:                return sizeMax;
819:            }
820:
821:            public MethodBinding getProgressListener() {
822:                return progressListener;
823:            }
824:
825:            public void setProgressListener(MethodBinding binding) {
826:                progressListener = binding;
827:            }
828:
829:            public int getProgress() {
830:                return progress;
831:            }
832:
833:            public void setProgress(int i) {
834:
835:                progress = i;
836:                fileInfo.setPercent(i);
837:                if (getProgressListener() != null)
838:                    getProgressListener().invoke(
839:                            FacesContext.getCurrentInstance(),
840:                            new Object[] { new EventObject(this ) });
841:            }
842:
843:            public String getCssFile() {
844:                return null;
845:            }
846:
847:            private String getDisabled() {
848:                return null;
849:            }
850:
851:            private String getStyleClassString() {
852:                return null;
853:            }
854:
855:            private String getStyleString() {
856:                return null;
857:            }
858:
859:            private String getStyleInfo() {
860:                return null;
861:            }
862:
863:            private String getInputTextClassString() {
864:                return null;
865:            }
866:
867:            private String getButtonClassString() {
868:                return null;
869:            }
870:
871:            private String getTitleAsString() {
872:                return null;
873:            }
874:
875:            private static ArrayList findOutputStyleComponents(
876:                    UIComponent parent) {
877:                ArrayList returnValue = null;
878:                Iterator children = parent.getChildren().iterator();
879:                UIComponent childComponent = null;
880:                while (children.hasNext()) {
881:                    childComponent = (UIComponent) children.next();
882:                    if (childComponent instanceof  OutputStyle) {
883:                        if (returnValue == null) {
884:                            returnValue = new ArrayList();
885:                        }
886:                        returnValue.add(childComponent);
887:                    } else {
888:                        ArrayList outputStyleComponents = findOutputStyleComponents(childComponent);
889:                        if (outputStyleComponents != null) {
890:                            if (returnValue == null) {
891:                                returnValue = outputStyleComponents;
892:                            } else {
893:                                returnValue.add(outputStyleComponents);
894:                            }
895:                        }
896:                    }
897:                }
898:                return returnValue;
899:            }
900:
901:            private String onfocus;
902:
903:            public void setOnfocus(String onfocus) {
904:                this .onfocus = onfocus;
905:            }
906:
907:            public String getOnfocus() {
908:                if (onfocus != null) {
909:                    return onfocus;
910:                }
911:                ValueBinding vb = getValueBinding("onfocus");
912:                return vb != null ? (String) vb.getValue(getFacesContext())
913:                        : null;
914:            }
915:
916:            private String onchange;
917:
918:            public void setOnchange(String onchange) {
919:                this .onchange = onchange;
920:            }
921:
922:            public String getOnchange() {
923:                if (onchange != null) {
924:                    return onchange;
925:                }
926:                ValueBinding vb = getValueBinding("onchange");
927:                return vb != null ? (String) vb.getValue(getFacesContext())
928:                        : null;
929:            }
930:
931:            private String accept;
932:
933:            public void setAccept(String accept) {
934:                this .accept = accept;
935:            }
936:
937:            public String getAccept() {
938:                if (accept != null) {
939:                    return accept;
940:                }
941:                ValueBinding vb = getValueBinding("accept");
942:                return vb != null ? (String) vb.getValue(getFacesContext())
943:                        : null;
944:            }
945:
946:            private String accesskey;
947:
948:            public void setAccesskey(String accesskey) {
949:                this .accesskey = accesskey;
950:            }
951:
952:            public String getAccesskey() {
953:                if (accesskey != null) {
954:                    return accesskey;
955:                }
956:                ValueBinding vb = getValueBinding("accesskey");
957:                return vb != null ? (String) vb.getValue(getFacesContext())
958:                        : null;
959:            }
960:
961:            private String onblur;
962:
963:            public void setOnblur(String onblur) {
964:                this .onblur = onblur;
965:            }
966:
967:            public String getOnblur() {
968:                if (onblur != null) {
969:                    return onblur;
970:                }
971:                ValueBinding vb = getValueBinding("onblur");
972:                return vb != null ? (String) vb.getValue(getFacesContext())
973:                        : null;
974:            }
975:
976:            private String tabindex;
977:
978:            public void setTabindex(String tabindex) {
979:                this .tabindex = tabindex;
980:            }
981:
982:            public String getTabindex() {
983:                if (tabindex != null) {
984:                    return tabindex;
985:                }
986:                ValueBinding vb = getValueBinding("tabindex");
987:                return vb != null ? (String) vb.getValue(getFacesContext())
988:                        : null;
989:            }
990:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.