tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From man...@hyperreal.org
Subject cvs commit: jakarta-tomcat/src/share/org/apache/jasper/resources messages.properties
Date Wed, 20 Oct 1999 21:20:56 GMT
mandar      99/10/20 14:20:53

  Modified:    src/examples/jsp/simpletag foo.jsp
               src/share/org/apache/jasper Constants.java
               src/share/org/apache/jasper/compiler JspUtil.java
                        TagLibraryInfoImpl.java
               src/share/org/apache/jasper/resources messages.properties
  Log:
  taglib in sync with the changes in PR2.
  
  TODO
  1) create a cache of taglib elements so that web.xml
     is not parsed everytime.
  2) take the jar stuff out once the code is tested.
  
  Revision  Changes    Path
  1.4       +1 -1      jakarta-tomcat/src/examples/jsp/simpletag/foo.jsp
  
  Index: foo.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/examples/jsp/simpletag/foo.jsp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- foo.jsp	1999/10/20 11:13:42	1.3
  +++ foo.jsp	1999/10/20 21:20:25	1.4
  @@ -14,4 +14,4 @@
   
   <akv:log toBrowser="true">
   Did you see me on the browser window as well?
  -</akv:log>
  \ No newline at end of file
  +</akv:log>
  
  
  
  1.5       +11 -3     jakarta-tomcat/src/share/org/apache/jasper/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/Constants.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Constants.java	1999/10/20 11:20:08	1.4
  +++ Constants.java	1999/10/20 21:20:29	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/Constants.java,v 1.4 1999/10/20
11:20:08 akv Exp $
  - * $Revision: 1.4 $
  - * $Date: 1999/10/20 11:20:08 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/Constants.java,v 1.5 1999/10/20
21:20:29 mandar Exp $
  + * $Revision: 1.5 $
  + * $Date: 1999/10/20 21:20:29 $
    *
    * ====================================================================
    * 
  @@ -157,6 +157,14 @@
       public static final String
           TAGLIB_DTD_RESOURCE = "/org/apache/jasper/resources/web-jsptaglib_1_1.dtd";
   
  +    /**
  +     * ID and location of the DTD for web-app deployment descriptors. 
  +     */
  +    public static final String 
  +        WEBAPP_DTD_PUBLIC_ID = "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN";
  +    public static final String
  +        WEBAPP_DTD_RESOURCE = "/org/apache/tomcat/deployment/web.dtd";
  +    
       /**
        * Default URLs to download the pluging for Netscape and IE.
        */
  
  
  
  1.2       +57 -3     jakarta-tomcat/src/share/org/apache/jasper/compiler/JspUtil.java
  
  Index: JspUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/JspUtil.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JspUtil.java	1999/10/09 00:20:36	1.1
  +++ JspUtil.java	1999/10/20 21:20:33	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/JspUtil.java,v
1.1 1999/10/09 00:20:36 duncan Exp $
  - * $Revision: 1.1 $
  - * $Date: 1999/10/09 00:20:36 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/JspUtil.java,v
1.2 1999/10/20 21:20:33 mandar Exp $
  + * $Revision: 1.2 $
  + * $Date: 1999/10/20 21:20:33 $
    *
    * ====================================================================
    * 
  @@ -60,7 +60,20 @@
    */ 
   package org.apache.jasper.compiler;
   
  +import java.net.URL;
  +
   import java.io.CharArrayWriter;
  +import java.io.IOException;
  +import java.io.InputStream;
  +
  +import org.apache.jasper.Constants;
  +import org.apache.jasper.JasperException;
  +
  +
  +import org.w3c.dom.*;
  +import org.xml.sax.*;
  +import com.sun.xml.tree.*;
  +import com.sun.xml.parser.*;
   
   /** 
    * This class has all the utility method(s).
  @@ -114,6 +127,47 @@
   	    returnString = returnString.substring (0, length - CLOSE_EXPR_2.length());
   	
   	return returnString;
  +    }
  +
  +    // Parses the XML document contained in the InputStream.
  +    public static XmlDocument parseXMLDoc(InputStream in, URL dtdURL, String dtdId)
  +    throws JasperException {
  +	XmlDocument tld;
  +	XmlDocumentBuilder builder = new XmlDocumentBuilder();
  +	
  +        com.sun.xml.parser.ValidatingParser 
  +            parser = new com.sun.xml.parser.ValidatingParser();
  +
  +        /***
  +         * These lines make sure that we have an internal catalog entry for 
  +         * the taglib.dtdfile; this is so that jasper can run standalone 
  +         * without running out to the net to pick up the taglib.dtd file.
  +         */
  +        Resolver resolver = new Resolver();
  +        resolver.registerCatalogEntry(dtdId, 
  +                                      dtdURL.toString());
  +        
  +        try {
  +            parser.setEntityResolver(resolver);
  +            builder.setParser(parser);
  +            builder.setDisableNamespaces(false);
  +            parser.parse(new InputSource(in));
  +        } catch (SAXException sx) {
  +            throw new JasperException(Constants.getString("jsp.error.parse.error.in.TLD",
  +                                                          new Object[] {
  +		sx.getMessage()
  +		    }
  +                                                          ));
  +        } catch (IOException io) {
  +            throw new JasperException(Constants.getString("jsp.error.unable.to.open.TLD",
  +                                                          new Object[] {
  +		io.getMessage()
  +		    }
  +                                                          ));
  +        }
  +        
  +        tld = builder.getDocument();
  +	return tld;
       }
   }
   
  
  
  
  1.3       +161 -132  jakarta-tomcat/src/share/org/apache/jasper/compiler/TagLibraryInfoImpl.java
  
  Index: TagLibraryInfoImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/TagLibraryInfoImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TagLibraryInfoImpl.java	1999/10/20 11:22:55	1.2
  +++ TagLibraryInfoImpl.java	1999/10/20 21:20:36	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/TagLibraryInfoImpl.java,v
1.2 1999/10/20 11:22:55 akv Exp $
  - * $Revision: 1.2 $
  - * $Date: 1999/10/20 11:22:55 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/TagLibraryInfoImpl.java,v
1.3 1999/10/20 21:20:36 mandar Exp $
  + * $Revision: 1.3 $
  + * $Date: 1999/10/20 21:20:36 $
    *
    * ====================================================================
    * 
  @@ -98,6 +98,7 @@
    */
   public class TagLibraryInfoImpl extends TagLibraryInfo {
       static private final String TLD = "META-INF/taglib.tld";
  +    static private final String WEBAPP_INF = "/WEB-INF/web.xml";
   
       XmlDocument tld;
   
  @@ -131,147 +132,176 @@
           return sw.toString();
       }
       
  -    TagLibraryInfoImpl(JspEngineContext ctxt, String prefix, String uri) 
  +    TagLibraryInfoImpl(JspEngineContext ctxt, String prefix, String uriIn) 
           throws IOException, JasperException
       {
  -        super(prefix, uri);
  +	// XXX. should super be initialized with "dummy" uri?
  +        super(prefix, uriIn);
   
  +	this.ctxt = ctxt;
           ZipInputStream zin;
           InputStream in = null;
           URL url = null;
           boolean relativeURL = false;
  -        
  -        if (!uri.startsWith("/")) {
  -            url = new URL(uri);
  -            in = url.openStream();
  -        } else {
  -            relativeURL = true;
  -            in = ctxt.getServletContext().getResourceAsStream(uri);
  -        }
  -        
  -        zin = new ZipInputStream(in);
  -        this.jarEntries = new Hashtable();
  -        this.ctxt = ctxt;
  -
  -        // First copy this file into our work directory! 
  -        {
  -            File jspFile = new File(ctxt.getJspFile());
  -            String jarFileName = ctxt.getOutputDir()+File.separatorChar+
  -                jspFile.getParent().toString();
  -            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 },
  -                              Constants.MED_VERBOSITY);
  -
  -            if (relativeURL)
  -                copy(ctxt.getServletContext().getResourceAsStream(uri),
  -                     jarFileName);
  -            else
  -                copy(url.openStream(), jarFileName);
  -            
  -            ctxt.getClassLoader().addJar(jarFileName);
  -        }
  -        
  +	this.uri = uriIn;
   
  -        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
  -                                                          }
  -                                                          ));
  +	if (!uriIn.endsWith("jar")) {
  +	    // Parse web.xml.
  +	    InputStream is = ctxt.getServletContext().getResourceAsStream(WEBAPP_INF);
  +	    
  +	    if (is == null) {
  +		throw new IOException(Constants.getString("jsp.error.webxml_not_found"));
  +	    }
  +	    
  +	    URL dtdURL =  this.getClass().getResource(Constants.WEBAPP_DTD_RESOURCE);
  +	    XmlDocument webtld = JspUtil.parseXMLDoc(is, dtdURL,
  +						     Constants.WEBAPP_DTD_PUBLIC_ID);
  +	    NodeList nList =  webtld.getElementsByTagName("taglib");
  +	    
  +	    // Check if a macthing "taglib" exists.
  +	    // XXX. Some changes that akv recommended.
  +	    if (nList.getLength() != 0) {
  +		for(int i = 0; i < nList.getLength(); i++) {
  +		    Element e = (Element) nList.item(i);
  +		    NodeList nodeL = e.getChildNodes();
  +		    String tagLoc = null;
  +		    boolean match = false;
  +		    for(int j = 0; j < nodeL.getLength(); j++) {
  +			Element em = (Element) nodeL.item(j);
  +			String tname = em.getNodeName();
  +			if (tname.equals("taglib-location")) {
  +			    tagLoc = ((Text)em.getFirstChild()).getData();
  +			}
  +			if (tname.equals("taglib-uri")) {
  +			    String tmpUri =  ((Text)em.getFirstChild()).getData();
  +			    if (tmpUri != null && tmpUri.equals(uriIn))
  +				match = true;
  +			}
  +		    }
  +		if (match == true && tagLoc != null) this.uri = tagLoc;
  +		}
  +	    }
  +	    
  +	    // "uri" should point to the correct tld location.
  +	    System.out.println ("modified uri = " + this.uri);
  +	    if (!uri.startsWith("/")) {
  +		url = new URL(uri);
  +		in = url.openStream();
  +	    } else {
  +		relativeURL = true;
  +		in = ctxt.getServletContext().getResourceAsStream(uri);
  +	    }
  +	    
  +	    if (in == null)
  +		throw new JasperException(Constants.getString("jsp.error.tld_not_found",
  +							      new Object[] {TLD}));
  +	    
  +	    //Now parse the tld.
  +	    parseTLD(in);
  +	}
  +	    
  +	// FIXME Take this stuff out when taglib changes are thoroughly tested.
  +	if (uriIn.endsWith("jar")) {
  +	    
  +	    if (!uriIn.startsWith("/")) {
  +		url = new URL(uriIn);
  +		in = url.openStream();
  +	    } else {
  +		relativeURL = true;
  +		in = ctxt.getServletContext().getResourceAsStream(uriIn);
  +	    }
  +	    
  +	    zin = new ZipInputStream(in);
  +	    this.jarEntries = new Hashtable();
  +	    this.ctxt = ctxt;
  +	    
  +	    // First copy this file into our work directory! 
  +	    {
  +		File jspFile = new File(ctxt.getJspFile());
  +		String jarFileName = ctxt.getOutputDir()+File.separatorChar+
  +		    jspFile.getParent().toString();
  +		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 },
  +				  Constants.MED_VERBOSITY);
  +	    
  +		if (relativeURL)
  +		    copy(ctxt.getServletContext().getResourceAsStream(uri),
  +			 jarFileName);
  +		else
  +		    copy(url.openStream(), jarFileName);
  +	    
  +	        ctxt.getClassLoader().addJar(jarFileName);
  +	    }
  +	    
  +	    
  +	    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")))
       }
       
           
       private void parseTLD(InputStream in) 
           throws JasperException
       {
  -        XmlDocumentBuilder builder = new XmlDocumentBuilder();
  -
  -                
  -        com.sun.xml.parser.ValidatingParser 
  -            parser = new com.sun.xml.parser.ValidatingParser();
  -
  -        /***
  -         * These lines make sure that we have an internal catalog entry for 
  -         * the taglib.dtd file; this is so that jasper can run standalone 
  -         * without running out to the net to pick up the taglib.dtd file.
  -         */
  -        Resolver resolver = new Resolver();
  -        URL dtdURL = this.getClass().getResource(Constants.TAGLIB_DTD_RESOURCE);
  -        
  -        resolver.registerCatalogEntry(Constants.TAGLIB_DTD_PUBLIC_ID, 
  -                                      dtdURL.toString());
  -        
  -        try {
  -            parser.setEntityResolver(resolver);
  -            parser.setDocumentHandler(builder);
  -            builder.setParser(parser);
  -            builder.setDisableNamespaces(false);
  -            parser.parse(new InputSource(in));
  -        } catch (SAXException sx) {
  -            throw new JasperException(Constants.getString("jsp.error.parse.error.in.TLD",
  -                                                          new Object[] {
  -                                                              sx.getMessage()
  -                                                          }
  -                                                          ));
  -        } catch (IOException io) {
  -            throw new JasperException(Constants.getString("jsp.error.unable.to.open.TLD",
  -                                                          new Object[] {
  -                                                              io.getMessage()
  -                                                          }
  -                                                          ));
  -        }
  -        
  -        tld = builder.getDocument();
  +	URL tagUrl = this.getClass().getResource(Constants.TAGLIB_DTD_RESOURCE);
  +	tld = JspUtil.parseXMLDoc(in, tagUrl,
  +				  Constants.TAGLIB_DTD_PUBLIC_ID);
  +	
           Vector tagVector = new Vector();
           NodeList list = tld.getElementsByTagName("taglib");
   
  @@ -367,9 +397,8 @@
           if (teiclass != null && !teiclass.equals(""))
               try {
                   Class teiClass = ctxt.getClassLoader().loadClass(teiclass);
  -
                   tei = (TagExtraInfo) teiClass.newInstance();
  -            } catch (ClassNotFoundException cex) {
  +	    } catch (ClassNotFoundException cex) {
                   Constants.message("jsp.warning.teiclass.is.null",
                                     new Object[] {
                                         teiclass, cex.getMessage()
  
  
  
  1.4       +1 -0      jakarta-tomcat/src/share/org/apache/jasper/resources/messages.properties
  
  Index: messages.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/resources/messages.properties,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- messages.properties	1999/10/20 11:24:38	1.3
  +++ messages.properties	1999/10/20 21:20:48	1.4
  @@ -125,6 +125,7 @@
   jsp.error.missing_attribute=According to the TLD attribute {0} is mandatory for tag {1}
   jsp.error.bad_attribute=Attribute {0} invalid according to the specified TLD
   jsp.error.tld_not_found=Could not locate TLD {0}
  +jsp.error.webxml_not_found=Could not locate web.xml
   jsp.cmd_line.usage=Usage: jsptoservlet [-o <path/to/outputDirectory>] [-keepgenerated]
\
   <.jsp files>
   jsp.message.cp_is=Classpath {0} is: {1}
  
  
  

Mime
View raw message