Source Code Cross Referenced for WarParser.java in  » Testing » jakarta-cactus » org » apache » cactus » integration » ant » deployment » 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 » Testing » jakarta cactus » org.apache.cactus.integration.ant.deployment 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * ========================================================================
003:         * 
004:         * Copyright 2003 The Apache Software Foundation.
005:         *
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         * 
010:         *   http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         * 
018:         * ========================================================================
019:         */
020:        package org.apache.cactus.integration.ant.deployment;
021:
022:        import java.io.File;
023:        import java.io.IOException;
024:        import java.util.Iterator;
025:
026:        import javax.xml.parsers.ParserConfigurationException;
027:
028:        import org.apache.cactus.integration.ant.deployment.webapp.DefaultWarArchive;
029:        import org.apache.cactus.integration.ant.deployment.webapp.WarArchive;
030:        import org.apache.tools.ant.BuildException;
031:        import org.xml.sax.SAXException;
032:
033:        /**
034:         * Parse an WAR descriptor to extract meaninful information for Cactus,
035:         * the results being stored in a {@link WarDeployableFile} object. 
036:         * 
037:         * @since Cactus 1.5
038:         * @version $Id: WarParser.java 239003 2004-05-31 20:05:27Z vmassol $
039:         */
040:        public class WarParser {
041:            /**
042:             * Parse an WAR descriptor to extract meaninful information for Cactus.
043:             * 
044:             * @param theDeployableFile the file to parse and deploy
045:             * @return the parse results as a {@link WarDeployableFile} object
046:             */
047:            public static final WarDeployableFile parse(File theDeployableFile) {
048:                WarDeployableFile deployable = new WarDeployableFile();
049:
050:                try {
051:                    deployable.setFile(theDeployableFile);
052:                    deployable.setWarArchive(new DefaultWarArchive(
053:                            theDeployableFile));
054:                    deployable
055:                            .setTestContext(parseWebContext(theDeployableFile));
056:                    deployable
057:                            .setServletRedirectorMapping(parseServletRedirectorMapping(deployable
058:                                    .getWarArchive()));
059:                    deployable
060:                            .setFilterRedirectorMapping(parseFilterRedirectorMapping(deployable
061:                                    .getWarArchive()));
062:                    deployable
063:                            .setJspRedirectorMapping(parseJspRedirectorMapping(deployable
064:                                    .getWarArchive()));
065:                } catch (IOException e) {
066:                    throw new BuildException(
067:                            "Failed to parse deployment descriptor "
068:                                    + "for WAR file [" + theDeployableFile
069:                                    + "].", e);
070:                } catch (ParserConfigurationException e) {
071:                    throw new BuildException(
072:                            "Failed to parse deployment descriptor "
073:                                    + "for WAR file [" + theDeployableFile
074:                                    + "].", e);
075:                } catch (SAXException e) {
076:                    throw new BuildException(
077:                            "Failed to parse deployment descriptor "
078:                                    + "for WAR file [" + theDeployableFile
079:                                    + "].", e);
080:                }
081:
082:                return deployable;
083:            }
084:
085:            /**
086:             * @param theDeployableFile the file to parse and deploy
087:             * @return the test context that will be used to verify if the container
088:             *         is started or not
089:             */
090:            protected static String parseWebContext(File theDeployableFile) {
091:                String context = theDeployableFile.getName();
092:                int warIndex = context.toLowerCase().lastIndexOf(".war");
093:                if (warIndex >= 0) {
094:                    context = context.substring(0, warIndex);
095:                }
096:                return context;
097:            }
098:
099:            /**
100:             * Find the first URL-pattern to which the Cactus servlet redirector is 
101:             * mapped in the deployment descriptor.
102:             *
103:             * @return the servlet redirector mapping if found or <code>null</code>
104:             *         if not found
105:             * @param theWar the WAR descriptor that is parsed when looking for
106:             *        a Cactus servlet redirector mapping  
107:             * @throws IOException If there was a problem reading the deployment
108:             *         descriptor in the WAR
109:             * @throws SAXException If the deployment descriptor of the WAR could not
110:             *         be parsed
111:             * @throws ParserConfigurationException If there is an XML parser
112:             *         configration problem
113:             */
114:            static String parseServletRedirectorMapping(WarArchive theWar)
115:                    throws SAXException, IOException,
116:                    ParserConfigurationException {
117:                Iterator servletNames = theWar
118:                        .getWebXml()
119:                        .getServletNamesForClass(
120:                                "org.apache.cactus.server.ServletTestRedirector");
121:                if (servletNames.hasNext()) {
122:                    // we only care about the first definition and the first mapping
123:                    String name = (String) servletNames.next();
124:                    Iterator mappings = theWar.getWebXml().getServletMappings(
125:                            name);
126:                    if (mappings.hasNext()) {
127:                        return (String) mappings.next();
128:                    }
129:                }
130:                return null;
131:            }
132:
133:            /**
134:             * Find the first URL-pattern to which the Cactus filter redirector is 
135:             * mapped in the deployment descriptor.
136:             * 
137:             * @return the filter redirector mapping if found or <code>null</code>
138:             *         if not found
139:             * @param theWar the WAR descriptor that is parsed when looking for
140:             *        a Cactus filter redirector mapping  
141:             * @throws IOException If there was a problem reading the  deployment
142:             *         descriptor in the WAR
143:             * @throws SAXException If the deployment descriptor of the WAR could not
144:             *         be parsed
145:             * @throws ParserConfigurationException If there is an XML parser
146:             *         configration problem
147:             */
148:            static String parseFilterRedirectorMapping(WarArchive theWar)
149:                    throws IOException, SAXException,
150:                    ParserConfigurationException {
151:                Iterator filterNames = theWar
152:                        .getWebXml()
153:                        .getFilterNamesForClass(
154:                                "org.apache.cactus.server.FilterTestRedirector");
155:                if (filterNames.hasNext()) {
156:                    // we only care about the first definition and the first mapping
157:                    String name = (String) filterNames.next();
158:                    Iterator mappings = theWar.getWebXml().getFilterMappings(
159:                            name);
160:                    if (mappings.hasNext()) {
161:                        return (String) mappings.next();
162:                    }
163:                }
164:                return null;
165:            }
166:
167:            /**
168:             * Find the first URL-pattern to which the Cactus JSP redirector is 
169:             * mapped in the deployment descriptor.
170:             * 
171:             * @return the JSP redirector mapping if found or <code>null</code>
172:             *         if not found
173:             * @param theWar the WAR descriptor that is parsed when looking for
174:             *        a Cactus JSP redirector mapping  
175:             * @throws IOException If there was a problem reading the  deployment
176:             *         descriptor in the WAR
177:             * @throws SAXException If the deployment descriptor of the WAR could not
178:             *         be parsed
179:             * @throws ParserConfigurationException If there is an XML parser
180:             *         configration problem
181:             */
182:            static String parseJspRedirectorMapping(WarArchive theWar)
183:                    throws IOException, SAXException,
184:                    ParserConfigurationException {
185:                // To get the JSP redirector mapping, we must first get the full path to
186:                // the corresponding JSP file in the WAR
187:                String jspRedirectorPath = theWar
188:                        .findResource("jspRedirector.jsp");
189:                if (jspRedirectorPath != null) {
190:                    jspRedirectorPath = "/" + jspRedirectorPath;
191:                    Iterator jspNames = theWar.getWebXml()
192:                            .getServletNamesForJspFile(jspRedirectorPath);
193:                    if (jspNames.hasNext()) {
194:                        // we only care about the first definition and the first
195:                        // mapping
196:                        String name = (String) jspNames.next();
197:                        Iterator mappings = theWar.getWebXml()
198:                                .getServletMappings(name);
199:                        if (mappings.hasNext()) {
200:                            return (String) mappings.next();
201:                        }
202:                    }
203:                }
204:                return null;
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.