You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@locus.apache.org on 2000/05/19 02:39:07 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/jasper/compiler JspUtil.java TagLibraryInfoImpl.java

mandar      00/05/18 17:39:06

  Modified:    src/share/org/apache/jasper/compiler JspUtil.java
                        TagLibraryInfoImpl.java
  Log:
  Using JAXP for parsing web.xml and *.tld.
  
  Revision  Changes    Path
  1.12      +69 -31    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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- JspUtil.java	2000/04/05 18:49:27	1.11
  +++ JspUtil.java	2000/05/19 00:39:06	1.12
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/JspUtil.java,v 1.11 2000/04/05 18:49:27 akv Exp $
  - * $Revision: 1.11 $
  - * $Date: 2000/04/05 18:49:27 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/JspUtil.java,v 1.12 2000/05/19 00:39:06 mandar Exp $
  + * $Revision: 1.12 $
  + * $Date: 2000/05/19 00:39:06 $
    *
    * ====================================================================
    * 
  @@ -65,6 +65,7 @@
   import java.io.CharArrayWriter;
   import java.io.IOException;
   import java.io.InputStream;
  +import java.io.FileInputStream;
   import java.util.Hashtable;
   import java.util.Enumeration;
   
  @@ -73,9 +74,12 @@
   
   
   import org.w3c.dom.*;
  -import org.xml.sax.*;
  -import com.sun.xml.tree.*;
  -import com.sun.xml.parser.*;
  +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;
   
   /** 
    * This class has all the utility method(s).
  @@ -128,30 +132,29 @@
       }
   
       // Parses the XML document contained in the InputStream.
  -    public static XmlDocument parseXMLDoc(InputStream in, URL dtdURL, 
  +    public static Document parseXMLDoc(InputStream in, URL dtdURL, 
       					  String dtdId) throws JasperException 
       {
  -	XmlDocument tld;
  -	XmlDocumentBuilder builder = new XmlDocumentBuilder();
  -	builder.setIgnoringLexicalInfo(true);
  -	
  -        com.sun.xml.parser.ValidatingParser 
  -            parser = new com.sun.xml.parser.ValidatingParser(true);
  -
  -        /***
  -         * 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));
  +	try {
  +	    Document tld;
  +	    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
  +	    docFactory.setValidating(true);
  +	    docFactory.setNamespaceAware(true);
  +	    DocumentBuilder builder = docFactory.newDocumentBuilder();
  +	    
  +	    /***
  +	     * 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.
  +	     */
  +	    MyEntityResolver resolver = new MyEntityResolver(dtdId, dtdURL.toString());
  +            builder.setEntityResolver(resolver);
  +	    tld = builder.parse(in);
  +	    return tld;
  +	} catch (ParserConfigurationException pcfe) {
  +	    throw new JasperException(Constants.getString(
  +		"jsp.error.parse.error.in.TLD", new Object[] {
  +		pcfe.getMessage() }));  
           } catch (SAXException sx) {
               throw new JasperException(Constants.getString(
   	    	"jsp.error.parse.error.in.TLD", new Object[] {
  @@ -162,9 +165,6 @@
   	    		"jsp.error.unable.to.open.TLD", new Object[] {
   							    io.getMessage() }));
           }
  -        
  -        tld = builder.getDocument();
  -	return tld;
       }
   
       public static void checkAttributes (String typeOfTag, Hashtable attrs,
  @@ -265,3 +265,41 @@
   	}
       }
   }
  +
  +class MyEntityResolver implements EntityResolver {
  +
  +    String dtdId;
  +    String dtdURL;
  +    
  +    public MyEntityResolver(String id, String url) {
  +	this.dtdId = id;
  +	this.dtdURL = url;
  +    }
  +    
  +    public InputSource resolveEntity(String publicId, String systemId)
  +	throws SAXException, IOException
  +    {
  +	//System.out.println ("publicId = " + publicId);
  +	//System.out.println ("dtdId = " + dtdId);
  +	//System.out.println ("systemId is " + systemId);
  +	if (publicId.equals(dtdId)) {
  +	    //System.out.println ("dtdURL is " + dtdURL);
  +	    String fileName = dtdURL.substring(dtdURL.indexOf("/"),dtdURL.length());
  +	    //System.out.println ("fileName is " + fileName);
  +	    InputSource isrc = 
  +		new InputSource(new FileInputStream (fileName));
  +	    //InputStream istr = new FileInputStream (fileName);
  +	    //if (istr == null) System.out.println ("Stream is null");
  +	    //System.out.println ("isrc = " + isrc);
  +	    return isrc;
  +	}
  +	else {
  +	    //System.out.println ("returning null though dtdURL is " + dtdURL);
  +	    return null;
  +	}
  +    }
  +}
  +
  +
  +
  +
  
  
  
  1.18      +48 -44    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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- TagLibraryInfoImpl.java	2000/05/01 15:46:48	1.17
  +++ TagLibraryInfoImpl.java	2000/05/19 00:39:06	1.18
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/TagLibraryInfoImpl.java,v 1.17 2000/05/01 15:46:48 craigmcc Exp $
  - * $Revision: 1.17 $
  - * $Date: 2000/05/01 15:46:48 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/TagLibraryInfoImpl.java,v 1.18 2000/05/19 00:39:06 mandar Exp $
  + * $Revision: 1.18 $
  + * $Date: 2000/05/19 00:39:06 $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -82,8 +82,6 @@
   
   import org.w3c.dom.*;
   import org.xml.sax.*;
  -import com.sun.xml.tree.*;
  -import com.sun.xml.parser.*;
   
   import org.apache.jasper.JspCompilationContext;
   import org.apache.jasper.JasperException;
  @@ -102,7 +100,7 @@
       static private final String TLD = "META-INF/taglib.tld";
       static private final String WEBAPP_INF = "/WEB-INF/web.xml";
   
  -    XmlDocument tld;
  +    Document tld;
   
       Hashtable jarEntries;
       Hashtable tagCaches = new Hashtable();
  @@ -169,52 +167,52 @@
   	    
   	    if (is != null) {
                   URL dtdURL =  this.getClass().getResource(Constants.WEBAPP_DTD_RESOURCE);
  -                XmlDocument webtld = JspUtil.parseXMLDoc(is, dtdURL,
  +                Document webtld = JspUtil.parseXMLDoc(is, dtdURL,
                                                            Constants.WEBAPP_DTD_PUBLIC_ID);
                   NodeList nList =  webtld.getElementsByTagName("taglib");
   	    
                   if (nList.getLength() != 0) {
   		    for(int i = 0; i < nList.getLength(); i++) {
  -			Element e = (Element) nList.item(i);
  -			NodeList list = e.getChildNodes();
   			String tagLoc = null;
   			boolean match = false;
  -			for(int j = 0; j < list.getLength(); j++) {
  -			    Element em = (Element) list.item(j);
  -			    String tname = em.getNodeName();
  -			    if (tname.equals("taglib-location")) {
  -				Text t = (Text) em.getFirstChild();
  -				if (t != null) {
  -				    tagLoc = t.getData();
  -				    if (tagLoc != null)
  -					tagLoc = tagLoc.trim();
  -				}
  -			    }
  -			    if (tname.equals("taglib-uri")) {
  -				Text t = (Text) em.getFirstChild();
  -				if (t != null) {
  -				    String tmpUri =  t.getData();
  -				    if (tmpUri != null) {
  -					tmpUri = tmpUri.trim();
  -					if (tmpUri.equals(uriIn))
  -					    match = true;
  +			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("/"))
  -                                uri = "/WEB-INF/"+uri;
  -                        }
  +			    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("/"))
  +				uri = "/WEB-INF/"+uri;
  +			}
   		    }
   		}
   	    }
  @@ -348,7 +346,9 @@
           list = elem.getChildNodes();
   
           for(int i = 0; i < list.getLength(); i++) {
  -            Element e = (Element) list.item(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();
  @@ -393,7 +393,9 @@
           Vector attributeVector = new Vector();
           NodeList list = elem.getChildNodes();
           for(int i = 0; i < list.getLength(); i++) {
  -            Element e = (Element) list.item(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();
  @@ -457,7 +459,7 @@
                                     Logger.WARNING
                                     );
               }
  -        
  +
           TagInfo taginfo = new TagInfo(name, tagclass, bodycontent,
                                         info, this, 
                                         tei,
  @@ -472,7 +474,9 @@
           
           NodeList list = elem.getChildNodes();
           for(int i = 0; i < list.getLength(); i++) {
  -            Element e = (Element) list.item(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();
  
  
  

Re: cvs commit: jakarta-tomcat/src/share/org/apache/jasper/compiler JspUtil.java TagLibraryInfoImpl.java

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
MANDAR RAJE wrote:

> "Craig R. McClanahan" wrote:
> >
> > mandar@locus.apache.org wrote:
> >
> > > mandar      00/05/18 17:39:06
> > >
> > >   Modified:    src/share/org/apache/jasper/compiler JspUtil.java
> > >                         TagLibraryInfoImpl.java
> > >   Log:
> > >   Using JAXP for parsing web.xml and *.tld.
> > >
> >
> > When I execute the simple custom tag example after this change, I get:
> >
> > org.apache.jasper.JapserException: Parse Error in the tag library descriptor: External entity not found:
> > "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd".
> >
> > (I'm making corresponding changes to XmlMapper so that the servlet container is also JAXP-compliant.  )
> >
> > Craig McClanahan
> >
>
> I added "web.dtd" to "src/share/org/apache/jasper/resources".
> Maybe that is missing in your workspace. If the parser can't
> find it, it will throw the ParseException.
>
> Mandar.
>

Hmm, it's there.  I'll try to do a little more digging.

Craig



Re: cvs commit: jakarta-tomcat/src/share/org/apache/jasper/compiler JspUtil.java TagLibraryInfoImpl.java

Posted by MANDAR RAJE <ma...@pathfinder.eng.sun.com>.
"Craig R. McClanahan" wrote:
> 
> mandar@locus.apache.org wrote:
> 
> > mandar      00/05/18 17:39:06
> >
> >   Modified:    src/share/org/apache/jasper/compiler JspUtil.java
> >                         TagLibraryInfoImpl.java
> >   Log:
> >   Using JAXP for parsing web.xml and *.tld.
> >
> 
> When I execute the simple custom tag example after this change, I get:
> 
> org.apache.jasper.JapserException: Parse Error in the tag library descriptor: External entity not found:
> "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd".
> 
> (I'm making corresponding changes to XmlMapper so that the servlet container is also JAXP-compliant.  )
> 
> Craig McClanahan
>

I added "web.dtd" to "src/share/org/apache/jasper/resources". 
Maybe that is missing in your workspace. If the parser can't 
find it, it will throw the ParseException.


Mandar.

Re: cvs commit: jakarta-tomcat/src/share/org/apache/jasper/compiler JspUtil.java TagLibraryInfoImpl.java

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
mandar@locus.apache.org wrote:

> mandar      00/05/18 17:39:06
>
>   Modified:    src/share/org/apache/jasper/compiler JspUtil.java
>                         TagLibraryInfoImpl.java
>   Log:
>   Using JAXP for parsing web.xml and *.tld.
>

When I execute the simple custom tag example after this change, I get:

org.apache.jasper.JapserException: Parse Error in the tag library descriptor: External entity not found:
"http://java.sun.com/j2ee/dtds/web-app_2.2.dtd".

(I'm making corresponding changes to XmlMapper so that the servlet container is also JAXP-compliant.  )

Craig McClanahan