📄 xmlconfig.java
字号:
public static void addAllAccounts(List accounts, boolean save) { for (int i = 0; i < accounts.size(); i++) { AccountInfo account = (AccountInfo) accounts.get(i); addAccount(account, false); } if (save == true) { saveDocument(); } } /** * 删除账号 * * @param info 待删除的账号信息 * @param save 是否立即保存文件 */ public static void deleteAccount(AccountInfo info, boolean save) { String name = info.getPersonalInfo().getName(); Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild("Mail").getChild("Accounts"); List children = child.getChildren(); for (int i = 0; i < children.size(); i++) { Element account = (Element) children.get(i); Element element = account.getChild("Personal"); if (element.getChild(NAME_NODE).getValue().equals(name) == true) { child.removeContent(account); break; } } if (save == true) { saveDocument(); } } /** * 删除所有账号 * * @param save 是否立即保存文件 */ public static void deleteAllAccounts(boolean save) { List accounts = getAllAccounts(); for (int i = 0; i < accounts.size(); i++) { AccountInfo account = (AccountInfo) accounts.get(i); deleteAccount(account, false); } if (save == true) { saveDocument(); } } /** * 返回所有的缓存 * * @return 所有的缓存 */ public static List getAllCaches() { List caches = new ArrayList(); Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(CHAT_NODE).getChild("Caches"); List children = child.getChildren(); for (int i = 0; i < children.size(); i++) { Element cache = (Element) children.get(i); caches.add(cache.getAttributeValue(ID_ATTR)); } return caches; } /** * 返回在线聊天的端口 * * @return 在线聊天的端口 */ public static int getChatPort() { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(CHAT_NODE); return Integer.parseInt(child.getAttributeValue(PORT_ATTR)); } /** * 返回在线聊天的类名 * * @return 在线聊天的类名 */ public static String getChatClass() { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(CHAT_NODE); return child.getAttributeValue(CLASS_ATTR); } /** * 返回在线聊天的方法名 * * @return 在线聊天的方法名 */ public static String getChatMethod() { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(CHAT_NODE); return child.getAttributeValue(METHOD_ATTR); } /** * 添加缓存 * * @param id 待添加的缓存 * @param save 是否立即保存文件 */ public static void addCache(String id, boolean save) { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(CHAT_NODE).getChild("Caches"); List children = child.getChildren(); for (int i = 0; i < children.size(); i++) { Element cache = (Element) children.get(i); if (cache.getAttributeValue(ID_ATTR).equals(id) == true) { child.removeContent(cache); break; } } Element cache = new Element("Cache"); cache.setAttribute(ID_ATTR, id); child.addContent(0, cache); if (save == true) { saveDocument(); } } /** * 删除缓存 * * @param id 待删除的缓存 * @param save 是否立即保存文件 */ public static void deleteCache(String id, boolean save) { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(CHAT_NODE).getChild("Caches"); List children = child.getChildren(); for (int i = 0; i < children.size(); i++) { Element cache = (Element) children.get(i); if (cache.getAttributeValue(ID_ATTR).equals(id) == true) { child.removeContent(cache); break; } } if (save == true) { saveDocument(); } } /** * 返回上传文件的绝对地址 * * @return 上传文件的绝对地址 */ public static String getUploadFile() { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(SHARE_NODE).getChild("Upload"); return child.getAttributeValue("file"); } /** * 返回文件请求的端口 * * @return 文件请求的端口 */ public static int getRequestPort() { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(SHARE_NODE).getChild(DOWNLOAD_NODE); String port = child.getChild("Request").getAttributeValue(PORT_ATTR); return Integer.parseInt(port); } /** * 返回文件请求的类名 * * @return 文件请求的类名 */ public static String getRequestClass() { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(SHARE_NODE).getChild(DOWNLOAD_NODE); return child.getChild("Request").getAttributeValue(CLASS_ATTR); } /** * 返回文件请求的方法名 * * @return 文件请求的方法名 */ public static String getRequestMethod() { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(SHARE_NODE).getChild(DOWNLOAD_NODE); return child.getChild("Request").getAttributeValue(METHOD_ATTR); } /** * 返回文件传输的端口 * * @return 文件传输的端口 */ public static int getTransferPort() { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(SHARE_NODE).getChild(DOWNLOAD_NODE); String port = child.getChild("Transfer").getAttributeValue(PORT_ATTR); return Integer.parseInt(port); } /** * 返回文件传输的类名 * * @return 文件传输的类名 */ public static String getTransferClass() { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(SHARE_NODE).getChild(DOWNLOAD_NODE); return child.getChild("Transfer").getAttributeValue(CLASS_ATTR); } /** * 返回文件传输的方法名 * * @return 文件传输的方法名 */ public static String getTransferMethod() { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(SHARE_NODE).getChild(DOWNLOAD_NODE); return child.getChild("Transfer").getAttributeValue(METHOD_ATTR); } /** * 返回远程服务的IP地址 * * @return 远程服务的IP地址 */ public static String getServicesIP() { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(SERVICES_NODE); return child.getAttributeValue("ip"); } /** * 返回注册服务的端口 * * @return 注册服务的端口 */ public static int getRegisterPort() { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(SERVICES_NODE).getChild("Register"); return Integer.parseInt(child.getAttributeValue(PORT_ATTR)); } /** * 返回注册服务的类名 * * @return 注册服务的类名 */ public static String getRegisterClass() { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(SERVICES_NODE).getChild("Register"); return child.getAttributeValue(CLASS_ATTR); } /** * 返回注册服务的方法名 * * @return 注册服务的方法名 */ public static String getRegisterMethod() { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(SERVICES_NODE).getChild("Register"); return child.getAttributeValue(METHOD_ATTR); } /** * 返回登录服务的端口 * * @return 登录服务的端口 */ public static int getLogonPort() { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(SERVICES_NODE).getChild("Logon"); return Integer.parseInt(child.getAttributeValue(PORT_ATTR)); } /** * 返回登录服务的类名 * * @return 登录服务的类名 */ public static String getLogonClass() { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(SERVICES_NODE).getChild("Logon"); return child.getAttributeValue(CLASS_ATTR); } /** * 返回登录服务的方法名 * * @return 登录服务的方法名 */ public static String getLogonMethod() { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(SERVICES_NODE).getChild("Logon"); return child.getAttributeValue(METHOD_ATTR); } /** * 返回注销服务的端口 * * @return 注销服务的端口 */ public static int getLogoutPort() { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(SERVICES_NODE).getChild("Logout"); return Integer.parseInt(child.getAttributeValue(PORT_ATTR)); } /** * 返回注销服务的类名 * * @return 注销服务的类名 */ public static String getLogoutClass() { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(SERVICES_NODE).getChild("Logout"); return child.getAttributeValue(CLASS_ATTR); } /** * 返回注销服务的方法名 * * @return 注销服务的方法名 */ public static String getLogoutMethod() { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(SERVICES_NODE).getChild("Logout"); return child.getAttributeValue(METHOD_ATTR); } /** * 返回地址服务的端口 * * @return 地址服务的端口 */ public static int getAddressPort() { Document doc = getDocument(); Element root = doc.getRootElement(); Element child = root.getChild(SERVICES_NODE).getChild("Address"); return Integer.parseInt(child.getAttributeValue(PORT_ATTR)); } /** * 返回地址服务的类名 * * @return 地址服务的类名 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -