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.components.source.impl;
18:
19: import java.io.IOException;
20: import java.net.MalformedURLException;
21: import java.util.Map;
22:
23: import org.apache.avalon.framework.component.ComponentManager;
24: import org.apache.avalon.framework.component.Composable;
25: import org.apache.avalon.framework.logger.AbstractLogEnabled;
26: import org.apache.avalon.framework.thread.ThreadSafe;
27:
28: import org.apache.excalibur.source.Source;
29: import org.apache.excalibur.source.SourceFactory;
30: import org.apache.excalibur.source.URIAbsolutizer;
31: import org.apache.excalibur.source.SourceUtil;
32:
33: /**
34: * This class implements the cocoon: protocol.
35: * It cannot be used like other source factories
36: * as it needs the current <code>Sitemap</code> as input.
37: *
38: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
39: * @version CVS $Id: SitemapSourceFactory.java 433543 2006-08-22 06:22:54Z crossley $
40: */
41: public final class SitemapSourceFactory extends AbstractLogEnabled
42: implements SourceFactory, ThreadSafe, Composable,
43: URIAbsolutizer {
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 location, Map parameters)
59: throws MalformedURLException, IOException {
60: if (getLogger().isDebugEnabled()) {
61: getLogger().debug("Creating source object for " + location);
62: }
63:
64: return new SitemapSource(this .manager, location, parameters,
65: getLogger());
66: }
67:
68: /**
69: * Release a {@link Source} object.
70: */
71: public void release(Source source) {
72: if (null != source) {
73: if (this .getLogger().isDebugEnabled()) {
74: this .getLogger().debug(
75: "Releasing source " + source.getURI());
76: }
77: ((SitemapSource) source).recycle();
78: }
79: }
80:
81: public String absolutize(String baseURI, String location) {
82: return SourceUtil.absolutize(baseURI, location, true);
83: }
84:
85: }
|