You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by peter lin <pe...@labs.gte.com> on 2002/03/19 15:44:29 UTC

xml bug?

has anyone tried the nightly 3-18 xml tags in jstl?  I'm experiencing a
problem accessing request parameters and http headers. Here is the test
page I used.

<%@ taglib prefix="x" uri="http://java.sun.com/jstl/ea/xml" %>

<br>$header:host = <x:out select="$header:host"/><br>
<br>S param = <x:out select="$param:S"/><br>

<%
        java.util.Enumeration enum = request.getHeaderNames();
        while ( enum.hasMoreElements() ) {
                out.println(enum.nextElement());
                out.println("<br>");
        }
        out.println(request.getHeader("user-agent"));
%>

According to the JSTL spec, it states in 11.1.2:

expression | mapping
--------------------------------------
$param:foo | request.getParameter("foo")
$header:foo| request.getHeader("foo")


I took a quick look at tag.common.xml package and noticed all of the
support tags use XPathUtil to access the context. Within XPathUtil is a
inner class JstlVariableContext, which contains the call
hsr.getHeader(localName) in JstlVariableContext.getVariableValue().

when I tried to debug getVariableValue method, it appears it never gets
to hsr.getHeader(localname). In fact, valueOf(node,string) never
instantiates JstlVariableContext, instead getLocalContext(node) is the
only method that instantiates that class.

Should valueOf(node,string) check the result of
xp.valueOf(getLocalContext(n)) and call getLocalContext?  I'm don't
completely understand XPathUtil.  Any tips are greatly appreciated.

peter lin

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: xml bug?

Posted by Shawn Bayern <ba...@essentially.net>.
Peter,

Thanks for the bug report.  There's actually no problem with the plumbing
of the XPathUtil class itself.  It's correctly establishing the context
and passes it to our XPath engine.  The problem was just that this XPath
engine wasn't resolving namespaces correctly.

I've fixed the problem by adjusting the matching logic to work against
prefixes, not namespaces.  I've also made error checking more aggressive;
a variable that doesn't match with a value now fails immediately during
resolution.

I've checked in changes to the CVS archive that should fix your problem.

Best,

-- 
Shawn Bayern
Author, "JSP Standard Tag Library"  http://www.jstlbook.com
(coming this summer from Manning Publications)

On Tue, 19 Mar 2002, peter lin wrote:

> 
> reading over my last paragraph, it's not clear what I meant, so here's a
> second attempt. The current 3-19 nightly of XPathUtil.valueOf is below:
> 
>     public String valueOf(Node n, String xpath) throws SAXPathException
> {
> 	staticInit();
>         XPath xp = new XPath(xpath);
>         return xp.valueOf(getLocalContext(n));
>     }
> 
> when it calls return, it the result of getLocalContext(node) to
> XPath.valueOf(). when I output that result, I get zero length string.
> the source for getLocalContext(node) is below.
> 
>     private Context getLocalContext(Node n) {
> 	// set up instance-specific contexts
>         VariableContext vc = new JstlVariableContext();
>         ContextSupport cs = new ContextSupport(nc, fc, vc, dn);
>         Context c = new Context(cs);
>         List l = new ArrayList(1);
>         l.add(n);
>         c.setNodeSet(l);
> 	return c;
>     }
> 
> an instance of JstlVariableContext is passed to the constructor of
> ContextSupport, but I don't see where
> JstlVariableContext.getVariableValue() is called. Within
> getLocalContext, should it check to make sure context was created
> correctly when it does Context c = new Context(cs)?
> 
> when I output the result of the hsr.getHeader(localName), it never
> reaches that chunk of code in getVariableValue().
> 
> 	    else if (namespace.equals(HEADER_NS_URL)) {
> 		HttpServletRequest hsr =
> 		    (HttpServletRequest) pageContext.getRequest();
> 		return hsr.getHeader(localName);
> 
> thanks.
> 
> peter lin
> 
> 
> 
> peter lin
> 
> 
> > Should valueOf(node,string) check the result of
> > xp.valueOf(getLocalContext(n)) and call getLocalContext?  I'm don't
> > completely understand XPathUtil.  Any tips are greatly appreciated.
> > 
> > peter lin
> > 
> > --
> > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: xml bug?

Posted by peter lin <pe...@labs.gte.com>.
reading over my last paragraph, it's not clear what I meant, so here's a
second attempt. The current 3-19 nightly of XPathUtil.valueOf is below:

    public String valueOf(Node n, String xpath) throws SAXPathException
{
	staticInit();
        XPath xp = new XPath(xpath);
        return xp.valueOf(getLocalContext(n));
    }

when it calls return, it the result of getLocalContext(node) to
XPath.valueOf(). when I output that result, I get zero length string.
the source for getLocalContext(node) is below.

    private Context getLocalContext(Node n) {
	// set up instance-specific contexts
        VariableContext vc = new JstlVariableContext();
        ContextSupport cs = new ContextSupport(nc, fc, vc, dn);
        Context c = new Context(cs);
        List l = new ArrayList(1);
        l.add(n);
        c.setNodeSet(l);
	return c;
    }

an instance of JstlVariableContext is passed to the constructor of
ContextSupport, but I don't see where
JstlVariableContext.getVariableValue() is called. Within
getLocalContext, should it check to make sure context was created
correctly when it does Context c = new Context(cs)?

when I output the result of the hsr.getHeader(localName), it never
reaches that chunk of code in getVariableValue().

	    else if (namespace.equals(HEADER_NS_URL)) {
		HttpServletRequest hsr =
		    (HttpServletRequest) pageContext.getRequest();
		return hsr.getHeader(localName);

thanks.

peter lin



peter lin


> Should valueOf(node,string) check the result of
> xp.valueOf(getLocalContext(n)) and call getLocalContext?  I'm don't
> completely understand XPathUtil.  Any tips are greatly appreciated.
> 
> peter lin
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>