You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Vadim Gritsenko <va...@verizon.net> on 2002/02/11 05:53:27 UTC

Help with AbstractEnvironment.changeContext

All, Giacomo, Carsten,

Looking into the AbstractEnvironment.changeContext() I do not understand
one part:

            File f = new File(this.context.getFile());
            if (f.isFile()) {
                this.context = f.getParentFile().toURL();
            } else {
                this.context = f.toURL();
            }

Is it essentially converting file to a directory entry where the file
belongs? Can it be then rewritten to something like:

            String s = this.context.toString();
            if (i != -1 && i + 1 < s.length()) {
                s = s.substring(0, s.lastIndexOf('/') + 1);
            }
            this.context = new URL(s);

With this change it:
1. Preserves original protocol. Before, "jndi:" URLs were converted to
"file:" URLs.
2. Works under tomcat as before.
3. Works under Borland App Server deployed as unpacked WAR (Thanks to
Nick Airey who tested this).

Does anybody see any issues with changing this bit of code?

Vadim



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


RE: Help with AbstractEnvironment.changeContext

Posted by Carsten Ziegeler <cz...@s-und-n.de>.
> Vadim Gritsenko wrote:
>
> All, Giacomo, Carsten,
>
> Looking into the AbstractEnvironment.changeContext() I do not understand
> one part:
>
>             File f = new File(this.context.getFile());
>             if (f.isFile()) {
>                 this.context = f.getParentFile().toURL();
>             } else {
>                 this.context = f.toURL();
>             }
>
> Is it essentially converting file to a directory entry where the file
> belongs? Can it be then rewritten to something like:
>
>             String s = this.context.toString();
>             if (i != -1 && i + 1 < s.length()) {
>                 s = s.substring(0, s.lastIndexOf('/') + 1);
>             }
>             this.context = new URL(s);
>
> With this change it:
> 1. Preserves original protocol. Before, "jndi:" URLs were converted to
> "file:" URLs.
> 2. Works under tomcat as before.
> 3. Works under Borland App Server deployed as unpacked WAR (Thanks to
> Nick Airey who tested this).
>
> Does anybody see any issues with changing this bit of code?
>
Hmm, to be honest - this code (I mean the old one) looks a little bit
strange
for me - perhaps it's too early this morning...
A new URL contained in this.context is build, this is converted to a file
object and it's then tested if it is a file. If not everything is as before
and if it is a file the parent directory is used instead.
Ok, so only if the context points to a file, the URL is changed.

I think your patch is slightly different: the URL is always changed to the
parent directory even if it is not a file, right? (I don't see what the
variable i means).
I assume - but haven't had time to look at it - that your approach might
fail with subsitemaps. You can define the src attribute for the subsitmap
by either giving the full sitemap name like "sub/sitemap.xmap" or by only
giving the directory name "sub".

Carsten


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


Re: Help with AbstractEnvironment.changeContext

Posted by giacomo <gi...@apache.org>.
On Sun, 10 Feb 2002, Vadim Gritsenko wrote:

> All, Giacomo, Carsten,
>
> Looking into the AbstractEnvironment.changeContext() I do not understand
> one part:
>
>             File f = new File(this.context.getFile());
>             if (f.isFile()) {
>                 this.context = f.getParentFile().toURL();
>             } else {
>                 this.context = f.toURL();
>             }
>
> Is it essentially converting file to a directory entry where the file
> belongs? Can it be then rewritten to something like:
>
>             String s = this.context.toString();
>             if (i != -1 && i + 1 < s.length()) {
>                 s = s.substring(0, s.lastIndexOf('/') + 1);
>             }
>             this.context = new URL(s);
>
> With this change it:
> 1. Preserves original protocol. Before, "jndi:" URLs were converted to
> "file:" URLs.
> 2. Works under tomcat as before.
> 3. Works under Borland App Server deployed as unpacked WAR (Thanks to
> Nick Airey who tested this).
>
> Does anybody see any issues with changing this bit of code?

I'm not sure anymore (long time ago since I've looked at that piece of
code). I think this is because of mounting sub-sitemaps which can denote
a directory (where a sitemap.xmap file is searched in) and the concrete
sitemap file to use in that directory, which is used a the new context.

Giacomo


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