Methods Summary |
---|
private void | checkPermissions(int pimListType, int mode)Checks for all the permissions that need to be present to open a list
int[] permissions = getPermissions(pimListType, mode);
MIDletSuite suite = Scheduler.getScheduler().getMIDletSuite();
/*
* Do a first pass on the permissions to make sure that none is
* automatically denied. This is for the case when both read permission
* and write permission are required. It is possible that, for example,
* read permission is granted only after asking the user, but write
* permission is automatically denied. In this case, the user should
* not be asked a question at all.
*/
for (int i = 0; i < permissions.length; i++) {
String name = Permissions.getName(permissions[i]);
int status = suite.checkPermission(name);
if (status == 0) {
// throw an exception
suite.checkIfPermissionAllowed(permissions[i]);
} else if (status == 1) {
// don't check this permission again
permissions[i] = -1;
}
}
for (int i = 0; i < permissions.length; i++) {
if (permissions[i] != -1) {
try {
suite.checkForPermission(permissions[i], null);
} catch (InterruptedException e) {
throw new SecurityException("Security check interrupted: "
+ e.getMessage());
}
}
}
|
public javax.microedition.pim.PIMItem[] | fromSerialFormat(java.io.InputStream is, java.lang.String enc)Gets an array of PIM items from an encoded input
stream.
return fromSerialFormat(is, enc, null);
|
private javax.microedition.pim.PIMItem[] | fromSerialFormat(java.io.InputStream is, java.lang.String enc, javax.microedition.pim.PIMList list)Gets an array of PIM items from an encoded input
stream and list.
if (enc == null) {
enc = "UTF-8" /* NO I18N */;
}
InputStream in = new MarkableInputStream(is);
in.mark(Integer.MAX_VALUE);
try {
for (int i = 0; i < formats.length; i++) {
try {
PIMItem[] items = formats[i].decode(in, enc, list);
if (items == null) {
throw new PIMException(
"Empty stream or insufficient data");
}
return items;
} catch (UnsupportedPIMFormatException e) {
in.reset();
in.mark(Integer.MAX_VALUE);
}
}
throw new PIMException("Format is not recognized");
} catch (UnsupportedEncodingException e) {
throw e;
} catch (IOException e) {
throw new PIMException(e.getMessage());
}
|
private int[] | getPermissions(int listType, int mode)Gets the permissions that need to be present to open a list
switch (listType) {
case CONTACT_LIST:
switch (mode) {
case READ_ONLY:
return new int[] { Permissions.PIM_CONTACT_READ };
case WRITE_ONLY:
return new int[] { Permissions.PIM_CONTACT_WRITE};
case READ_WRITE:
return new int[] {
Permissions.PIM_CONTACT_READ,
Permissions.PIM_CONTACT_WRITE };
default:
throw new IllegalArgumentException("Not a valid mode: "
+ mode);
}
case EVENT_LIST:
switch (mode) {
case READ_ONLY:
return new int[] { Permissions.PIM_EVENT_READ };
case WRITE_ONLY:
return new int[] { Permissions.PIM_EVENT_WRITE};
case READ_WRITE:
return new int[] {
Permissions.PIM_EVENT_READ,
Permissions.PIM_EVENT_WRITE };
default:
throw new IllegalArgumentException("Not a valid mode: "
+ mode);
}
case TODO_LIST:
switch (mode) {
case READ_ONLY:
return new int[] { Permissions.PIM_TODO_READ };
case WRITE_ONLY:
return new int[] { Permissions.PIM_TODO_WRITE};
case READ_WRITE:
return new int[] {
Permissions.PIM_TODO_READ,
Permissions.PIM_TODO_WRITE };
default:
throw new IllegalArgumentException("Not a valid mode: "
+ mode);
}
default:
throw new IllegalArgumentException("Not a valid list type: "
+ listType);
}
|
public java.lang.String[] | listPIMLists(int pimListType)Gets the current PIM lists.
checkPermissions(pimListType, PIM.READ_ONLY);
validatePimListType(pimListType);
return PIMHandler.getInstance().getListNames(pimListType);
|
public javax.microedition.pim.PIMList | openPIMList(int pimListType, int mode)Opens the PIM list.
validatePimListType(pimListType);
validateMode(mode);
checkPermissions(pimListType, mode);
String listName = PIMHandler.getInstance()
.getDefaultListName(pimListType);
if (listName == null) {
throw new PIMException("List not available");
}
return openPIMListImpl(pimListType, mode, listName);
|
public javax.microedition.pim.PIMList | openPIMList(int pimListType, int mode, java.lang.String name)Opens the PIM list.
if (name == null) {
throw new NullPointerException("PIM list name cannot be null");
}
validatePimListType(pimListType);
validateMode(mode);
checkPermissions(pimListType, mode);
validateName(pimListType, name);
return openPIMListImpl(pimListType, mode, name);
|
private javax.microedition.pim.PIMList | openPIMListImpl(int pimListType, int mode, java.lang.String name)Does the same as openPIMList, without any validation
AbstractPIMList list;
PIMHandler handler = PIMHandler.getInstance();
Object listHandle = handler.openList(pimListType, name, mode);
switch (pimListType) {
case PIM.CONTACT_LIST:
list = new ContactListImpl(name, mode, listHandle);
break;
case PIM.EVENT_LIST:
list = new EventListImpl(name, mode, listHandle);
break;
case PIM.TODO_LIST:
list = new ToDoListImpl(name, mode, listHandle);
break;
default:
// pimListType has been verified
throw new Error("Unreachable code");
}
Object[] keys = handler.getListKeys(listHandle);
for (int i = 0; i < keys.length; i++) {
byte[] data = handler.getListElement(listHandle, keys[i]);
String [] categories = handler.getListElementCategories(listHandle,
keys[i]);
try {
PIMItem[] items =
fromSerialFormat(new ByteArrayInputStream(data),
"UTF-8", list);
for (int j = 0; j < items.length; j++) {
AbstractPIMItem item = (AbstractPIMItem) items[j];
item.setKey(keys[i]);
list.addItem(item);
item.setDefaultValues();
for (int index = 0; index < categories.length; index ++) {
item.addToCategory(categories[index]);
}
item.setModified(false);
}
} catch (UnsupportedEncodingException e) {
throw new Error("UTF-8 not supported");
} catch (PIMException e) {
// skip element
}
}
return list;
|
public java.lang.String[] | supportedSerialFormats(int pimListType)Gets the list of supported serial formats.
validatePimListType(pimListType);
int supportedFormatCount = 0;
for (int i = 0; i < formats.length; i++) {
if (formats[i].isTypeSupported(pimListType)) {
supportedFormatCount ++;
}
}
String[] supportedFormats = new String[supportedFormatCount];
for (int i = 0; i < formats.length; i++) {
if (formats[i].isTypeSupported(pimListType)) {
supportedFormats[--supportedFormatCount] = formats[i].getName();
}
}
return supportedFormats;
|
public void | toSerialFormat(javax.microedition.pim.PIMItem item, java.io.OutputStream os, java.lang.String enc, java.lang.String dataFormat)Converts to serial format.
if (enc == null) {
enc = "UTF-8" /* NO I18N */;
}
if (dataFormat == null) {
throw new NullPointerException("Null data format");
}
if (dataFormat.trim().length() == 0) {
throw new IllegalArgumentException("Empty data format");
}
if (item == null) {
throw new NullPointerException("Null PIM item");
}
try {
for (int i = 0; i < formats.length; i++) {
if (formats[i].getName().equals(dataFormat)) {
formats[i].encode(os, enc, item);
return;
}
}
throw new IllegalArgumentException("Data format '" + dataFormat
+ "' is not supported");
} catch (UnsupportedEncodingException e) {
throw e;
} catch (IOException e) {
throw new PIMException(e.getMessage());
}
|
private void | validateMode(int mode)Ensures that the given PIM list mode is valid.
switch (mode) {
case READ_ONLY:
case WRITE_ONLY:
case READ_WRITE:
break;
default:
throw new IllegalArgumentException(
"Invalid PIM list mode: " + mode);
}
|
private void | validateName(int pimListType, java.lang.String name)Ensures that the given PIM list name is valid.
String[] names = PIMHandler.getInstance().getListNames(pimListType);
for (int i = 0; i < names.length; i++) {
if (name.equals(names[i])) {
return;
}
}
throw new PIMException("PIM list does not exist: '" + name + "'");
|
private void | validatePimListType(int pimListType)Ensures that the given PIM list type is valid.
switch (pimListType) {
case PIM.CONTACT_LIST:
case PIM.EVENT_LIST:
case PIM.TODO_LIST:
// ok
break;
default:
throw new IllegalArgumentException("Not a valid PIM list type: "
+ pimListType);
}
|