You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2008/01/23 22:33:50 UTC

svn commit: r614687 - /myfaces/trinidad-maven/branches/1.2.6.1-branch/maven-jdev-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/jdeveloper/TldContentHandler.java

Author: matzew
Date: Wed Jan 23 13:33:49 2008
New Revision: 614687

URL: http://svn.apache.org/viewvc?rev=614687&view=rev
Log:
TRINIDAD-919

Modified:
    myfaces/trinidad-maven/branches/1.2.6.1-branch/maven-jdev-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/jdeveloper/TldContentHandler.java

Modified: myfaces/trinidad-maven/branches/1.2.6.1-branch/maven-jdev-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/jdeveloper/TldContentHandler.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad-maven/branches/1.2.6.1-branch/maven-jdev-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/jdeveloper/TldContentHandler.java?rev=614687&r1=614686&r2=614687&view=diff
==============================================================================
--- myfaces/trinidad-maven/branches/1.2.6.1-branch/maven-jdev-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/jdeveloper/TldContentHandler.java (original)
+++ myfaces/trinidad-maven/branches/1.2.6.1-branch/maven-jdev-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/jdeveloper/TldContentHandler.java Wed Jan 23 13:33:49 2008
@@ -6,9 +6,9 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -18,9 +18,11 @@
  */
 package org.apache.myfaces.trinidadbuild.plugin.jdeveloper;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
 
+import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
@@ -30,6 +32,8 @@
 
 import org.w3c.dom.NodeList;
 
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
 public class TldContentHandler
@@ -40,9 +44,9 @@
   public TldContentHandler()
   {
   }
-  
+
   /**
-    * Parse the .tld file to get the information 
+    * Parse the .tld file to get the information
     * needed for the .jpr
     */
   public void parseTld(File file)
@@ -53,9 +57,15 @@
     // Create a builder factory
     DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     factory.setValidating(false);
-    
+
     // Create the Builder and parse the file
-    Document document = factory.newDocumentBuilder().parse(file);
+    DocumentBuilder docBuilder = factory.newDocumentBuilder();
+    
+    // Set Entity Resolver to resolve external entities, i.e.
+    // the "http://...." in the <!DOCTYPE tag
+    EntityResolver entityResolver = new PluginEntityResolver();
+    docBuilder.setEntityResolver(entityResolver);
+    Document document = docBuilder.parse(file);
     
     _processTldNodes(document);
   }
@@ -118,13 +128,13 @@
   /**
     * Find all the TLD nodes we want, get each node's value
     * and set the value on the proper class property.
-    * 
+    *
     * @param document  - DOM Document from the TLD file
-    */  
+    */
   private void _processTldNodes(Document document)
   {
     Node node = null;
-    
+
     // Get the Nodes first node.  We can be specific here
     // because we know we want the first node.
     NodeList nodeList = document.getElementsByTagName(_TLIB_VERSION);
@@ -168,20 +178,56 @@
       setURI(node.getFirstChild().getNodeValue());
     }
   }
-  
+
   //========================================================================
   // Private variables
   //========================================================================
-  
+
   private String _version    = null; // tlib-version
   private String _name       = null; // display-name
   private String _prefix     = null; // short-name
   private String _jspVersion = null; // jsp-version
   private String _uri        = null; // uri
- 
+
   private final static String _TLIB_VERSION = "tlib-version"; //version NOTRANS
   private final static String _DISPLAY_NAME = "display-name"; //name NOTRANS
   private final static String _SHORT_NAME   = "short-name";   //prefix NOTRANS
   private final static String _JSP_VERSION  = "jsp-version";   //NOTRANS
   private final static String _URI          = "uri";
+  
+
+  /**
+   * Gary Kind 01/22/2008. This class is used solely to get around a 
+   * java.net.NoRouteToHostException that occurs in the tag libs 
+   * <!DOCTYPE... tag, which is:
+   * 
+   * <!DOCTYPE taglib
+   * PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
+   * "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
+   * 
+   * The http URL causes this exception for some unknown reason. I have
+   * searched high and low on the web for a real solution and finally found
+   * this workaround at 
+   * http://forum.java.sun.com/thread.jspa?threadID=284209&forumID=34
+   * Apparently a LOT of developers are seeing similar problems and they too
+   * are not able to find a solution. This workaround works perfectly and all
+   * is well.
+   */
+  private class PluginEntityResolver
+    implements EntityResolver
+  {
+    public InputSource resolveEntity(String publicId, String systemId)
+    {
+      if ("-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN".equals(publicId))
+      {
+        String xmlStr = "<?xml version='1.0' encoding='UTF-8'?>";
+        byte[] buf = xmlStr.getBytes();
+        ByteArrayInputStream bais = new ByteArrayInputStream(buf);
+        return new InputSource(bais);
+      }
+      else 
+        return null;
+    }
+  }
+
 } // endclass TldContentHandler