org.apache.cocoon.components.url
public class: URLFactoryImpl [javadoc |
source]
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.cocoon.components.url.URLFactoryImpl
All Implemented Interfaces:
org.apache.avalon.framework.activity.Disposable, URLFactory, org.apache.avalon.framework.thread.ThreadSafe, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.context.Contextualizable, org.apache.avalon.framework.component.Composable
Deprecated! by - the new source resolving of avalon excalibur
- author:
< - a href="mailto:giacomo@apache.org">Giacomo Pati
- version:
CVS - $Id: URLFactoryImpl.java 433543 2006-08-22 06:22:54Z crossley $
| Field Summary |
|---|
| protected Context | context | The context |
| protected Map | factories | The special URL factories |
| Method from org.apache.cocoon.components.url.URLFactoryImpl Detail: |
public void compose(ComponentManager manager) throws ComponentException {
this.manager = manager;
} Deprecated!Set the current ComponentManager instance used by this
Composable. |
public void configure(Configuration conf) throws ConfigurationException {
try {
getLogger().debug("Getting the URLFactories");
factories = new HashMap();
Configuration[] configs = conf.getChildren("protocol");
URLFactory urlFactory = null;
String protocol = null;
for (int i = 0; i < configs.length; i++) {
protocol = configs[i].getAttribute("name");
if (factories.containsKey(protocol)) {
throw new ConfigurationException("URLFactory defined twice for protocol: " + protocol);
}
if (getLogger().isDebugEnabled()) {
getLogger().debug("\tfor protocol: " + protocol + " " + configs[i].getAttribute("class"));
}
urlFactory = (URLFactory) ClassUtils.newInstance(configs[i].getAttribute("class"));
this.init(urlFactory, configs[i]);
factories.put(protocol, urlFactory);
}
} catch (Exception e) {
getLogger().error("Could not get URLFactories", e);
throw new ConfigurationException("Could not get parameters because: " +
e.getMessage());
}
} Deprecated!Configure the URLFactories |
public void contextualize(Context context) throws ContextException {
if (this.context == null) {
this.context = context;
}
} Deprecated! |
public void dispose() {
Iterator iter = this.factories.values().iterator();
URLFactory current;
while (iter.hasNext()) {
current = (URLFactory) iter.next();
this.deinit(current);
}
this.factories = null;
} Deprecated! |
public URL getURL(String location) throws MalformedURLException {
Iterator iter = factories.keySet().iterator();
String protocol = null;
while (iter.hasNext()) {
protocol = (String)iter.next();
if (location.startsWith(protocol + "://")) {
return ((URLFactory)factories.get(protocol)).getURL(location.substring(protocol.length() + 3));
}
}
try {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Making URL from " + location);
}
return new URL(location);
} catch (MalformedURLException mue) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Making URL - MalformedURLException in getURL:" , mue);
}
org.apache.cocoon.environment.Context envContext = null;
try {
envContext = (org.apache.cocoon.environment.Context)
context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
} catch (ContextException e){
getLogger().error("Making URL - ContextException in getURL",e);
}
final String path = envContext.getRealPath(location);
if (path != null)
return (new File(path)).toURL();
if (getLogger().isDebugEnabled()) {
getLogger().debug("Making URL a Resource:" + location);
}
URL url = envContext.getResource(location);
if(url != null)
return url;
if (getLogger().isDebugEnabled()) {
getLogger().debug("Making URL a File (assuming that it is full path):" + location);
}
return (new File(location)).toURL();
}
} Deprecated!Create a URL from a location. This method supports specific
pseudo-protocol as defined in its configuration |
public URL getURL(URL base,
String location) throws MalformedURLException {
if ( base != null ) {
if (base.getProtocol().equals("file")) {
File temp = new File(base.toExternalForm().substring("file:".length()), location);
String path = temp.getAbsolutePath();
// VG: M$ paths starts with drive letter
if (path.charAt(0) != File.separator.charAt(0)) {
return getURL("file:/" + path);
} else {
return getURL("file:" + path);
}
}
return getURL(new URL(base, location).toExternalForm());
} else {
return getURL(location);
}
} Deprecated! |