cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Giacomo Pati <giac...@apache.org>
Subject Re: question on getLogger()
Date Tue, 03 Apr 2001 20:56:55 GMT
Donald Ball wrote:
> 
> i thought i'd try my hand at a little LoggingEntityResolver so that we can
> try to track file/uri dependencies for the various sitemap components.
> unfortunately, i'm having trouble getting access to the Logger -
> getLogger() returns null. here's my sample code:
> 
> package org.apache.cocoon.xml;
> 
> import org.xml.sax.EntityResolver;
> import org.xml.sax.InputSource;
> import org.xml.sax.SAXException;
> import java.io.IOException;
> import org.apache.log.Logger;
> import org.apache.avalon.AbstractLoggable;
> import org.apache.avalon.configuration.Configurable;
> import org.apache.avalon.configuration.Configuration;
> import org.apache.avalon.configuration.ConfigurationException;
> 
> public class LoggingEntityResolver extends AbstractLoggable implements
> EntityResolver,Configurable {
> 
>   protected EntityResolver resolver;
> 
>   public LoggingEntityResolver(EntityResolver resolver) {
>     this.resolver = resolver;
>   }
> 
>   public void configure(Configuration conf) throws ConfigurationException
> {}
> 
>   public InputSource resolveEntity(String public_id, String system_id)
> throws SAXException,IOException {
>     InputSource input_source =
> resolver.resolveEntity(public_id,system_id);
>     StringBuffer sb = new StringBuffer();
>     sb.append("Resolving entity: ");
>     if (public_id != null) {
>       sb.append("public_id: "+public_id);
>     }
>     if (system_id != null) {
>       sb.append("system_id: "+system_id);
>     }
>     if (input_source != null) {
>       sb.append("input_source: "+input_source.toString());
>     }
>     getLogger().debug(sb.toString());
>     return input_source;
>   }
> 
> }
> 
> what's the most succinct way of configuring the class so that getLogger()
> is valid and doesn't return null?

You need to put your class under the controll of a ComponentManager by
defining it as a component in the cocoon.xconf file and getting it via
the ComponentManager. This depends where you are instanciating your
class. Can you elaborate more on the use case of your class?

Giacomo

> 
> - donald
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
> For additional commands, email: cocoon-dev-help@xml.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message