You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Andreas Schmid <co...@sa-lsa.com> on 2004/06/02 08:45:35 UTC

Something goes wrong with SourceResolver

I just tried to write an Component under Cocoon 2.1.5. and Tomcat 5.0.25

public class DocumentManagerXML implements DocumentManager, ThreadSafe, 
Component, Serviceable, Parameterizable, LogEnabled, Initializable, 
Disposable

This class should read a File when it is initialized... so implemented 
the Interface Initializable an redeclared the function like this...

 public void initialize() throws Exception {
        SourceResolver sourceResolver = null;
        Source src = null;
        try{
             .....

            sourceResolver = 
(SourceResolver)this.serviceManager.lookup(SourceResolver.ROLE);
            src = 
sourceResolver.resolveURI("cms/navigation/navigation.xml");
           
             .....

             String path = SourceUtil.getPath(src);   // Here the path 
looks like /D:/tomcat5/bin/cms/navigation/navigation.xml

             .....
       }catch{
            .....
       }finally{
          -----
       }
}

But this is not the Result i expected... so i wrote a function like 
this.. called from within JavaFlow...

public Document getDocument(){
        SourceResolver sourceResolver = null;
        Source src = null;
        try{
             .....

            sourceResolver = 
(SourceResolver)this.serviceManager.lookup(SourceResolver.ROLE);
            src = 
sourceResolver.resolveURI("cms/navigation/navigation.xml");
           
             .....

             String path = SourceUtil.getPath(src);   // Here the path 
looks like /D:/tomcat5/webapp/ROOT/cms/navigation/navigation.xml

             .....
       }catch{
            .....
       }finally{
          -----
       }
}


I think i does not make a sense, a functions doing the same thing (of 
course at different times) are returning different values... I think 
this is a bug... because the SourceResolver cannot lookup URLs from 
within the Initialize Method.. or is there a workaround for that ?


Thanks

Andreas Schmid


RE: Something goes wrong with SourceResolver

Posted by Carsten Ziegeler <cz...@s-und-n.de>.
Andreas Schmid wrote:
> 
> I just tried to write an Component under Cocoon 2.1.5. and 
> Tomcat 5.0.25
> 
> public class DocumentManagerXML implements DocumentManager, 
> ThreadSafe, Component, Serviceable, Parameterizable, 
> LogEnabled, Initializable, Disposable
> 
> This class should read a File when it is initialized... so 
> implemented the Interface Initializable an redeclared the 
> function like this...
> 
>  public void initialize() throws Exception {
>         SourceResolver sourceResolver = null;
>         Source src = null;
>         try{
>              .....
> 
>             sourceResolver =
> (SourceResolver)this.serviceManager.lookup(SourceResolver.ROLE);
>             src =
> sourceResolver.resolveURI("cms/navigation/navigation.xml");
>            
>              .....
> 
>              String path = SourceUtil.getPath(src);   // Here 
> the path 
> looks like /D:/tomcat5/bin/cms/navigation/navigation.xml
> 
>              .....
>        }catch{
>             .....
>        }finally{
>           -----
>        }
> }
> 
> But this is not the Result i expected... so i wrote a 
> function like this.. called from within JavaFlow...
> 
> public Document getDocument(){
>         SourceResolver sourceResolver = null;
>         Source src = null;
>         try{
>              .....
> 
>             sourceResolver =
> (SourceResolver)this.serviceManager.lookup(SourceResolver.ROLE);
>             src =
> sourceResolver.resolveURI("cms/navigation/navigation.xml");
>            
>              .....
> 
>              String path = SourceUtil.getPath(src);   // Here 
> the path 
> looks like /D:/tomcat5/webapp/ROOT/cms/navigation/navigation.xml
> 
>              .....
>        }catch{
>             .....
>        }finally{
>           -----
>        }
> }
> 
> 
> I think i does not make a sense, a functions doing the same 
> thing (of course at different times) are returning different 
> values... I think this is a bug... because the SourceResolver 
> cannot lookup URLs from within the Initialize Method.. or is 
> there a workaround for that ?
> 
This is not a bug but a problem of the time the functions are
running unfortunately. The first one runs on startup, at this
time the current directory is the start directory of the JVM.
As soon as Cocoon is serving requests like in the second
example, the current directory for the source resolver is
the directory of the current sitemap.

But you can (and should) use the context protocol in the
first case, so using

context://cms/navigation/navigation.xml

should do the trick.

Carsten