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.cocoon.transformation;
19:
20: import java.io.IOException;
21: import java.util.Map;
22:
23: import org.apache.avalon.framework.parameters.Parameters;
24: import org.apache.cocoon.ProcessingException;
25: import org.apache.cocoon.environment.ObjectModelHelper;
26: import org.apache.cocoon.environment.Request;
27: import org.apache.cocoon.environment.SourceResolver;
28: import org.apache.lenya.cms.linking.IncomingLinkRewriter;
29: import org.apache.lenya.cms.linking.LinkRewriter;
30: import org.apache.lenya.cms.publication.DocumentFactory;
31: import org.apache.lenya.cms.publication.DocumentUtil;
32: import org.apache.lenya.cms.publication.URLInformation;
33: import org.apache.lenya.cms.repository.RepositoryUtil;
34: import org.apache.lenya.cms.repository.Session;
35: import org.apache.lenya.util.ServletHelper;
36: import org.xml.sax.SAXException;
37:
38: /**
39: * Converts links in proxy syntax to web application links.
40: * @see IncomingLinkRewriter
41: */
42: public class IncomingProxyTransformer extends AbstractLinkTransformer {
43:
44: private LinkRewriter rewriter;
45:
46: public void setup(SourceResolver _resolver, Map _objectModel,
47: String _source, Parameters _parameters)
48: throws ProcessingException, SAXException, IOException {
49: super .setup(_resolver, _objectModel, _source, _parameters);
50: Request request = ObjectModelHelper.getRequest(_objectModel);
51:
52: try {
53: Session session = RepositoryUtil.getSession(this .manager,
54: request);
55: DocumentFactory factory = DocumentUtil
56: .createDocumentFactory(this .manager, session);
57: URLInformation info = new URLInformation(ServletHelper
58: .getWebappURI(request));
59: String pubId = info.getPublicationId();
60: this .rewriter = new IncomingLinkRewriter(factory
61: .getPublication(pubId));
62: } catch (final Exception e) {
63: throw new RuntimeException(e);
64: }
65: }
66:
67: protected LinkRewriter getLinkRewriter() {
68: return this.rewriter;
69: }
70: }
|