tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject cvs commit: jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/jsptree JspPageInfo.java TagLibraries.java TagLibraryInfoImpl.java package.html TreeUtil.java
Date Thu, 07 Jun 2001 06:59:08 GMT
costin      01/06/06 23:59:08

  Modified:    jasper34/generator/org/apache/jasper34/core Compiler.java
                        ContainerLiaison.java JspCompilationContext.java
               jasper34/generator/org/apache/jasper34/generator
                        JspParseEventListener.java JspUtil.java
                        ServletWriter.java
               jasper34/generator/org/apache/jasper34/jsptree
                        JspPageInfo.java TagLibraries.java
                        TagLibraryInfoImpl.java package.html
  Removed:     jasper34/generator/org/apache/jasper34/jsptree TreeUtil.java
  Log:
  Few changes in TagLibrary reading.
  
  Removed all the code that reads the web.xml/tld, moved to liaison
  ( you can plug any piece that does the same thing without touching
  the generator ).
  
  This simplifies a lot the code in jsptree.
  
  Next step will be to refactor JspCompilationContext - part will be a
  singleton ( per webapp ), the ContainerLiaison, and part will go into
  JspPageInfo ( the servlet name, jsp page, etc )
  
  Revision  Changes    Path
  1.2       +3 -1      jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/core/Compiler.java
  
  Index: Compiler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/core/Compiler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Compiler.java	2001/06/06 06:25:11	1.1
  +++ Compiler.java	2001/06/07 06:58:55	1.2
  @@ -94,9 +94,11 @@
       protected JavaCompiler javac;
       protected Mangler mangler;
       protected JspCompilationContext ctxt;
  +    protected ContainerLiaison liaison;
   
  -    public Compiler(JspCompilationContext ctxt) {
  +    public Compiler(ContainerLiaison liaison, JspCompilationContext ctxt) {
           this.ctxt = ctxt;
  +	this.liaison=liaison;
       }
       
       /** 
  
  
  
  1.2       +43 -0     jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/core/ContainerLiaison.java
  
  Index: ContainerLiaison.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/core/ContainerLiaison.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ContainerLiaison.java	2001/06/06 06:27:02	1.1
  +++ ContainerLiaison.java	2001/06/07 06:58:55	1.2
  @@ -107,6 +107,49 @@
        */
       public abstract String getRealPath(String path);
   
  +    // -------------------- WEB-INF access --------------------
  +
  +    /** Read web.xml and add all the taglib locations to the
  +	TagLibraries ( if it wasn't done already ).
  +	It'll call back addTaglibLocation.
  +	You can use the default implementation ( TagLibReader )
  +	or container specific code.
  +    */
  +    public void readWebXml( TagLibraries tli )
  +	throws IOException, JasperException;
  +
  +    /** Read a tag lib descriptor ( tld ). You can use the default
  +	implementation ( TagLibReader ).
  +    */
  +    public void readTLD( TagLibraries libs, TagLibraryInfoImpl tl,
  +			 String prefix, String uri )
  +	throws IOException, JasperException;
  +
  +
  +    // -------------------- Classpath and class loader
  +
  +    /**
  +     * The classpath that is passed off to the Java compiler. 
  +     */
  +    public String getClassPath();
  +
  +    /**
  +     * What class loader to use for loading classes while compiling
  +     * this JSP? I don't think this is used right now -- akv. 
  +     */
  +    public ClassLoader getClassLoader();
  +
  +    // -------------------- Locations --------------------
  +
  +    /**
  +     * What is the scratch directory we are generating code into?
  +     * FIXME: In some places this is called scratchDir and in some
  +     * other places it is called outputDir.
  +     */
  +    public String getOutputDir();
  +
  +
  +    
       // -------------------- messages --------------------
       /**
        * Get hold of a "message" or any string from our resources
  
  
  
  1.3       +46 -26    jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/core/JspCompilationContext.java
  
  Index: JspCompilationContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/core/JspCompilationContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JspCompilationContext.java	2001/06/06 06:27:38	1.2
  +++ JspCompilationContext.java	2001/06/07 06:58:56	1.3
  @@ -63,6 +63,7 @@
   
   import org.apache.jasper34.generator.*;
   import org.apache.jasper34.parser.*;
  +import org.apache.jasper34.jsptree.*;
   import java.io.IOException;
   import org.apache.jasper34.runtime.JasperException;
   
  @@ -85,10 +86,17 @@
   public interface JspCompilationContext {
   
       /**
  -     * The classpath that is passed off to the Java compiler. 
  +     * Get hold of the Options object for this context. 
        */
  -    public String getClassPath();
  -    
  +    public Options getOptions();
  +
  +    /**
  +     * Create a "Compiler" object based on some init param data. This
  +     * is not done yet. Right now we're just hardcoding the actual
  +     * compilers that are created. 
  +     */
  +    public Compiler createCompiler() throws JasperException;
  +
       /**
        * Get the input reader for the JSP text. 
        */
  @@ -99,16 +107,13 @@
        */
       public ServletWriter getWriter();
       
  -    /**
  -     * What class loader to use for loading classes while compiling
  -     * this JSP? I don't think this is used right now -- akv. 
  -     */
  -    public ClassLoader getClassLoader();
  -
       /** Add a jar to the classpath used by the loader
        */
       public void addJar( String jar ) throws IOException ;
   
  +
  +    // -------------------- This goes to pageinfo --------------------
  +    
       /**
        * Are we processing something that has been declared as an
        * errorpage? 
  @@ -116,13 +121,6 @@
       public boolean isErrorPage();
       
       /**
  -     * What is the scratch directory we are generating code into?
  -     * FIXME: In some places this is called scratchDir and in some
  -     * other places it is called outputDir.
  -     */
  -    public String getOutputDir();
  -    
  -    /**
        * Path of the JSP URI. Note that this is not a file name. This is
        * the context rooted URI of the JSP file. 
        */
  @@ -162,11 +160,6 @@
        */
       public String getContentType();
   
  -    /**
  -     * Get hold of the Options object for this context. 
  -     */
  -    public Options getOptions();
  -
       public void setContentType(String contentType);
   
       public void setReader(JspReader reader);
  @@ -181,14 +174,26 @@
       
       public void setErrorPage(boolean isErrPage);
   
  +    // XXX move to ContainerLiaison --------------------
  +    
       /**
  -     * Create a "Compiler" object based on some init param data. This
  -     * is not done yet. Right now we're just hardcoding the actual
  -     * compilers that are created. 
  +     * The classpath that is passed off to the Java compiler. 
        */
  -    public Compiler createCompiler() throws JasperException;
  -
  +    public String getClassPath();
  +    
  +    /**
  +     * What class loader to use for loading classes while compiling
  +     * this JSP? I don't think this is used right now -- akv. 
  +     */
  +    public ClassLoader getClassLoader();
   
  +    /**
  +     * What is the scratch directory we are generating code into?
  +     * FIXME: In some places this is called scratchDir and in some
  +     * other places it is called outputDir.
  +     */
  +    public String getOutputDir();
  +    
       /** 
        * Get the full value of a URI relative to this compilations context
        */
  @@ -208,5 +213,20 @@
        */
       public String getRealPath(String path);
   
  +    /** Read web.xml and add all the taglib locations to the
  +	TagLibraries ( if it wasn't done already ).
  +	It'll call back addTaglibLocation.
  +	You can use the default implementation ( TagLibReader )
  +	or container specific code.
  +    */
  +    public void readWebXml( TagLibraries tli )
  +	throws IOException, JasperException;
  +
  +    /** Read a tag lib descriptor ( tld ). You can use the default
  +	implementation ( TagLibReader ).
  +    */
  +    public void readTLD( TagLibraries libs, TagLibraryInfoImpl tl,
  +			 String prefix, String uri )
  +	throws IOException, JasperException;
   }
   
  
  
  
  1.4       +1 -4      jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/generator/JspParseEventListener.java
  
  Index: JspParseEventListener.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/generator/JspParseEventListener.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JspParseEventListener.java	2001/06/06 06:10:40	1.3
  +++ JspParseEventListener.java	2001/06/07 06:59:00	1.4
  @@ -149,10 +149,7 @@
               String uri = (String) attrs.get("uri");
               String prefix = (String) attrs.get("prefix");
               try {
  -                TagLibraryInfo tl = new TagLibraryInfoImpl(ctxt,
  -                                                               prefix,
  -                                                               uri);
  -                pageInfo.libraries.addTagLibrary(prefix, tl);
  +		pageInfo.libraries.addTagLibrary( prefix, uri );
               } catch (Exception ex) {
                   Object[] args = new Object[] { uri, ex.getMessage() };
                   throw new CompileException(start, Constants.getString("jsp.error.badtaglib",
  
  
  
  1.3       +0 -7      jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/generator/JspUtil.java
  
  Index: JspUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/generator/JspUtil.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JspUtil.java	2001/06/06 06:16:56	1.2
  +++ JspUtil.java	2001/06/07 06:59:01	1.3
  @@ -69,13 +69,6 @@
   import org.apache.jasper34.core.*;
   import org.apache.jasper34.runtime.JasperException;
   
  -import org.w3c.dom.*;
  -import javax.xml.parsers.DocumentBuilder;
  -import javax.xml.parsers.DocumentBuilderFactory;
  -import javax.xml.parsers.ParserConfigurationException;
  -import org.xml.sax.EntityResolver;
  -import org.xml.sax.SAXException;
  -import org.xml.sax.InputSource;
   
   import org.apache.jasper34.jsptree.*;
   
  
  
  
  1.3       +6 -1      jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/generator/ServletWriter.java
  
  Index: ServletWriter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/generator/ServletWriter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ServletWriter.java	2001/06/06 06:12:45	1.2
  +++ ServletWriter.java	2001/06/07 06:59:02	1.3
  @@ -312,6 +312,7 @@
   	this.println();
   	this.println("JspFactory _jspxFactory = JspFactory.getDefaultFactory();");
   	this.println("PageContext pageContext = null;");
  +	this.println("JspWriter out=null;");
   	
   	this.println("try {");
   	this.pushIndent();
  @@ -322,6 +323,7 @@
           this.println("_jspx_init();");
   	
   	this.println("pageContext = _getPageContext(request, response);");
  +	this.println("out=pageContext.getOut();");
   	this.println();
   	this.println("_jspService( pageContext, request, response );");
   	//writer.println("} catch (Throwable t) {");
  @@ -348,9 +350,12 @@
   	
   	// Use flush buffer ( which just empty JspWriterImpl buffer )
   	// instead of commiting the response.
  -	this.println("JspWriter out=pageContext.getOut();");
  +	this.println("if( out instanceof " + Constants.JSP_RUNTIME_PACKAGE +
  +		     ".JspWriterImpl )");
  +	this.pushIndent();
   	this.println("((" +  Constants.JSP_RUNTIME_PACKAGE +
   		     ".JspWriterImpl)out).flushBuffer();");
  +	this.popIndent();
   	this.println("if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);");
   	this.popIndent();
   	this.println("}");
  
  
  
  1.2       +1 -1      jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/jsptree/JspPageInfo.java
  
  Index: JspPageInfo.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/jsptree/JspPageInfo.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JspPageInfo.java	2001/06/06 05:50:28	1.1
  +++ JspPageInfo.java	2001/06/07 06:59:05	1.2
  @@ -138,7 +138,7 @@
   
       public JspPageInfo(JspCompilationContext ctxt) {
   	this.beanInfo = new BeanRepository(ctxt.getClassLoader());
  -        this.libraries = new TagLibraries(ctxt.getClassLoader());
  +        this.libraries = new TagLibraries(ctxt);
           this.ctxt = ctxt;
   
           // FIXME: Is this good enough? (I'm just taking the easy way out - akv)
  
  
  
  1.3       +53 -29    jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/jsptree/TagLibraries.java
  
  Index: TagLibraries.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/jsptree/TagLibraries.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TagLibraries.java	2001/06/06 06:54:02	1.2
  +++ TagLibraries.java	2001/06/07 06:59:05	1.3
  @@ -57,6 +57,7 @@
   import java.lang.reflect.Constructor;
   
   import java.util.Hashtable;
  +import java.io.IOException;
   
   import javax.servlet.jsp.tagext.TagLibraryInfo;
   import javax.servlet.jsp.tagext.TagInfo;
  @@ -79,13 +80,62 @@
    * @author Mandar Raje
    */
   public class TagLibraries {
  +
  +    private Hashtable tagLibInfos;
  +    private JspCompilationContext ctxt;
  +
  +    // used to keep web.xml taglib-locations
  +    private Hashtable locations=null;
       
  -    public TagLibraries(ClassLoader cl) {
  +    public TagLibraries(JspCompilationContext ctxt)
  +    {
           this.tagLibInfos = new Hashtable();
  -	//	this.tagCaches = new Hashtable();
  -        this.cl = cl;
  +	this.ctxt=ctxt;
  +    }
  +
  +    /** Add a location mapping. The container may do so if it
  +	has parsed web.xml ( and wants to share this info with
  +	us ), so we'll not have to do that again.
  +    */
  +    public void addTaglibLocation( String uri, String loc ) {
  +	if(locations==null )
  +	    locations=new Hashtable();
  +	locations.put( uri, loc );
       }
  +
  +    // Get the taglib uri from web.xml data
  +    public String findLocation( String uriIn )
  +	throws IOException, JasperException
  +    {
  +	if( locations==null )
  +	    ctxt.readWebXml( this );
  +	
  +	// ignorecase or toLowerCase
  +	return (String)locations.get( uriIn );
  +    }
  +
  +
       
  +    /** Add a taglib prefix and the associated URI.
  +	This is the result of a taglib directive, we'll need to
  +	read the descriptor if not already there.
  +    */
  +    public void addTagLibrary( String prefix, String uri )
  +	throws JasperException, IOException
  +    {
  +	if( tagLibInfos.get( prefix ) != null ) {
  +	    return;
  +	    // we already parsed this 
  +	}
  +
  +	TagLibraryInfoImpl tl = new TagLibraryInfoImpl(prefix, uri);
  +
  +	ctxt.readTLD(  this, tl, prefix, uri );
  +
  +
  +	addTagLibrary(prefix, tl);
  +    }
  +    
       public void addTagLibrary(String prefix, TagLibraryInfo tli) {
           tagLibInfos.put(prefix, tli);
       }
  @@ -110,31 +160,5 @@
           return (TagLibraryInfo) tagLibInfos.get(prefix);
       }
   
  -//     public TagInfoImpl getTagInfoImpl(String prefix, String shortTagName) {
  -// 	// Should use TagLibraryInfoImpl
  -// 	Hashtable tagLib=(Hashtable)tagCaches.get( prefix );
  -// 	if( tagLib==null ) return null;
  -	
  -// 	return (TagInfoImpl) tagLib.get( shortTagName );
  -//     }
  -
  -//     public Class getTagHandlerClass( String prefix, String shortTagName ) {
  -// 	return getTagInfoImpl( prefix, shortTagName ).getTagHandlerClass();
  -//     }
  -
  -//     public void putTagInfoImpl(String prefix, String shortTagName,
  -// 			       TagInfoImpl tc)
  -//     {
  -// 	Hashtable tagLib=(Hashtable)tagCaches.get( prefix );
  -// 	if( tagLib==null ) {
  -// 	    tagLib=new Hashtable();
  -// 	    tagCaches.put( prefix, tagLib );
  -// 	}
  -// 	tagLib.put( shortTagName, tc);
  -//     }
  -
  -    private Hashtable tagLibInfos;
  -    //    private Hashtable tagCaches;
  -    private ClassLoader cl;
   }
   
  
  
  
  1.2       +73 -410   jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/jsptree/TagLibraryInfoImpl.java
  
  Index: TagLibraryInfoImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/jsptree/TagLibraryInfoImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TagLibraryInfoImpl.java	2001/06/06 05:52:10	1.1
  +++ TagLibraryInfoImpl.java	2001/06/07 06:59:06	1.2
  @@ -70,6 +70,7 @@
   import java.io.FileNotFoundException;
   import java.util.Vector;
   import java.util.Hashtable;
  +import java.util.Enumeration;
   
   import javax.servlet.jsp.tagext.TagLibraryInfo;
   import javax.servlet.jsp.tagext.TagInfo;
  @@ -93,25 +94,81 @@
    * @author Mandar Raje
    */
   public class TagLibraryInfoImpl extends TagLibraryInfo {
  -    static private final String TLD = "META-INF/taglib.tld";
  -    static private final String WEBAPP_INF = "/WEB-INF/web.xml";
   
  -    Document tld;
  +    public TagLibraryInfoImpl(String prefix, String uriIn) 
  +        throws IOException, JasperException
  +    {
  +        super(prefix, uriIn);
  +    }
  +
  +    // -------------------- Setter methods --------------------
  +    // Used by the tag reader to set the fields
  +    // May be used by XmlMapper, or container-specific code
  +
  +    public void setURI( String uri ) {
  +	this.uri=uri;
  +    }
  +
  +    public void setPrefixString( String p ) {
  +	prefix=p;
  +    }
   
  -    Hashtable jarEntries;
  +    public void setShortName( String s ) {
  +	shortname=s;
  +    }
   
  -    JspCompilationContext ctxt;
  +    public void setReliableURN( String s ) {
  +	urn=s;
  +    }
   
  +    public void setInfoString( String s ) {
  +	info=s;
  +    }
  +
  +    public void setRequiredVersion( String s ) {
  +	jspversion=s;
  +    }
  +
  +    // We can add only TagInfoImpl, we need the extra fields
  +    // for correct processing. You can't mix other implementations,
  +    // those things work togheter
  +    public void addTagInfo( TagInfoImpl ti ) {
  +	tagsH.put( ti.getTagName(), ti );
  +	tags=null; // clear previous cached values
  +    }
  +
  +    // override the base method in javax.servlet.jsp
  +    public TagInfo getTag( String shortname ) {
  +	return (TagInfo)tagsH.get( shortname );
  +    }
       
  +    // overrid base method 
  +    public TagInfo[] getTagInfo() {
  +	if( tags==null ) {
  +	    int size=tagsH.size();
  +	    if( size==0 ) return null;
  +	    tags=new TagInfo[ size ];
  +	    Enumeration els=tagsH.elements();
  +	    for( int i=0; els.hasMoreElements(); i++ ) {
  +		tags[i]=(TagInfo)els.nextElement();
  +	    }
  +	}
  +	return tags;
  +    }
   
  -    private final void print(String name, String value, PrintWriter w) {
  -        if (value != null) {
  -            w.print(name+" = {\n\t");
  -            w.print(value);
  -            w.print("\n}\n");
  -        }
  +    public void setVersion( String s ) {
  +	tlibversion=s;
       }
  +    
  +    // Special internal representation for tags[]
  +    // Use a hashtable instead of linear search
  +    // 
   
  +    Hashtable tagsH=new Hashtable();
  +    
  +    
  +    // -------------------- Debug info --------------------
  +    
       public String toString() {
           StringWriter sw = new StringWriter();
           PrintWriter out = new PrintWriter(sw);
  @@ -128,407 +185,13 @@
           return sw.toString();
       }
       
  -    // XXX FIXME
  -    // resolveRelativeUri and/or getResourceAsStream don't seem to properly
  -    // handle relative paths when dealing when home and getDocBase are set
  -    // the following is a workaround until these problems are resolved.
  -    private InputStream getResourceAsStream(String uri) 
  -        throws FileNotFoundException 
  -    {
  -        if (uri.indexOf(":") > 0) {
  -            // may be fully qualified (Windows) or may be a URL.  Let
  -            // getResourceAsStream deal with it.
  -            return ctxt.getResourceAsStream(uri);
  -        } else {
  -            // assume it translates to a real file, and use getRealPath
  -            String real = ctxt.getRealPath(uri);
  -            return (real == null) ? null : new FileInputStream(real);
  -        }
  -    }
  -
  -    public TagLibraryInfoImpl(JspCompilationContext ctxt, String prefix, String uriIn)

  -        throws IOException, JasperException
  -    {
  -        super(prefix, uriIn);
  -
  -	this.ctxt = ctxt;
  -        ZipInputStream zin;
  -        InputStream in = null;
  -        URL url = null;
  -        boolean relativeURL = false;
  -	this.uri = uriIn;
  -
  -        // Parse web.xml.
  -        InputStream is = getResourceAsStream(WEBAPP_INF);
  -
  -        if (is != null) {
  -            Document webtld =
  -                TreeUtil.parseXMLDoc(is,
  -                                    Constants.WEBAPP_DTD_RESOURCE,
  -                                    Constants.WEBAPP_DTD_PUBLIC_ID);
  -            NodeList nList =  webtld.getElementsByTagName("taglib");
  -
  -            if (nList.getLength() != 0) {
  -                for(int i = 0; i < nList.getLength(); i++) {
  -                    String tagLoc = null;
  -                    boolean match = false;
  -                    Element e =  (Element) nList.item(i);
  -
  -                    // Assume only one entry for location and uri.
  -                    NodeList uriList = e.getElementsByTagName("taglib-uri");
  -                    Element uriElem = (Element) uriList.item(0);
  -                    Text t = (Text) uriElem.getFirstChild();
  -
  -                    if (t != null) {
  -                        String tmpUri = t.getData();
  -                        if (tmpUri != null) {
  -                            tmpUri = tmpUri.trim();
  -                            if (tmpUri.equals(uriIn)) {
  -                                match = true;
  -                                NodeList locList = e.getElementsByTagName
  -                                    ("taglib-location");
  -                                Element locElem = (Element) locList.item(0);
  -                                Text tl = (Text) locElem.getFirstChild();
  -                                if (tl != null) {
  -                                    tagLoc = tl.getData();
  -                                    if (tagLoc != null)
  -                                        tagLoc = tagLoc.trim();
  -                                }
  -                            }
  -                        }
  -                    }
  -                    if (match == true && tagLoc != null) {
  -                        this.uri = tagLoc;
  -
  -                        // If this is a relative path, then it has to be
  -                        // relative to where web.xml is.
  -
  -                        // I'm taking the simple way out. Since web.xml 
  -                        // has to be directly under WEB-INF, I'm making 
  -                        // an absolute URI out of it by prepending WEB-INF
  -
  -                        if (!uri.startsWith("/") && isRelativeURI(uri))
  -                            uri = "/WEB-INF/"+uri;
  -                    }
  -                }
  -            }
  -        }
  -
  -        // Try to resolve URI relative to the current JSP page
  -        if (!uri.startsWith("/") && isRelativeURI(uri))
  -            uri = ctxt.resolveRelativeUri(uri);
  -
  -
  -        if (!uri.endsWith("jar")) {
  -	    in = getResourceAsStream(uri);
  -	    
  -	    if (in == null)
  -		throw new JasperException(Constants.getString("jsp.error.tld_not_found",
  -							      new Object[] {uri}));
  -	    // Now parse the tld.
  -	    parseTLD(in);
  -	}
  -	    
  -	// FIXME Take this stuff out when taglib changes are thoroughly tested.
  -        // 2000.11.15 commented out the 'copy to work dir' section,
  -        // which I believe is what this FIXME comment referred to. (pierred)
  -	if (uri.endsWith("jar")) {
  -	    
  -	    if (!isRelativeURI(uri)) {
  -		url = new URL(uri);
  -		in = url.openStream();
  -	    } else {
  -		relativeURL = true;
  -		in = getResourceAsStream(uri);
  -	    }
  -	    
  -	    zin = new ZipInputStream(in);
  -	    this.jarEntries = new Hashtable();
  -	    this.ctxt = ctxt;
  -	    
  -            /* NOT COMPILED
  -	    // First copy this file into our work directory! 
  -	    {
  -		File jspFile = new File(ctxt.getJspFile());
  -                String parent = jspFile.getParent();
  -                String jarFileName = ctxt.getOutputDir();
  -                if (parent != null) {
  -                   jarFileName = jarFileName + File.separatorChar +
  -                       parent;
  -                }
  -                File jspDir = new File(jarFileName);
  -		jspDir.mkdirs();
  -	    
  -		if (relativeURL)
  -		    jarFileName = jarFileName+File.separatorChar+new File(uri).getName();
  -		else                    
  -		    jarFileName = jarFileName+File.separatorChar+
  -			new File(url.getFile()).getName();
  -	    
  -		Constants.message("jsp.message.copyinguri", 
  -	                          new Object[] { uri, jarFileName },
  -				  Log.DEBUG);
  -	    
  -		if (relativeURL)
  -		    copy(getResourceAsStream(uri),
  -			 jarFileName);
  -		else
  -		    copy(url.openStream(), jarFileName);
  -	    
  -	        ctxt.addJar(jarFileName);
  -	    }
  -            */ // END NOT COMPILED
  -	    boolean tldFound = false;
  -	    ZipEntry entry;
  -	    while ((entry = zin.getNextEntry()) != null) {
  -		if (entry.getName().equals(TLD)) {
  -		    /*******
  -		     * This hack is necessary because XML reads until the end 
  -		     * of an inputstream -- does not use available()
  -		     * -- and closes the inputstream when it can't
  -		     * read no more.
  -		     */
  -		    
  -		    // BEGIN HACK
  -		    ByteArrayOutputStream baos = new ByteArrayOutputStream();
  -		    int b;
  -		    while (zin.available() != 0) {
  -			b = zin.read();
  -			if (b == -1)
  -			    break;
  -			baos.write(b);
  -		    }
  -
  -		    baos.close();
  -		    ByteArrayInputStream bais 
  -			= new ByteArrayInputStream(baos.toByteArray());
  -		    // END HACK
  -		    tldFound = true;
  -		    parseTLD(bais);
  -		} else {
  -		    ByteArrayOutputStream baos = new ByteArrayOutputStream();
  -		    int b;
  -		    while (zin.available() != 0) {
  -			b = zin.read();
  -			if (b == -1)
  -			    break;
  -			baos.write(b);
  -		    }
  -		    baos.close();
  -		    jarEntries.put(entry.getName(), baos.toByteArray());
  -		}
  -		zin.closeEntry();
  -	    }
  -	    
  -	    if (!tldFound)
  -		throw new JasperException(Constants.getString("jsp.error.tld_not_found",
  -							      new Object[] {
  -		    TLD
  -			}
  -							      ));
  -	} // Take this out (END of if(endsWith("jar")))
  -    }
  -    
  -    /** Returns true if the given URI is relative in this web application, false if it
is an internet URI.
  -     */
  -    private boolean isRelativeURI(String uri) {
  -        return (uri.indexOf(':') == -1);
  -    }
  -    
  -        
  -    private void parseTLD(InputStream in) 
  -        throws JasperException
  -    {
  -	tld = TreeUtil.parseXMLDoc(in,
  -				  Constants.TAGLIB_DTD_RESOURCE,
  -				  Constants.TAGLIB_DTD_PUBLIC_ID);
  -	
  -        Vector tagVector = new Vector();
  -        NodeList list = tld.getElementsByTagName("taglib");
  -
  -        if (list.getLength() != 1)
  -            throw new JasperException(Constants.getString("jsp.error.more.than.one.taglib"));
  -
  -        Element elem = (Element) list.item(0);
  -        list = elem.getChildNodes();
  -
  -        for(int i = 0; i < list.getLength(); i++) {
  -	    Node tmp = list.item(i);
  -	    if (! (tmp instanceof Element)) continue;
  -            Element e = (Element) tmp;
  -            String tname = e.getTagName();
  -            if (tname.equals("tlibversion")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    this.tlibversion = t.getData().trim();
  -            } else if (tname.equals("jspversion")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    this.jspversion = t.getData().trim();
  -            } else if (tname.equals("shortname")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    this.shortname = t.getData().trim();
  -            } else if (tname.equals("uri")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    this.urn = t.getData().trim();
  -            } else if (tname.equals("info")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    this.info = t.getData().trim();
  -            } else if (tname.equals("tag"))
  -                tagVector.addElement(createTagInfo(e));
  -            else
  -                Constants.message("jsp.warning.unknown.element.in.TLD", 
  -                                  new Object[] {
  -                                      e.getTagName()
  -                                  },
  -                                  Log.WARNING
  -                                  );
  -        }
  -
  -        this.tags = new TagInfo[tagVector.size()];
  -        tagVector.copyInto (this.tags);
  -    }
  -
  -    private TagInfoImpl createTagInfo(Element elem) throws JasperException {
  -        String name = null, tagclass = null, teiclass = null;
  -        String bodycontent = "JSP"; // Default body content is JSP
  -	String info = null;
  -        
  -        Vector attributeVector = new Vector();
  -        NodeList list = elem.getChildNodes();
  -        for(int i = 0; i < list.getLength(); i++) {
  -            Node tmp  =  list.item(i);
  -	    if (! (tmp instanceof Element)) continue;
  -	    Element e = (Element) tmp;
  -            String tname = e.getTagName();
  -            if (tname.equals("name")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    name = t.getData().trim();
  -            } else if (tname.equals("tagclass")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    tagclass = t.getData().trim();
  -            } else if (tname.equals("teiclass")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    teiclass = t.getData().trim();
  -            } else if (tname.equals("bodycontent")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    bodycontent = t.getData().trim();
  -            } else if (tname.equals("info")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    info = t.getData().trim();
  -            } else if (tname.equals("attribute"))
  -                attributeVector.addElement(createAttribute(e));
  -            else 
  -                Constants.message("jsp.warning.unknown.element.in.tag", 
  -                                  new Object[] {
  -                                      e.getTagName()
  -                                  },
  -                                  Log.WARNING
  -                                  );
  -        }
  -	TagAttributeInfo[] tagAttributeInfo 
  -            = new TagAttributeInfo[attributeVector.size()];
  -	attributeVector.copyInto (tagAttributeInfo);
  -
  -        TagExtraInfo tei = null;
  -
  -        if (teiclass != null && !teiclass.equals(""))
  -            try {
  -                Class teiClass = ctxt.getClassLoader().loadClass(teiclass);
  -                tei = (TagExtraInfo) teiClass.newInstance();
  -	    } catch (ClassNotFoundException cex) {
  -                Constants.message("jsp.warning.teiclass.is.null",
  -                                  new Object[] {
  -                                      teiclass, cex.getMessage()
  -                                  },
  -                                  Log.WARNING
  -                                  );
  -            } catch (IllegalAccessException iae) {
  -                Constants.message("jsp.warning.teiclass.is.null",
  -                                  new Object[] {
  -                                      teiclass, iae.getMessage()
  -                                  },
  -                                  Log.WARNING
  -                                  );
  -            } catch (InstantiationException ie) {
  -                Constants.message("jsp.warning.teiclass.is.null",
  -                                  new Object[] {
  -                                      teiclass, ie.getMessage()
  -                                  },
  -                                  Log.WARNING
  -                                  );
  -            }
  -
  -        TagInfoImpl taginfo = new TagInfoImpl(name, tagclass, bodycontent,
  -					      info, this, 
  -					      tei,
  -					      tagAttributeInfo);
  -        return taginfo;
  -    }
  -
  -    TagAttributeInfo createAttribute(Element elem) {
  -        String name = null;
  -        boolean required = false, rtexprvalue = false, reqTime = false;
  -        String type = null;
  -        
  -        NodeList list = elem.getChildNodes();
  -        for(int i = 0; i < list.getLength(); i++) {
  -            Node tmp  = list.item(i);
  -	    if (! (tmp instanceof Element)) continue;
  -	    Element e = (Element) tmp;
  -            String tname = e.getTagName();
  -            if (tname.equals("name"))  {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    name = t.getData().trim();
  -            } else if (tname.equals("required"))  {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null) {
  -                    required = Boolean.valueOf(t.getData().trim()).booleanValue();
  -                    if( t.getData().equalsIgnoreCase("yes") )
  -                        required = true;
  -                }
  -            } else if (tname.equals("rtexprvalue")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null) {
  -                    rtexprvalue = Boolean.valueOf(t.getData().trim()).booleanValue();
  -                    if( t.getData().equalsIgnoreCase("yes") )
  -                        rtexprvalue = true;
  -                }
  -            } else if (tname.equals("type")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    type = t.getData().trim();
  -            } else 
  -                Constants.message("jsp.warning.unknown.element.in.attribute", 
  -                                  new Object[] {
  -                                      e.getTagName()
  -                                  },
  -                                  Log.WARNING
  -                                  );
  +    private final void print(String name, String value, PrintWriter w) {
  +        if (value != null) {
  +            w.print(name+" = {\n\t");
  +            w.print(value);
  +            w.print("\n}\n");
           }
  -        
  -	//     return new TagAttributeInfo(name, required, rtexprvalue, type);
  -        return new TagAttributeInfo(name, required, type, rtexprvalue);
       }
   
  -    static void copy(InputStream in, String fileName) 
  -        throws IOException, FileNotFoundException 
  -    {
  -        byte[] buf = new byte[1024];
  -
  -        FileOutputStream out = new FileOutputStream(fileName);
  -        int nRead;
  -        while ((nRead = in.read(buf, 0, buf.length)) != -1)
  -            out.write(buf, 0, nRead);
  -    }
   
   }
  
  
  
  1.2       +20 -0     jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/jsptree/package.html
  
  Index: package.html
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/jsptree/package.html,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- package.html	2001/06/06 05:55:56	1.1
  +++ package.html	2001/06/07 06:59:06	1.2
  @@ -1,5 +1,25 @@
   <h2>Tree representation of a JSP page</h2>
   
  +JspPageInfo is the main class, collecting all the informations about a page.
  +It contains a tree of JspNode ( TODO - right now it's a tree of Generators).
  +It also contains informations about all the tag libs and all the tags.
  +
  +<h2>Tags</h2>
  +
  +Tags are special because they affect the way the source is parsed. This is 
  +a very tricky thing, and the reason the parser needs to depend on the 
  +jsptree and implement/use the directive processing.
  +
  +<p>
  +
  +We keep all the informations available in TagLibraries, which collects 
  +all the taglibs for a webapps ( TODO: make sure it's singeleton/webapp ).
  +This avoids re-reading the tlds and allows the container to push 
  +the information into jasper ( if it has it already - like from parsing
  +web.xml or preprocessing at deployment time ). The liaison also makes callbacks
  +to the container, which could implement a more efficient reading or use
  +the default ( which now is quite bad - DOM and quite complex )
  +
   <h2>History</h2>
   
   jasper33 and 40 creates a tree of Generators, and then it traverses the
  
  
  

Mime
View raw message