📄 configmanager.java
字号:
initDeviceIdFromJad(midlet);
}
private static int loadRmsSize() {
int size = 512*1024;
try {
RecordStore rs = RecordStore.openRecordStore(MailClientConfig.NAME, true);
size = rs.getSizeAvailable();
rs.closeRecordStore();
} catch (RecordStoreNotOpenException ex) {
Log.error("RecordStoreNotOpenException: " + ex.getMessage());
ex.printStackTrace();
} catch (RecordStoreException ex) {
Log.error("RecordStoreException: " + ex.getMessage());
ex.printStackTrace();
}
return size;
}
/**
* Save the cached mail config, if previously loaded.
*/
public static void saveConfig() throws ConfigException, IOException {
if(mailClientConfig != null) {
save(MailClientConfig.NAME, mailClientConfig);
}
}
/**
* Save the new mail config, and cache it.
*/
public static void saveConfig(MailClientConfig mcc)
throws ConfigException, IOException {
if(mcc != null) {
save(MailClientConfig.NAME, mcc);
mailClientConfig = mcc;
}
}
/** Get the name full of the Mail Client */
public static String getClientName() {
// TODO: get it from jad
//return "Funambol Mail Client";
return clientName;
}
/** Get the version of the mail client */
public static String getClientVersion() {
// TODO: get it from jad
//return "6.0.0";
return clientVersion;
}
/**
* Accessor method to retrieve Storage size
* @return int value of rms storage size.
*/
public int getStorageSize() {
return storageSize;
}
//--------------------------------------------------------- Private Methods
// retrieve account and configuration settings from JAD attributes
private static MailClientConfig getConfigFromJad(MIDlet midlet) {
Log.info("MailClientConfig from JAD or default\n");
MailClientConfig configFromJad = new MailClientConfig();
configFromJad.setMailAccount(getMailAccountFromJad(midlet));
int logLevel = getLogLevelFromJAD(midlet);
configFromJad.setLogLevel(logLevel);
String pollInterval = midlet.getAppProperty(POLL_INTERVAL_ATTR);
if (pollInterval != null && !pollInterval.equals("") ) {
try {
int pollIntervalInt = Integer.parseInt(pollInterval);
configFromJad.setPollInterval(pollIntervalInt);
} catch(NumberFormatException nfe) {
Log.error("Error parsing pollInterval attribute: "
+ nfe.toString());
}
}
boolean flag = StringUtil.getBooleanValue(
midlet.getAppProperty(ENABLE_SCHEDULER_ATTR));
configFromJad.enableScheduler(flag);
flag = StringUtil.getBooleanValue(
midlet.getAppProperty(ENABLE_SMS_LISTENER_ATTR));
configFromJad.enableSmsListener(flag);
flag = StringUtil.getBooleanValue(
midlet.getAppProperty(ENABLE_DELETE_PROPAGATION));
configFromJad.enableDeletePropagation(flag);
return configFromJad;
}
private static int getLogLevelFromJAD(MIDlet midlet) {
String jadStr = midlet.getAppProperty(LOGLEVEL_ATTR);
if ((jadStr == null) || (jadStr.equals(""))) {
return Log.DISABLED;
} else if (StringUtil.equalsIgnoreCase(jadStr, "DISABLED")) {
return Log.DISABLED;
} else if (StringUtil.equalsIgnoreCase(jadStr, "ERROR")) {
return Log.ERROR;
} else if (StringUtil.equalsIgnoreCase(jadStr, "INFO")) {
return Log.INFO;
} else if (StringUtil.equalsIgnoreCase(jadStr, "DEBUG")) {
return Log.DEBUG;
} else if (StringUtil.equalsIgnoreCase(jadStr, "TRACE")) {
return Log.TRACE;
} else {
return Log.ERROR;
}
}
// get account settings from JAD
private static Account getMailAccountFromJad(MIDlet midlet) {
Account mailAccount = new Account();
String user = midlet.getAppProperty(USER_ATTR);
if (StringUtil.isNullOrEmpty(user)) {
Log.info("No user defined in JAD file");
} else {
Log.info("User got from JAD: " + "[" + user + "]");
mailAccount.setUser(user);
}
String url = midlet.getAppProperty(URL_ATTR);
if (StringUtil.isNullOrEmpty(url)) {
Log.info("No url defined in JAD file");
} else {
Log.info("Url got from JAD: " + "[" + url + "]");
mailAccount.setUrl(url);
}
String password = midlet.getAppProperty(PASSWORD_ATTR);
if (StringUtil.isNullOrEmpty(password)) {
Log.info("No password defined in JAD file");
} else {
Log.info("Password got from JAD: " + "[" + password + "]");
mailAccount.setPassword(password);
}
String name = midlet.getAppProperty(NAME_ATTR);
if (StringUtil.isNullOrEmpty(name)) {
Log.info("No name defined in JAD file");
} else {
Log.info("Name got from JAD: " + "[" + name + "]");
mailAccount.setName(name);
}
String address = midlet.getAppProperty(ADDRESS_ATTR);
if (StringUtil.isNullOrEmpty(address)) {
Log.info("No address defined in JAD file");
} else {
Log.info("Address got from JAD: " + "[" + address + "]");
mailAccount.setAddress(address);
}
String remoteURI = midlet.getAppProperty(REMOTEURI_ATTR);
if (StringUtil.isNullOrEmpty(remoteURI)) {
Log.info("No remoteURI defined in JAD file");
} else {
Log.info("RemoteURI got from JAD: " + "[" + remoteURI + "]");
mailAccount.setRemoteURI(remoteURI);
}
String pimRemoteURI = midlet.getAppProperty(PIM_REMOTEURI_ATTR);
if (StringUtil.isNullOrEmpty(pimRemoteURI)) {
Log.info("No pimRemoteURI defined in JAD file");
} else {
Log.info("pimRemoteURI got from JAD: " + "[" + pimRemoteURI + "]");
mailAccount.setPimRemoteURI(pimRemoteURI);
}
return mailAccount;
}
/**
* Get the device ID specifird in the JAD, if present.
* The device ID can be obtained from the JAD to avoid the
* generation of a new dev-id each time the application is installed
* without keeping the old configurration.
* It is mainly intented for debug purposes, but the portal can also
* set this value to have always the same id for a registered device.
*/
private static void initDeviceIdFromJad(MIDlet midlet)
throws ConfigException, IOException {
//Get SyncClientConfig for SyncML specific parameters...
SyncClientConfig syncClientConf = new SyncClientConfig();
//get the device ID from the JAD (if available)
String devID = midlet.getAppProperty(DEVID_ATTR);
if (StringUtil.isNullOrEmpty(devID)) {
Log.info("No device ID defined in JAD file");
} else {
Log.info("Device ID got from JAD: " + "[" + devID + "]");
// ... set device ID in the SyncClientConfig object...
syncClientConf.setDeviceId(devID);
save(SyncClientConfig.CONFIGNAME, syncClientConf);
}
}
public static int getMaxMessageNumber() {
return maxMessageNumber;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -