You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Stuart Roebuck <st...@adolos.co.uk> on 2002/06/12 14:58:20 UTC

SourceResolving in non-sitemap components

I'm trying to get my head round SourceResolving and would be grateful 
for clarification.

There appear to be at a number of SourceResolver classes:

> 	org.apache.excalibur.source.SourceResolver
>  	org.apache.avalon.excalibur.source.SourceResolver
>  	org.apache.cocoon.environment.SourceResolver

I want to use a SourceResolver in one Component but in two different 
kinds of context.

In the first case, I would like to use a SourceResolver during 
Configuration to obtain a ModifiableSource relative to the root context, 
and then refer to it from time to time.  I think that I need something 
like this...

>        this.resolver = (SourceResolver) 
> this.manager.lookup(SourceResolver.ROLE);
> 		Source source = this.resolver.resolveURI("context://path/to/file");
> 		// Do something with source
>
> 		// After a while... (when source may have changed)
> 		if (source instanceof ModifiableSource) {
> 			( (ModifiableSource) source).refresh()
> 			}
> 		// Do something else with source
>
> 		// Finally (not sure if this is required)
> 		this.resolver.release(source);

In the second case I would like to be able to use a SourceResolver to 
obtain a Source relative to current context when this component is 
called from within another sitemap component.  In these cases a 
SourceResolver is already passed to the Action or Generator, so I can 
pass this on to my component for use.

Stuart.


            Public Key - 1024D/88DD65AF 2001-11-23 Stuart Roebuck (Adolos)
      Key fingerprint = 89D9 E405 F8B1 9B22 0FA2  F2C1 9E57 5AB1 88DD 65AF
-------------------------------------------------------------------------
Stuart Roebuck                                  stuart.roebuck@adolos.com
Systems Architect                             Java, XML, MacOS X, XP, 
etc.
ADOLOS                                           <http://www.adolos.com/>


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


RE: SourceResolving in non-sitemap components

Posted by Carsten Ziegeler <cz...@s-und-n.de>.
Stuart Roebuck wrote:
> 
> I'm trying to get my head round SourceResolving and would be grateful 
> for clarification.
> 
> There appear to be at a number of SourceResolver classes:
> 
> > 	org.apache.excalibur.source.SourceResolver
This is the real source resolver.

> >  	org.apache.avalon.excalibur.source.SourceResolver
Forget this one, it has removed. Basically it was the same
as the first one, but then the excalibur team decided to
remove "avalon" from the package names for new components.

> >  	org.apache.cocoon.environment.SourceResolver
This is a convenience source resolver which is passed to the sitemap
components. It inherits from org.apache.excalibur.source.SourceResolver
and adds a usefull toSAX() method especiall for Cocoon.

org.apache.excalibur.source.SourceResolver is a real component,
so you can look it up everywhere you have a ComponentManager.
You can use this component to get Source objects by calling
resolveURI() and you have to release() them later on.


> 
> I want to use a SourceResolver in one Component but in two different 
> kinds of context.
> 
> In the first case, I would like to use a SourceResolver during 
> Configuration to obtain a ModifiableSource relative to the root context, 
> and then refer to it from time to time.  I think that I need something 
> like this...
> 
> >        this.resolver = (SourceResolver) 
> > this.manager.lookup(SourceResolver.ROLE);
> > 		Source source = 
> this.resolver.resolveURI("context://path/to/file");
> > 		// Do something with source
> >
> > 		// After a while... (when source may have changed)
> > 		if (source instanceof ModifiableSource) {
> > 			( (ModifiableSource) source).refresh()
> > 			}
> > 		// Do something else with source
> >
> > 		// Finally (not sure if this is required)
> > 		this.resolver.release(source);
>
Yes, exactly with the exception that the ModifiableSource interface
is deprecated. You have to use the discardValidity() method of
the Source interface instead.
 
> In the second case I would like to be able to use a SourceResolver to 
> obtain a Source relative to current context when this component is 
> called from within another sitemap component.  In these cases a 
> SourceResolver is already passed to the Action or Generator, so I can 
> pass this on to my component for use.
Yes, exactly.

HTH
Carsten 

Carsten Ziegeler     Chief Architect     Open Source Group, S&N AG
------------------------------------------------------------------
             Cocoon Consulting, Training and Projects
------------------------------------------------------------------
mailto:cziegeler@s-und-n.de                  http://www.s-und-n.de
                    http://ziegeler.bei.t-online.de


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