|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ServletWebContext.java | 100% | 100% | 100% | 100% |
|
1 |
// Copyright 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
14 |
|
|
15 |
package org.apache.tapestry.web;
|
|
16 |
|
|
17 |
import java.net.MalformedURLException;
|
|
18 |
import java.net.URL;
|
|
19 |
import java.util.List;
|
|
20 |
|
|
21 |
import javax.servlet.ServletContext;
|
|
22 |
|
|
23 |
import org.apache.commons.logging.Log;
|
|
24 |
import org.apache.commons.logging.LogFactory;
|
|
25 |
import org.apache.hivemind.util.Defense;
|
|
26 |
import org.apache.tapestry.describe.DescriptionReceiver;
|
|
27 |
|
|
28 |
/**
|
|
29 |
* Adapts {@link javax.servlet.ServletContext} as {@link org.apache.tapestry.web.WebContext}.
|
|
30 |
*
|
|
31 |
* @author Howard M. Lewis Ship
|
|
32 |
* @since 4.0
|
|
33 |
*/
|
|
34 |
public class ServletWebContext implements WebContext |
|
35 |
{ |
|
36 |
private static final Log LOG = LogFactory.getLog(ServletWebContext.class); |
|
37 |
|
|
38 |
private final ServletContext _servletContext;
|
|
39 |
|
|
40 | 22 |
public void describeTo(DescriptionReceiver receiver) |
41 |
{ |
|
42 | 22 |
receiver.describeAlternate(_servletContext); |
43 |
} |
|
44 |
|
|
45 | 53 |
public ServletWebContext(ServletContext context)
|
46 |
{ |
|
47 | 53 |
Defense.notNull(context, "context");
|
48 |
|
|
49 | 53 |
_servletContext = context; |
50 |
} |
|
51 |
|
|
52 | 1 |
public List getAttributeNames()
|
53 |
{ |
|
54 | 1 |
return WebUtils.toSortedList(_servletContext.getAttributeNames());
|
55 |
} |
|
56 |
|
|
57 | 1 |
public Object getAttribute(String name)
|
58 |
{ |
|
59 | 1 |
return _servletContext.getAttribute(name);
|
60 |
} |
|
61 |
|
|
62 | 2 |
public void setAttribute(String name, Object attribute) |
63 |
{ |
|
64 | 2 |
if (attribute == null) |
65 | 1 |
_servletContext.removeAttribute(name); |
66 |
else
|
|
67 | 1 |
_servletContext.setAttribute(name, attribute); |
68 |
|
|
69 |
} |
|
70 |
|
|
71 | 817 |
public URL getResource(String path)
|
72 |
{ |
|
73 | 817 |
try
|
74 |
{ |
|
75 | 817 |
return _servletContext.getResource(path);
|
76 |
} |
|
77 |
catch (MalformedURLException ex)
|
|
78 |
{ |
|
79 | 1 |
LOG.error(WebMessages.errorGettingResource(path, ex), ex); |
80 |
|
|
81 | 1 |
return null; |
82 |
} |
|
83 |
} |
|
84 |
|
|
85 | 1271 |
public String getInitParameterValue(String name)
|
86 |
{ |
|
87 | 1271 |
return _servletContext.getInitParameter(name);
|
88 |
} |
|
89 |
|
|
90 | 1 |
public List getInitParameterNames()
|
91 |
{ |
|
92 | 1 |
return WebUtils.toSortedList(_servletContext.getInitParameterNames());
|
93 |
} |
|
94 |
|
|
95 | 1 |
public String getMimeType(String resourcePath)
|
96 |
{ |
|
97 | 1 |
return _servletContext.getMimeType(resourcePath);
|
98 |
} |
|
99 |
} |
|