Source Code Cross Referenced for WebApplication.java in  » Web-Framework » JAT » com » jat » core » installer » step » 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 » Web Framework » JAT » com.jat.core.installer.step 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.jat.core.installer.step;
002:
003:        import java.io.File;
004:        import java.io.IOException;
005:        import javax.xml.parsers.ParserConfigurationException;
006:
007:        import org.w3c.dom.Document;
008:        import org.w3c.dom.Node;
009:        import org.w3c.dom.NodeList;
010:        import org.xml.sax.SAXException;
011:        import com.jat.core.installer.util.CommandExec;
012:        import com.jat.core.log.LogManager;
013:        import com.jat.util.file.FileUtil;
014:        import com.jat.util.xml.XMLDocument;
015:        import com.jat.util.xml.XMLUtil;
016:
017:        /**
018:         * <p>Title: JAT</p>
019:         * <p>Description:</p>
020:         * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
021:         * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p>
022:         * @author stf
023:         * @version 1.1
024:         * @since 1.2
025:         */
026:
027:        public class WebApplication {
028:
029:            public static WebApplication getWebApplication() {
030:                String osName = System.getProperty("os.name");
031:                if (osName != null
032:                        && osName.toLowerCase().indexOf("microsoft") == -1
033:                        && osName.toLowerCase().indexOf("window") == -1
034:                        && osName.toLowerCase().indexOf("ms") == -1)
035:                    return new UnixWebApplication();
036:                return new WebApplication();
037:            }
038:
039:            public void unwar(String warFile, String tempDir) throws Exception {
040:                createPath(tempDir);
041:                CommandExec commandEx = new CommandExec();
042:                String[] cmd = new String[4];
043:                cmd[0] = JatProject.getFilename(new File("bin")
044:                        .getAbsolutePath(), "unwar.bat");
045:                cmd[1] = new File(tempDir).getAbsolutePath();
046:                cmd[2] = "-xf";
047:                cmd[3] = new File(warFile).getAbsolutePath();
048:                commandEx.execute(cmd);
049:            }
050:
051:            public void modifyWebXml(String tempDir, String projectPath,
052:                    String configFileName) throws Exception {
053:                File webXml = new File(JatProject.getFilename(JatProject
054:                        .getFilename(tempDir, "WEB-INF"), "web.xml"));
055:                String dtd = "<!DOCTYPE web-app PUBLIC \"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN\" \"http://java.sun.com/dtd/web-app_2_3.dtd\">";
056:                try {
057:                    String content = com.jat.util.StringUtil.replace(FileUtil
058:                            .readFile(webXml), dtd, "");
059:                    XMLDocument doc = XMLUtil.getXMLDocument(content, false);
060:                    Document w3cDoc = doc.getDocument();
061:                    Node sub = getNode4Change(w3cDoc);
062:                    sub.setNodeValue(JatProject.getFilename(projectPath,
063:                            configFileName));
064:                    doc.saveToFile(JatProject.getFilename(JatProject
065:                            .getFilename(tempDir, "WEB-INF"), "web.xml"));
066:                } catch (SAXException ex) {
067:                    LogManager.sendError("Installer error: " + ex.getMessage());
068:                    throw new Exception(ex);
069:                } catch (ParserConfigurationException ex) {
070:                    LogManager.sendError("Installer error: " + ex.getMessage());
071:                    throw new Exception(ex);
072:                } catch (IOException ex) {
073:                    LogManager.sendError("Installer error: " + ex.getMessage());
074:                    throw new Exception(ex);
075:                }
076:            }
077:
078:            public String war(String tempDir, String projectName)
079:                    throws Exception {
080:                CommandExec commandEx = new CommandExec();
081:                String[] cmd = new String[5];
082:                cmd[0] = JatProject.getFilename(new File("bin")
083:                        .getAbsolutePath(), "war.bat");
084:                cmd[1] = new File(tempDir).getAbsolutePath();
085:                cmd[2] = "-cf0";
086:                cmd[3] = projectName + ".war";
087:                cmd[4] = "*";
088:                commandEx.execute(cmd);
089:                return projectName + ".war";
090:            }
091:
092:            public void moveWar(String tempDir, String fileName, String appDir)
093:                    throws Exception {
094:                // check se appDir esiste
095:                File dir = new File(appDir);
096:                if (!dir.exists()) {
097:                    LogManager.sendError("Installer error: appDir '" + appDir
098:                            + "' doesn't exist");
099:                    throw new Exception("appDir '" + appDir + "' doesn't exist");
100:                }
101:                File fileFromFile = new File(JatProject.getFilename(tempDir,
102:                        fileName));
103:
104:                File fileToFile = new File(JatProject.getFilename(appDir,
105:                        fileName));
106:                if (fileToFile.exists()) {
107:                    fileToFile.delete();
108:                }
109:                boolean moveFile = fileFromFile.renameTo(new File(JatProject
110:                        .getFilename(appDir, fileName)));
111:                if (!moveFile) {
112:                    LogManager.sendError("Installer error: cannot war file '"
113:                            + fileName + "'");
114:                    throw new Exception("cannot war file '" + fileName + "'");
115:                }
116:
117:            }
118:
119:            public void deleteTemp(String tempDir) throws Exception {
120:                File tempToDelete = new File(tempDir);
121:                deleteEntireDir(tempToDelete.getAbsoluteFile());
122:            }
123:
124:            protected WebApplication() {
125:            }
126:
127:            private Node getNode4Change(Document w3cDoc) throws Exception {
128:                Node substition = null;
129:                NodeList list = w3cDoc.getElementsByTagName("servlet");
130:                Node change = null;
131:                for (int i = 0; i < list.getLength(); i++) {
132:                    if (change != null) {
133:                        break;
134:                    }
135:                    Node aNode = (Node) list.item(i);
136:                    NodeList aSubList = aNode.getChildNodes();
137:                    for (int j = 0; j < aSubList.getLength(); j++) {
138:                        Node aSubNode = (Node) aSubList.item(j);
139:
140:                        if (aSubNode.getNodeName().equals("servlet-name")) {
141:                            NodeList a = aSubNode.getChildNodes();
142:                            for (int k = 0; k < a.getLength(); k++) {
143:                                Node b = a.item(k);
144:                                if (b.getNodeValue().equals("projectservlet")) {
145:                                    change = aSubNode.getParentNode();
146:                                    break;
147:                                }
148:                            }
149:                        }
150:                    }
151:                }
152:                if (change == null)
153:                    throw new Exception("projectservlet not found");
154:                NodeList aList = change.getChildNodes();
155:                for (int i = 0; i < aList.getLength(); i++) {
156:                    Node aNode = aList.item(i);
157:                    if (aNode.getNodeName().equals("init-param")) {
158:                        NodeList aSubList = aNode.getChildNodes();
159:                        for (int j = 0; j < aSubList.getLength(); j++) {
160:                            Node aSubNode = aSubList.item(j);
161:                            if (aSubNode.getNodeName().equals("param-value")) {
162:                                substition = aSubNode.getFirstChild();
163:                            }
164:                        }
165:                    }
166:                }
167:                return substition;
168:            }
169:
170:            protected void createPath(String path) throws Exception {
171:                File dir = new File(path);
172:                if (dir.exists()) {
173:                    deleteEntireDir(dir);
174:                }
175:                dir.mkdirs();
176:            }
177:
178:            private void deleteEntireDir(File dir) throws IOException {
179:                FileUtil.deleteDirectory(dir);
180:            }
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.