Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 package zirc.xml ; 2 3 import java.io.* ; 4 import java.util.* ; 5 import javax.xml.parsers.* ; 6 import javax.xml.transform.* ; 7 import javax.xml.transform.dom.* ; 8 import javax.xml.transform.stream.* ; 9 10 import org.w3c.dom.* ; 11 import org.xml.sax.* ; 12 13 26 33 34 35 36 public class XmlConfig 37 { 38 private Document document ; 39 private final String configFile = "fichiers/config.xml" ; 40 41 public XmlConfig() 42 { 43 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance() ; 44 factory.setNamespaceAware(true) ; 46 47 try 48 { 49 DocumentBuilder builder = factory.newDocumentBuilder() ; 50 document = builder.parse(configFile) ; 51 } 52 53 catch (SAXException sxe) 54 { 55 Exception x = sxe ; 57 if (sxe.getException() != null) 58 { 59 x = sxe.getException() ; 60 } 61 x.printStackTrace() ; 62 } 63 catch (ParserConfigurationException pce) 64 { 65 pce.printStackTrace() ; 67 } 68 catch (IOException ioe) 69 { 70 ioe.printStackTrace() ; 72 } 73 } 74 75 public ArrayList getOptionTreeNode0() 77 { 78 NodeList listeElementsEnDOM = document.getElementsByTagName("level0") ; 79 ArrayList liste = new ArrayList() ; 80 for (int i = 0 ; i < listeElementsEnDOM.getLength() ; i++) 81 { 82 if (listeElementsEnDOM.item(i).getChildNodes().getLength() 83 == 1) 84 { 85 Text texte ; 86 87 texte = (Text)listeElementsEnDOM.item(i).getChildNodes().item(0 88 ) ; 89 liste.add(texte.getNodeValue()) ; 90 } 91 } 92 return liste ; 93 } 94 95 public ArrayList getOptionTreeNode1() 97 { 98 NodeList listeElementsEnDOM = document.getElementsByTagName("level1") ; 99 ArrayList liste = new ArrayList() ; 100 for (int i = 0 ; i < listeElementsEnDOM.getLength() ; i++) 101 { 102 if (listeElementsEnDOM.item(i).getChildNodes().getLength() == 1) 103 { 104 Text texte ; 105 106 texte = (Text)listeElementsEnDOM.item(i).getChildNodes().item(0) ; 107 liste.add(texte.getNodeValue()) ; 108 } 109 } 110 return liste ; 111 } 112 113 public ArrayList getOnConnectActions() 114 { 115 NodeList listeElementsEnDOM = document.getElementsByTagName("onconnect") ; 116 ArrayList liste = new ArrayList() ; 117 for (int i = 0 ; i < listeElementsEnDOM.getLength() ; i++) 118 { 119 if (listeElementsEnDOM.item(i).getChildNodes().getLength() == 1) 120 { 121 Text texte ; 122 123 texte = (Text)listeElementsEnDOM.item(i).getChildNodes().item(0) ; 124 liste.add(texte.getNodeValue().toString()) ; 125 } 126 } 127 return liste ; 128 } 129 130 public String getUserName() 131 { 132 NodeList listeElementsEnDOM = document.getElementsByTagName("name") ; 133 return listeElementsEnDOM.item(0).getChildNodes().item(0).toString() ; 134 } 135 136 public String getUserNick() 137 { 138 NodeList listeElementsEnDOM = document.getElementsByTagName("nick") ; 139 return listeElementsEnDOM.item(0).getChildNodes().item(0).toString() ; 140 } 141 142 public String getUserEmail() 143 { 144 NodeList listeElementsEnDOM = document.getElementsByTagName("email") ; 145 return listeElementsEnDOM.item(0).getChildNodes().item(0).toString() ; 146 } 147 148 public String getServer() 149 { 150 NodeList listeElementsEnDOM = document.getElementsByTagName("serveur") ; 151 return listeElementsEnDOM.item(0).getChildNodes().item(0).toString() ; 152 } 153 154 public String getPorts() 155 { 156 NodeList listeElementsEnDOM = document.getElementsByTagName("ports") ; 157 return listeElementsEnDOM.item(0).getChildNodes().item(0).toString() ; 158 } 159 160 public String getSonIsEnabled() 161 { 162 NodeList listeElementsEnDOM = document.getElementsByTagName("son") ; 163 return listeElementsEnDOM.item(0).getChildNodes().item(0).toString() ; 164 } 165 166 public String getUserQuitMSG() 167 { 168 NodeList listeElementsEnDOM = document.getElementsByTagName("quitmsg") ; 169 return listeElementsEnDOM.item(0).getChildNodes().item(0).toString() ; 170 } 171 172 public String getUserPartMSG() 173 { 174 NodeList listeElementsEnDOM = document.getElementsByTagName("partmsg") ; 175 return listeElementsEnDOM.item(0).getChildNodes().item(0).toString() ; 176 } 177 178 public void setUserName(String name) 179 { 180 NodeList listeElementsEnDOM = document.getElementsByTagName("name") ; 181 listeElementsEnDOM.item(0).getChildNodes().item(0).setNodeValue(name.trim()) ; 182 } 183 184 public void setUserNick(String nick) 185 { 186 NodeList listeElementsEnDOM = document.getElementsByTagName("nick") ; 187 listeElementsEnDOM.item(0).getChildNodes().item(0).setNodeValue(nick.trim()) ; 188 } 189 190 public void setUserEmail(String email) 191 { 192 NodeList listeElementsEnDOM = document.getElementsByTagName("email") ; 193 listeElementsEnDOM.item(0).getChildNodes().item(0).setNodeValue(email.trim()) ; 194 } 195 196 public void setPorts(String ports) 197 { 198 NodeList listeElementsEnDOM = document.getElementsByTagName("ports") ; 199 listeElementsEnDOM.item(0).getChildNodes().item(0).setNodeValue(ports.trim()) ; 200 } 201 202 public void setSonsActives(String bool) 203 { 204 NodeList listeElementsEnDOM = document.getElementsByTagName("son") ; 205 listeElementsEnDOM.item(0).getChildNodes().item(0).setNodeValue(bool.trim()) ; 206 } 207 208 public void setServer(String server) 209 { 210 NodeList listeElementsEnDOM = document.getElementsByTagName("serveur") ; 211 listeElementsEnDOM.item(0).getChildNodes().item(0).setNodeValue(server.trim()) ; 212 } 213 214 public void setOnConnectActions(String text) 215 { 216 NodeList listeElementsEnDOM = document.getElementsByTagName("onconnect") ; 217 listeElementsEnDOM.item(0).getChildNodes().item(0).setNodeValue(text.trim()) ; 218 } 219 220 public void setUserQuitMSG(String quitMSG) 221 { 222 NodeList listeElementsEnDOM = document.getElementsByTagName("quitmsg") ; 223 listeElementsEnDOM.item(0).getChildNodes().item(0).setNodeValue(quitMSG.trim()) ; 224 } 225 226 public void setUserPartMSG(String partMSG) 227 { 228 NodeList listeElementsEnDOM = document.getElementsByTagName("partmsg") ; 229 listeElementsEnDOM.item(0).getChildNodes().item(0).setNodeValue(partMSG.trim()) ; 230 } 231 232 public void saveXmlConfig() 233 { 234 try 235 { 236 DOMSource domSource = new DOMSource(document) ; 237 StreamResult fluxDestination = new StreamResult(new File(configFile)) ; 238 TransformerFactory fabrique = TransformerFactory.newInstance() ; 239 Transformer transformationIdentite = null ; 240 transformationIdentite = fabrique.newTransformer() ; 241 transformationIdentite.transform(domSource, fluxDestination) ; 242 } 243 catch (TransformerConfigurationException ex1) 244 { 245 } 246 catch (TransformerException ex) 247 { 248 } 249 } 250 251 } 252
| Popular Tags
|