You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Per Kreipke <pe...@onclave.com> on 2002/09/10 05:03:04 UTC
XSP bug: can get generate() to skip elements using java 'if's
The following XSP snippet will cause an ArrayIndexOutOfBoundsException in
Cocoon 2.0.3 because the start of the outer element is never emitted to the
SAX stream.
XSP Snippet:
<xsp:page ....>
<page>
<xsp:logic>
if (!request.isUserInRole("root"))
{
<xsp:attribute name="security-error">Not authorized</xsp:attribute>
}
else
{
</xsp:logic
<!-- Build the page if authorized -->
<content />
<xsp:logic>
}
</xsp:logic>
</page>
</xsp:page>
Generated Java code:
if (!request.isUserInRole("root"))
{
xspAttr.addAttribute("", "security-error", "security-error", "CDATA", "Not
authorized");
}
else
{
this.contentHandler.startElement("", "page", "page", xspAttr);
xspAttr.clear();
}
this.contentHandler.endElement("", "page", "page");
The culprit is the <xsp:attribute>. If I comment it out, the error doesn't
happen.
E.g. the start code for <page> isn't emitted. And I can't find a workaround:
neither emitting characters or another element inside the 'if' makes it
emit.
Note: in xsp.xsl, the topmost non-xsp element is handled specially but this
error still occurs if you nest like this:
<page>
<foo>
<xsp:logic>if (...) {
<xsp:attribute...>
}
else
{
</xsp:logic>
...
<xsp:logic>
}
</xsp:logic>
</foo>
</page>
Per
---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org
RE: XSP bug: can get generate() to skip elements using java 'if's
Posted by Per Kreipke <pe...@onclave.com>.
Per-Olof,
Ah. You put the closing </xsp:logic before the <xsp:attribute>.
So the full snippet should be:
<xsp:page>
<page>
<xsp:logic>
if (!request.isUserInRole("root"))
{
</xsp:logic> <!-- Note this -->
<xsp:attribute name="security-error">Not authorized</xsp:attribute>
<xsp:logic>
}
else
{
</xsp:logic>
<content>
...
</content>
<xsp:logic>
}
</xsp:logic>
</page>
</xsp:page>
Ugh. Will try.
Per
> Hi per and Michael,
>
> I had to end the logic tag to make theese sort of things work:
> <xsp:page>
> <page>
> <xsp:logic>
> if (!request.isUserInRole("root"))
> {
> </xsp:logic> <!-- Note this -->
>
> <xsp:attribute name="security-error">Not authorized</xsp:attribute>
>
> <xsp:logic>
> }
> </xsp:logic>
>
> </page>
> </xsp:page>
>
> As I figured it´s like <% in asp. You´re in different "modes" when in
> logic element and outside.
>
> Attached is a real-life example (with for loops, not if statements, but
> the behaviour is probably the same) that is used from a flowscript to
> generate a "datePicker" calendar.
>
>
> Regards,
> Per-Olof Noren
>
>
>
> <
> >>
> >> <page>
> >> <xsp:logic>
> >> if (!request.isUserInRole("root"))
> >> {
> >> <xsp:attribute name="security-error">Not
> authorized</xsp:attribute>
> >> }
> >> else
> >> {
> >> <xsp:content>
> >>
> >> <!-- Build the page if authorized -->
> >> <content />
> >>
> >> </xsp:content>
> >> }
> >> </xsp:logic>
> >> </page>
> >>
> >> </xsp:page>
>
>
> Per Kreipke wrote:
> > Michael,
> >
> > Thanks for the tip. However, your tip makes the problem even more
> > interesting.
> >
> > When the 'if' statement is true, the <xsp:attribute> does appear on the
> > toplevel element and the XML is valid (no more array bounds exception).
> >
> > But when the 'if' statement is false, the <page> element isn't
> the top most,
> > it's emitted after the <content> element. E.g. <page> is a
> sibling of the
> > <content> element and the XML has _two_ top level elements,
> also invalid.
> >
> > Per
> >
> >
> >>-----Original Message-----
> >>From: Enke, Michael [mailto:michael.enke@wincor-nixdorf.com]
> >>Sent: Tuesday, September 10, 2002 2:58 AM
> >>To: cocoon-dev@xml.apache.org
> >>Subject: Re: XSP bug: can get generate() to skip elements using java
> >>'if's
> >>
> >>
> >>Per Kreipke wrote:
> >>
> >>>The following XSP snippet will cause an
> >>
> >>ArrayIndexOutOfBoundsException in
> >>
> >>>Cocoon 2.0.3 because the start of the outer element is never
> >>
> >>emitted to the
> >>
> >>>SAX stream.
> >>>
> >>>XSP Snippet:
> >>
> >>
> >>I would always write it as:
> >>
> >> <xsp:page ....>
> >>
> >> <page>
> >> <xsp:logic>
> >> if (!request.isUserInRole("root"))
> >> {
> >> <xsp:attribute name="security-error">Not
> authorized</xsp:attribute>
> >> }
> >> else
> >> {
> >> <xsp:content>
> >>
> >> <!-- Build the page if authorized -->
> >> <content />
> >>
> >> </xsp:content>
> >> }
> >> </xsp:logic>
> >> </page>
> >>
> >> </xsp:page>
> >>
> >>note: </xsp:logic> replaced by <xsp:content>
> >>and <xsp:logic> replaced by </xsp:content>
> >>
> >>Michael
> >>
> >>---------------------------------------------------------------------
> >>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
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org
Re: XSP bug: can get generate() to skip elements using java 'if's
Posted by Per-Olof Norén <pe...@alma.nu>.
Hi per and Michael,
I had to end the logic tag to make theese sort of things work:
<xsp:page>
<page>
<xsp:logic>
if (!request.isUserInRole("root"))
{
</xsp:logic> <!-- Note this -->
<xsp:attribute name="security-error">Not authorized</xsp:attribute>
<xsp:logic>
}
</xsp:logic>
</page>
</xsp:page>
As I figured it´s like <% in asp. You´re in different "modes" when in
logic element and outside.
Attached is a real-life example (with for loops, not if statements, but
the behaviour is probably the same) that is used from a flowscript to
generate a "datePicker" calendar.
Regards,
Per-Olof Noren
<
>>
>> <page>
>> <xsp:logic>
>> if (!request.isUserInRole("root"))
>> {
>> <xsp:attribute name="security-error">Not
authorized</xsp:attribute>
>> }
>> else
>> {
>> <xsp:content>
>>
>> <!-- Build the page if authorized -->
>> <content />
>>
>> </xsp:content>
>> }
>> </xsp:logic>
>> </page>
>>
>> </xsp:page>
Per Kreipke wrote:
> Michael,
>
> Thanks for the tip. However, your tip makes the problem even more
> interesting.
>
> When the 'if' statement is true, the <xsp:attribute> does appear on the
> toplevel element and the XML is valid (no more array bounds exception).
>
> But when the 'if' statement is false, the <page> element isn't the top most,
> it's emitted after the <content> element. E.g. <page> is a sibling of the
> <content> element and the XML has _two_ top level elements, also invalid.
>
> Per
>
>
>>-----Original Message-----
>>From: Enke, Michael [mailto:michael.enke@wincor-nixdorf.com]
>>Sent: Tuesday, September 10, 2002 2:58 AM
>>To: cocoon-dev@xml.apache.org
>>Subject: Re: XSP bug: can get generate() to skip elements using java
>>'if's
>>
>>
>>Per Kreipke wrote:
>>
>>>The following XSP snippet will cause an
>>
>>ArrayIndexOutOfBoundsException in
>>
>>>Cocoon 2.0.3 because the start of the outer element is never
>>
>>emitted to the
>>
>>>SAX stream.
>>>
>>>XSP Snippet:
>>
>>
>>I would always write it as:
>>
>> <xsp:page ....>
>>
>> <page>
>> <xsp:logic>
>> if (!request.isUserInRole("root"))
>> {
>> <xsp:attribute name="security-error">Not authorized</xsp:attribute>
>> }
>> else
>> {
>> <xsp:content>
>>
>> <!-- Build the page if authorized -->
>> <content />
>>
>> </xsp:content>
>> }
>> </xsp:logic>
>> </page>
>>
>> </xsp:page>
>>
>>note: </xsp:logic> replaced by <xsp:content>
>>and <xsp:logic> replaced by </xsp:content>
>>
>>Michael
>>
>>---------------------------------------------------------------------
>>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
RE: XSP bug: can get generate() to skip elements using java 'if's
Posted by Per Kreipke <pe...@onclave.com>.
Michael,
Thanks for the tip. However, your tip makes the problem even more
interesting.
When the 'if' statement is true, the <xsp:attribute> does appear on the
toplevel element and the XML is valid (no more array bounds exception).
But when the 'if' statement is false, the <page> element isn't the top most,
it's emitted after the <content> element. E.g. <page> is a sibling of the
<content> element and the XML has _two_ top level elements, also invalid.
Per
> -----Original Message-----
> From: Enke, Michael [mailto:michael.enke@wincor-nixdorf.com]
> Sent: Tuesday, September 10, 2002 2:58 AM
> To: cocoon-dev@xml.apache.org
> Subject: Re: XSP bug: can get generate() to skip elements using java
> 'if's
>
>
> Per Kreipke wrote:
> >
> > The following XSP snippet will cause an
> ArrayIndexOutOfBoundsException in
> > Cocoon 2.0.3 because the start of the outer element is never
> emitted to the
> > SAX stream.
> >
> > XSP Snippet:
>
>
> I would always write it as:
>
> <xsp:page ....>
>
> <page>
> <xsp:logic>
> if (!request.isUserInRole("root"))
> {
> <xsp:attribute name="security-error">Not authorized</xsp:attribute>
> }
> else
> {
> <xsp:content>
>
> <!-- Build the page if authorized -->
> <content />
>
> </xsp:content>
> }
> </xsp:logic>
> </page>
>
> </xsp:page>
>
> note: </xsp:logic> replaced by <xsp:content>
> and <xsp:logic> replaced by </xsp:content>
>
> Michael
>
> ---------------------------------------------------------------------
> 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
Re: XSP bug: can get generate() to skip elements using java 'if's
Posted by "Enke, Michael" <mi...@wincor-nixdorf.com>.
Per Kreipke wrote:
>
> The following XSP snippet will cause an ArrayIndexOutOfBoundsException in
> Cocoon 2.0.3 because the start of the outer element is never emitted to the
> SAX stream.
>
> XSP Snippet:
I would always write it as:
<xsp:page ....>
<page>
<xsp:logic>
if (!request.isUserInRole("root"))
{
<xsp:attribute name="security-error">Not authorized</xsp:attribute>
}
else
{
<xsp:content>
<!-- Build the page if authorized -->
<content />
</xsp:content>
}
</xsp:logic>
</page>
</xsp:page>
note: </xsp:logic> replaced by <xsp:content>
and <xsp:logic> replaced by </xsp:content>
Michael
---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org