Source Code Cross Referenced for PortalFileHandler.java in  » Portal » Open-Portal » com » sun » portal » fabric » tasks » 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 » Portal » Open Portal » com.sun.portal.fabric.tasks 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Id: PortalFileHandler.java,v 1.4 2007/01/26 03:48:33 portalbld Exp $
003:         * Copyright 2004 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.fabric.tasks;
014:
015:        import java.io.File;
016:        import java.io.FileInputStream;
017:        import java.io.FileOutputStream;
018:        import java.io.FileReader;
019:        import java.io.FileNotFoundException;
020:        import java.io.InputStream;
021:        import java.io.InputStreamReader;
022:        import java.io.IOException;
023:
024:        import java.util.logging.Level;
025:        import java.util.logging.Logger;
026:        import java.util.Enumeration;
027:        import java.util.ArrayList;
028:        import java.util.Iterator;
029:        import java.util.List;
030:        import java.util.zip.ZipEntry;
031:        import java.util.zip.ZipFile;
032:        import java.util.zip.ZipOutputStream;
033:        import com.sun.portal.fabric.util.FileUtil;
034:        import com.sun.portal.log.common.PortalLogger;
035:        import com.sun.portal.util.Platform;
036:
037:        /**
038:         * This is a utility class that creates a zip file out of the portal
039:         * resources on the filesystem. This zipped file can be unzipped to setup the 
040:         * directory structure for a portal on a new host.
041:         */
042:        public class PortalFileHandler {
043:
044:            private static Logger logger = PortalLogger
045:                    .getLogger(PortalFileHandler.class);
046:
047:            public static void zipFilesystem(String portalDir, String output) {
048:
049:                if (!portalDir.endsWith(Platform.fs)) {
050:                    portalDir = portalDir + Platform.fs;
051:                }
052:
053:                File outputFile = new File(output);
054:                List fileList = new ArrayList(100);
055:                getFiles(new File(portalDir), fileList);
056:
057:                try {
058:                    // If a file with the output filename exists, delete it
059:                    if (outputFile.exists()) {
060:                        outputFile.delete();
061:                    }
062:
063:                    // Define the file read buffer size
064:                    byte[] buf = new byte[1024];
065:
066:                    // Create the ZIP file
067:                    FileOutputStream dest = new FileOutputStream(output);
068:                    ZipOutputStream out = new ZipOutputStream(dest);
069:
070:                    try {
071:
072:                        // Compress the files
073:                        Iterator itr = fileList.iterator();
074:                        while (itr.hasNext()) {
075:
076:                            File file = (File) itr.next();
077:                            String fpath = file.getAbsolutePath();
078:                            // Open input stream to transfer bytes from the file to the ZIP file
079:                            FileInputStream in = new FileInputStream(fpath);
080:                            String zipEntryPath = fpath.replaceAll(portalDir,
081:                                    "");
082:                            try {
083:                                // Add ZIP entry to output stream.
084:                                out.putNextEntry(new ZipEntry(zipEntryPath));
085:                                int len;
086:                                while ((len = in.read(buf)) > 0) {
087:                                    out.write(buf, 0, len);
088:                                }
089:                            } finally {
090:                                // Complete the entry
091:                                out.closeEntry();
092:                                in.close();
093:                            }
094:                        }
095:
096:                    } finally {
097:                        // Complete the ZIP file
098:                        out.close();
099:                    }
100:
101:                } catch (Exception e) {
102:                    logger.log(Level.SEVERE, "PSFB_CSPFT0281", e);
103:                    // Discard the uncomplete file
104:                    if (outputFile.exists()) {
105:                        outputFile.delete();
106:                    }
107:                }
108:            }
109:
110:            public static void unzipFilesystem(String portalDir,
111:                    String portalZip) {
112:
113:                if (!portalDir.endsWith(Platform.fs)) {
114:                    portalDir = portalDir + Platform.fs;
115:                }
116:
117:                try {
118:                    // Open the zip.
119:                    ZipFile zip = new ZipFile(portalZip);
120:                    // Get entries in this zip file
121:                    Enumeration en = zip.entries();
122:                    try {
123:                        while (en.hasMoreElements()) {
124:                            // Get the entry
125:                            ZipEntry entry = (ZipEntry) en.nextElement();
126:                            // If the entry is not null, extract it.
127:                            if (entry != null) {
128:                                // Get an input stream for the entry.
129:                                InputStream entryStream = zip
130:                                        .getInputStream(entry);
131:                                try {
132:                                    // Create the output file
133:                                    File outFile = new File(portalDir
134:                                            + entry.getName());
135:                                    File parent = outFile.getParentFile();
136:                                    if (!parent.exists()) {
137:                                        parent.mkdirs();
138:                                    }
139:                                    FileOutputStream file = new FileOutputStream(
140:                                            outFile);
141:                                    try {
142:                                        // Allocate a buffer for reading the entry data.
143:                                        byte[] buffer = new byte[1024];
144:                                        int bytesRead;
145:                                        // Read the entry data and write it to the output file.
146:                                        while ((bytesRead = entryStream
147:                                                .read(buffer)) != -1) {
148:                                            file.write(buffer, 0, bytesRead);
149:                                        }
150:                                    } finally {
151:                                        file.close();
152:                                    }
153:                                } finally {
154:                                    entryStream.close();
155:                                }
156:                            }
157:                        }
158:                    } finally {
159:                        zip.close();
160:                    }
161:                } catch (Exception e) {
162:                    logger.log(Level.SEVERE, "PSFB_CSPFT0282", e);
163:                }
164:            }
165:
166:            /**
167:             * Builds a list of Files (absolute path) by recursively entering the dir.
168:             */
169:            private static void getFiles(File startDir, List fileList) {
170:                File[] files = startDir.listFiles();
171:                if (files != null) {
172:                    for (int i = 0; i < files.length; i++) {
173:                        File file = (File) files[i];
174:                        if (file.isDirectory()) {
175:                            getFiles(file, fileList);
176:                        } else {
177:                            fileList.add(file);
178:                        }
179:                    }
180:                }
181:            }
182:
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.