KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > source > CocoonSourceFactory


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

37 public final class CocoonSourceFactory
38 extends AbstractLogEnabled
39 implements SourceFactory {
40
41     /** The component manager */
42     private ComponentManager manager;
43
44     public CocoonSourceFactory(Processor processor,
45                                ComponentManager manager) {
46         this.manager = manager;
47     }
48
49     /**
50      * Resolve the source
51      */

52     public Source getSource(Environment environment, String JavaDoc location)
53     throws ProcessingException, IOException JavaDoc, MalformedURLException JavaDoc {
54         if (environment == null)
55             throw new ProcessingException("CocoonSourceFactory: environment is required.");
56         return new SitemapSource(this.manager,
57                                  location,
58                                  this.getLogger());
59     }
60
61     /**
62      * Resolve the source
63      */

64     public Source getSource(Environment environment, URL JavaDoc base, String JavaDoc location)
65     throws ProcessingException, IOException JavaDoc, MalformedURLException JavaDoc {
66         if (environment == null)
67             throw new ProcessingException("CocoonSourceFactory: environment is required.");
68         return this.getSource(environment, base.toExternalForm() + location);
69     }
70 }
71
Popular Tags