32 |
import java.awt.MenuItem; |
import java.awt.MenuItem; |
33 |
import java.awt.event.WindowAdapter; |
import java.awt.event.WindowAdapter; |
34 |
import java.awt.event.WindowEvent; |
import java.awt.event.WindowEvent; |
35 |
import java.io.File; |
import java.io.*; |
36 |
import java.io.IOException; |
import java.util.StringTokenizer; |
37 |
import java.net.MalformedURLException; |
import java.net.MalformedURLException; |
38 |
import java.net.URL; |
import java.net.URL; |
39 |
import java.net.URLClassLoader; |
import java.net.URLClassLoader; |
135 |
System.out.println ("Usage: gcjappletviewer [options] <filename>.class | <filename>.html... | url..."); |
System.out.println ("Usage: gcjappletviewer [options] <filename>.class | <filename>.html... | url..."); |
136 |
System.out.println ("Options:"); |
System.out.println ("Options:"); |
137 |
System.out.println (" --help Display this message"); |
System.out.println (" --help Display this message"); |
138 |
|
System.out.println (" --code=<classname>[.class] Run applet by class name or file name"); |
139 |
|
System.out.println (" --codebase=<directory> Set applet codebase"); |
140 |
System.out.println (" --archive=<filename>.jar[,...] Add archives to applet class loader"); |
System.out.println (" --archive=<filename>.jar[,...] Add archives to applet class loader"); |
141 |
System.out.println (" --param=<name>,<value> Pass parameter to applet"); |
System.out.println (" --param=<name>,<value> Pass parameter to applet"); |
142 |
System.out.println (" --width=<width> Set width of applet viewer frame"); |
System.out.println (" --width=<width> Set width of applet viewer frame"); |
156 |
|
|
157 |
LongOpt[] longOptions = new LongOpt[] |
LongOpt[] longOptions = new LongOpt[] |
158 |
{ |
{ |
159 |
new LongOpt ("archive", LongOpt.REQUIRED_ARGUMENT, null, 0), |
new LongOpt ("code", LongOpt.REQUIRED_ARGUMENT, null, 0), |
160 |
new LongOpt ("param", LongOpt.REQUIRED_ARGUMENT, null, 0), |
new LongOpt ("codebase", LongOpt.REQUIRED_ARGUMENT, null, 0), |
161 |
new LongOpt ("width", LongOpt.REQUIRED_ARGUMENT, null, 0), |
new LongOpt ("archive", LongOpt.REQUIRED_ARGUMENT, null, 0), |
162 |
new LongOpt ("height", LongOpt.REQUIRED_ARGUMENT, null, 0), |
new LongOpt ("param", LongOpt.REQUIRED_ARGUMENT, null, 0), |
163 |
new LongOpt ("plugin", LongOpt.NO_ARGUMENT, null, 0), |
new LongOpt ("width", LongOpt.REQUIRED_ARGUMENT, null, 0), |
164 |
new LongOpt ("help", LongOpt.NO_ARGUMENT, null, 0), |
new LongOpt ("height", LongOpt.REQUIRED_ARGUMENT, null, 0), |
165 |
|
new LongOpt ("plugin", LongOpt.NO_ARGUMENT, null, 0), |
166 |
|
new LongOpt ("help", LongOpt.NO_ARGUMENT, null, 0), |
167 |
}; |
}; |
168 |
|
|
169 |
Getopt opts = new Getopt("gcjappletviewer", args, "", longOptions); |
Getopt opts = new Getopt("gcjappletviewer", args, "", longOptions); |
171 |
int optionValue; |
int optionValue; |
172 |
int optionIndex; |
int optionIndex; |
173 |
|
|
174 |
|
String code = ""; |
175 |
|
String codebase = ""; |
176 |
String archives = ""; |
String archives = ""; |
177 |
List parameters = new ArrayList (); |
List parameters = new ArrayList (); |
178 |
Dimension dimensions = new Dimension (-1, -1); |
Dimension dimensions = new Dimension (-1, -1); |
190 |
{ |
{ |
191 |
optionIndex = opts.getLongind(); |
optionIndex = opts.getLongind(); |
192 |
|
|
193 |
if (optionIndex == 0) // --archive |
if (optionIndex == 0) // --code |
194 |
|
code = opts.getOptarg(); |
195 |
|
if (optionIndex == 1) // --codebase |
196 |
|
codebase = opts.getOptarg(); |
197 |
|
if (optionIndex == 2) // --archive |
198 |
archives = opts.getOptarg(); |
archives = opts.getOptarg(); |
199 |
else if (optionIndex == 1) // --param |
else if (optionIndex == 3) // --param |
200 |
parameters.add (opts.getOptarg()); |
parameters.add (opts.getOptarg()); |
201 |
else if (optionIndex == 2) // --width |
else if (optionIndex == 4) // --width |
202 |
{ |
{ |
203 |
widthGiven = true; |
widthGiven = true; |
204 |
dimensions.width = |
dimensions.width = |
205 |
Math.max (1, Integer.parseInt(opts.getOptarg())); |
Math.max (1, Integer.parseInt(opts.getOptarg())); |
206 |
} |
} |
207 |
else if (optionIndex == 3) // --height |
else if (optionIndex == 5) // --height |
208 |
{ |
{ |
209 |
heightGiven = true; |
heightGiven = true; |
210 |
dimensions.height = |
dimensions.height = |
211 |
Math.max (1, Integer.parseInt(opts.getOptarg())); |
Math.max (1, Integer.parseInt(opts.getOptarg())); |
212 |
} |
} |
213 |
else if (optionIndex == 4) // --plugin |
else if (optionIndex == 6) // --plugin |
214 |
{ |
{ |
215 |
pluginMode = true; |
pluginMode = true; |
216 |
break; |
break; |
217 |
} |
} |
218 |
else if (optionIndex == 5) // --help |
else if (optionIndex == 7) // --help |
219 |
printHelpMessage (0); |
printHelpMessage (0); |
220 |
} |
} |
221 |
} |
} |
233 |
boolean classFileGiven = false; |
boolean classFileGiven = false; |
234 |
|
|
235 |
int optind = opts.getOptind (); |
int optind = opts.getOptind (); |
236 |
if (optind == args.length) |
if (optind == args.length && code.equals ("")) |
237 |
{ |
{ |
238 |
System.out.println ("gcjappletviewer: no input files"); |
System.out.println ("gcjappletviewer: no input files"); |
239 |
printHelpMessage (1); |
printHelpMessage (1); |
243 |
// the command line. |
// the command line. |
244 |
List appletTags = new LinkedList (); |
List appletTags = new LinkedList (); |
245 |
|
|
246 |
for (int i = optind; i < args.length; i++) |
// Only handle .class files on the command line if --code was not |
247 |
|
// given. |
248 |
|
if (code.equals ("")) |
249 |
{ |
{ |
250 |
// If this argument doesn't end in a file separator and there |
for (int i = optind; i < args.length; i++) |
|
// is no dot between the last file separator and the end of |
|
|
// the string, then assume we're dealing with a class file and |
|
|
// append the .class extension. |
|
|
String basename = |
|
|
args[i].substring(args[i].lastIndexOf(File.separatorChar) + 1, |
|
|
args[i].length()); |
|
|
|
|
|
if (!basename.equals ("") |
|
|
&& basename.lastIndexOf ('.') < 0) |
|
|
args[i] = args[i] + ".class"; |
|
|
|
|
|
if (args[i].endsWith(".class")) |
|
251 |
{ |
{ |
252 |
classFileGiven = true; |
// If this argument doesn't end in a file separator and there |
253 |
|
// is no dot between the last file separator and the end of |
254 |
|
// the string, then assume we're dealing with a class file and |
255 |
|
// append the .class extension. |
256 |
|
String basename = |
257 |
|
args[i].substring(args[i].lastIndexOf(File.separatorChar) + 1, |
258 |
|
args[i].length()); |
259 |
|
|
260 |
|
if (!basename.equals ("") |
261 |
|
&& basename.lastIndexOf ('.') < 0) |
262 |
|
args[i] = args[i] + ".class"; |
263 |
|
|
264 |
|
if (args[i].endsWith(".class")) |
265 |
|
{ |
266 |
|
classFileGiven = true; |
267 |
|
|
268 |
appletTags.add (new AppletTag (args[i], |
appletTags.add (new AppletTag (args[i], |
269 |
archives, |
archives, |
270 |
parameters, |
parameters, |
271 |
dimensions)); |
dimensions)); |
272 |
// Process only the first .class file we encounter on the |
// Process only the first .class file we encounter on the |
273 |
// command line. |
// command line. |
274 |
break; |
break; |
275 |
|
} |
276 |
} |
} |
277 |
} |
} |
278 |
|
|
286 |
for (int i = opts.getOptind (); i < args.length; i++) |
for (int i = opts.getOptind (); i < args.length; i++) |
287 |
appletTags.addAll (AppletTag.parseAppletTags (args[i])); |
appletTags.addAll (AppletTag.parseAppletTags (args[i])); |
288 |
|
|
289 |
|
// Handle --code option, if it was given. |
290 |
|
if (!code.equals ("")) |
291 |
|
{ |
292 |
|
String tagString = "<EMBED CODE=\"" + code + "\"" |
293 |
|
+ " CODEBASE=\"" + codebase + "\"" |
294 |
|
+ " ARCHIVE=\"" + archives + "\""; |
295 |
|
|
296 |
|
// Handle parameters. |
297 |
|
Iterator pairs = parameters.iterator (); |
298 |
|
while (pairs.hasNext ()) |
299 |
|
{ |
300 |
|
StringTokenizer paramTokenizer = |
301 |
|
new StringTokenizer ((String) pairs.next(), ","); |
302 |
|
tagString += " " + paramTokenizer.nextToken().trim() |
303 |
|
+ "=\"" + paramTokenizer.nextToken().trim() + "\""; |
304 |
|
} |
305 |
|
|
306 |
|
tagString += " WIDTH=" + dimensions.width; |
307 |
|
tagString += " HEIGHT=" + dimensions.height; |
308 |
|
|
309 |
|
tagString += "></EMBED>"; |
310 |
|
|
311 |
|
System.err.println ("code option given:"); |
312 |
|
System.err.println (tagString); |
313 |
|
|
314 |
|
StringReader reader = new StringReader(tagString); |
315 |
|
String path = System.getProperty("user.dir") + File.separator; |
316 |
|
appletTags.add (AppletTag.parseNextTag (new StreamTokenizer (reader), |
317 |
|
new URL ("file", "", path))); |
318 |
|
} |
319 |
|
|
320 |
System.err.println ("parsed applet tags:"); |
System.err.println ("parsed applet tags:"); |
321 |
|
|
322 |
for (int i = 0; i < appletTags.size(); i++) |
for (int i = 0; i < appletTags.size(); i++) |