01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.pluto.core;
18:
19: import org.apache.commons.logging.Log;
20: import org.apache.commons.logging.LogFactory;
21:
22: import javax.servlet.ServletContext;
23: import java.net.URL;
24: import java.net.MalformedURLException;
25:
26: public class DefaultApplicationIdResolver implements
27: ApplicationIdResolver {
28:
29: private static final Log LOG = LogFactory
30: .getLog(DefaultApplicationIdResolver.class);
31:
32: private static final String WEB_XML = "/WEB-INF/web.xml";
33:
34: public String resolveApplicationId(ServletContext context) {
35: try {
36: URL webXmlUrl = context.getResource(WEB_XML);
37: String path = webXmlUrl.toExternalForm();
38: path = path.substring(0, path.indexOf(WEB_XML));
39: path = path.substring(path.lastIndexOf("/"));
40:
41: int id = path.indexOf(".war");
42: if (id > 0) {
43: path = path.substring(0, id);
44: }
45: return path;
46: } catch (MalformedURLException e) {
47: LOG
48: .warn("Erorr retrieving web.xml from ServletContext. Unable to derive contextPath.");
49: return null;
50: }
51: }
52:
53: public int getAuthority() {
54: return DEFAULT;
55: }
56: }
|