Source Code Cross Referenced for MockServletContext.java in  » J2EE » facelets » com » sun » facelets » mock » 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 » facelets » com.sun.facelets.mock 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003:         * Licensed under the Common Development and Distribution License,
004:         * you may not use this file except in compliance with the License.
005:         * You may obtain a copy of the License at
006:         * 
007:         *   http://www.sun.com/cddl/
008:         *   
009:         * Unless required by applicable law or agreed to in writing, software
010:         * distributed under the License is distributed on an "AS IS" BASIS,
011:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
012:         * implied. See the License for the specific language governing
013:         * permissions and limitations under the License.
014:         */package com.sun.facelets.mock;
015:
016:        import java.io.File;
017:        import java.io.IOException;
018:        import java.io.InputStream;
019:        import java.net.MalformedURLException;
020:        import java.net.URI;
021:        import java.net.URL;
022:        import java.util.Collections;
023:        import java.util.Enumeration;
024:        import java.util.HashSet;
025:        import java.util.Hashtable;
026:        import java.util.Properties;
027:        import java.util.Set;
028:        import java.util.logging.Level;
029:        import java.util.logging.Logger;
030:
031:        import javax.servlet.RequestDispatcher;
032:        import javax.servlet.Servlet;
033:        import javax.servlet.ServletContext;
034:        import javax.servlet.ServletException;
035:
036:        /**
037:         * 
038:         * @author Jacob Hookom
039:         * @version $Id: MockServletContext.java,v 1.1 2005/07/18 08:25:42 jhook Exp $
040:         */
041:        public class MockServletContext implements  ServletContext {
042:
043:            protected final Properties initParams = new Properties();
044:
045:            protected final Logger log = Logger
046:                    .getLogger("facelets.mock.ServletContext");
047:
048:            protected final Hashtable attributes = new Hashtable();
049:
050:            protected final URI base;
051:
052:            public MockServletContext(URI base) {
053:                this .base = base;
054:                File f = new File(base);
055:                if (!f.exists()) {
056:                    throw new IllegalArgumentException("File: "
057:                            + base.getPath() + " doesn't exist");
058:                }
059:            }
060:
061:            public ServletContext getContext(String name) {
062:                throw new UnsupportedOperationException();
063:            }
064:
065:            public int getMajorVersion() {
066:                return 2;
067:            }
068:
069:            public int getMinorVersion() {
070:                return 3;
071:            }
072:
073:            public String getMimeType(String path) {
074:                throw new UnsupportedOperationException();
075:            }
076:
077:            public Set getResourcePaths(String path) {
078:                URI uri = this .resolve(path);
079:                if (uri != null) {
080:                    File f = new File(uri);
081:                    if (f.exists() && f.isDirectory()) {
082:                        File[] c = f.listFiles();
083:                        Set s = new HashSet();
084:                        int start = f.getAbsolutePath().length();
085:                        for (int i = 0; i < c.length; i++) {
086:                            s.add(c[i].getAbsolutePath().substring(start));
087:                        }
088:                        return s;
089:                    }
090:                }
091:                return Collections.EMPTY_SET;
092:            }
093:
094:            public URL getResource(String path) throws MalformedURLException {
095:                URI uri = this .resolve(path);
096:                if (uri != null) {
097:                    File f = new File(uri);
098:                    if (f.exists()) {
099:                        return uri.toURL();
100:                    }
101:                }
102:                return null;
103:            }
104:
105:            public InputStream getResourceAsStream(String path) {
106:                URI uri = this .resolve(path);
107:                if (uri != null) {
108:                    try {
109:                        File f = new File(uri);
110:                        if (f.exists()) {
111:                            return uri.toURL().openStream();
112:                        }
113:                    } catch (MalformedURLException e) {
114:                        this .log.severe(e.getMessage());
115:                        return null;
116:                    } catch (IOException e) {
117:                        this .log.severe(e.getMessage());
118:                        return null;
119:                    }
120:                }
121:                return null;
122:            }
123:
124:            public RequestDispatcher getRequestDispatcher(String path) {
125:                URI uri = this .resolve(path);
126:                if (uri != null) {
127:                    File f = new File(uri);
128:                    if (f.exists()) {
129:                        try {
130:                            return new MockRequestDispatcher(uri.toURL());
131:                        } catch (MalformedURLException e) {
132:                            this .log.severe(e.getMessage());
133:                            return null;
134:                        }
135:                    }
136:
137:                }
138:                return null;
139:            }
140:
141:            public RequestDispatcher getNamedDispatcher(String fileName) {
142:                throw new UnsupportedOperationException();
143:            }
144:
145:            public Servlet getServlet(String name) throws ServletException {
146:                throw new UnsupportedOperationException();
147:            }
148:
149:            public Enumeration getServlets() {
150:                throw new UnsupportedOperationException();
151:            }
152:
153:            public Enumeration getServletNames() {
154:                throw new UnsupportedOperationException();
155:            }
156:
157:            public void log(String message) {
158:                this .log.info(message);
159:            }
160:
161:            public void log(Exception error, String message) {
162:                this .log.log(Level.INFO, message, error);
163:
164:            }
165:
166:            public void log(String message, Throwable error) {
167:                this .log.log(Level.INFO, message, error);
168:            }
169:
170:            public String getRealPath(String path) {
171:                URI uri = this .resolve(path);
172:                if (uri != null) {
173:                    File f = new File(uri);
174:                    if (f.exists()) {
175:                        return f.getAbsolutePath();
176:                    }
177:                }
178:                return null;
179:            }
180:
181:            private final URI resolve(String path) {
182:                if (path == null) {
183:                    throw new NullPointerException("Path cannot be null");
184:                }
185:                if (path.charAt(0) == '/') {
186:                    if (path.length() > 1) {
187:                        return this .base.resolve(path.substring(1));
188:                    }
189:                    return this .base;
190:                }
191:                return null;
192:            }
193:
194:            public String getServerInfo() {
195:                return this .getClass().getName();
196:            }
197:
198:            public String getInitParameter(String name) {
199:                return this .initParams.getProperty(name);
200:            }
201:
202:            public Enumeration getInitParameterNames() {
203:                return this .initParams.keys();
204:            }
205:
206:            public void setInitParameter(String name, String value) {
207:                this .initParams.setProperty(name, value);
208:            }
209:
210:            public Object getAttribute(String name) {
211:                return this .attributes.get(name);
212:            }
213:
214:            public Enumeration getAttributeNames() {
215:                return this .attributes.keys();
216:            }
217:
218:            public void setAttribute(String name, Object value) {
219:                this .attributes.put(name, value);
220:            }
221:
222:            public void removeAttribute(String name) {
223:                this .attributes.remove(name);
224:            }
225:
226:            public String getServletContextName() {
227:                return this.getClass().getName();
228:            }
229:
230:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.