Skip to content

Commit d9c0787

Browse files
committed
Added ServletRegistrationProvider for Servlet 2.5
1 parent 23764a4 commit d9c0787

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2011 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.ocpsoft.rewrite.servlet.impl;
17+
18+
import java.io.IOException;
19+
import java.io.InputStream;
20+
import java.util.List;
21+
22+
import javax.servlet.ServletContext;
23+
24+
import org.ocpsoft.logging.Logger;
25+
import org.ocpsoft.rewrite.servlet.ServletRegistration;
26+
import org.ocpsoft.rewrite.servlet.spi.ServletRegistrationProvider;
27+
28+
/**
29+
* Implementation of {@link ServletRegistrationProvider} that parses <code>web.xml</code> to look for Servlets.
30+
*
31+
* @author Christian Kaltepoth
32+
*/
33+
public class WebXmlServletRegistrationProvider implements ServletRegistrationProvider
34+
{
35+
36+
private final Logger log = Logger.getLogger(WebXmlServletRegistrationProvider.class);
37+
38+
@Override
39+
public int priority()
40+
{
41+
return 20;
42+
}
43+
44+
@Override
45+
public List<ServletRegistration> getServletRegistrations(ServletContext context)
46+
{
47+
48+
InputStream webXmlStream = context.getResourceAsStream("/WEB-INF/web.xml");
49+
50+
if (webXmlStream != null) {
51+
52+
try {
53+
54+
WebXmlServletRegistrationParser parser = new WebXmlServletRegistrationParser();
55+
parser.parse(webXmlStream);
56+
return parser.getRegistrations();
57+
58+
}
59+
catch (IOException e) {
60+
log.warn("Failed to parse web.xml to look for servlet registations", e);
61+
}
62+
63+
}
64+
65+
return null;
66+
67+
}
68+
69+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.ocpsoft.rewrite.servlet.impl.WebXmlServletRegistrationProvider

0 commit comments

Comments
 (0)