View Javadoc

1   /*
2    *  MicroEmulator
3    *  Copyright (C) 2001 Bartek Teodorczyk <barteo@barteo.net>
4    *
5    *  This library is free software; you can redistribute it and/or
6    *  modify it under the terms of the GNU Lesser General Public
7    *  License as published by the Free Software Foundation; either
8    *  version 2.1 of the License, or (at your option) any later version.
9    *
10   *  This library is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   *  Lesser General Public License for more details.
14   *
15   *  You should have received a copy of the GNU Lesser General Public
16   *  License along with this library; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   *  
19   *  @version $Id: JadProperties.java 1105 2007-03-10 17:37:23Z vlads $
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 }