You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by bu...@apache.org on 2004/03/26 12:54:15 UTC

DO NOT REPLY [Bug 27978] New: - URLTag nesting into BodyTag does not work more then one URLTag used

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=27978>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=27978

URLTag nesting into BodyTag does not work more then one URLTag used

           Summary: URLTag nesting into BodyTag does not work more then one
                    URLTag used
           Product: Taglibs
           Version: 1.0
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: IO Taglib
        AssignedTo: taglibs-dev@jakarta.apache.org
        ReportedBy: mistadl@bigfoot.com


URLTag showed a strange behavior




An URLTag was nested inside of a BodyTagSupport based Tag, another URLTag was 
positioned before.




When there were 2 URLTags and 1 of it nested, the output of both was written 
before the BodyTag output instead of: one output before and one nested.






jsp:




<%@taglib uri="http://jakarta.apache.org/taglibs/io-1.0" prefix="io" %>


<%@taglib uri="http://testtags" prefix="tt" %>




<io:request url="file:/C:/foo.txt" />




<tt:writebodycontent>


	ahead


		<io:request url="file:/C:/foo.txt" />


	after


</tt:writebodycontent>




---




Output: 




[content of foo.txt] [content of foo.txt] (writebodycontent: ahead after ) 




this is incorrect. The second "[content of foo.txt]" must be nested between 
"ahead after", i.e. inside of the output of the writebodycontent tag. If only 
one URLTag output is used, the nesting works. If two, no more. This is the bug.






---




temporary Resolution: Changed readURL() method in URLTag.java to avoid class 
casting of the java.io.Writer




After this the output was as expected:




[content of foo.txt] (writebodycontent: ahead [content of foo.txt] after ) 






---




Attachment 1: 


Changed readURL() method in URLTag.java


demonstration purpose: avoiding cast to JSPWriter to java.io.Writer 






    protected void readURL() throws IOException, JspException {


        Tag parent = getParent();


        if ( writer == null && parent instanceof PipeConsumer ) {


            PipeConsumer consumer = (PipeConsumer) parent;


            consumer.setReader( getURLReader() );


        }


        else {


            if ( writer == null ) {


                writer = pageContext.getOut();


            }




            Reader reader = getURLReader();


            try {




                //PipeHelper.pipe( reader, writer );




				// code of PipeHelper inserted here


				char[] buffer = new char[ 50000 ];


				try {


					while (true) {


						int size = reader.read( buffer );


						if ( size <= 0 ) {


							return;


						}


						//writer.write( buffer, 0, size );


						


						//this is the difference. Class cast avoided


						pageContext.getOut().write( buffer, 0, size );


					}


				}


				finally {


					try {


						reader.close();


					}


					catch (Exception e) {


					}


				}


            } catch (Exception ex) {


				pageContext.getOut().print(ex.toString());


            }


        }


    }






---




Attachment 2: 


writebodycontent Tag used for demonstration






package test;




import javax.servlet.jsp.*;


import javax.servlet.jsp.tagext.*;


import java.io.*;




public class WriteBodyContentTag extends BodyTagSupport {




    public int doStartTag() {


        return EVAL_BODY_BUFFERED;


    }




    public int doEndTag() throws JspException {




        if( (bodyContent == null) ) {


            return EVAL_PAGE;


        }




        try {


			getBodyContent().getEnclosingWriter().print (


				"(writebodycontent: "+ bodyContent.getString() + ")");


			


        } catch (IOException e) {


            throw new JspException(e.toString());


        }


        


        return SKIP_BODY;


    }


}






---


Attachment 3:


TLD for writebodycontent Tag








<?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" 


"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">


<taglib>


  <tlibversion>1.0</tlibversion>


  <jspversion>1.1</jspversion>


  <uri>http://testtags</uri>


  <tag>


    <name>writebodycontent</name>


    <tagclass>test.WriteBodyContentTag</tagclass>


    <bodycontent>JSP</bodycontent>


    <info>Simply write out bodycontent</info>


  </tag>


</taglib>

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org