forked from mbebenita/j2me.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
57 changed files
with
11,570 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* Copyright 1990-2009 Sun Microsystems, Inc. All Rights Reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License version | ||
* 2 only, as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License version 2 for more details (a copy is | ||
* included at /legal/license.txt). | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* version 2 along with this work; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA | ||
* | ||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa | ||
* Clara, CA 95054 or visit www.sun.com if you need additional | ||
* information or have any questions. | ||
*/ | ||
|
||
package com.sun.j2me.app; | ||
|
||
import com.sun.j2me.security.Permission; | ||
import com.sun.j2me.security.AccessController; | ||
import com.sun.midp.midlet.MIDletStateHandler; | ||
import com.sun.midp.midletsuite.MIDletSuiteImpl; | ||
import com.sun.midp.midlet.MIDletSuite; | ||
import java.io.InputStream; | ||
|
||
/** | ||
* Abstraction for application package | ||
*/ | ||
public class AppPackage { | ||
|
||
/** Static instance. Only one package can be run in a isolate */ | ||
private static AppPackage instance = new AppPackage(); | ||
|
||
/** Guard from 'new' operator */ | ||
private AppPackage() { | ||
} | ||
|
||
public static AppPackage getInstance() { | ||
return instance; | ||
} | ||
|
||
public int getId() { | ||
return MIDletStateHandler.getMidletStateHandler(). | ||
getMIDletSuite().getID(); | ||
} | ||
|
||
|
||
/** Unused ID */ | ||
public static final int UNUSED_APP_ID = -1; | ||
|
||
/** | ||
* Returns permission status for the specified permission | ||
* | ||
* @param p permission to check | ||
* @return 1 if allowed; 0 if denied; -1 if status is unknown | ||
*/ | ||
public int checkPermission(Permission p) { | ||
/* | ||
* IMPL_NOTE: The corresponding method in MIDletSuite used to check | ||
* for permissions silently, i.e. without throwing SecurityException | ||
* or asking user if he allows to proceed. | ||
* This functionality should be added to AccessController; until then, | ||
* it is acceptable to return "unknown", so that security-sensitive | ||
* code will call checkForPermission() anyway. | ||
*/ | ||
return -1; | ||
} | ||
|
||
/** | ||
* Checks for specified permission status. Throws an exception | ||
* if permission is not allowed. May be blocked to ask user | ||
* | ||
* @param p a permission to check | ||
* @exception SecurityException if permission is not allowed | ||
* @exception InterruptedException if another thread interrupts a calling | ||
* thread while asking user | ||
*/ | ||
public void checkForPermission(Permission p) throws InterruptedException { | ||
AccessController.checkPermission(p.getName(), p.getResource(), p.getExtraValue()); | ||
} | ||
|
||
/** | ||
* Throws an exception if a status for the permission is not allowed | ||
* | ||
* @param p a permission to check | ||
* @exception SecurityException if a status for the permission is not allowed | ||
*/ | ||
public void checkIfPermissionAllowed(Permission p) { | ||
if (checkPermission(p) != 1) { | ||
throw new SecurityException(); | ||
} | ||
} | ||
|
||
/** | ||
* Gets the name of CA that authorized this suite. | ||
* | ||
* @return name of a CA or null if the suite was not signed | ||
*/ | ||
public String getCA() { | ||
MIDletSuite ms = | ||
MIDletStateHandler.getMidletStateHandler().getMIDletSuite(); | ||
|
||
if (ms instanceof com.sun.midp.midletsuite.MIDletSuiteImpl) { | ||
return ((MIDletSuiteImpl)ms).getInstallInfo().getCA(); | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Finds a resource with a given name. This method returns null if no | ||
* resource with this name is found. | ||
* | ||
* @param name name of the desired resource | ||
* @return a <code>java.io.InputStream</code> object. | ||
* @throws NullPointerException if <code>name</code> is <code>null</code>. | ||
*/ | ||
public InputStream getResourceAsStream(String name) { | ||
return getClass().getResourceAsStream(name); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 1990-2009 Sun Microsystems, Inc. All Rights Reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License version | ||
* 2 only, as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License version 2 for more details (a copy is | ||
* included at /legal/license.txt). | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* version 2 along with this work; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA | ||
* | ||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa | ||
* Clara, CA 95054 or visit www.sun.com if you need additional | ||
* information or have any questions. | ||
*/ | ||
|
||
package com.sun.j2me.i18n; | ||
|
||
/** | ||
* Intermediate class for logging facilities | ||
*/ | ||
public class Resource extends com.sun.midp.i18n.Resource { | ||
static final int[] months = { ResourceConstants.LCDUI_DF_JAN_SHORT, | ||
ResourceConstants.LCDUI_DF_FEB_SHORT, | ||
ResourceConstants.LCDUI_DF_MAR_SHORT, | ||
ResourceConstants.LCDUI_DF_APR_SHORT, | ||
ResourceConstants.LCDUI_DF_MAY_SHORT, | ||
ResourceConstants.LCDUI_DF_JUN_SHORT, | ||
ResourceConstants.LCDUI_DF_JUL_SHORT, | ||
ResourceConstants.LCDUI_DF_AUG_SHORT, | ||
ResourceConstants.LCDUI_DF_SEP_SHORT, | ||
ResourceConstants.LCDUI_DF_OCT_SHORT, | ||
ResourceConstants.LCDUI_DF_NOV_SHORT, | ||
ResourceConstants.LCDUI_DF_DEC_SHORT }; | ||
|
||
static final int[] days = { ResourceConstants.LCDUI_DF_SUN, | ||
ResourceConstants.LCDUI_DF_MON, | ||
ResourceConstants.LCDUI_DF_TUE, | ||
ResourceConstants.LCDUI_DF_WED, | ||
ResourceConstants.LCDUI_DF_THU, | ||
ResourceConstants.LCDUI_DF_FRI, | ||
ResourceConstants.LCDUI_DF_SAT }; | ||
|
||
|
||
public static String getMonthName(int key) { | ||
return getString(months[key]); | ||
} | ||
|
||
public static String getShortDayName(int key) { | ||
return getString(days[key]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 1990-2009 Sun Microsystems, Inc. All Rights Reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License version | ||
* 2 only, as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License version 2 for more details (a copy is | ||
* included at /legal/license.txt). | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* version 2 along with this work; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA | ||
* | ||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa | ||
* Clara, CA 95054 or visit www.sun.com if you need additional | ||
* information or have any questions. | ||
*/ | ||
|
||
package com.sun.j2me.i18n; | ||
|
||
public class ResourceConstants extends com.sun.midp.i18n.ResourceConstants {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* | ||
* | ||
* Copyright 1990-2009 Sun Microsystems, Inc. All Rights Reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License version | ||
* 2 only, as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License version 2 for more details (a copy is | ||
* included at /legal/license.txt). | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* version 2 along with this work; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA | ||
* | ||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa | ||
* Clara, CA 95054 or visit www.sun.com if you need additional | ||
* information or have any questions. | ||
*/ | ||
|
||
package com.sun.j2me.jsr75; | ||
|
||
import java.util.Vector; | ||
|
||
/** | ||
* Supporting methods for interpreting vCard and vCalendar encodings. | ||
* | ||
*/ | ||
public class StringUtil { | ||
/** | ||
* Parses a separated list of strings into a string array. | ||
* An escaped separator (backslash followed by separatorChar) is not | ||
* treated as a separator. | ||
* | ||
* @param data input list to be parsed | ||
* @param separatorChar the character used to separate items | ||
* @param startingPoint Only use the part of the string that | ||
* follows this index | ||
* @param skipFirstIfEmpty whether the first element should be skiped | ||
* if it's empty (data starts with the separator). | ||
* This flag is used to support empty category name | ||
* @return a non-null string array containing string elements | ||
*/ | ||
public static String[] split(String data, char separatorChar, | ||
int startingPoint, boolean skipFirstIfEmpty) { | ||
if (startingPoint == data.length()) { | ||
return new String[0]; | ||
} | ||
|
||
// support for empty tokens: | ||
// if data starts with separator, just skip it | ||
if (skipFirstIfEmpty && data.charAt(startingPoint) == separatorChar) { | ||
startingPoint++; | ||
} | ||
|
||
// tokenize elements | ||
Vector elementList = new Vector(); | ||
int startSearchAt = startingPoint; | ||
int startOfElement = startingPoint; | ||
for (int i; (i = data.indexOf(separatorChar, startSearchAt)) != -1; ) { | ||
if (i != 0 && data.charAt(i - 1) == '\\') { | ||
// escaped separator. don't treat it as a real separator | ||
startSearchAt = i + 1; | ||
} else { | ||
String element = data.substring(startOfElement, i); | ||
elementList.addElement(element); | ||
startSearchAt = startOfElement = i + 1; | ||
} | ||
} | ||
|
||
// there is no separator found | ||
if (elementList.size() == 0) { | ||
return new String[] { data.substring(startOfElement) }; | ||
} | ||
|
||
// add the last element | ||
elementList.addElement(data.substring(startOfElement)); | ||
|
||
// convert Vector to array | ||
int size = elementList.size(); | ||
String[] elements = new String[size]; | ||
for (int i = 0; i < size; i++) { | ||
elements[i] = (String) elementList.elementAt(i); | ||
} | ||
|
||
return elements; | ||
} | ||
|
||
/** | ||
* Parses a separated list of strings into a string array. | ||
* An escaped separator (backslash followed by separatorChar) is not | ||
* treated as a separator. | ||
* | ||
* @param data input list to be parsed | ||
* @param separatorChar the character used to separate items | ||
* @param startingPoint Only use the part of the string that | ||
* follows this index | ||
* @return a non-null string array containing string elements | ||
*/ | ||
public static String[] split(String data, char separatorChar, | ||
int startingPoint) { | ||
return split(data, separatorChar, startingPoint, true); | ||
} | ||
|
||
/** | ||
* Joins the elements of a string array together into a single string. | ||
* | ||
* @param elements the string array | ||
* @param separator the string to be included between each pair of | ||
* successive elements | ||
* @return a string containing, alternately, elements of the string array | ||
* and the separator string | ||
*/ | ||
public static String join(String[] elements, String separator) { | ||
StringBuffer sb = new StringBuffer(); | ||
for (int i = 0; i < elements.length; i++) { | ||
if (i > 0) { | ||
sb.append(separator); | ||
} | ||
sb.append(elements[i]); | ||
} | ||
return sb.toString(); | ||
} | ||
} |
Oops, something went wrong.