KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > url > ResourceURLFactory


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.url;
17
18 import org.apache.avalon.framework.context.Context;
19 import org.apache.avalon.framework.context.ContextException;
20 import org.apache.avalon.framework.context.Contextualizable;
21 import org.apache.avalon.framework.logger.AbstractLogEnabled;
22
23 import org.apache.cocoon.util.ClassUtils;
24
25 import java.net.MalformedURLException JavaDoc;
26 import java.net.URL JavaDoc;
27
28 /**
29  * @deprecated by the new source resolving of avalon excalibur
30  *
31  * @author <a HREF="mailto:giacomo@apache.org">Giacomo Pati</a>
32  * @version CVS $Id: ResourceURLFactory.java 30932 2004-07-29 17:35:38Z vgritsenko $
33  */

34 public class ResourceURLFactory extends AbstractLogEnabled implements URLFactory, Contextualizable {
35
36     /**
37      * The context
38      */

39     protected Context context;
40
41     /**
42      * Create a URL from a location. This method supports the
43      * <i>resource://</i> pseudo-protocol for loading resources
44      * accessible to this same class' <code>ClassLoader</code>
45      *
46      * @param location The location
47      * @return The URL pointed to by the location
48      * @exception MalformedURLException If the location is malformed
49      */

50     public URL JavaDoc getURL(String JavaDoc location) throws MalformedURLException JavaDoc {
51         URL JavaDoc u = ClassUtils.getResource(location);
52         if (u != null)
53             return u;
54         else {
55             getLogger().error(location + " could not be found. (possible classloader problem)");
56             throw new RuntimeException JavaDoc(location + " could not be found. (possible classloader problem)");
57         }
58     }
59
60     public URL JavaDoc getURL(URL JavaDoc base, String JavaDoc location) throws MalformedURLException JavaDoc {
61         return getURL (base.toExternalForm() + location);
62     }
63
64     /**
65      * Get the context
66      */

67     public void contextualize(Context context) throws ContextException {
68         if (this.context == null) {
69             this.context = context;
70         }
71     }
72 }
73
Popular Tags