📄 bloggersettings.java
字号:
/* * Copyright (C) 2004 MobileBlogger Development Team */package net.sourceforge.mobileblogger;import java.io.*;import java.util.*;import javax.microedition.lcdui.*;import javax.microedition.midlet.*;import javax.microedition.rms.*;public class BloggerSettings { // RecordStore name private static final String SETTINGS = "BloggerSettings"; // RecordIDs // Don't modify existing IDs! Add to the end of this list. private static final int USERNAME = 1; private static final int PASSWORD = 2; private static final int HOST = 3; private static final int PORT = 4; private static final int ENDPOINT = 5; private static final int BLOGID = 6; // Default values private static final String DEF_USERNAME = "0"; private static final String DEF_PASSWORD = "0"; private static final String DEF_HOST = "plant.blogger.com"; private static final String DEF_PORT = "80"; private static final String DEF_ENDPOINT = "/api/RPC2"; private static final String DEF_BLOGID = "0"; public static RecordStore getRecordStore() { RecordStore rs = null; try { rs = RecordStore.openRecordStore(SETTINGS, false); } catch(RecordStoreException rse) { } return rs; } public static boolean hasSettings() { RecordStore rs = null; try { rs = RecordStore.openRecordStore(SETTINGS, false); } catch(RecordStoreException rse) { } if(rs == null) return false; else return true; } public static void setDefaults() { RecordStore rs = null; System.out.println("Setting default values!"); try { rs = RecordStore.openRecordStore(SETTINGS, true); rs.addRecord(DEF_USERNAME.getBytes(), 0, DEF_USERNAME.length()); rs.addRecord(DEF_PASSWORD.getBytes(), 0, DEF_PASSWORD.length()); rs.addRecord(DEF_HOST.getBytes(), 0, DEF_HOST.length()); rs.addRecord(DEF_PORT.getBytes(), 0, DEF_PORT.length()); rs.addRecord(DEF_ENDPOINT.getBytes(), 0, DEF_ENDPOINT.length()); rs.addRecord(DEF_BLOGID.getBytes(), 0, DEF_BLOGID.length()); } catch(RecordStoreException rse) { } } private void createRecordStore() { RecordStore rs = null; try { rs = RecordStore.openRecordStore(SETTINGS, true); } catch(RecordStoreException rse) { } } /** * I don't know if this will be useful in the actual program * but it sure helps in debugging! */ public static void printRecords() { RecordStore rs = null; try { rs = RecordStore.openRecordStore(SETTINGS, false); for(int i = 1; i <= 6; i++) { byte[] record = rs.getRecord(i); if(record != null) System.out.println(new String(record)); } } catch(RecordStoreException rse) { rse.printStackTrace(); } } public static String getUsername() { RecordStore rs = null; byte[] username = null; try { rs = RecordStore.openRecordStore(SETTINGS, false); username = rs.getRecord(USERNAME); } catch(RecordStoreException rse) { } return new String(username); } public static String getPassword() { RecordStore rs = null; byte[] password = null; try { rs = RecordStore.openRecordStore(SETTINGS, false); password = rs.getRecord(PASSWORD); } catch(RecordStoreException rse) { } return new String(password); } public static String getHost() { RecordStore rs = null; byte[] host = null; try { rs = RecordStore.openRecordStore(SETTINGS, false); host = rs.getRecord(HOST); } catch(RecordStoreException rse) { } return new String(host); } public static String getPort() { RecordStore rs = null; byte[] port = null; try { rs = RecordStore.openRecordStore(SETTINGS, false); port = rs.getRecord(PORT); } catch(RecordStoreException rse) { } return new String(port); } public static String getEndpoint() { RecordStore rs = null; byte[] endpoint = null; try { rs = RecordStore.openRecordStore(SETTINGS, false); endpoint = rs.getRecord(ENDPOINT); } catch(RecordStoreException rse) { } return new String(endpoint); } public static String getBlogid() { RecordStore rs = null; byte[] blogid = null; try { rs = RecordStore.openRecordStore(SETTINGS, false); blogid = rs.getRecord(BLOGID); } catch(RecordStoreException rse) { } return new String(blogid); } public static void setUsername(String username) { RecordStore rs = null; try { rs = RecordStore.openRecordStore(SETTINGS, false); rs.setRecord(USERNAME, username.getBytes(), 0, username.length()); } catch(RecordStoreException rse) { } } public static void setPassword(String password) { RecordStore rs = null; try { rs = RecordStore.openRecordStore(SETTINGS, false); rs.setRecord(PASSWORD, password.getBytes(), 0, password.length()); } catch(RecordStoreException rse) { } } public static void setHost(String host) { RecordStore rs = null; try { rs = RecordStore.openRecordStore(SETTINGS, false); rs.setRecord(HOST, host.getBytes(), 0, host.length()); } catch(RecordStoreException rse) { } } public static void setPort(String port) { RecordStore rs = null; try { rs = RecordStore.openRecordStore(SETTINGS, false); rs.setRecord(PORT, port.getBytes(), 0, port.length()); } catch(RecordStoreException rse) { } } public static void setEndpoint(String endpoint) { RecordStore rs = null; try { rs = RecordStore.openRecordStore(SETTINGS, false); rs.setRecord(ENDPOINT, endpoint.getBytes(), 0, endpoint.length()); } catch(RecordStoreException rse) { } } public static void setBlogid(String blogid) { RecordStore rs = null; try { rs = RecordStore.openRecordStore(SETTINGS, false); rs.setRecord(BLOGID, blogid.getBytes(), 0, blogid.length()); } catch(RecordStoreException rse) { } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -