Bug 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
Status: RESOLVED LATER
Alias: None
Product: Taglibs
Classification: Unclassified
Component: IO Taglib (show other bugs)
Version: 1.0
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-03-26 11:54 UTC by Michael Stadler
Modified: 2009-11-29 19:39 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Stadler 2004-03-26 11:54:14 UTC
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 [details]: 


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 [details]: 


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 [details]:


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>
Comment 1 Henri Yandell 2009-11-29 19:39:00 UTC
Resolving. Taglib has been retired.