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.url;
18:
19: import org.apache.avalon.framework.context.Context;
20: import org.apache.avalon.framework.context.ContextException;
21: import org.apache.avalon.framework.context.Contextualizable;
22: import org.apache.avalon.framework.logger.AbstractLogEnabled;
23:
24: import org.apache.cocoon.util.ClassUtils;
25:
26: import java.net.MalformedURLException;
27: import java.net.URL;
28:
29: /**
30: * @deprecated by the new source resolving of avalon excalibur
31: *
32: * @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
33: * @version CVS $Id: ResourceURLFactory.java 433543 2006-08-22 06:22:54Z crossley $
34: */
35: public class ResourceURLFactory extends AbstractLogEnabled implements
36: URLFactory, Contextualizable {
37:
38: /**
39: * The context
40: */
41: protected Context context;
42:
43: /**
44: * Create a URL from a location. This method supports the
45: * <i>resource://</i> pseudo-protocol for loading resources
46: * accessible to this same class' <code>ClassLoader</code>
47: *
48: * @param location The location
49: * @return The URL pointed to by the location
50: * @exception MalformedURLException If the location is malformed
51: */
52: public URL getURL(String location) throws MalformedURLException {
53: URL u = ClassUtils.getResource(location);
54: if (u != null)
55: return u;
56: else {
57: getLogger()
58: .error(
59: location
60: + " could not be found. (possible classloader problem)");
61: throw new RuntimeException(
62: location
63: + " could not be found. (possible classloader problem)");
64: }
65: }
66:
67: public URL getURL(URL base, String location)
68: throws MalformedURLException {
69: return getURL(base.toExternalForm() + location);
70: }
71:
72: /**
73: * Get the context
74: */
75: public void contextualize(Context context) throws ContextException {
76: if (this.context == null) {
77: this.context = context;
78: }
79: }
80: }
|