Source Code Cross Referenced for UnpackWar.java in  » J2EE » Enhydra-Application-Framework » org » enhydra » server » util » 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 » Enhydra Application Framework » org.enhydra.server.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.enhydra.server.util;
002:
003:        /**
004:         * <p>Title: </p>
005:         * <p>Description: Util class for unpack WAR file to destination directory</p>
006:         * <p>Copyright: Copyright (c) 2002</p>
007:         * <p>Company: </p>
008:         * @author Damir Milovic
009:         * @version 1.0
010:         */
011:
012:        import java.io.File;
013:        import java.io.FileInputStream;
014:        import java.io.FileNotFoundException;
015:        import java.io.FileOutputStream;
016:        import java.io.IOException;
017:        import java.io.InputStream;
018:        import java.util.zip.ZipEntry;
019:        import java.util.zip.ZipInputStream;
020:
021:        import org.enhydra.server.EnhydraServerException;
022:
023:        public class UnpackWar {
024:
025:            /**
026:             * If this constructor is used must call <code>setWar()</code> and
027:             * <code>setDestDir()</code> methods.
028:             */
029:            public UnpackWar() {
030:            }
031:
032:            /**
033:             * Default constructor
034:             * @param warPath path to war file
035:             * @param destDirPath path to destination directory for unpack files
036:             */
037:            public UnpackWar(String warPath, String destDirPath) {
038:                setWar(new File(warPath));
039:                setDestDir(new File(destDirPath));
040:            }
041:
042:            private File dest;
043:
044:            private File source;
045:
046:            /**
047:             * Unpack war to destination directory.
048:             */
049:            public void execute() throws EnhydraServerException {
050:                expandFile(source, dest);
051:            }
052:
053:            private void expandFile(File srcF, File dir)
054:                    throws EnhydraServerException {
055:                log("Expanding: " + srcF + " into " + dir);
056:                ZipInputStream zis = null;
057:                try {
058:
059:                    zis = new ZipInputStream(new FileInputStream(srcF));
060:                    ZipEntry ze = null;
061:
062:                    while ((ze = zis.getNextEntry()) != null) {
063:                        extractFile(srcF, dir, zis, ze.getName(), ze
064:                                .isDirectory());
065:                    }
066:
067:                    log("expand complete");
068:                } catch (IOException ioe) {
069:                    throw new EnhydraServerException("Error while expanding "
070:                            + srcF.getPath(), ioe);
071:                } finally {
072:                    if (zis != null) {
073:                        try {
074:                            zis.close();
075:                        } catch (IOException e) {
076:                        }
077:                    }
078:                }
079:            }
080:
081:            private void extractFile(File srcF, File dir,
082:                    InputStream compressedInputStream, String entryName,
083:                    boolean isDirectory) throws IOException {
084:
085:                String filePath = PathUtil.makeAbsolutePath(dir
086:                        .getAbsolutePath(), entryName);
087:                File f = new File(filePath);
088:                try {
089:                    log("expanding " + entryName + " to " + f);
090:                    // create intermediary directories - sometimes zip don't add them
091:                    File dirF = f.getParentFile();
092:                    if (dirF != null) {
093:                        dirF.mkdirs();
094:                    }
095:
096:                    if (isDirectory) {
097:                        f.mkdirs();
098:                    } else {
099:                        byte[] buffer = new byte[1024];
100:                        int length = 0;
101:                        FileOutputStream fos = null;
102:                        try {
103:                            fos = new FileOutputStream(f);
104:
105:                            while ((length = compressedInputStream.read(buffer)) >= 0) {
106:                                fos.write(buffer, 0, length);
107:                            }
108:
109:                            fos.close();
110:                            fos = null;
111:                        } finally {
112:                            if (fos != null) {
113:                                try {
114:                                    fos.close();
115:                                } catch (IOException e) {
116:                                }
117:                            }
118:                        }
119:                    }
120:
121:                } catch (FileNotFoundException ex) {
122:                    log("Unable to expand to file " + f.getPath());
123:                }
124:
125:            }
126:
127:            /**
128:             * Set the destination directory. File will be unzipped into the
129:             * destination directory.
130:             *
131:             * @param d Path to the directory.
132:             */
133:            public void setDestDir(File d) {
134:                this .dest = d;
135:            }
136:
137:            /**
138:             * Set the path to War-file.
139:             *
140:             * @param s Path to war-file.
141:             */
142:            public void setWar(File s) {
143:                this .source = s;
144:            }
145:
146:            // todo: set logger
147:            private void log(String message) {
148:                System.out.println(message);
149:            }
150:
151:            //For Test only
152:            public static void main(String[] args) {
153:                UnpackWar test = new UnpackWar(
154:                        "c:/Temp/testwar/testKelpDist.war",
155:                        "c:/Temp/testwar/webapps/test");
156:                try {
157:                    test.execute();
158:                } catch (Exception e) {
159:                    e.printStackTrace();
160:                }
161:            }
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.