16 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
17 |
along with gcjappletviewer; if not, write to the Free Software |
along with gcjappletviewer; if not, write to the Free Software |
18 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
|
|
20 |
|
Linking this library statically or dynamically with other modules is |
21 |
|
making a combined work based on this library. Thus, the terms and |
22 |
|
conditions of the GNU General Public License cover the whole |
23 |
|
combination. |
24 |
|
|
25 |
|
As a special exception, the copyright holders of this library give you |
26 |
|
permission to link this library with independent modules to produce an |
27 |
|
executable, regardless of the license terms of these independent |
28 |
|
modules, and to copy and distribute the resulting executable under |
29 |
|
terms of your choice, provided that you also meet, for each linked |
30 |
|
independent module, the terms and conditions of the license of that |
31 |
|
module. An independent module is a module which is not derived from |
32 |
|
or based on this library. If you modify this library, you may extend |
33 |
|
this exception to your version of the library, but you are not |
34 |
|
obligated to do so. If you do not wish to do so, delete this |
35 |
|
exception statement from your version. |
36 |
*/ |
*/ |
37 |
|
|
38 |
|
|
39 |
package gnu.gcjwebplugin; |
package gnu.gcjwebplugin; |
40 |
|
|
41 |
import java.awt.Dimension; |
import java.awt.Dimension; |
49 |
import java.net.URLConnection; |
import java.net.URLConnection; |
50 |
import java.net.MalformedURLException; |
import java.net.MalformedURLException; |
51 |
import java.util.ArrayList; |
import java.util.ArrayList; |
52 |
|
import java.util.Map; |
53 |
import java.util.HashMap; |
import java.util.HashMap; |
54 |
import java.util.List; |
import java.util.List; |
55 |
|
|
60 |
String codebase; |
String codebase; |
61 |
URL[] archives; |
URL[] archives; |
62 |
HashMap parameters; |
HashMap parameters; |
63 |
Dimension dimensions = new Dimension (0, 0); |
Dimension dimensions; |
64 |
|
|
65 |
// documentbase is not specified in an applet tag but we keep it |
// documentbase is not specified in an applet tag but we keep it |
66 |
// here anyway, for convenience. |
// here anyway, for convenience. |
67 |
URL documentbase; |
URL documentbase; |
68 |
|
|
69 |
|
public AppletTag (String code, String archives, |
70 |
|
String[] parameters, Dimension dimensions) |
71 |
|
throws MalformedURLException, IOException |
72 |
|
{ |
73 |
|
// Calculate codebase. |
74 |
|
int slashpos = code.lastIndexOf('/'); |
75 |
|
if (slashpos != -1) |
76 |
|
codebase = code.substring(0, slashpos + 1); |
77 |
|
|
78 |
|
// Calculate code. |
79 |
|
this.code = code.substring(slashpos + 1, code.length()); |
80 |
|
name = this.code; |
81 |
|
|
82 |
|
// documentbase is the current working directory. |
83 |
|
documentbase = new URL ("file", "", System.getProperty("user.dir") + "/"); |
84 |
|
|
85 |
|
// Parse archives. |
86 |
|
if (archives != null) |
87 |
|
this.archives = parseArchives (new StringTokenizer (archives)); |
88 |
|
|
89 |
|
// Parse parameters. |
90 |
|
if (parameters != null) |
91 |
|
{ |
92 |
|
this.parameters = new HashMap(); |
93 |
|
for (int i = 0; i < parameters.length; i++) |
94 |
|
{ |
95 |
|
StringTokenizer paramTokenizer = new StringTokenizer (parameters[i], ","); |
96 |
|
this.parameters.put (paramTokenizer.nextToken().trim(), |
97 |
|
paramTokenizer.nextToken().trim()); |
98 |
|
} |
99 |
|
} |
100 |
|
this.dimensions = dimensions; |
101 |
|
} |
102 |
|
|
103 |
private AppletTag (StreamTokenizer tagTokenizer, URL documentbase) |
private AppletTag (StreamTokenizer tagTokenizer, URL documentbase) |
104 |
throws IOException |
throws IOException |
105 |
{ |
{ |
106 |
this.documentbase = documentbase; |
this.documentbase = documentbase; |
107 |
|
dimensions = new Dimension (0, 0); |
108 |
String archives = null; |
String archives = null; |
109 |
|
|
110 |
while (tagTokenizer.nextToken() != '>') |
while (tagTokenizer.nextToken() != '>') |
229 |
{ |
{ |
230 |
key = key.toLowerCase(); |
key = key.toLowerCase(); |
231 |
if (parameters == null) |
if (parameters == null) |
232 |
parameters = new HashMap (); |
parameters = new HashMap(); |
233 |
parameters.put(key, val); |
parameters.put(key, val); |
234 |
} |
} |
235 |
} |
} |
260 |
} |
} |
261 |
catch (MalformedURLException e) |
catch (MalformedURLException e) |
262 |
{ |
{ |
263 |
if (location.endsWith (".class")) |
// location is not a URL. See if it is an HTML file. |
264 |
{ |
String path; |
265 |
System.out.println ("unrecognized file: " + location); |
|
266 |
} |
if (location.startsWith(File.separator)) |
267 |
|
path = new File (location).getCanonicalPath(); |
268 |
else |
else |
269 |
{ |
path = new File (System.getProperty("user.dir") |
270 |
// location is not a URL. See if it is an HTML file. |
+ File.separator |
271 |
String path; |
+ location).getCanonicalPath(); |
272 |
|
|
273 |
if (location.startsWith(File.separator)) |
documentbase = new URL("file", "", path); |
274 |
{ |
System.out.println ("recognized file: " + location); |
|
path = new File (location).getCanonicalPath(); |
|
|
} |
|
|
else |
|
|
{ |
|
|
path = new File (System.getProperty("user.dir") |
|
|
+ File.separator |
|
|
+ location).getCanonicalPath(); |
|
|
} |
|
|
documentbase = new URL("file", "", path); |
|
|
System.out.println ("recognized file: " + location); |
|
275 |
|
|
276 |
List urlTags = parseAppletTags (documentbase); |
List urlTags = parseAppletTags (documentbase); |
277 |
|
|
278 |
tags.addAll (urlTags); |
tags.addAll (urlTags); |
|
} |
|
279 |
} |
} |
280 |
return tags; |
return tags; |
281 |
} |
} |