KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > sitemap > LinkTranslator


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.sitemap;
17
18 import org.apache.avalon.framework.parameters.Parameters;
19 import org.apache.cocoon.Constants;
20 import org.apache.cocoon.ProcessingException;
21 import org.apache.cocoon.caching.CacheableProcessingComponent;
22 import org.apache.cocoon.environment.SourceResolver;
23 import org.apache.cocoon.transformation.Transformer;
24 import org.apache.cocoon.xml.xlink.ExtendedXLinkPipe;
25 import org.apache.excalibur.source.SourceValidity;
26 import org.apache.excalibur.source.impl.validity.NOPValidity;
27
28 import org.xml.sax.Attributes JavaDoc;
29 import org.xml.sax.SAXException JavaDoc;
30
31 import java.io.IOException JavaDoc;
32 import java.util.Map JavaDoc;
33
34 /**
35  * @author <a HREF="mailto:stefano@apache.org">Stefano Mazzocchi</a>
36  * @version CVS $Id: LinkTranslator.java 37206 2004-08-30 14:52:42Z cziegeler $
37  */

38 public class LinkTranslator extends ExtendedXLinkPipe implements Transformer, CacheableProcessingComponent {
39     
40     private Map JavaDoc links;
41
42     /**
43      * Set the <code>SourceResolver</code>, objectModel <code>Map</code>,
44      * the source and sitemap <code>Parameters</code> used to process the request.
45      */

46     public void setup(SourceResolver resolver, Map JavaDoc objectModel, String JavaDoc src, Parameters par)
47     throws ProcessingException, SAXException JavaDoc, IOException JavaDoc {
48         this.links = (Map JavaDoc)objectModel.get(Constants.LINK_OBJECT);
49     }
50
51     /**
52      * Generate the unique key.
53      * This key must be unique inside the space of this component.
54      *
55      * @return The generated key hashes the src
56      */

57     public java.io.Serializable JavaDoc getKey() {
58         return "1";
59     }
60
61     /**
62      * Generate the validity object.
63      *
64      * @return The generated validity object or <code>null</code> if the
65      * component is currently not cacheable.
66      */

67     public SourceValidity getValidity() {
68         return NOPValidity.SHARED_INSTANCE;
69     }
70
71     public void simpleLink(String JavaDoc href, String JavaDoc role, String JavaDoc arcrole,
72                            String JavaDoc title, String JavaDoc show, String JavaDoc actuate, String JavaDoc uri,
73                            String JavaDoc name, String JavaDoc raw, Attributes JavaDoc attr)
74     throws SAXException JavaDoc {
75         final String JavaDoc newHref = (String JavaDoc)this.links.get(href);
76         super.simpleLink((newHref != null) ? newHref : href, role, arcrole, title, show, actuate, uri, name, raw, attr);
77     }
78
79     public void startLocator(String JavaDoc href, String JavaDoc role, String JavaDoc title,
80                              String JavaDoc label, String JavaDoc uri, String JavaDoc name, String JavaDoc raw,
81                              Attributes JavaDoc attr)
82     throws SAXException JavaDoc {
83         final String JavaDoc newHref = (String JavaDoc)this.links.get(href);
84         super.startLocator((newHref != null) ? newHref : href, role, title, label, uri, name, raw, attr);
85     }
86 }
87
Popular Tags