changeset 23:33f17695e034

Fix possible null dtd in Swing applications 2010-10-26 Omair Majid <omajid@redhat.com> * netx/net/sourceforge/jnlp/Launcher.java (doPerApplicationAppContextHacks): New method. Create a new ParserDelegate to intialize the per AppContext dtd used by Swing HTML controls. (TgThread.run): Call doPerApplicationAppContextHacks. * netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java (initialize): Call doMainAppContextHacks. (doMainAppContextHacks): New method. Create a new ParserDelegate to initialize the per AppContext dtd used by Swing HTML controls.
author Omair Majid <omajid@redhat.com>
date Tue, 26 Oct 2010 18:14:11 -0400
parents a3941697dcdd
children 92c589a2cf8f
files ChangeLog netx/net/sourceforge/jnlp/Launcher.java netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java
diffstat 3 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Oct 26 18:00:35 2010 -0400
+++ b/ChangeLog	Tue Oct 26 18:14:11 2010 -0400
@@ -1,3 +1,14 @@
+2010-10-26  Omair Majid  <omajid@redhat.com>
+
+	* netx/net/sourceforge/jnlp/Launcher.java
+	(doPerApplicationAppContextHacks): New method. Create a new ParserDelegate
+	to intialize the per AppContext dtd used by Swing HTML controls.
+	(TgThread.run): Call doPerApplicationAppContextHacks.
+	* netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java
+	(initialize): Call doMainAppContextHacks.
+	(doMainAppContextHacks): New method. Create a new ParserDelegate to
+	initialize the per AppContext dtd used by Swing HTML controls.
+
 2010-10-26  Omair Majid  <omajid@redhat.com>
 
 	* netx/net/sourceforge/jnlp/Launcher.java
--- a/netx/net/sourceforge/jnlp/Launcher.java	Tue Oct 26 18:00:35 2010 -0400
+++ b/netx/net/sourceforge/jnlp/Launcher.java	Tue Oct 26 18:14:11 2010 -0400
@@ -50,6 +50,7 @@
 import net.sourceforge.jnlp.util.Reflect;
 
 import javax.swing.SwingUtilities;
+import javax.swing.text.html.parser.ParserDelegator;
 
 import sun.awt.SunToolkit;
 
@@ -779,6 +780,22 @@
         }
     }
 
+    /**
+     * Do hacks on per-application level to allow different AppContexts to work
+     *
+     * @see JNLPRuntime#doMainAppContextHacks
+     */
+    private static void doPerApplicationAppContextHacks() {
+
+        /*
+         * With OpenJDK6 (but not with 7) a per-AppContext dtd is maintained.
+         * This dtd is created by the ParserDelgate. However, the code in
+         * HTMLEditorKit (used to render HTML in labels and textpanes) creates
+         * the ParserDelegate only if there are no existing ParserDelegates. The
+         * result is that all other AppContexts see a null dtd.
+         */
+        new ParserDelegator();
+    }
 
     /**
      * This runnable is used to call the appropriate launch method
@@ -816,6 +833,8 @@
                 if (context && !isPlugin)
                         SunToolkit.createNewAppContext();
 
+                doPerApplicationAppContextHacks();
+
                 if (isPlugin) {
                         // Do not display download indicators if we're using gcjwebplugin.
                         JNLPRuntime.setDefaultDownloadIndicator(null);
--- a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java	Tue Oct 26 18:00:35 2010 -0400
+++ b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java	Tue Oct 26 18:14:11 2010 -0400
@@ -27,6 +27,7 @@
 import javax.jnlp.*;
 import javax.naming.ConfigurationException;
 import javax.swing.UIManager;
+import javax.swing.text.html.parser.ParserDelegator;
 
 import net.sourceforge.jnlp.*;
 import net.sourceforge.jnlp.cache.*;
@@ -232,6 +233,8 @@
             // ignore it
         }
 
+        doMainAppContextHacks();
+
         if (securityEnabled) {
             Policy.setPolicy(policy); // do first b/c our SM blocks setPolicy
             System.setSecurityManager(security);
@@ -261,6 +264,23 @@
     }
 
     /**
+     * Performs a few hacks that are needed for the main AppContext
+     *
+     * @see Launcher#doPerApplicationAppContextHacks
+     */
+    private static void doMainAppContextHacks() {
+
+        /*
+         * With OpenJDK6 (but not with 7) a per-AppContext dtd is maintained.
+         * This dtd is created by the ParserDelgate. However, the code in
+         * HTMLEditorKit (used to render HTML in labels and textpanes) creates
+         * the ParserDelegate only if there are no existing ParserDelegates. The
+         * result is that all other AppContexts see a null dtd.
+         */
+        new ParserDelegator();
+    }
+
+    /**
      * Gets the Configuration associated with this runtime
      * @return a {@link DeploymentConfiguration} object that can be queried to
      * find relevant configuration settings