/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cocoon.components.url;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.cocoon.util.ClassUtils;
import java.net.MalformedURLException;
import java.net.URL;
/**
* @deprecated by the new source resolving of avalon excalibur
*
* @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
* @version CVS $Id$
*/
public class ResourceURLFactory extends AbstractLogEnabled implements URLFactory, Contextualizable {
/**
* The context
*/
protected Context context;
/**
* Create a URL from a location. This method supports the
* <i>resource://</i> pseudo-protocol for loading resources
* accessible to this same class' <code>ClassLoader</code>
*
* @param location The location
* @return The URL pointed to by the location
* @exception MalformedURLException If the location is malformed
*/
public URL getURL(String location) throws MalformedURLException {
URL u = ClassUtils.getResource(location);
if (u != null)
return u;
else {
getLogger().error(location + " could not be found. (possible classloader problem)");
throw new RuntimeException(location + " could not be found. (possible classloader problem)");
}
}
public URL getURL(URL base, String location) throws MalformedURLException {
return getURL (base.toExternalForm() + location);
}
/**
* Get the context
*/
public void contextualize(Context context) throws ContextException {
if (this.context == null) {
this.context = context;
}
}
}