Source Code Cross Referenced for UploadRenderer.java in  » ERP-CRM-Financial » sakai » com » corejsf » 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 » ERP CRM Financial » sakai » com.corejsf 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/sam/tags/sakai_2-4-1/samigo-app/src/java/com/corejsf/UploadRenderer.java $
003:         * $Id: UploadRenderer.java 14907 2006-09-19 02:39:19Z daisyf@stanford.edu $
004:         ***********************************************************************************
005:         * Copyright (c) 2004 Sun Microsystems from the Java Series, Core Java ServerFaces
006:         * source freely distributable.
007:         * see http://www.sun.com/books/java_series.html
008:         ***********************************************************************************
009:         * Modifications Copyright (c) 2005
010:         * The Regents of the University of Michigan, Trustees of Indiana University,
011:         * Board of Trustees of the Leland Stanford, Jr., University, and The MIT Corporation
012:         *
013:         * Licensed under the Educational Community License Version 1.0 (the "License");
014:         * By obtaining, using and/or copying this Original Work, you agree that you have read,
015:         * understand, and will comply with the terms and conditions of the Educational Community License.
016:         * You may obtain a copy of the License at:
017:         *
018:         *      http://cvs.sakaiproject.org/licenses/license_1_0.html
019:         *
020:         * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
021:         * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
022:         * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
023:         * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
024:         * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
025:         *
026:         **********************************************************************************/package com.corejsf;
027:
028:        import java.io.File;
029:        import java.io.IOException;
030:        import java.util.Date;
031:
032:        import javax.servlet.ServletContext;
033:        import javax.faces.FacesException;
034:        import javax.faces.component.EditableValueHolder;
035:        import javax.faces.component.UIComponent;
036:        import javax.faces.context.ExternalContext;
037:        import javax.faces.context.FacesContext;
038:        import javax.faces.context.ResponseWriter;
039:        import javax.faces.el.ValueBinding;
040:        import javax.faces.render.Renderer;
041:        import javax.servlet.http.HttpServletRequest;
042:
043:        import org.apache.commons.fileupload.FileItem;
044:        import org.apache.commons.logging.Log;
045:        import org.apache.commons.logging.LogFactory;
046:
047:        public class UploadRenderer extends Renderer {
048:
049:            private static Log log = LogFactory.getLog(UploadRenderer.class);
050:            private static final String UPLOAD = ".upload";
051:
052:            public UploadRenderer() {
053:            }
054:
055:            public void encodeBegin(FacesContext context, UIComponent component)
056:                    throws IOException {
057:                if (!component.isRendered())
058:                    return;
059:                ResponseWriter writer = context.getResponseWriter();
060:                ExternalContext external = context.getExternalContext();
061:                HttpServletRequest request = (HttpServletRequest) external
062:                        .getRequest();
063:
064:                String clientId = component.getClientId(context);
065:                log.debug("** encodeBegin, clientId =" + clientId);
066:                encodeUploadField(writer, clientId, component);
067:            }
068:
069:            public void encodeUploadField(ResponseWriter writer,
070:                    String clientId, UIComponent component) throws IOException {
071:                // write <input type=file> for browsing and upload
072:                writer.startElement("input", component);
073:                writer.writeAttribute("type", "file", "type");
074:                writer.writeAttribute("name", clientId + UPLOAD, "clientId");
075:                writer.writeAttribute("size", "50", null);
076:                writer.endElement("input");
077:                writer.flush();
078:            }
079:
080:            public void decode(FacesContext context, UIComponent component) {
081:                log.debug("**** decode =");
082:                boolean mediaIsValid = true;
083:                ExternalContext external = context.getExternalContext();
084:                HttpServletRequest request = (HttpServletRequest) external
085:                        .getRequest();
086:                String clientId = component.getClientId(context);
087:                FileItem item = (FileItem) request.getAttribute(clientId
088:                        + UPLOAD);
089:                // check if file > maxSize allowed
090:                log.debug("clientId =" + clientId);
091:                log.debug("fileItem =" + item);
092:                // if (item!=null) log.debug("***UploadRender: fileItem size ="+ item.getSize());
093:                Long maxSize = (Long) ((ServletContext) external.getContext())
094:                        .getAttribute("FILEUPLOAD_SIZE_MAX");
095:                if (item == null || item.getSize() / 1000 > maxSize.intValue()) {
096:                    ((ServletContext) external.getContext()).setAttribute(
097:                            "TEMP_FILEUPLOAD_SIZE", new Long(
098:                                    item.getSize() / 1000));
099:                    mediaIsValid = false;
100:                }
101:
102:                Object target;
103:                ValueBinding binding = component.getValueBinding("target");
104:                if (binding != null)
105:                    target = binding.getValue(context);
106:                else
107:                    target = component.getAttributes().get("target");
108:
109:                String repositoryPath = (String) ((ServletContext) external
110:                        .getContext())
111:                        .getAttribute("FILEUPLOAD_REPOSITORY_PATH");
112:                log.debug("****" + repositoryPath);
113:                if (target != null) {
114:                    File dir = new File(repositoryPath + target.toString()); //directory where file would be saved
115:                    if (!dir.exists())
116:                        dir.mkdirs();
117:                    if (item != null && !("").equals(item.getName())) {
118:                        String fullname = item.getName();
119:                        fullname = fullname.replace('\\', '/'); // replace c:\fullname to c:/fullname
120:                        fullname = fullname
121:                                .substring(fullname.lastIndexOf("/") + 1);
122:                        int dot_index = fullname.lastIndexOf(".");
123:                        String filename = fullname.substring(0, dot_index)
124:                                + "_" + (new Date()).getTime()
125:                                + fullname.substring(dot_index);
126:                        File file = new File(dir.getPath() + "/" + filename);
127:                        log.debug("**1. filename=" + file.getPath());
128:                        try {
129:                            if (mediaIsValid)
130:                                item.write(file);
131:                            // change value so we can evoke the listener
132:                            ((EditableValueHolder) component)
133:                                    .setSubmittedValue(file.getPath());
134:                        } catch (Exception ex) {
135:                            throw new FacesException(ex);
136:                        }
137:                    }
138:                }
139:            }
140:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.