KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > source > impl > SitemapSourceFactory


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.components.source.impl;
17
18 import java.io.IOException JavaDoc;
19 import java.net.MalformedURLException JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import org.apache.avalon.framework.component.ComponentManager;
23 import org.apache.avalon.framework.component.Composable;
24 import org.apache.avalon.framework.logger.AbstractLogEnabled;
25 import org.apache.avalon.framework.thread.ThreadSafe;
26
27 import org.apache.excalibur.source.Source;
28 import org.apache.excalibur.source.SourceFactory;
29 import org.apache.excalibur.source.URIAbsolutizer;
30 import org.apache.excalibur.source.SourceUtil;
31
32 /**
33  * This class implements the cocoon: protocol.
34  * It cannot be used like other source factories
35  * as it needs the current <code>Sitemap</code> as input.
36  *
37  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
38  * @version CVS $Id: SitemapSourceFactory.java 30932 2004-07-29 17:35:38Z vgritsenko $
39  */

40 public final class SitemapSourceFactory
41     extends AbstractLogEnabled
42     implements SourceFactory, ThreadSafe, Composable, URIAbsolutizer
43 {
44     /** The <code>ComponentManager</code> */
45     private ComponentManager manager;
46
47     /**
48      * Composable
49      */

50     public void compose(ComponentManager manager) {
51         this.manager = manager;
52     }
53
54     /**
55      * Get a <code>Source</code> object.
56      * @param parameters This is optional.
57      */

58     public Source getSource( String JavaDoc location, Map JavaDoc parameters )
59         throws MalformedURLException JavaDoc, IOException JavaDoc {
60         if( getLogger().isDebugEnabled() ) {
61             getLogger().debug( "Creating source object for " + location );
62         }
63
64         return new SitemapSource( this.manager,
65                                   location,
66                                   parameters,
67                                   getLogger());
68     }
69     
70     /**
71      * Release a {@link Source} object.
72      */

73     public void release( Source source ) {
74         if ( null != source ) {
75             if ( this.getLogger().isDebugEnabled() ) {
76                 this.getLogger().debug("Releasing source " + source.getURI());
77             }
78             ((SitemapSource)source).recycle();
79         }
80     }
81
82     public String JavaDoc absolutize(String JavaDoc baseURI, String JavaDoc location) {
83         return SourceUtil.absolutize(baseURI, location, true);
84     }
85
86 }
87
Popular Tags