diff options
author | Adam Domurad <[email protected]> | 2012-12-04 10:43:59 -0500 |
---|---|---|
committer | Adam Domurad <[email protected]> | 2012-12-04 10:43:59 -0500 |
commit | 1f595aba1e38b1a0113f45492288e22d3fa90799 (patch) | |
tree | 422a8d29652e3084915801fdc960c1c3099ae2a4 /netx/net | |
parent | 7aff0a246448bef22d89859b07fef92c128e14e5 (diff) |
Remove redundant HTML-tag scanner from ITW. Do not reconstruct tags.
Diffstat (limited to 'netx/net')
-rw-r--r-- | netx/net/sourceforge/jnlp/NetxPanel.java | 57 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/PluginBridge.java | 64 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/PluginParameterException.java | 43 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/PluginParameters.java | 238 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/resources/Messages.properties | 1 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/resources/Messages_cs_CZ.properties | 1 |
6 files changed, 323 insertions, 81 deletions
diff --git a/netx/net/sourceforge/jnlp/NetxPanel.java b/netx/net/sourceforge/jnlp/NetxPanel.java index ce20d5c..1afa416 100644 --- a/netx/net/sourceforge/jnlp/NetxPanel.java +++ b/netx/net/sourceforge/jnlp/NetxPanel.java @@ -27,7 +27,6 @@ import net.sourceforge.jnlp.runtime.JNLPRuntime; import java.net.URL; import java.util.HashMap; -import java.util.Hashtable; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -45,12 +44,12 @@ import sun.awt.SunToolkit; * @author Francis Kung <[email protected]> */ public class NetxPanel extends AppletViewerPanel implements SplashController { + private final PluginParameters parameters; private PluginBridge bridge = null; private boolean exitOnFailure = true; private AppletInstance appInst = null; private SplashController splashController; private boolean appletAlive; - private final String uKey; // We use this so that we can create exactly one thread group // for all panels with the same uKey. @@ -68,51 +67,24 @@ public class NetxPanel extends AppletViewerPanel implements SplashController { private static final ConcurrentMap<String, Boolean> appContextCreated = new ConcurrentHashMap<String, Boolean>(); - public NetxPanel(URL documentURL, Hashtable<String, String> atts) { - super(documentURL, atts); + public NetxPanel(URL documentURL, PluginParameters params) { + super(documentURL, params.getUnderlyingHashtable()); - /* According to http://download.oracle.com/javase/6/docs/technotes/guides/deployment/deployment-guide/applet-compatibility.html, - * classloaders are shared iff these properties match: - * codebase, cache_archive, java_archive, archive - * - * To achieve this, we create the uniquekey based on those 4 values, - * always in the same order. The initial "<NAME>=" parts ensure a - * bad tag cannot trick the loader into getting shared with another. - */ - - // Firefox sometimes skips the codebase if it is default -- ".", - // so set it that way if absent - String codebaseAttr = atts.get("codebase") != null ? - atts.get("codebase") : "."; - - String cache_archiveAttr = atts.get("cache_archive") != null ? - atts.get("cache_archive") : ""; - - String java_archiveAttr = atts.get("java_archive") != null ? - atts.get("java_archive") : ""; + this.parameters = params; - String archiveAttr = atts.get("archive") != null ? - atts.get("archive") : ""; - - this.uKey = "codebase=" + codebaseAttr + - "cache_archive=" + cache_archiveAttr + - "java_archive=" + java_archiveAttr + - "archive=" + archiveAttr; - - // when this was being done (incorrectly) in Launcher, the call was - // new AppThreadGroup(mainGroup, file.getTitle()); + String uniqueKey = params.getUniqueKey(); synchronized(TGMapMutex) { - if (!uKeyToTG.containsKey(this.uKey)) { + if (!uKeyToTG.containsKey(uniqueKey)) { ThreadGroup tg = new ThreadGroup(Launcher.mainGroup, this.documentURL.toString()); - uKeyToTG.put(this.uKey, tg); + uKeyToTG.put(uniqueKey, tg); } } } // overloaded constructor, called when initialized via plugin - public NetxPanel(URL documentURL, Hashtable<String, String> atts, + public NetxPanel(URL documentURL, PluginParameters params, boolean exitOnFailure) { - this(documentURL, atts); + this(documentURL, params); this.exitOnFailure = exitOnFailure; this.appletAlive = true; } @@ -129,6 +101,7 @@ public class NetxPanel extends AppletViewerPanel implements SplashController { //Overriding to use Netx classloader. You might need to relax visibility //in sun.applet.AppletPanel for runLoader(). + @Override protected void runLoader() { try { @@ -138,7 +111,7 @@ public class NetxPanel extends AppletViewerPanel implements SplashController { getCode(), getWidth(), getHeight(), - atts, uKey); + parameters); doInit = true; dispatchAppletEvent(APPLET_LOADING, null); @@ -188,6 +161,7 @@ public class NetxPanel extends AppletViewerPanel implements SplashController { * the applet */ // Reminder: Relax visibility in sun.applet.AppletPanel + @Override protected synchronized void createAppletThread() { // initialize JNLPRuntime in the main threadgroup synchronized (JNLPRuntime.initMutex) { @@ -208,8 +182,7 @@ public class NetxPanel extends AppletViewerPanel implements SplashController { } public void updateSizeInAtts(int height, int width) { - this.atts.put("height", Integer.toString(height)); - this.atts.put("width", Integer.toString(width)); + parameters.updateSize(width, height); } public ClassLoader getAppletClassLoader() { @@ -222,7 +195,7 @@ public class NetxPanel extends AppletViewerPanel implements SplashController { public ThreadGroup getThreadGroup() { synchronized(TGMapMutex) { - return uKeyToTG.get(uKey); + return uKeyToTG.get(parameters.getUniqueKey()); } } @@ -232,7 +205,7 @@ public class NetxPanel extends AppletViewerPanel implements SplashController { } // only create a new context if one hasn't already been created for the // applets with this unique key. - if (null == appContextCreated.putIfAbsent(uKey, Boolean.TRUE)) { + if (null == appContextCreated.putIfAbsent(parameters.getUniqueKey(), Boolean.TRUE)) { SunToolkit.createNewAppContext(); } } diff --git a/netx/net/sourceforge/jnlp/PluginBridge.java b/netx/net/sourceforge/jnlp/PluginBridge.java index 37b72e6..1e34c49 100644 --- a/netx/net/sourceforge/jnlp/PluginBridge.java +++ b/netx/net/sourceforge/jnlp/PluginBridge.java @@ -45,26 +45,23 @@ import net.sourceforge.jnlp.runtime.JNLPRuntime; */ public class PluginBridge extends JNLPFile { - private String name; + private PluginParameters params; private Set<String> jars = new HashSet<String>(); //Folders can be added to the code-base through the archive tag private List<String> codeBaseFolders = new ArrayList<String>(); private String[] cacheJars = new String[0]; private String[] cacheExJars = new String[0]; - private Map<String, String> atts; private boolean usePack; private boolean useVersion; - private boolean codeBaseLookup; private boolean useJNLPHref; /** * Creates a new PluginBridge using a default JNLPCreator. */ public PluginBridge(URL codebase, URL documentBase, String jar, String main, - int width, int height, Map<String, String> atts, - String uKey) + int width, int height, PluginParameters params) throws Exception { - this(codebase, documentBase, jar, main, width, height, atts, uKey, new JNLPCreator()); + this(codebase, documentBase, jar, main, width, height, params, new JNLPCreator()); } /** @@ -86,25 +83,24 @@ public class PluginBridge extends JNLPFile { } public PluginBridge(URL codebase, URL documentBase, String archive, String main, - int width, int height, Map<String, String> atts, - String uKey, JNLPCreator jnlpCreator) + int width, int height, PluginParameters params, JNLPCreator jnlpCreator) throws Exception { specVersion = new Version("1.0"); fileVersion = new Version("1.1"); this.codeBase = codebase; this.sourceLocation = documentBase; - this.atts = atts; + this.params = params; - if (atts.containsKey("jnlp_href")) { + if (params.getJNLPHref() != null) { useJNLPHref = true; try { // Use codeBase as the context for the URL. If jnlp_href's // value is a complete URL, it will replace codeBase's context. - URL jnlp = new URL(codeBase, atts.get("jnlp_href")); + URL jnlp = new URL(codeBase, params.getJNLPHref()); JNLPFile jnlpFile = null; - if (atts.containsKey("jnlp_embedded")) { - InputStream jnlpInputStream = new ByteArrayInputStream(decodeBase64String(atts.get("jnlp_embedded"))); + if (params.getJNLPEmbedded() != null) { + InputStream jnlpInputStream = new ByteArrayInputStream(decodeBase64String(params.getJNLPEmbedded())); jnlpFile = new JNLPFile(jnlpInputStream, codeBase, false); } else { jnlpFile = jnlpCreator.create(jnlp, null, false, JNLPRuntime.getDefaultUpdatePolicy(), codeBase); @@ -118,7 +114,7 @@ public class PluginBridge extends JNLPFile { // Change the parameter name to lowercase to follow conventions. for (Map.Entry<String, String> entry : jnlpParams.entrySet()) { - this.atts.put(entry.getKey().toLowerCase(), entry.getValue()); + this.params.put(entry.getKey().toLowerCase(), entry.getValue()); } JARDesc[] jarDescs = jnlpFile.getResources().getJARs(); for (JARDesc jarDesc : jarDescs) { @@ -128,7 +124,7 @@ public class PluginBridge extends JNLPFile { } catch (MalformedURLException e) { // Don't fail because we cannot get the jnlp file. Parameters are optional not required. // it is the site developer who should ensure that file exist. - System.err.println("Unable to get JNLP file at: " + atts.get("jnlp_href") + System.err.println("Unable to get JNLP file at: " + params.getJNLPHref() + " with context of URL as: " + codeBase.toExternalForm()); } } else { @@ -138,14 +134,14 @@ public class PluginBridge extends JNLPFile { } // also, see if cache_archive is specified - String cacheArchive = atts.get("cache_archive"); - if (cacheArchive != null && cacheArchive.length() > 0) { + String cacheArchive = params.getCacheArchive(); + if (!cacheArchive.isEmpty()) { String[] versions = new String[0]; // are there accompanying versions? - String cacheVersion = atts.get("cache_version"); - if (cacheVersion != null) { + String cacheVersion = params.getCacheVersion(); + if (!cacheVersion.isEmpty()) { versions = cacheVersion.split(","); } @@ -162,8 +158,8 @@ public class PluginBridge extends JNLPFile { } } - String cacheArchiveEx = atts.get("cache_archive_ex"); - if (cacheArchiveEx != null && cacheArchiveEx.length() > 0) { + String cacheArchiveEx = params.getCacheArchiveEx(); + if (!cacheArchiveEx.isEmpty()) { cacheExJars = cacheArchiveEx.split(","); } @@ -178,19 +174,13 @@ public class PluginBridge extends JNLPFile { } } - name = atts.get("name"); - if (name == null) - name = "Applet"; - else - name = name + " applet"; - if (main.endsWith(".class")) main = main.substring(0, main.length() - 6); // the class name should be of the form foo.bar.Baz not foo/bar/Baz String mainClass = main.replace('/', '.'); - launchType = new AppletDesc(name, mainClass, documentBase, width, - height, atts); + launchType = new AppletDesc(params.getAppletTitle(), mainClass, documentBase, width, + height, params.getUnmodifiableMap()); if (main.endsWith(".class")) //single class file only security = new SecurityDesc(this, SecurityDesc.SANDBOX_PERMISSIONS, @@ -198,11 +188,11 @@ public class PluginBridge extends JNLPFile { else security = null; - this.uniqueKey = uKey; + this.uniqueKey = params.getUniqueKey(); usePack = false; useVersion = false; - String jargs = atts.get("java_arguments"); - if (jargs != null) { + String jargs = params.getJavaArguments(); + if (!jargs.isEmpty()) { for (String s : jargs.split(" ")) { String[] parts = s.trim().split("="); if (parts.length == 2 && Boolean.valueOf(parts[1])) { @@ -214,12 +204,10 @@ public class PluginBridge extends JNLPFile { } } } - String cbl = atts.get("codebase_lookup"); - codeBaseLookup = cbl == null || (Boolean.valueOf(cbl)); } public boolean codeBaseLookup() { - return codeBaseLookup; + return params.useCodebaseLookup(); } public boolean useJNLPHref() { @@ -235,7 +223,7 @@ public class PluginBridge extends JNLPFile { } public String getTitle() { - return name; + return params.getAppletTitle(); } public ResourcesDesc getResources(final Locale locale, final String os, @@ -258,9 +246,7 @@ public class PluginBridge extends JNLPFile { } boolean cacheable = true; - - String cacheOption = atts.get("cache_option"); - if (cacheOption != null && cacheOption.equalsIgnoreCase("no")) + if (params.getCacheOption().equalsIgnoreCase("no")) cacheable = false; for (String cacheJar : cacheJars) { diff --git a/netx/net/sourceforge/jnlp/PluginParameterException.java b/netx/net/sourceforge/jnlp/PluginParameterException.java new file mode 100644 index 0000000..b1e1e9d --- /dev/null +++ b/netx/net/sourceforge/jnlp/PluginParameterException.java @@ -0,0 +1,43 @@ +/* Copyright (C) 2012 Red Hat + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package net.sourceforge.jnlp; + +public class PluginParameterException extends RuntimeException { + public PluginParameterException(String detail) { + super(detail); + } +} diff --git a/netx/net/sourceforge/jnlp/PluginParameters.java b/netx/net/sourceforge/jnlp/PluginParameters.java new file mode 100644 index 0000000..6f0152e --- /dev/null +++ b/netx/net/sourceforge/jnlp/PluginParameters.java @@ -0,0 +1,238 @@ +/* PluginAppletAttributes -- Provides parsing for applet attributes + Copyright (C) 2012 Red Hat + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package net.sourceforge.jnlp; + +import java.util.Collections; +import java.util.Hashtable; +import java.util.Map; + +import static net.sourceforge.jnlp.runtime.Translator.R; + +/** + * Represents plugin applet parameters, backed by a Hashtable. + */ + +public class PluginParameters { + private final Hashtable<String, String> parameters; + + public PluginParameters(Map<String, String> params) { + this.parameters = createParameterTable(params); + + if (this.parameters.get("code") == null + && this.parameters.get("object") == null) { + throw new PluginParameterException(R("BNoCodeOrObjectApplet")); + } + } + + // Note, lower-case key expected + public String get(String key) { + return this.parameters.get(key); + } + + public void put(String key, String value) { + parameters.put(key.toLowerCase(), value); + } + + public Map<String, String> getUnmodifiableMap() { + return Collections.unmodifiableMap(parameters); + } + + /** + * Used for compatibility with Hashtable-expecting classes. + * + * @return the underlying hashtable. + */ + Hashtable<String, String> getUnderlyingHashtable() { + return parameters; + } + + public String getDefaulted(String key, String defaultStr) { + String value = get(key); + return (value != null) ? value : defaultStr; + } + + public String getAppletTitle() { + String name = get("name"); + if (name == null) { + return "Applet"; + } else { + return name + " applet"; + } + } + + public String getCodebase() { + return getDefaulted("codebase", "."); + } + + public boolean useCodebaseLookup() { + return Boolean.valueOf(getDefaulted("codebase_lookup", "true")); + } + + public String getArchive() { + return getDefaulted("archive", ""); + } + + public String getJavaArchive() { + return getDefaulted("java_archive", ""); + } + + public String getJavaArguments() { + return getDefaulted("java_arguments", ""); + } + + public String getCacheArchive() { + return getDefaulted("cache_archive", ""); + } + + public String getCacheArchiveEx() { + return getDefaulted("cache_archive_ex", ""); + } + + public String getCacheOption() { + return getDefaulted("cache_option", ""); + } + + public String getCacheVersion() { + return getDefaulted("cache_version", ""); + } + + public String getCode() { + return getDefaulted("code", ""); + } + + public String getJNLPHref() { + return get("jnlp_href"); + } + + public String getJNLPEmbedded() { + return get("jnlp_embedded"); + } + + public String getJarFiles() { + return getDefaulted("archive", ""); + } + + public int getWidth() { + String widthStr = getDefaulted("width", "0"); + return Integer.valueOf(widthStr); + } + + public int getHeight() { + String heightStr = getDefaulted("height", "0"); + return Integer.valueOf(heightStr); + } + + public void updateSize(int width, int height) { + parameters.put("width", Integer.toString(width)); + parameters.put("height", Integer.toString(height)); + } + + public String getUniqueKey() { + /* According to http://download.oracle.com/javase/6/docs/technotes/guides/deployment/deployment-guide/applet-compatibility.html, + * classloaders are shared iff these properties match: + * codebase, cache_archive, java_archive, archive + * + * To achieve this, we create the uniquekey based on those 4 values, + * always in the same order. The initial "<NAME>=" parts ensure a + * bad tag cannot trick the loader into getting shared with another. + */ + return "codebase=" + getCodebase() + "cache_archive=" + getCacheArchive() + + "java_archive=" + getJavaArchive() + "archive=" + getArchive(); + } + + /** + * Replace an attribute with its 'java_'-prefixed version. + * Note that java_* aliases override older names: + * http://java.sun.com/j2se/1.4.2/docs/guide/plugin/developer_guide/using_tags.html#in-nav + */ + static void ensureJavaPrefixTakesPrecedence(Map<String, String> params, + String attribute) { + String javaPrefixAttribute = params.get("java_" + attribute); + if (javaPrefixAttribute != null) { + params.put(attribute, javaPrefixAttribute); + } + } + + /** + * Creates the underlying hash table with the proper overrides. Ensure all + * keys are lowercase consistently. + * + * @param params + * the properties, before parameter aliasing rules. + * @return the resulting parameter table + */ + static Hashtable<String, String> createParameterTable( + Map<String, String> rawParams) { + Hashtable<String, String> params = new Hashtable<String, String>(); + + for (Map.Entry<String, String> entry : rawParams.entrySet()) { + String key = entry.getKey().toLowerCase(); + String value = entry.getValue(); + params.put(key, value); + } + + String codeTag = params.get("code"); + String classID = params.get("classid"); + + // If there is a classid and no code tag present, transform it to code tag + if (codeTag == null && classID != null && !classID.startsWith("clsid:")) { + codeTag = classID; + params.put("code", codeTag); + } + + // remove java: from code tag + if (codeTag != null && codeTag.startsWith("java:")) { + codeTag = codeTag.substring("java:".length()); + params.put("code", codeTag); + } + + // java_* aliases override older names: + // http://java.sun.com/j2se/1.4.2/docs/guide/plugin/developer_guide/using_tags.html#in-nav + ensureJavaPrefixTakesPrecedence(params, "code"); + ensureJavaPrefixTakesPrecedence(params, "codebase"); + ensureJavaPrefixTakesPrecedence(params, "archive"); + ensureJavaPrefixTakesPrecedence(params, "object"); + ensureJavaPrefixTakesPrecedence(params, "type"); + + return params; + } + + public String toString() { + return parameters.toString(); + } +}
\ No newline at end of file diff --git a/netx/net/sourceforge/jnlp/resources/Messages.properties b/netx/net/sourceforge/jnlp/resources/Messages.properties index e74cf36..ed34397 100644 --- a/netx/net/sourceforge/jnlp/resources/Messages.properties +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties @@ -141,6 +141,7 @@ BFileLoc=JNLP file location BBadProp=Incorrect property format {0} (should be key=value)
BBadParam=Incorrect parameter format {0} (should be name=value)
BNoDir=Directory {0} does not exist.
+BNoCodeOrObjectApplet=Applet tag must specify a 'code' or 'object' attribute.
RNoResource=Missing Resource: {0}
RShutdown=This exception to prevent shutdown of JVM, but the process has been terminated.
RExitTaken=Exit class already set and caller is not exit class.
diff --git a/netx/net/sourceforge/jnlp/resources/Messages_cs_CZ.properties b/netx/net/sourceforge/jnlp/resources/Messages_cs_CZ.properties index 3fcbfbb..9663e19 100644 --- a/netx/net/sourceforge/jnlp/resources/Messages_cs_CZ.properties +++ b/netx/net/sourceforge/jnlp/resources/Messages_cs_CZ.properties @@ -139,6 +139,7 @@ BFileLoc=Um\u00edst\u011bn\u00ed souboru JNLP BBadProp=Neplatn\u00fd form\u00e1t vlastnosti {0} (platn\u00fd form\u00e1t: kl\u00ed\u010d=hodnota) BBadParam=Neplatn\u00fd form\u00e1t parametru {0} (platn\u00fd form\u00e1t: n\u00e1zev=hodnota) BNoDir=Adres\u00e1\u0159 {0} neexistuje. +BNoCodeOrObjectApplet=Zna\u010dka applet mus\u00ed m\u00edt defnov\u00e1n k\u00f3d nebo objekt - atributy 'code' nebo 'object' chyb\u00ed. RNoResource=Chyb\u011bj\u00edc\u00ed zdroj: {0} RShutdown=Tato v\u00fdjimka zabra\u0148uje ukon\u010den\u00ed prost\u0159ed\u00ed JVM, av\u0161ak proces byl ukon\u010den. RExitTaken=T\u0159\u00edda exit class m\u016f\u017ee b\u00fdt nastavena pouze jednou a pouze ta pak m\u016f\u017ee ukon\u010dit prost\u0159ed\u00ed JVM. |