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.LinkResolver;
29: import org.apache.lenya.cms.linking.LinkRewriter;
30: import org.apache.lenya.cms.linking.UrlToUuidRewriter;
31: import org.apache.lenya.cms.publication.Area;
32: import org.apache.lenya.cms.publication.DocumentFactory;
33: import org.apache.lenya.cms.publication.DocumentUtil;
34: import org.apache.lenya.cms.publication.Publication;
35: import org.apache.lenya.cms.publication.URLInformation;
36: import org.apache.lenya.cms.repository.RepositoryUtil;
37: import org.apache.lenya.cms.repository.Session;
38: import org.apache.lenya.util.ServletHelper;
39: import org.xml.sax.SAXException;
40:
41: /**
42: * <p>
43: * URL to UUID transformer.
44: * </p>
45: *
46: * <p>
47: * This transformer is applied to an XHMTL document. It processes all URL-based
48: * links to links following the {@link LinkResolver} syntax.
49: * </p>
50: *
51: * $Id: LinkRewritingTransformer.java,v 1.7 2004/03/16 11:12:16 gregor
52: */
53: public class UrlToUuidTransformer extends AbstractLinkTransformer {
54:
55: private LinkRewriter rewriter;
56:
57: /**
58: * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver,
59: * java.util.Map, java.lang.String,
60: * org.apache.avalon.framework.parameters.Parameters)
61: */
62: public void setup(SourceResolver _resolver, Map _objectModel,
63: String _source, Parameters _parameters)
64: throws ProcessingException, SAXException, IOException {
65: super .setup(_resolver, _objectModel, _source, _parameters);
66:
67: Request _request = ObjectModelHelper.getRequest(_objectModel);
68: try {
69: Session session = RepositoryUtil.getSession(this .manager,
70: _request);
71: DocumentFactory factory = DocumentUtil
72: .createDocumentFactory(this .manager, session);
73: String url = ServletHelper.getWebappURI(_request);
74: URLInformation info = new URLInformation(url);
75: Publication pub = factory.getPublication(info
76: .getPublicationId());
77: Area area = pub.getArea(info.getArea());
78: this .rewriter = new UrlToUuidRewriter(area);
79: } catch (final Exception e1) {
80: throw new ProcessingException(e1);
81: }
82: }
83:
84: protected LinkRewriter getLinkRewriter() {
85: return this.rewriter;
86: }
87:
88: }
|