src/share/classes/sun/applet/AppletViewer.java
Print this page
rev 10175 : 8042872: Fix raw and unchecked warnings in sun.applet
Reviewed-by:
*** 92,102 ****
*/
final class StdAppletViewerFactory implements AppletViewerFactory {
@Override
public AppletViewer createAppletViewer(int x, int y,
! URL doc, Hashtable atts) {
return new AppletViewer(x, y, doc, atts, System.out, this);
}
@Override
public MenuBar getBaseMenuBar() {
--- 92,102 ----
*/
final class StdAppletViewerFactory implements AppletViewerFactory {
@Override
public AppletViewer createAppletViewer(int x, int y,
! URL doc, Hashtable<String, String> atts) {
return new AppletViewer(x, y, doc, atts, System.out, this);
}
@Override
public MenuBar getBaseMenuBar() {
*** 154,164 ****
}
/**
* Create the applet viewer.
*/
! public AppletViewer(int x, int y, URL doc, Hashtable atts,
PrintStream statusMsgStream, AppletViewerFactory factory) {
this.factory = factory;
this.statusMsgStream = statusMsgStream;
setTitle(amh.getMessage("tool.title", atts.get("code")));
--- 154,164 ----
}
/**
* Create the applet viewer.
*/
! public AppletViewer(int x, int y, URL doc, Hashtable<String, String> atts,
PrintStream statusMsgStream, AppletViewerFactory factory) {
this.factory = factory;
this.statusMsgStream = statusMsgStream;
setTitle(amh.getMessage("tool.title", atts.get("code")));
*** 348,358 ****
* @return An array of strings. Each string in the array is determined
* by the location of the provided sep in the original string,
* s. Whitespace not stripped.
*/
private String [] splitSeparator(String sep, String s) {
! Vector v = new Vector();
int tokenStart = 0;
int tokenEnd = 0;
while ((tokenEnd = s.indexOf(sep, tokenStart)) != -1) {
v.addElement(s.substring(tokenStart, tokenEnd));
--- 348,358 ----
* @return An array of strings. Each string in the array is determined
* by the location of the provided sep in the original string,
* s. Whitespace not stripped.
*/
private String [] splitSeparator(String sep, String s) {
! Vector<String> v = new Vector<>();
int tokenStart = 0;
int tokenEnd = 0;
while ((tokenEnd = s.indexOf(sep, tokenStart)) != -1) {
v.addElement(s.substring(tokenStart, tokenEnd));
*** 368,395 ****
/*
* Methods for java.applet.AppletContext
*/
! private static Map audioClips = new HashMap();
/**
* Get an audio clip.
*/
@Override
public AudioClip getAudioClip(URL url) {
checkConnect(url);
synchronized (audioClips) {
! AudioClip clip = (AudioClip)audioClips.get(url);
if (clip == null) {
audioClips.put(url, clip = new AppletAudioClip(url));
}
return clip;
}
}
! private static Map imageRefs = new HashMap();
/**
* Get an image.
*/
@Override
--- 368,395 ----
/*
* Methods for java.applet.AppletContext
*/
! private static Map<URL, AudioClip> audioClips = new HashMap<>();
/**
* Get an audio clip.
*/
@Override
public AudioClip getAudioClip(URL url) {
checkConnect(url);
synchronized (audioClips) {
! AudioClip clip = audioClips.get(url);
if (clip == null) {
audioClips.put(url, clip = new AppletAudioClip(url));
}
return clip;
}
}
! private static Map<URL, AppletImageRef> imageRefs = new HashMap<>();
/**
* Get an image.
*/
@Override
*** 401,411 ****
* Get an image.
*/
static Image getCachedImage(URL url) {
// System.getSecurityManager().checkConnection(url.getHost(), url.getPort());
synchronized (imageRefs) {
! AppletImageRef ref = (AppletImageRef)imageRefs.get(url);
if (ref == null) {
ref = new AppletImageRef(url);
imageRefs.put(url, ref);
}
return ref.get();
--- 401,411 ----
* Get an image.
*/
static Image getCachedImage(URL url) {
// System.getSecurityManager().checkConnection(url.getHost(), url.getPort());
synchronized (imageRefs) {
! AppletImageRef ref = imageRefs.get(url);
if (ref == null) {
ref = new AppletImageRef(url);
imageRefs.put(url, ref);
}
return ref.get();
*** 417,439 ****
*/
static void flushImageCache() {
imageRefs.clear();
}
! static Vector appletPanels = new Vector();
/**
* Get an applet by name.
*/
@Override
public Applet getApplet(String name) {
AppletSecurity security = (AppletSecurity)System.getSecurityManager();
name = name.toLowerCase();
SocketPermission panelSp =
new SocketPermission(panel.getCodeBase().getHost(), "connect");
! for (Enumeration e = appletPanels.elements() ; e.hasMoreElements() ;) {
! AppletPanel p = (AppletPanel)e.nextElement();
String param = p.getParameter("name");
if (param != null) {
param = param.toLowerCase();
}
if (name.equals(param) &&
--- 417,439 ----
*/
static void flushImageCache() {
imageRefs.clear();
}
! static Vector<AppletPanel> appletPanels = new Vector<>();
/**
* Get an applet by name.
*/
@Override
public Applet getApplet(String name) {
AppletSecurity security = (AppletSecurity)System.getSecurityManager();
name = name.toLowerCase();
SocketPermission panelSp =
new SocketPermission(panel.getCodeBase().getHost(), "connect");
! for (Enumeration<AppletPanel> e = appletPanels.elements() ; e.hasMoreElements() ;) {
! AppletPanel p = e.nextElement();
String param = p.getParameter("name");
if (param != null) {
param = param.toLowerCase();
}
if (name.equals(param) &&
*** 453,470 ****
/**
* Return an enumeration of all the accessible
* applets on this page.
*/
@Override
! public Enumeration getApplets() {
AppletSecurity security = (AppletSecurity)System.getSecurityManager();
! Vector v = new Vector();
SocketPermission panelSp =
new SocketPermission(panel.getCodeBase().getHost(), "connect");
! for (Enumeration e = appletPanels.elements() ; e.hasMoreElements() ;) {
! AppletPanel p = (AppletPanel)e.nextElement();
if (p.getDocumentBase().equals(panel.getDocumentBase())) {
SocketPermission sp =
new SocketPermission(p.getCodeBase().getHost(), "connect");
if (panelSp.implies(sp)) {
--- 453,470 ----
/**
* Return an enumeration of all the accessible
* applets on this page.
*/
@Override
! public Enumeration<Applet> getApplets() {
AppletSecurity security = (AppletSecurity)System.getSecurityManager();
! Vector<Applet> v = new Vector<>();
SocketPermission panelSp =
new SocketPermission(panel.getCodeBase().getHost(), "connect");
! for (Enumeration<AppletPanel> e = appletPanels.elements() ; e.hasMoreElements() ;) {
! AppletPanel p = e.nextElement();
if (p.getDocumentBase().equals(panel.getDocumentBase())) {
SocketPermission sp =
new SocketPermission(p.getCodeBase().getHost(), "connect");
if (panelSp.implies(sp)) {
*** 507,525 ****
// We do nothing.
return null;
}
@Override
! public Iterator getStreamKeys(){
// We do nothing.
return null;
}
/**
* System parameters.
*/
! static Hashtable systemParam = new Hashtable();
static {
systemParam.put("codebase", "codebase");
systemParam.put("code", "code");
systemParam.put("alt", "alt");
--- 507,525 ----
// We do nothing.
return null;
}
@Override
! public Iterator<String> getStreamKeys(){
// We do nothing.
return null;
}
/**
* System parameters.
*/
! static Hashtable<String, String> systemParam = new Hashtable<>();
static {
systemParam.put("codebase", "codebase");
systemParam.put("code", "code");
systemParam.put("alt", "alt");
*** 531,577 ****
}
/**
* Print the HTML tag.
*/
! public static void printTag(PrintStream out, Hashtable atts) {
out.print("<applet");
! String v = (String)atts.get("codebase");
if (v != null) {
out.print(" codebase=\"" + v + "\"");
}
! v = (String)atts.get("code");
if (v == null) {
v = "applet.class";
}
out.print(" code=\"" + v + "\"");
! v = (String)atts.get("width");
if (v == null) {
v = "150";
}
out.print(" width=" + v);
! v = (String)atts.get("height");
if (v == null) {
v = "100";
}
out.print(" height=" + v);
! v = (String)atts.get("name");
if (v != null) {
out.print(" name=\"" + v + "\"");
}
out.println(">");
// A very slow sorting algorithm
int len = atts.size();
String params[] = new String[len];
len = 0;
! for (Enumeration e = atts.keys() ; e.hasMoreElements() ;) {
! String param = (String)e.nextElement();
int i = 0;
for (; i < len ; i++) {
if (params[i].compareTo(param) >= 0) {
break;
}
--- 531,577 ----
}
/**
* Print the HTML tag.
*/
! public static void printTag(PrintStream out, Hashtable<String, String> atts) {
out.print("<applet");
! String v = atts.get("codebase");
if (v != null) {
out.print(" codebase=\"" + v + "\"");
}
! v = atts.get("code");
if (v == null) {
v = "applet.class";
}
out.print(" code=\"" + v + "\"");
! v = atts.get("width");
if (v == null) {
v = "150";
}
out.print(" width=" + v);
! v = atts.get("height");
if (v == null) {
v = "100";
}
out.print(" height=" + v);
! v = atts.get("name");
if (v != null) {
out.print(" name=\"" + v + "\"");
}
out.println(">");
// A very slow sorting algorithm
int len = atts.size();
String params[] = new String[len];
len = 0;
! for (Enumeration<String> e = atts.keys() ; e.hasMoreElements() ;) {
! String param = e.nextElement();
int i = 0;
for (; i < len ; i++) {
if (params[i].compareTo(param) >= 0) {
break;
}
*** 647,657 ****
/**
* Save the applet to a well known file (for now) as a serialized object
*/
void appletSave() {
! AccessController.doPrivileged(new PrivilegedAction() {
@Override
public Object run() {
// XXX: this privileged block should be made smaller
// by initializing a private static variable with "user.dir"
--- 647,657 ----
/**
* Save the applet to a well known file (for now) as a serialized object
*/
void appletSave() {
! AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
// XXX: this privileged block should be made smaller
// by initializing a private static variable with "user.dir"
*** 700,711 ****
* Clone the viewer and the applet.
*/
void appletClone() {
Point p = location();
updateAtts();
factory.createAppletViewer(p.x + XDELTA, p.y + YDELTA,
! panel.documentURL, (Hashtable)panel.atts.clone());
}
/**
* Show the applet tag.
*/
--- 700,713 ----
* Clone the viewer and the applet.
*/
void appletClone() {
Point p = location();
updateAtts();
+ @SuppressWarnings("unchecked")
+ Hashtable<String, String> tmp = (Hashtable<String, String>) panel.atts.clone();
factory.createAppletViewer(p.x + XDELTA, p.y + YDELTA,
! panel.documentURL, tmp);
}
/**
* Show the applet tag.
*/
*** 882,893 ****
new Thread(new Runnable()
{
@Override
public void run()
{
! for (Enumeration e = appletPanels.elements() ; e.hasMoreElements() ;) {
! AppletPanel p = (AppletPanel)e.nextElement();
appletShutdown(p);
}
appletSystemExit();
}
}).start();
--- 884,895 ----
new Thread(new Runnable()
{
@Override
public void run()
{
! for (Enumeration<AppletPanel> e = appletPanels.elements() ; e.hasMoreElements() ;) {
! AppletPanel p = e.nextElement();
appletShutdown(p);
}
appletSystemExit();
}
}).start();
*** 1014,1025 ****
}
/**
* Scan tag
*/
! public static Hashtable scanTag(Reader in) throws IOException {
! Hashtable atts = new Hashtable();
skipSpace(in);
while (c >= 0 && c != '>') {
String att = scanIdentifier(in);
String val = "";
skipSpace(in);
--- 1016,1027 ----
}
/**
* Scan tag
*/
! public static Hashtable<String, String> scanTag(Reader in) throws IOException {
! Hashtable<String, String> atts = new Hashtable<>();
skipSpace(in);
while (c >= 0 && c != '>') {
String att = scanIdentifier(in);
String val = "";
skipSpace(in);
*** 1120,1130 ****
* sets it to whatever URL/codebase we ended up getting
*/
url = conn.getURL();
int ydisp = 1;
! Hashtable atts = null;
while(true) {
c = in.read();
if (c == -1)
break;
--- 1122,1132 ----
* sets it to whatever URL/codebase we ended up getting
*/
url = conn.getURL();
int ydisp = 1;
! Hashtable<String, String> atts = null;
while(true) {
c = in.read();
if (c == -1)
break;
*** 1170,1185 ****
}
}
else {
String nm = scanIdentifier(in);
if (nm.equalsIgnoreCase("param")) {
! Hashtable t = scanTag(in);
! String att = (String)t.get("name");
if (att == null) {
statusMsgStream.println(requiresNameWarning);
} else {
! String val = (String)t.get("value");
if (val == null) {
statusMsgStream.println(requiresNameWarning);
} else if (atts != null) {
atts.put(att.toLowerCase(), val);
} else {
--- 1172,1187 ----
}
}
else {
String nm = scanIdentifier(in);
if (nm.equalsIgnoreCase("param")) {
! Hashtable<String, String> t = scanTag(in);
! String att = t.get("name");
if (att == null) {
statusMsgStream.println(requiresNameWarning);
} else {
! String val = t.get("value");
if (val == null) {
statusMsgStream.println(requiresNameWarning);
} else if (atts != null) {
atts.put(att.toLowerCase(), val);
} else {
*** 1233,1249 ****
atts = null;
}
}
else if (nm.equalsIgnoreCase("app")) {
statusMsgStream.println(appNotLongerSupportedWarning);
! Hashtable atts2 = scanTag(in);
! nm = (String)atts2.get("class");
if (nm != null) {
atts2.remove("class");
atts2.put("code", nm + ".class");
}
! nm = (String)atts2.get("src");
if (nm != null) {
atts2.remove("src");
atts2.put("codebase", nm);
}
if (atts2.get("width") == null) {
--- 1235,1251 ----
atts = null;
}
}
else if (nm.equalsIgnoreCase("app")) {
statusMsgStream.println(appNotLongerSupportedWarning);
! Hashtable<String, String> atts2 = scanTag(in);
! nm = atts2.get("class");
if (nm != null) {
atts2.remove("class");
atts2.put("code", nm + ".class");
}
! nm = atts2.get("src");
if (nm != null) {
atts2.remove("src");
atts2.put("codebase", nm);
}
if (atts2.get("width") == null) {