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


001:        /* 
002:         * Copyright 2002 Sun Microsystems, Inc.  All rights reserved. 
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms. 
004:         */
005:        package com.sun.portal.portlet.cli;
006:
007:        import java.io.File;
008:        import java.io.FileInputStream;
009:        import java.io.FileOutputStream;
010:        import java.io.InputStream;
011:        import java.io.IOException;
012:        import java.io.FileNotFoundException;
013:
014:        import java.util.ArrayList;
015:        import java.util.List;
016:        import java.util.Enumeration;
017:        import java.util.Properties;
018:
019:        import java.util.jar.Manifest;
020:        import java.util.jar.JarEntry;
021:        import java.util.jar.JarFile;
022:        import java.util.jar.JarOutputStream;
023:
024:        import org.jdom.Document;
025:        import org.jdom.Element;
026:        import org.jdom.Comment;
027:        import org.jdom.JDOMException;
028:        import org.jdom.IllegalAddException;
029:        import org.jdom.input.SAXBuilder;
030:        import org.jdom.output.XMLOutputter;
031:
032:        /**
033:         * PDWarUpdater is responsible for inserting the
034:         * Context Params, listener classes and PAE servlet 
035:         * definition into the web.xml of the war file and inserting
036:         * the PAE jar file into the war file.
037:         */
038:        public class PDWarUpdater {
039:
040:            private File warFile = null;
041:            private JarFile jar = null;
042:            private Properties configProps = null;
043:
044:            private static final String PAE_LOCATION = "PAEJarLocation";
045:            private static final String TLD_LOCATION = "tldLocation";
046:            private static final String WEB_INF_PREFIX = "WEB-INF" + "/";
047:            private static final String WEB_XML = "web.xml";
048:            private static final String WEB_XML_NAME = WEB_INF_PREFIX + WEB_XML;
049:            private static final String PAE_PREFIX = WEB_INF_PREFIX + "lib"
050:                    + "/";
051:            private static final String DD_LOCATION = "DDFileLocation";
052:
053:            public PDWarUpdater(File warFile, Properties props)
054:                    throws IOException {
055:                this .warFile = warFile;
056:                jar = new JarFile(warFile);
057:                configProps = props;
058:            }
059:
060:            public JarFile getJarFile() {
061:                return jar;
062:            }
063:
064:            public File getUpdatedWarFile(File webXMLFile) throws IOException {
065:
066:                //portletappengine jar.
067:                String PAEFilename = configProps.getProperty(PAE_LOCATION);
068:                File paeFile = new File(PAEFilename);
069:
070:                //get tld file
071:                String tldFileName = configProps.getProperty(TLD_LOCATION);
072:                File tldFile = new File(tldFileName);
073:
074:                //location of portlet tmp dir
075:                String ddLocation = configProps.getProperty(DD_LOCATION);
076:
077:                // Create temp war file.
078:                File tempJarFile = new File(ddLocation, warFile.getName()
079:                        + ".tmp");
080:                tempJarFile.deleteOnExit();
081:
082:                // Initialize a flag that will indicate that the jar was updated.
083:                boolean jarUpdated = false;
084:
085:                try {
086:                    // Create a temp jar file with no manifest. (The manifest will
087:                    // be copied when the entries are copied.)
088:                    Manifest jarManifest = jar.getManifest();
089:                    JarOutputStream tempJar = new JarOutputStream(
090:                            new FileOutputStream(tempJarFile));
091:
092:                    // Allocate a buffer for reading entry data.
093:                    byte[] buffer = new byte[1024];
094:                    int bytesRead;
095:
096:                    try {
097:                        // Open the pae file.
098:                        FileInputStream file = new FileInputStream(paeFile);
099:
100:                        try {
101:                            // Create a jar entry and add it to the temp jar.
102:                            JarEntry entry = new JarEntry(PAE_PREFIX
103:                                    + paeFile.getName());
104:                            tempJar.putNextEntry(entry);
105:
106:                            // Read the file and write it to the jar.
107:                            while ((bytesRead = file.read(buffer)) != -1) {
108:                                tempJar.write(buffer, 0, bytesRead);
109:                            }
110:
111:                            //System.out.println(entry.getName() + " added.");
112:                        } finally {
113:                            file.close();
114:                        }
115:
116:                        //open the web.xml file
117:                        FileInputStream webXMLin = new FileInputStream(
118:                                webXMLFile);
119:
120:                        try {
121:                            // Create a jar entry and add it to the temp jar.
122:                            JarEntry entry = new JarEntry(WEB_XML_NAME);
123:                            tempJar.putNextEntry(entry);
124:
125:                            // Read the file and write it to the jar.
126:                            while ((bytesRead = webXMLin.read(buffer)) != -1) {
127:                                tempJar.write(buffer, 0, bytesRead);
128:                            }
129:
130:                            //System.out.println(entry.getName() + " added.");
131:                        } finally {
132:                            webXMLin.close();
133:                        }
134:
135:                        // open the tld file.
136:                        FileInputStream tldin = new FileInputStream(tldFile);
137:                        try {
138:                            // Create a jar entry and add it to the temp jar.
139:                            JarEntry entry = new JarEntry(WEB_INF_PREFIX
140:                                    + tldFile.getName());
141:                            tempJar.putNextEntry(entry);
142:
143:                            // Read the file and write it to the jar.
144:                            while ((bytesRead = tldin.read(buffer)) != -1) {
145:                                tempJar.write(buffer, 0, bytesRead);
146:                            }
147:
148:                            //System.out.println(entry.getName() + " added.");
149:                        } finally {
150:                            tldin.close();
151:                        }
152:
153:                        // Loop through the jar entries and add them to the temp jar,
154:                        // skipping the entry that was added to the temp jar already.
155:
156:                        for (Enumeration entries = jar.entries(); entries
157:                                .hasMoreElements();) {
158:                            // Get the next entry.
159:                            JarEntry entry = (JarEntry) entries.nextElement();
160:
161:                            // If the entry has not been added already, add it.
162:                            if ((!entry.getName().equals(WEB_XML_NAME))
163:                                    && (!entry.getName().equals(
164:                                            PAE_PREFIX + paeFile.getName()))
165:                                    && (!entry.getName().equals(
166:                                            WEB_INF_PREFIX + tldFile.getName()))) {
167:                                // Get an input stream for the entry.
168:                                InputStream entryStream = jar
169:                                        .getInputStream(entry);
170:
171:                                // Read the entry and write it to the temp jar.
172:                                tempJar.putNextEntry(entry);
173:
174:                                while ((bytesRead = entryStream.read(buffer)) != -1) {
175:                                    tempJar.write(buffer, 0, bytesRead);
176:                                }
177:                            }
178:                        }
179:
180:                        jarUpdated = true;
181:                    } catch (Exception ex) {
182:                        PortletDeployerLocalizer.error(ex.toString());
183:
184:                        // Add a stub entry here, so that the jar will close without an
185:                        // exception.
186:                        tempJar.putNextEntry(new JarEntry("stub"));
187:                    } finally {
188:                        tempJar.close();
189:                    }
190:                } finally {
191:                    jar.close();
192:                    //System.out.println(warFile.getName() + " closed.");
193:
194:                    // If the jar was not updated, delete the temp jar file.
195:
196:                    if (!jarUpdated) {
197:                        tempJarFile.delete();
198:                    }
199:                }
200:
201:                // If the jar was updated, delete the original jar file and rename the
202:                // temp jar file to the original name.
203:
204:                if (jarUpdated) {
205:                    //System.out.println(warFile.getName() + " updated.");
206:                    return tempJarFile;
207:                }
208:                return null;
209:            }
210:
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.