Source Code Cross Referenced for LocalServletConfig.java in  » Web-Services » xins » org » xins » common » servlet » container » 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 Services » xins » org.xins.common.servlet.container 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: LocalServletConfig.java,v 1.19 2007/09/18 08:45:09 agoubard Exp $
003:         *
004:         * Copyright 2003-2007 Orange Nederland Breedband B.V.
005:         * See the COPYRIGHT file for redistribution and use restrictions.
006:         */
007:        package org.xins.common.servlet.container;
008:
009:        import java.io.ByteArrayInputStream;
010:        import java.io.File;
011:        import java.io.InputStream;
012:        import java.util.Enumeration;
013:        import java.util.Properties;
014:        import java.util.jar.JarEntry;
015:        import java.util.jar.JarFile;
016:        import javax.servlet.ServletConfig;
017:        import javax.servlet.ServletContext;
018:
019:        import org.xins.common.Log;
020:        import org.xins.common.xml.SAXParserProvider;
021:
022:        import org.xml.sax.Attributes;
023:        import org.xml.sax.InputSource;
024:        import org.xml.sax.SAXException;
025:        import org.xml.sax.helpers.DefaultHandler;
026:
027:        /**
028:         * This class is an implementation of the ServletConfig that can be
029:         * called locally.
030:         *
031:         * @version $Revision: 1.19 $ $Date: 2007/09/18 08:45:09 $
032:         * @author <a href="mailto:anthony.goubard@japplis.com">Anthony Goubard</a>
033:         */
034:        public class LocalServletConfig implements  ServletConfig {
035:
036:            /**
037:             * The name of the servlet.
038:             */
039:            private String _servletName;
040:
041:            /**
042:             * The class of the servlet.
043:             */
044:            private String _servletClass;
045:
046:            /**
047:             * The properties of the servlet.
048:             */
049:            private Properties _initParameters;
050:
051:            /**
052:             * The servlet context.
053:             */
054:            private ServletContext _context;
055:
056:            /**
057:             * The WAR file.
058:             */
059:            private File _warFile;
060:
061:            /**
062:             * Creates a new Servlet configuration.
063:             *
064:             * @param warFileLocation
065:             *    the war file containing the servlet to deploy,
066:             *    cannot be <code>null</code>.
067:             */
068:            public LocalServletConfig(File warFileLocation) {
069:                _warFile = warFileLocation;
070:                _initParameters = new Properties();
071:                _context = new XINSServletContext(this );
072:
073:                try {
074:                    JarFile warFile = new JarFile(warFileLocation);
075:                    JarEntry webxmlEntry = warFile
076:                            .getJarEntry("WEB-INF/web.xml");
077:                    InputStream webxmlInputStream = warFile
078:                            .getInputStream(webxmlEntry);
079:                    parseWebXML(webxmlInputStream);
080:                } catch (Exception ex) {
081:
082:                    Log.log_1512(ex);
083:                }
084:            }
085:
086:            /**
087:             * Parses the web.xml file.
088:             *
089:             * @param webxmlInputStream
090:             *    the web.xml file input stream.
091:             *
092:             * @throws Exception
093:             *    if the file cannot be parsed for any reason.
094:             */
095:            private void parseWebXML(InputStream webxmlInputStream)
096:                    throws Exception {
097:                DefaultHandler handler = new WebInfoParser();
098:                SAXParserProvider.get().parse(webxmlInputStream, handler);
099:                webxmlInputStream.close();
100:            }
101:
102:            public String getInitParameter(String param) {
103:                return _initParameters.getProperty(param);
104:            }
105:
106:            public String getServletName() {
107:                return _servletName;
108:            }
109:
110:            /**
111:             * Gets the class name of the Servlet.
112:             *
113:             * @return
114:             *    the class name of the servlet, cannot be <code>null</code>.
115:             */
116:            public String getServletClass() {
117:                return _servletClass;
118:            }
119:
120:            public ServletContext getServletContext() {
121:                return _context;
122:            }
123:
124:            public Enumeration getInitParameterNames() {
125:                return _initParameters.keys();
126:            }
127:
128:            /**
129:             * Gets the WAR file location.
130:             *
131:             * @return
132:             *    the WAR file, never <code>null</code>
133:             */
134:            File getWarFile() {
135:                return _warFile;
136:            }
137:
138:            /**
139:             * Parser for the web.xml containing the information about the Servlet.
140:             */
141:            private class WebInfoParser extends DefaultHandler {
142:                /**
143:                 * The PCDATA element of the tag that is actually parsed.
144:                 */
145:                private StringBuffer _pcdata;
146:
147:                /**
148:                 * The name of the property that is currently parsed.
149:                 */
150:                private String _paramName;
151:
152:                public void startElement(String namespaceURI, String localName,
153:                        String qName, Attributes atts)
154:                        throws IllegalArgumentException, SAXException {
155:                    _pcdata = new StringBuffer(80);
156:                }
157:
158:                public void endElement(String namespaceURI, String localName,
159:                        String qName) throws IllegalArgumentException,
160:                        SAXException {
161:                    if (qName.equals("param-name")) {
162:                        _paramName = _pcdata.toString();
163:                    } else if (qName.equals("param-value")) {
164:                        _initParameters.setProperty(_paramName, _pcdata
165:                                .toString());
166:                    } else if (qName.equals("servlet-name")) {
167:                        _servletName = _pcdata.toString();
168:                    } else if (qName.equals("servlet-class")) {
169:                        _servletClass = _pcdata.toString();
170:                    }
171:                    _pcdata = null;
172:                }
173:
174:                public void characters(char[] ch, int start, int length)
175:                        throws IndexOutOfBoundsException {
176:
177:                    if (_pcdata != null) {
178:                        _pcdata.append(ch, start, length);
179:                    }
180:                }
181:
182:                public InputSource resolveEntity(String publicId,
183:                        String systemId) {
184:                    return new InputSource(
185:                            new ByteArrayInputStream(new byte[0]));
186:                }
187:            }
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.