1 /*
   2  * Copyright (c) 1995, 2005, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.applet;
  27 
  28 import java.util.*;
  29 import java.io.*;
  30 import java.net.URL;
  31 import java.net.MalformedURLException;
  32 import java.awt.*;
  33 import java.applet.*;
  34 
  35 
  36 /**
  37  * Sample applet panel class. The panel manages and manipulates the
  38  * applet as it is being loaded. It forks a seperate thread in a new
  39  * thread group to call the applet's init(), start(), stop(), and
  40  * destroy() methods.
  41  *
  42  * @author      Arthur van Hoff
  43  *
  44  * @deprecated The Applet API is deprecated. See the
  45  * <a href="../../java/applet/package-summary.html"> java.applet package
  46  * documentation</a> for further information.
  47  */
  48 @Deprecated(since = "9")
  49 class AppletViewerPanel extends AppletPanel {
  50 
  51     /* Are we debugging? */
  52     static boolean debug = false;
  53 
  54     /**
  55      * The document url.
  56      */
  57     URL documentURL;
  58 
  59     /**
  60      * The base url.
  61      */
  62     URL baseURL;
  63 
  64     /**
  65      * The attributes of the applet.
  66      */
  67     Hashtable<String, String> atts;
  68 
  69     /*
  70      * JDK 1.1 serialVersionUID
  71      */
  72     private static final long serialVersionUID = 8890989370785545619L;
  73 
  74     /**
  75      * Construct an applet viewer and start the applet.
  76      */
  77     AppletViewerPanel(URL documentURL, Hashtable<String, String> atts) {
  78         this.documentURL = documentURL;
  79         this.atts = atts;
  80 
  81         String att = getParameter("codebase");
  82         if (att != null) {
  83             if (!att.endsWith("/")) {
  84                 att += "/";
  85             }
  86             try {
  87                 baseURL = new URL(documentURL, att);
  88             } catch (MalformedURLException e) {
  89             }
  90         }
  91         if (baseURL == null) {
  92             String file = documentURL.getFile();
  93             int i = file.lastIndexOf('/');
  94             if (i >= 0 && i < file.length() - 1) {
  95                 try {
  96                     baseURL = new URL(documentURL, file.substring(0, i + 1));
  97                 } catch (MalformedURLException e) {
  98                 }
  99             }
 100         }
 101 
 102         // when all is said & done, baseURL shouldn't be null
 103         if (baseURL == null)
 104                 baseURL = documentURL;
 105 
 106 
 107     }
 108 
 109     /**
 110      * Get an applet parameter.
 111      */
 112     public String getParameter(String name) {
 113         return atts.get(name.toLowerCase());
 114     }
 115 
 116     /**
 117      * Get the document url.
 118      */
 119     public URL getDocumentBase() {
 120         return documentURL;
 121 
 122     }
 123 
 124     /**
 125      * Get the base url.
 126      */
 127     public URL getCodeBase() {
 128         return baseURL;
 129     }
 130 
 131     /**
 132      * Get the width.
 133      */
 134     public int getWidth() {
 135         String w = getParameter("width");
 136         if (w != null) {
 137             return Integer.valueOf(w).intValue();
 138         }
 139         return 0;
 140     }
 141 
 142 
 143     /**
 144      * Get the height.
 145      */
 146     public int getHeight() {
 147         String h = getParameter("height");
 148         if (h != null) {
 149             return Integer.valueOf(h).intValue();
 150         }
 151         return 0;
 152     }
 153 
 154     /**
 155      * Get initial_focus
 156      */
 157     public boolean hasInitialFocus()
 158     {
 159 
 160         // 6234219: Do not set initial focus on an applet
 161         // during startup if applet is targeted for
 162         // JDK 1.1/1.2. [stanley.ho]
 163         if (isJDK11Applet() || isJDK12Applet())
 164             return false;
 165 
 166         String initialFocus = getParameter("initial_focus");
 167 
 168         if (initialFocus != null)
 169         {
 170             if (initialFocus.toLowerCase().equals("false"))
 171                 return false;
 172         }
 173 
 174         return true;
 175     }
 176 
 177     /**
 178      * Get the code parameter
 179      */
 180     public String getCode() {
 181         return getParameter("code");
 182     }
 183 
 184 
 185     /**
 186      * Return the list of jar files if specified.
 187      * Otherwise return null.
 188      */
 189     public String getJarFiles() {
 190         return getParameter("archive");
 191     }
 192 
 193     /**
 194      * Return the value of the object param
 195      */
 196     public String getSerializedObject() {
 197         return getParameter("object");// another name?
 198     }
 199 
 200 
 201     /**
 202      * Get the applet context. For now this is
 203      * also implemented by the AppletPanel class.
 204      */
 205     @SuppressWarnings("deprecation")
 206     public AppletContext getAppletContext() {
 207         return (AppletContext)getParent();
 208     }
 209 
 210     static void debug(String s) {
 211         if(debug)
 212             System.err.println("AppletViewerPanel:::" + s);
 213     }
 214 
 215     static void debug(String s, Throwable t) {
 216         if(debug) {
 217             t.printStackTrace();
 218             debug(s);
 219         }
 220     }
 221 }