Source Code Cross Referenced for UploadRequest.java in  » Content-Management-System » openedit » com » openedit » modules » admin » filemanager » 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 » Content Management System » openedit » com.openedit.modules.admin.filemanager 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.openedit.modules.admin.filemanager;
002:
003:        import java.io.File;
004:        import java.io.IOException;
005:        import java.util.ArrayList;
006:        import java.util.Iterator;
007:        import java.util.List;
008:        import java.util.Map;
009:
010:        import org.apache.commons.logging.Log;
011:        import org.apache.commons.logging.LogFactory;
012:        import org.openedit.repository.ContentItem;
013:        import org.openedit.repository.InputStreamItem;
014:
015:        import com.openedit.OpenEditException;
016:        import com.openedit.page.Page;
017:        import com.openedit.page.manage.PageManager;
018:        import com.openedit.users.User;
019:        import com.openedit.util.PathUtilities;
020:        import com.openedit.util.ZipUtil;
021:
022:        public class UploadRequest {
023:            private static final Log log = LogFactory
024:                    .getLog(UploadRequest.class);
025:            protected List fieldUploadItems;
026:            protected Map fieldProperties;
027:            protected PageManager fieldPageManager;
028:            protected File fieldRoot;
029:            protected ZipUtil fieldZipUtil;
030:
031:            public void addUploadItem(FileUploadItem inItem) {
032:                getUploadItems().add(inItem);
033:            }
034:
035:            public List getUploadItems() {
036:                if (fieldUploadItems == null) {
037:                    fieldUploadItems = new ArrayList();
038:                }
039:                return fieldUploadItems;
040:            }
041:
042:            public void setUploadItems(List inUploadItems) {
043:                fieldUploadItems = inUploadItems;
044:            }
045:
046:            public Map getProperties() {
047:                return fieldProperties;
048:            }
049:
050:            public void setProperties(Map inProperties) {
051:                fieldProperties = inProperties;
052:            }
053:
054:            public String get(String inString) {
055:                return (String) getProperties().get(inString);
056:            }
057:
058:            public String getPathFor(String home, FileUploadItem inItem)
059:                    throws OpenEditException {
060:                String path = inItem.get("path");
061:                if (path == null) {
062:                    path = get("path");
063:                }
064:
065:                if (path == null) {
066:                    log.error("No path specified in multipart form");
067:                    throw new OpenEditException(
068:                            "No path passed in with the upload");
069:                }
070:                if (home != null && home.length() > 0 && path.startsWith(home)) {
071:                    path = path.substring(home.length());
072:                }
073:
074:                String finalpath = null;
075:                //TODO: Check to see if it is already a directory or ends with /
076:                String name = inItem.getName();
077:                name = name = name.replace('\\', '/');
078:                name = PathUtilities.extractFileName(name);
079:                name = name.replaceAll(" ", "");
080:
081:                if (path.endsWith("/")) {
082:                    finalpath = path + name;
083:                } else {
084:                    Page page = getPageManager().getPage(path);
085:                    if (page.isFolder()) //upload to an exising folder
086:                    {
087:                        finalpath = path + "/" + name;
088:                    } else {
089:                        finalpath = path;
090:                    }
091:                }
092:                return finalpath;
093:            }
094:
095:            public PageManager getPageManager() {
096:                return fieldPageManager;
097:            }
098:
099:            public void setPageManager(PageManager inPageManager) {
100:                fieldPageManager = inPageManager;
101:            }
102:
103:            public void saveFile(FileUploadItem inItem, String inHome,
104:                    User inUser) throws OpenEditException {
105:                /**
106:                 * inPath is full filename
107:                 * @param inProps
108:                 */
109:                //		public Page saveFile(Map inProps, String inPath, WebPageRequest inContext) throws OpenEditException
110:                //From now on we are going to assume people always upload to a directory
111:                //now put the file there
112:                String inPath = getPathFor(inHome, inItem);
113:                if (inPath.indexOf("..") > -1) {
114:                    throw new OpenEditException("Illegal path name");
115:                }
116:                final String path = PathUtilities.resolveRelativePath(inPath,
117:                        "/");
118:                saveFileAs(inItem, path, inUser);
119:            }
120:
121:            private void saveFileAs(FileUploadItem inItem, final String path,
122:                    User inUser) throws OpenEditException {
123:                Page page = getPageManager().getPage(path);
124:                InputStreamItem revision = new InputStreamItem();
125:                //	final Date lastModified = new Date();
126:                if (inUser == null) {
127:                    throw new IllegalArgumentException("No user logged in");
128:                }
129:                revision.setAuthor(inUser.getUserName());
130:                revision.setType(ContentItem.TYPE_ADDED);
131:                revision.setMessage("Uploaded file");
132:                revision.setPath(path);
133:                try {
134:                    revision.setInputStream(inItem.getFileItem()
135:                            .getInputStream());
136:                } catch (IOException ex) {
137:                    throw new OpenEditException(ex);
138:                }
139:                page.setContentItem(revision);
140:                getPageManager().putPage(page);
141:                inItem.setSavedPage(page);
142:            }
143:
144:            public void unzipFiles(boolean inForceUnzip)
145:                    throws OpenEditException {
146:                for (Iterator iterator = getUploadItems().iterator(); iterator
147:                        .hasNext();) {
148:                    FileUploadItem item = (FileUploadItem) iterator.next();
149:                    Page page = item.getSavedPage();
150:                    if (page.getPath().toLowerCase().endsWith(".zip")) {
151:                        String ok = (String) item.get("unzip");
152:                        if (inForceUnzip || "checked".equals(ok)
153:                                || Boolean.parseBoolean(ok)) {
154:                            log.info("Unzipping " + page.getPath());
155:                            File in = new File(getRoot(), page.getContentItem()
156:                                    .getPath());
157:                            try {
158:                                getZipUtil().unzip(in, in.getParentFile());
159:                            } catch (Exception ex) {
160:                                log.error("Could not unzip : "
161:                                        + in.getAbsolutePath());
162:                                log.error(ex);
163:                                return;
164:                            }
165:                            getPageManager().removePage(page);
166:                        }
167:                    }
168:                }
169:            }
170:
171:            public File getRoot() {
172:                return fieldRoot;
173:            }
174:
175:            public void setRoot(File inRoot) {
176:                fieldRoot = inRoot;
177:            }
178:
179:            public ZipUtil getZipUtil() {
180:                if (fieldZipUtil == null) {
181:                    fieldZipUtil = new ZipUtil();
182:                }
183:                return fieldZipUtil;
184:            }
185:
186:            public void setZipUtil(ZipUtil inZipUtil) {
187:                fieldZipUtil = inZipUtil;
188:            }
189:
190:            public Page saveFirstFileAs(String inPath, User inUser)
191:                    throws OpenEditException {
192:                FileUploadItem item = getFirstItem();
193:                saveFileAs(item, inPath, inUser);
194:                return item.getSavedPage();
195:            }
196:
197:            public FileUploadItem getFirstItem() {
198:                for (Iterator iterator = getUploadItems().iterator(); iterator
199:                        .hasNext();) {
200:                    FileUploadItem item = (FileUploadItem) iterator.next();
201:                    return item;
202:                }
203:                return null;
204:            }
205:
206:            public FileUploadItem getUploadItem(int inI) {
207:                for (Iterator iterator = getUploadItems().iterator(); iterator
208:                        .hasNext();) {
209:                    FileUploadItem item = (FileUploadItem) iterator.next();
210:                    if (item.getCount() == inI) {
211:                        return item;
212:                    }
213:                }
214:                return null;
215:            }
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.