1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.microemu.util;
23
24 import java.util.Enumeration;
25 import java.util.Properties;
26 import java.util.Vector;
27
28 public class JadProperties extends Properties {
29
30 private static final long serialVersionUID = 1L;
31
32 static String MIDLET_PREFIX = "MIDlet-";
33
34 Vector midletEntries = null;
35
36 String correctedJarURL = null;
37
38 public void clear() {
39 super.clear();
40
41 midletEntries = null;
42 correctedJarURL = null;
43 }
44
45 public String getSuiteName() {
46 return getProperty("MIDlet-Name");
47 }
48
49 public String getVersion() {
50 return getProperty("MIDlet-Version");
51 }
52
53 public String getVendor() {
54 return getProperty("MIDlet-Vendor");
55 }
56
57 public String getProfile() {
58 return getProperty("MicroEdition-Profile");
59 }
60
61 public String getConfiguration() {
62 return getProperty("MicroEdition-Configuration");
63 }
64
65 public String getJarURL() {
66 if (correctedJarURL != null) {
67 return correctedJarURL;
68 } else {
69 return getProperty("MIDlet-Jar-URL");
70 }
71 }
72
73 public void setCorrectedJarURL(String correctedJarURL) {
74 this.correctedJarURL = correctedJarURL;
75 }
76
77 public int getJarSize() {
78 return Integer.parseInt(getProperty("MIDlet-Jar-Size"));
79 }
80
81 public Vector getMidletEntries() {
82 String name, icon, className, test;
83 int pos;
84
85 if (midletEntries == null) {
86 midletEntries = new Vector();
87
88 for (Enumeration e = propertyNames(); e.hasMoreElements();) {
89 test = (String) e.nextElement();
90 if (test.startsWith(MIDLET_PREFIX)) {
91 try {
92 Integer.parseInt(test.substring(MIDLET_PREFIX.length()));
93 test = getProperty(test);
94 pos = test.indexOf(',');
95 name = test.substring(0, pos).trim();
96 icon = test.substring(pos + 1, test.indexOf(',', pos + 1)).trim();
97 className = test.substring(test.indexOf(',', pos + 1) + 1).trim();
98 midletEntries.addElement(new JadMidletEntry(name, icon, className));
99 } catch (NumberFormatException ex) {
100 }
101 }
102 }
103 }
104
105 return midletEntries;
106 }
107
108 public String getProperty(String key, String defaultValue) {
109 String result = super.getProperty(key, defaultValue);
110 if (result != null) {
111 return result.trim();
112 } else {
113 return null;
114 }
115 }
116
117 public String getProperty(String key) {
118 String result = super.getProperty(key);
119 if (result != null) {
120 return result.trim();
121 } else {
122 return null;
123 }
124 }
125
126 }