1 |
/* AppletTag.java - representation of an HTML APPLET tag |
/* AppletTag.java - representation of an HTML APPLET tag |
2 |
Copyright (C) 2003 Thomas Fitzsimmons <fitzsim@redhat.com> |
Copyright (C) 2003 Thomas Fitzsimmons <fitzsim@redhat.com> |
3 |
|
|
4 |
This file is part of gcjappletviewer. |
This file is part of GCJ Applet Viewer. |
5 |
|
|
6 |
gcjappletviewer is free software; you can redistribute it and/or |
GCJ Applet Viewer is free software; you can redistribute it and/or |
7 |
modify it under the terms of the GNU General Public License as |
modify it under the terms of the GNU General Public License as |
8 |
published by the Free Software Foundation; either version 2 of the |
published by the Free Software Foundation; either version 2 of the |
9 |
License, or (at your option) any later version. |
License, or (at your option) any later version. |
10 |
|
|
11 |
gcjappletviewer is distributed in the hope that it will be useful, |
GCJ Applet Viewer is distributed in the hope that it will be |
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
useful, but WITHOUT ANY WARRANTY; without even the implied warranty |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
General Public License for more details. |
GNU General Public License for more details. |
15 |
|
|
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 GCJ Applet Viewer; 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 |
|
|
|
|
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. |
|
19 |
*/ |
*/ |
20 |
|
|
21 |
package gnu.gcjwebplugin; |
package gnu.gcjwebplugin; |
22 |
|
|
23 |
import java.awt.Dimension; |
import java.awt.Dimension; |
24 |
import java.io.File; |
import java.io.*; |
|
import java.io.InputStream; |
|
|
import java.io.IOException; |
|
|
import java.io.InputStreamReader; |
|
|
import java.io.StreamTokenizer; |
|
25 |
import java.util.Arrays; |
import java.util.Arrays; |
26 |
import java.util.StringTokenizer; |
import java.util.StringTokenizer; |
27 |
import java.net.URL; |
import java.net.URL; |
292 |
return value; |
return value; |
293 |
} |
} |
294 |
|
|
295 |
// Return a list of applet tag objects representing the applet tags |
public static URL locationToURL (String location) |
|
// that appear in the file or URL "location." |
|
|
public static List parseAppletTags (String location) |
|
296 |
throws IOException |
throws IOException |
297 |
{ |
{ |
298 |
List tags; |
URL documentbase = null; |
|
URL documentbase; |
|
|
|
|
299 |
try |
try |
300 |
{ |
{ |
301 |
// Try parsing location as a URL. |
// Try parsing location as a URL. |
308 |
|
|
309 |
System.err.println ("recognized URL: " + location); |
System.err.println ("recognized URL: " + location); |
310 |
|
|
|
tags = parseAppletTags (documentbase); |
|
311 |
} |
} |
312 |
catch (MalformedURLException e) |
catch (MalformedURLException e) |
313 |
{ |
{ |
322 |
+ location).getCanonicalPath(); |
+ location).getCanonicalPath(); |
323 |
|
|
324 |
documentbase = new URL("file", "", path); |
documentbase = new URL("file", "", path); |
325 |
|
|
326 |
System.err.println ("recognized file: " + location); |
System.err.println ("recognized file: " + location); |
327 |
|
} |
328 |
|
return documentbase; |
329 |
|
} |
330 |
|
|
331 |
tags = parseAppletTags (documentbase); |
// Return a list of applet tag objects representing the applet tags |
332 |
|
// that appear in the file or URL "location." |
333 |
|
public static List parseAppletTags (String location) |
334 |
|
throws IOException |
335 |
|
{ |
336 |
|
ArrayList tags = new ArrayList (); |
337 |
|
AppletTag currentTag; |
338 |
|
InputStream input; |
339 |
|
StreamTokenizer tagTokenizer; |
340 |
|
|
341 |
|
URL documentbase = locationToURL (location); |
342 |
|
|
343 |
|
input = documentbase.openStream (); |
344 |
|
tagTokenizer = new StreamTokenizer(new InputStreamReader(input)); |
345 |
|
|
346 |
|
currentTag = parseNextTag (tagTokenizer, documentbase); |
347 |
|
while (currentTag != null) |
348 |
|
{ |
349 |
|
tags.add (currentTag); |
350 |
|
currentTag = parseNextTag (tagTokenizer, documentbase); |
351 |
} |
} |
352 |
return tags; |
return tags; |
353 |
} |
} |
354 |
|
|
355 |
// Parse all applet tags that appear in the documentbase URL. |
// Parse the next applet tag in the tagTokenizer stream. |
356 |
private static List parseAppletTags(URL documentbase) |
public static AppletTag parseNextTag (StreamTokenizer tagTokenizer, URL documentbase) |
357 |
throws IOException |
throws IOException |
358 |
{ |
{ |
|
InputStream input = documentbase.openStream(); |
|
|
StreamTokenizer tagTokenizer = |
|
|
new StreamTokenizer(new InputStreamReader(input)); |
|
359 |
AppletTag currentTag = null; |
AppletTag currentTag = null; |
|
ArrayList tags = new ArrayList (); |
|
360 |
int token; |
int token; |
361 |
|
|
362 |
tagTokenizer.lowerCaseMode(true); |
tagTokenizer.lowerCaseMode(true); |
413 |
// URLs using the documentbase and |
// URLs using the documentbase and |
414 |
// codebase fields. |
// codebase fields. |
415 |
currentTag.parseArchives (); |
currentTag.parseArchives (); |
416 |
tags.add (currentTag); |
return currentTag; |
|
currentTag = null; |
|
417 |
} |
} |
418 |
} |
} |
419 |
} |
} |
422 |
} |
} |
423 |
token = tagTokenizer.nextToken(); |
token = tagTokenizer.nextToken(); |
424 |
} |
} |
425 |
|
return null; |
|
input.close(); |
|
|
return tags; |
|
426 |
} |
} |
427 |
|
|
428 |
public String toString() |
public String toString() |