1 19 package org.lucane.client; 20 21 import javax.xml.parsers.*; 22 23 import org.lucane.common.Logging; 24 import org.w3c.dom.*; 25 26 29 public class ClientConfig 30 { 31 private String login = ""; 33 private String serverHost = null; 34 private int listenerPort = 0; 35 private int serverPort = 9115; 36 private String language = "en"; 37 private String font = null; 38 private String looknfeel = null; 39 private String proxyHost = null; 40 private int proxyPort = 5119; 41 private String publicIpAddress = null; 42 private String publicIpInterface = null; 43 44 49 public ClientConfig(String filename) 50 throws Exception 51 { 52 DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 53 Document document = builder.parse(filename); 54 55 Node node = document.getFirstChild(); 57 while(node != null && node.getNodeType() != Node.ELEMENT_NODE) 58 node = node.getNextSibling(); 59 60 if(node == null || ! node.getNodeName().equals("lucane-client")) 61 throw new Exception ("root element is different from 'lucane-client'"); 62 63 node = node.getFirstChild(); 64 while(node != null) 65 { 66 if(node.getNodeType() == Node.ELEMENT_NODE) 67 { 68 if(node.getNodeName().equals("login")) 69 handleLogin(node); 70 else if(node.getNodeName().equals("server")) 71 handleServer(node); 72 else if(node.getNodeName().equals("language")) 73 handleLanguage(node); 74 else if(node.getNodeName().equals("looknfeel")) 75 handleLooknfeel(node); 76 else if(node.getNodeName().equals("proxy")) 77 handleProxy(node); 78 else if(node.getNodeName().equals("public-ip")) 79 handlePublicIp(node); 80 else if(node.getNodeName().equals("listener")) 81 handleListener(node); 82 else 83 Logging.getLogger().warning("unexepected node : " + node.getNodeName()); 84 } 85 node = node.getNextSibling(); 86 } 87 } 88 89 94 private void handleLogin(Node node) 95 { 96 this.login = node.getAttributes().getNamedItem("value").getNodeValue(); 97 } 98 99 104 private void handleServer(Node node) 105 { 106 this.serverHost = node.getAttributes().getNamedItem("host").getNodeValue(); 107 this.serverPort = Integer.parseInt(node.getAttributes().getNamedItem("port").getNodeValue()); 108 } 109 110 115 private void handleLanguage(Node node) 116 { 117 this.language = node.getAttributes().getNamedItem("value").getNodeValue(); 118 try { 119 this.font = node.getAttributes().getNamedItem("font").getNodeValue(); 120 } catch(Exception e) { 121 this.font = null; 122 } 123 } 124 125 130 private void handleLooknfeel(Node node) 131 { 132 this.looknfeel = node.getAttributes().getNamedItem("class").getNodeValue(); 133 } 134 135 140 private void handleProxy(Node node) 141 { 142 this.proxyHost = node.getAttributes().getNamedItem("host").getNodeValue(); 143 this.proxyPort = Integer.parseInt(node.getAttributes().getNamedItem("port").getNodeValue()); 144 } 145 146 151 private void handlePublicIp(Node node) 152 { 153 if(node.getAttributes().getNamedItem("address") != null) 154 this.publicIpAddress = node.getAttributes().getNamedItem("address").getNodeValue(); 155 156 if(node.getAttributes().getNamedItem("interface") != null) 157 this.publicIpInterface = node.getAttributes().getNamedItem("interface").getNodeValue(); 158 } 159 160 165 private void handleListener(Node node) 166 { 167 this.listenerPort = Integer.parseInt(node.getAttributes().getNamedItem("port").getNodeValue()); 168 } 169 170 172 177 public String getLogin() 178 { 179 return login; 180 } 181 182 187 public String getServerHost() 188 { 189 return serverHost; 190 } 191 192 197 public int getServerPort() 198 { 199 return serverPort; 200 } 201 202 207 public String getLanguage() 208 { 209 return language; 210 } 211 212 217 public String getFont() 218 { 219 return font; 220 } 221 222 227 public String getLooknfeel() 228 { 229 return looknfeel; 230 } 231 232 237 public String getProxyHost() 238 { 239 return proxyHost; 240 } 241 242 247 public int getProxyPort() 248 { 249 return proxyPort; 250 } 251 252 257 public String getPublicIpAddress() 258 { 259 return publicIpAddress; 260 } 261 262 267 public String getPublicIpInterface() 268 { 269 return publicIpInterface; 270 } 271 272 277 public int getListenerPort() 278 { 279 return listenerPort; 280 } 281 } | Popular Tags |