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.cocoon.sitemap;
18:
19: import org.apache.avalon.framework.parameters.Parameters;
20: import org.apache.cocoon.Constants;
21: import org.apache.cocoon.ProcessingException;
22: import org.apache.cocoon.caching.CacheableProcessingComponent;
23: import org.apache.cocoon.environment.SourceResolver;
24: import org.apache.cocoon.transformation.Transformer;
25: import org.apache.cocoon.xml.xlink.ExtendedXLinkPipe;
26: import org.apache.excalibur.source.SourceValidity;
27: import org.apache.excalibur.source.impl.validity.NOPValidity;
28:
29: import org.xml.sax.Attributes;
30: import org.xml.sax.SAXException;
31:
32: import java.io.IOException;
33: import java.util.Map;
34:
35: /**
36: * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
37: * @version CVS $Id: LinkTranslator.java 433543 2006-08-22 06:22:54Z crossley $
38: */
39: public class LinkTranslator extends ExtendedXLinkPipe implements
40: Transformer, CacheableProcessingComponent {
41:
42: private Map links;
43:
44: /**
45: * Set the <code>SourceResolver</code>, objectModel <code>Map</code>,
46: * the source and sitemap <code>Parameters</code> used to process the request.
47: */
48: public void setup(SourceResolver resolver, Map objectModel,
49: String src, Parameters par) throws ProcessingException,
50: SAXException, IOException {
51: this .links = (Map) objectModel.get(Constants.LINK_OBJECT);
52: }
53:
54: /**
55: * Generate the unique key.
56: * This key must be unique inside the space of this component.
57: *
58: * @return The generated key hashes the src
59: */
60: public java.io.Serializable getKey() {
61: return "1";
62: }
63:
64: /**
65: * Generate the validity object.
66: *
67: * @return The generated validity object or <code>null</code> if the
68: * component is currently not cacheable.
69: */
70: public SourceValidity getValidity() {
71: return NOPValidity.SHARED_INSTANCE;
72: }
73:
74: public void simpleLink(String href, String role, String arcrole,
75: String title, String show, String actuate, String uri,
76: String name, String raw, Attributes attr)
77: throws SAXException {
78: final String newHref = (String) this .links.get(href);
79: super .simpleLink((newHref != null) ? newHref : href, role,
80: arcrole, title, show, actuate, uri, name, raw, attr);
81: }
82:
83: public void startLocator(String href, String role, String title,
84: String label, String uri, String name, String raw,
85: Attributes attr) throws SAXException {
86: final String newHref = (String) this.links.get(href);
87: super.startLocator((newHref != null) ? newHref : href, role,
88: title, label, uri, name, raw, attr);
89: }
90: }
|