OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [tools/] [gnu/] [classpath/] [tools/] [appletviewer/] [Main.java] - Blame information for rev 779

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 779 jeremybenn
/* Main.java -- a standalone viewer for Java applets
2
   Copyright (C) 2003, 2004, 2006  Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
package gnu.classpath.tools.appletviewer;
39
 
40
import gnu.classpath.tools.common.ClasspathToolParser;
41
import gnu.classpath.tools.getopt.Option;
42
import gnu.classpath.tools.getopt.OptionException;
43
import gnu.classpath.tools.getopt.OptionGroup;
44
import gnu.classpath.tools.getopt.Parser;
45
import java.applet.Applet;
46
import java.awt.Dimension;
47
import java.io.BufferedReader;
48
import java.io.FileInputStream;
49
import java.io.FileOutputStream;
50
import java.io.IOException;
51
import java.io.InputStream;
52
import java.io.InputStreamReader;
53
import java.io.OutputStream;
54
import java.net.URL;
55
import java.util.ArrayList;
56
import java.util.HashMap;
57
import java.util.List;
58
 
59
 
60
class Main
61
{
62
  private static HashMap classLoaderCache = new HashMap();
63
 
64
  private static ClassLoader getClassLoader(URL codebase, ArrayList archives)
65
  {
66
    // Should load class loader each time. It is possible that there
67
    // are more than one applet to be loaded with different archives.
68
    AppletClassLoader loader = new AppletClassLoader(codebase, archives);
69
    classLoaderCache.put(codebase, loader);
70
 
71
    return loader;
72
  }
73
 
74
  private static String code = null;
75
  private static String codebase = null;
76
  private static String archive = null;
77
  private static List parameters = new ArrayList();
78
  private static Dimension dimensions = new Dimension(-1, -1);
79
  private static String pipeInName = null;
80
  private static String pipeOutName = null;
81
  private static boolean pluginMode = false;
82
  private static Parser parser = null;
83
 
84
  static Applet createApplet(AppletTag tag)
85
  {
86
    Applet applet = null;
87
 
88
    try
89
      {
90
        ClassLoader loader = getClassLoader(tag.prependCodeBase(""),
91
                                            tag.getArchives());
92
        String code = tag.getCode();
93
 
94
        if (code.endsWith(".class"))
95
          code = code.substring(0, code.length() - 6).replace('/', '.');
96
 
97
        Class c = loader.loadClass(code);
98
        applet = (Applet) c.newInstance();
99
      }
100
    catch (Exception e)
101
      {
102
        e.printStackTrace();
103
      }
104
 
105
    if (applet == null)
106
      applet = new ErrorApplet(Messages.getString ("Main.ErrorApplet"));
107
 
108
    return applet;
109
  }
110
 
111
  protected static boolean verbose;
112
 
113
  /**
114
   * The main method starting the applet viewer.
115
   *
116
   * @param args the arguments given on the command line.
117
   *
118
   * @exception IOException if an error occurs.
119
   */
120
  public static void main(String[] args) throws IOException
121
  {
122
    parser = new ClasspathToolParser("appletviewer", true);
123
    parser.setHeader(Messages.getString("Main.Usage"));
124
 
125
    OptionGroup attributeGroup
126
      = new OptionGroup(Messages.getString("Main.AppletTagOptions"));
127
 
128
    attributeGroup.add(new Option("code",
129
                                  Messages.getString("Main.CodeDescription"),
130
                                  Messages.getString("Main.CodeArgument"))
131
      {
132
        public void parsed(String argument) throws OptionException
133
        {
134
          code = argument;
135
        }
136
      });
137
    attributeGroup.add
138
      (new Option("codebase",
139
                  Messages.getString("Main.CodebaseDescription"),
140
                  Messages.getString("Main.CodebaseArgument"))
141
      {
142
        public void parsed(String argument) throws OptionException
143
        {
144
          codebase = argument;
145
        }
146
      });
147
    attributeGroup.add
148
      (new Option("archive",
149
                  Messages.getString("Main.ArchiveDescription"),
150
                  Messages.getString("Main.ArchiveArgument"))
151
      {
152
        public void parsed(String argument) throws OptionException
153
        {
154
          archive = argument;
155
        }
156
      });
157
    attributeGroup.add(new Option("width",
158
                                  Messages.getString("Main.WidthDescription"),
159
                                  Messages.getString("Main.WidthArgument"))
160
      {
161
        public void parsed(String argument) throws OptionException
162
        {
163
          dimensions.width = Integer.parseInt(argument);
164
        }
165
      });
166
    attributeGroup.add(new Option("height",
167
                                  Messages.getString("Main.HeightDescription"),
168
                                  Messages.getString("Main.HeightArgument"))
169
      {
170
        public void parsed(String argument) throws OptionException
171
        {
172
          dimensions.height = Integer.parseInt(argument);
173
        }
174
      });
175
    attributeGroup.add(new Option("param",
176
                                  Messages.getString("Main.ParamDescription"),
177
                                  Messages.getString("Main.ParamArgument"))
178
      {
179
        public void parsed(String argument) throws OptionException
180
        {
181
          parameters.add(argument);
182
        }
183
      });
184
    OptionGroup pluginGroup
185
      = new OptionGroup(Messages.getString("Main.PluginOption"));
186
    pluginGroup.add(new Option("plugin",
187
                               Messages.getString("Main.PluginDescription"),
188
                               Messages.getString("Main.PluginArgument"))
189
      {
190
        public void parsed(String argument) throws OptionException
191
        {
192
          pluginMode = true;
193
          int comma = argument.indexOf(',');
194
          pipeInName = argument.substring(0, comma);
195
          pipeOutName = argument.substring(comma + 1);
196
        }
197
      });
198
    OptionGroup debuggingGroup
199
      = new OptionGroup(Messages.getString("Main.DebuggingOption"));
200
    debuggingGroup.add
201
      (new Option("verbose",
202
                  Messages.getString("Main.VerboseDescription"),
203
                  (String) null)
204
      {
205
        public void parsed(String argument) throws OptionException
206
        {
207
          verbose = true;
208
        }
209
      });
210
    OptionGroup compatibilityGroup
211
      = new OptionGroup(Messages.getString("Main.CompatibilityOptions"));
212
    compatibilityGroup.add
213
      (new Option("debug",
214
                  Messages.getString("Main.DebugDescription"),
215
                  (String) null)
216
      {
217
        public void parsed(String argument) throws OptionException
218
        {
219
          // Currently ignored.
220
        }
221
      });
222
    compatibilityGroup.add
223
      (new Option("encoding",
224
                  Messages.getString("Main.EncodingDescription"),
225
                  Messages.getString("Main.EncodingArgument"))
226
      {
227
        public void parsed(String argument) throws OptionException
228
        {
229
          // FIXME: We should probably be using
230
          // java.nio.charset.CharsetDecoder to handle the encoding.  What
231
          // is the status of Classpath's implementation?
232
        }
233
      });
234
    parser.add(attributeGroup);
235
    parser.add(pluginGroup);
236
    parser.add(debuggingGroup);
237
    parser.add(compatibilityGroup);
238
 
239
    String[] urls = parser.parse(args);
240
 
241
    // Print arguments.
242
    printArguments(args);
243
 
244
    args = urls;
245
 
246
    if (dimensions.height < 0)
247
      dimensions.height = 200;
248
 
249
    if (dimensions.width < 0)
250
      dimensions.width = (int) (1.6 * dimensions.height);
251
 
252
    //System.setSecurityManager(new AppletSecurityManager(pluginMode));
253
 
254
    if (pluginMode)
255
      {
256
        // Plugin will warn user about missing security manager.
257
        InputStream in;
258
        OutputStream out;
259
 
260
        in = new FileInputStream(pipeInName);
261
        out = new FileOutputStream(pipeOutName);
262
 
263
        PluginAppletViewer.start(in, out);
264
      }
265
    else
266
      {
267
        // Warn user about missing security manager.
268
        System.err.println(Messages.getString("Main.SecurityWarning") + "\n");
269
 
270
        System.err.println(Messages.getString("Main.ContinuationPrompt"));
271
 
272
        BufferedReader stdin
273
          = new BufferedReader(new InputStreamReader(System.in));
274
        String response = null;
275
 
276
        try
277
          {
278
            response = stdin.readLine();
279
          }
280
        catch (IOException e)
281
          {
282
            throw new RuntimeException("Failed to read response"
283
                                       + " to continuation prompt.", e);
284
          }
285
 
286
        if (!(response.equals("c") || response.equals("C")))
287
          {
288
            System.exit(0);
289
          }
290
 
291
        if (code == null)
292
          {
293
            // The --code option wasn't given and there are no URL
294
            // arguments so we have nothing to work with.
295
            if (args.length == 0)
296
              {
297
                System.err.println(Messages.getString("Main.NoInputFiles"));
298
                System.exit(1);
299
              }
300
            // Create a standalone appletviewer from a list of URLs.
301
            new StandaloneAppletViewer(args);
302
          }
303
        else
304
          {
305
            // Create a standalone appletviewer from the --code
306
            // option.
307
            new StandaloneAppletViewer(code, codebase, archive,
308
                                       parameters, dimensions);
309
          }
310
      }
311
  }
312
 
313
  static void printArguments(String[] args)
314
  {
315
    if (verbose)
316
      {
317
        System.out.println(Messages.getString("Main.RawArguments"));
318
 
319
        for (int i = 0; i < args.length; i++)
320
          System.out.println(" " + args[i]);
321
      }
322
  }
323
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.