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: */
18: package org.apache.lenya.cms.linking;
19:
20: import org.apache.avalon.framework.service.ServiceException;
21: import org.apache.avalon.framework.service.ServiceManager;
22: import org.apache.lenya.cms.cocoon.components.context.ContextUtility;
23:
24: /**
25: * Abstract base class for servlet-oriented link rewriters.
26: */
27: public abstract class ServletLinkRewriter implements LinkRewriter {
28:
29: protected ServiceManager manager;
30:
31: /**
32: * @param manager The service manager.
33: */
34: public ServletLinkRewriter(ServiceManager manager) {
35: this .manager = manager;
36: }
37:
38: private String contextPath;
39:
40: protected String getContextPath() {
41: if (this .contextPath == null) {
42: ContextUtility context = null;
43: try {
44: context = (ContextUtility) this .manager
45: .lookup(ContextUtility.ROLE);
46: this .contextPath = context.getRequest()
47: .getContextPath();
48: } catch (ServiceException e) {
49: throw new RuntimeException(e);
50: } finally {
51: if (context != null) {
52: this.manager.release(context);
53: }
54: }
55: }
56: return this.contextPath;
57: }
58:
59: }
|