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/] [AppletTag.java] - Blame information for rev 779

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 779 jeremybenn
/* AppletTag.java -- a representation of an HTML APPLET tag
2
   Copyright (C) 2003, 2004, 2005, 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.xml.dom.html2.DomHTMLAppletElement;
41
import gnu.xml.dom.html2.DomHTMLEmbedElement;
42
import gnu.xml.dom.html2.DomHTMLObjectElement;
43
 
44
import java.awt.Dimension;
45
import java.awt.Toolkit;
46
 
47
import java.io.File;
48
 
49
import java.net.MalformedURLException;
50
import java.net.URL;
51
 
52
import java.text.NumberFormat;
53
import java.text.ParseException;
54
 
55
import java.util.ArrayList;
56
import java.util.HashMap;
57
import java.util.Locale;
58
 
59
/**
60
 * @author Lillian Angel (langel@redhat.com)
61
 * @author Thomas Fitzsimmons (fitzsim@redhat.com)
62
 */
63
class AppletTag
64
{
65
 
66
  /**
67
   * The document base of this applet.
68
   */
69
  URL documentbase;
70
 
71
  /**
72
   * name of applet tag.
73
   */
74
  String name = "";
75
 
76
  /**
77
   * code of applet tag.
78
   */
79
  String code = "";
80
 
81
  /**
82
   * codebase of applet tag.
83
   */
84
  String codebase = "";
85
 
86
  /**
87
   * The archives.
88
   */
89
  ArrayList archives = new ArrayList();
90
 
91
  /**
92
   * The parameters.
93
   */
94
  HashMap parameters = new HashMap();
95
 
96
  /**
97
   * The screen size.
98
   */
99
  Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
100
 
101
  /**
102
   * Default constructor.
103
   */
104
  AppletTag()
105
  {
106
    // Do nothing.
107
  }
108
 
109
  /**
110
   * Constructs an AppletTag and parses the given applet element.
111
   *
112
   * @param appElement - the Applet element to parse.
113
   */
114
  AppletTag(DomHTMLAppletElement appElement)
115
  {
116
    name = appElement.getName();
117
    parameters.put("name", name);
118
 
119
    parameters.put("object", appElement.getObject());
120
    parameters.put("align", appElement.getAlign());
121
    parameters.put("alt", appElement.getAlt());
122
    parameters.put("height", appElement.getHeight());
123
    parameters.put("hspace", Integer.toString(appElement.getHspace()));
124
    parameters.put("vspace", Integer.toString(appElement.getVspace()));
125
    parameters.put("width", appElement.getWidth());
126
 
127
    TagParser.parseParams(appElement, this);
128
 
129
    if (code.equals(""))
130
      {
131
        code = appElement.getCode();
132
        if (code.equals(""))
133
          code = appElement.getCls();
134
      }
135
 
136
    // Must initialize codebase before archives
137
    if (codebase.equals(""))
138
      {
139
        codebase = appElement.getCodeBase();
140
        if (codebase.equals(""))
141
          codebase = appElement.getSrc();
142
      }
143
 
144
    if (archives.size() == 0)
145
      {
146
        String arcs = "";
147
        String arch = appElement.getArchive();
148
 
149
        if (code.indexOf(".") < 0)
150
          arcs = code + ".jar";
151
 
152
        if (!arch.equals(""))
153
          arcs += "," + arch;
154
 
155
        if (!arcs.equals(""))
156
          archives = TagParser.parseArchives(arcs, this);
157
      }
158
  }
159
 
160
  /**
161
   * Constructs an AppletTag and parses the given embed element.
162
   *
163
   * @param embElement - the Embed element to parse.
164
   */
165
  AppletTag(DomHTMLEmbedElement embElement)
166
  {
167
    // In an EMBED tag, a parameter is any non-standard attribute. This
168
    // is a problem for applets that take parameters named "code",
169
    // "codebase", "archive", "object", or "type". The solution is to
170
    // allow the same attributes, prefixed by "java_". The presence of
171
    // a "java_" attribute indicates that the non-prefixed attribute
172
    // should be interpreted as a parameter. For example if "java_code"
173
    // and "code" attributes are present in the EMBED tag then the
174
    // "code" attribute is interpreted as a parameter.
175
 
176
    name = embElement.getName();
177
    parameters.put("name", name);
178
 
179
    String jobj = embElement.getJavaObject();
180
    if (!jobj.equals(""))
181
      parameters.put("java_object", jobj);
182
    else
183
      parameters.put("object", embElement.getObject());
184
 
185
    parameters.put("width", embElement.getWidth());
186
    parameters.put("height", embElement.getHeight());
187
    parameters.put("align", embElement.getAlign());
188
    parameters.put("alt", embElement.getAlt());
189
    parameters.put("hspace", Integer.toString(embElement.getHspace()));
190
    parameters.put("mayscript", embElement.getMayscript());
191
    parameters.put("pluginspage", embElement.getPluginsPage());
192
    parameters.put("title", embElement.getTitle());
193
    parameters.put("type", embElement.getType());
194
    parameters.put("java_type", embElement.getJavaType());
195
    parameters.put("vspace", Integer.toString(embElement.getVspace()));
196
 
197
    TagParser.parseParams(embElement, this);
198
 
199
    // Must initialize codebase before archives
200
    if (codebase.equals(""))
201
      {
202
        String javacb = embElement.getJavaCodeBase();
203
        if (!javacb.equals(""))
204
          codebase = javacb;
205
        else
206
          codebase = embElement.getCodeBase();
207
      }
208
 
209
    if (code.equals(""))
210
      {
211
        String jcode = embElement.getJavaCode();
212
        if (!jcode.equals(""))
213
          code = jcode;
214
        else
215
          code = embElement.getCode();
216
      }
217
 
218
    if (archives.size() == 0)
219
      {
220
        String arcs = "";
221
        String jarch = embElement.getJavaArchive();
222
        String arch = embElement.getArchive();
223
 
224
        if (code.indexOf(".") < 0)
225
          arcs = code + ".jar";
226
 
227
        if (!jarch.equals(""))
228
          arcs += "," + jarch;
229
        else if (!arch.equals(""))
230
          arcs += "," + arch;
231
 
232
        if (!arcs.equals(""))
233
          archives = TagParser.parseArchives(arcs, this);
234
      }
235
  }
236
 
237
  /**
238
   * Constructs an AppletTag and parses the given object element.
239
   *
240
   * @param objElement - the Object element to parse.
241
   */
242
  AppletTag(DomHTMLObjectElement objElement)
243
  {
244
    // In an OBJECT tag, a parameter is any non-standard attribute. This
245
    // is a problem for applets that take parameters named "code",
246
    // "codebase", "archive", "object", or "type". The solution is to
247
    // allow the same attributes, prefixed by "java_". The presence of
248
    // a "java_" attribute indicates that the non-prefixed attribute
249
    // should be interpreted as a parameter. For example if "java_code"
250
    // and "code" attributes are present in the OBJECT tag then the
251
    // "code" attribute is interpreted as a parameter.
252
 
253
    name = objElement.getName();
254
    parameters.put("name", name);
255
 
256
    String jobj = objElement.getJavaObject();
257
    if (!jobj.equals(""))
258
      parameters.put("java_object", jobj);
259
    else
260
      parameters.put("object", objElement.getObject());
261
 
262
    parameters.put("type", objElement.getType());
263
    parameters.put("java_type", objElement.getJavaType());
264
    parameters.put("align", objElement.getAlign());
265
    parameters.put("codetype", objElement.getCodeType());
266
    parameters.put("data", objElement.getData());
267
    parameters.put("declare", Boolean.toString(objElement.getDeclare()));
268
    parameters.put("height", objElement.getHeight());
269
    parameters.put("hspace", Integer.toString(objElement.getHspace()));
270
    parameters.put("border", objElement.getBorder());
271
    parameters.put("standby", objElement.getStandby());
272
    parameters.put("tabindex", Integer.toString(objElement.getTabIndex()));
273
    parameters.put("usemap", objElement.getUseMap());
274
    parameters.put("vspace", Integer.toString(objElement.getVspace()));
275
    parameters.put("width", objElement.getWidth());
276
    parameters.put("mayscript", objElement.getMayscript());
277
    parameters.put("scriptable", objElement.getScriptable());
278
 
279
    TagParser.parseParams(objElement, this);
280
 
281
    // Must initialize codebase before archives
282
    if (codebase.equals(""))
283
      {
284
        String javacb = objElement.getJavaCodeBase();
285
        if (! javacb.equals(""))
286
          codebase = javacb;
287
        else
288
          codebase = objElement.getCodeBase();
289
      }
290
 
291
    if (code.equals(""))
292
      {
293
        String jcode = objElement.getJavaCode();
294
        if (!jcode.equals(""))
295
          code = jcode;
296
        else
297
          code = objElement.getCode();
298
      }
299
 
300
    if (archives.size() == 0)
301
      {
302
        String arcs = "";
303
        String jarch = objElement.getJavaArchive();
304
        String arch = objElement.getArchive();
305
 
306
        if (code.indexOf(".") < 0)
307
          arcs = code + ".jar";
308
 
309
        if (!jarch.equals(""))
310
          arcs += "," + jarch;
311
        else if (!arch.equals(""))
312
          arcs += "," + arch;
313
 
314
        if (!arcs.equals(""))
315
          archives = TagParser.parseArchives(arcs, this);
316
      }
317
  }
318
 
319
  /**
320
   * String representation of the tag.
321
   *
322
   * @return the string representation.
323
   */
324
  public String toString()
325
  {
326
    return ("  name=" + name + "\n" + "  code=" + code + "\n" + "  codebase="
327
            + codebase + "\n" + "  archive=" + archives + "\n" + "  parameters="
328
            + parameters + "\n" + "  documentbase=" + documentbase + "\n");
329
  }
330
 
331
  /**
332
   * Returns the size of the applet.
333
   *
334
   * @return the size.
335
   */
336
  Dimension getSize()
337
  {
338
    Dimension size = new Dimension(320, 200);
339
 
340
    try
341
      {
342
        String widthStr = (String) parameters.get("width");
343
 
344
        if (widthStr != null && ! widthStr.equals(""))
345
          {
346
            if (widthStr.charAt(widthStr.length() - 1) == '%')
347
              {
348
                double p = NumberFormat.getPercentInstance(Locale.US).parse(widthStr).intValue() / 100.0;
349
                size.width = (int)(p * screenSize.width);
350
              }
351
            else
352
              size.width = NumberFormat.getInstance(Locale.US).parse(widthStr).intValue();
353
          }
354
      }
355
    catch (ParseException e)
356
      {
357
        // Use default.
358
      }
359
 
360
    try
361
      {
362
        String heightStr = (String) parameters.get("height");
363
 
364
        if (heightStr != null && !heightStr.equals(""))
365
          {
366
            if (heightStr.charAt(heightStr.length() - 1) == '%')
367
              {
368
                double p = NumberFormat.getPercentInstance(Locale.US).parse(heightStr).intValue() / 100.0;
369
                size.height = (int) (p * screenSize.height);
370
              }
371
            else
372
              size.height = NumberFormat.getInstance(Locale.US).parse(heightStr).intValue();
373
          }
374
      }
375
    catch (ParseException e)
376
      {
377
        // Use default.
378
      }
379
 
380
    return size;
381
  }
382
 
383
  /**
384
   * Gets the code base.
385
   *
386
   * @return the codebase.
387
   */
388
  String getCodeBase()
389
  {
390
    return codebase;
391
  }
392
 
393
  /**
394
   * Gets the archive list.
395
   *
396
   * @return the archive list.
397
   */
398
  ArrayList getArchives()
399
  {
400
    return archives;
401
  }
402
 
403
  /**
404
   * Gets the code.
405
   *
406
   * @return the code.
407
   */
408
  String getCode()
409
  {
410
    return code;
411
  }
412
 
413
  /**
414
   * Gets the document base.
415
   *
416
   * @return the document base.
417
   */
418
  URL getDocumentBase()
419
  {
420
    return documentbase;
421
  }
422
 
423
  /**
424
   * Gets the specified parameter.
425
   *
426
   * @param name - the specified parameter.
427
   * @return the parameter.
428
   */
429
  String getParameter(String name)
430
  {
431
    return (String) parameters.get(name.toLowerCase());
432
  }
433
 
434
  /**
435
   * Prepends the base to the codebase.
436
   *
437
   * @return the new URL.
438
   */
439
  URL prependCodeBase(String base) throws MalformedURLException
440
  {
441
    if (documentbase == null)
442
      documentbase = TagParser.db;
443
 
444
    URL fullcodebase;
445
 
446
    //If no codebase was specified, default to documentbase.
447
    if (codebase.equals(""))
448
      {
449
        if (documentbase.getFile().endsWith(File.separator))
450
          fullcodebase = documentbase;
451
        else
452
          {
453
            String dirname = documentbase.getFile();
454
            if (dirname.indexOf(".") < 0)
455
              fullcodebase = new URL(documentbase + File.separator);
456
            else
457
              {
458
                // Determine dirname for file by stripping everything
459
                // past the last file separator.
460
                dirname = dirname.substring(0,
461
                                            dirname.lastIndexOf(File.separatorChar) + 1);
462
 
463
                fullcodebase = new URL(documentbase.getProtocol(),
464
                                       documentbase.getHost(),
465
                                       documentbase.getPort(), dirname);
466
              }
467
          }
468
      }
469
    else
470
      {
471
        // codebase was specified.
472
        URL codebaseURL = new URL(documentbase, codebase);
473
 
474
        if ("file".equals(codebaseURL.getProtocol()))
475
          {
476
            if (new File(codebaseURL.getFile()).isDirectory() && !codebase.endsWith(File.separator))
477
              fullcodebase = new URL(documentbase, codebase + File.separator);
478
            else
479
              fullcodebase = new URL(documentbase, codebase);
480
          }
481
        else if (codebase.endsWith(File.separator))
482
          fullcodebase = new URL(documentbase, codebase);
483
        else
484
          fullcodebase = new URL(documentbase, codebase + File.separator);
485
      }
486
 
487
    return new URL(fullcodebase, base);
488
  }
489
}

powered by: WebSVN 2.1.0

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