View Javadoc
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  import sun.tools.jar.*;
35  
36  
37  /**
38   * Sample applet panel class. The panel manages and manipulates the
39   * applet as it is being loaded. It forks a seperate thread in a new
40   * thread group to call the applet's init(), start(), stop(), and
41   * destroy() methods.
42   *
43   * @author      Arthur van Hoff
44   */
45  class AppletViewerPanel extends AppletPanel {
46  
47      /* Are we debugging? */
48      static boolean debug = false;
49  
50      /**
51       * The document url.
52       */
53      URL documentURL;
54  
55      /**
56       * The base url.
57       */
58      URL baseURL;
59  
60      /**
61       * The attributes of the applet.
62       */
63      Hashtable atts;
64  
65      /*
66       * JDK 1.1 serialVersionUID
67       */
68      private static final long serialVersionUID = 8890989370785545619L;
69  
70      /**
71       * Construct an applet viewer and start the applet.
72       */
73      AppletViewerPanel(URL documentURL, Hashtable atts) {
74          this.documentURL = documentURL;
75          this.atts = atts;
76  
77          String att = getParameter("codebase");
78          if (att != null) {
79              if (!att.endsWith("/")) {
80                  att += "/";
81              }
82              try {
83                  baseURL = new URL(documentURL, att);
84              } catch (MalformedURLException e) {
85              }
86          }
87          if (baseURL == null) {
88              String file = documentURL.getFile();
89              int i = file.lastIndexOf('/');
90              if (i >= 0 && i < file.length() - 1) {
91                  try {
92                      baseURL = new URL(documentURL, file.substring(0, i + 1));
93                  } catch (MalformedURLException e) {
94                  }
95              }
96          }
97  
98          // when all is said & done, baseURL shouldn't be null
99          if (baseURL == null)
100                 baseURL = documentURL;
101 
102 
103     }
104 
105     /**
106      * Get an applet parameter.
107      */
108     public String getParameter(String name) {
109         return (String)atts.get(name.toLowerCase());
110     }
111 
112     /**
113      * Get the document url.
114      */
115     public URL getDocumentBase() {
116         return documentURL;
117 
118     }
119 
120     /**
121      * Get the base url.
122      */
123     public URL getCodeBase() {
124         return baseURL;
125     }
126 
127     /**
128      * Get the width.
129      */
130     public int getWidth() {
131         String w = getParameter("width");
132         if (w != null) {
133             return Integer.valueOf(w).intValue();
134         }
135         return 0;
136     }
137 
138 
139     /**
140      * Get the height.
141      */
142     public int getHeight() {
143         String h = getParameter("height");
144         if (h != null) {
145             return Integer.valueOf(h).intValue();
146         }
147         return 0;
148     }
149 
150     /**
151      * Get initial_focus
152      */
153     public boolean hasInitialFocus()
154     {
155 
156         // 6234219: Do not set initial focus on an applet
157         // during startup if applet is targeted for
158         // JDK 1.1/1.2. [stanley.ho]
159         if (isJDK11Applet() || isJDK12Applet())
160             return false;
161 
162         String initialFocus = getParameter("initial_focus");
163 
164         if (initialFocus != null)
165         {
166             if (initialFocus.toLowerCase().equals("false"))
167                 return false;
168         }
169 
170         return true;
171     }
172 
173     /**
174      * Get the code parameter
175      */
176     public String getCode() {
177         return getParameter("code");
178     }
179 
180 
181     /**
182      * Return the list of jar files if specified.
183      * Otherwise return null.
184      */
185     public String getJarFiles() {
186         return getParameter("archive");
187     }
188 
189     /**
190      * Return the value of the object param
191      */
192     public String getSerializedObject() {
193         return getParameter("object");// another name?
194     }
195 
196 
197     /**
198      * Get the applet context. For now this is
199      * also implemented by the AppletPanel class.
200      */
201     public AppletContext getAppletContext() {
202         return (AppletContext)getParent();
203     }
204 
205     static void debug(String s) {
206         if(debug)
207             System.err.println("AppletViewerPanel:::" + s);
208     }
209 
210     static void debug(String s, Throwable t) {
211         if(debug) {
212             t.printStackTrace();
213             debug(s);
214         }
215     }
216 }