Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/jabbee/util/ConfigWriter.java


1   /*
2    * ConfigWriter.java
3    *
4    * Created on November 1, 2002, 8:03 AM
5    *
6    *
7    * License:
8    *
9    * The contents of this file are subject to the Jabber Open Source
10   * License Version 1.0 (the "License"). You may not copy or use this
11   * file, in either source code or executable form, except in compliance
12   * with the License. You may obtain a copy of the License at
13   * http://www.jabber.com/license/ or at http://www.opensource.org/.
14   * Software distributed under the License is distributed on an "AS IS" 
15   * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
16   * the License for the specific language governing rights and limitations
17   * under the License.
18   *
19   * Copyrights:
20   *
21   * Portions created by or assigned to Jabber.com, Inc. are Copyright
22   * (c) 1999-2000 Jabber.com, Inc. All Rights Reserved. Contact information
23   * for Jabber.com, Inc. is available at http://www.jabber.com/. Portions
24   * Copyright (c) 1998-1999 Jeremie Miller.
25   *
26   * Acknowledgements:
27   *
28   * Special thanks to the Jabber Open Source Contributors for their
29   * suggestions and support of Jabber.
30   *
31   */
32  
33  package org.jabbee.util;
34  
35  import java.io.File;
36  import java.io.FileOutputStream;
37  import java.io.IOException;
38  import javax.swing.JOptionPane;
39  import javax.xml.transform.dom.DOMSource;
40  import javax.xml.transform.stream.StreamResult;
41  import javax.xml.transform.Transformer;
42  import javax.xml.transform.TransformerException;
43  import javax.xml.transform.TransformerFactory;
44  import org.jabbee.Jabbee;
45  import org.jabbee.util.ConfigHandler;
46  import org.w3c.dom.Document;
47  import org.w3c.dom.Element;
48  import org.w3c.dom.NamedNodeMap;
49  import org.w3c.dom.Node;
50  import org.w3c.dom.NodeList;
51  import org.w3c.dom.Text;
52  
53  /**
54   * Obtains information from the panels and writes out the values to the jabber
55   * configuration file.
56   *
57   * @author  Gregory Kaczmarczyk
58   *
59   * @version 0.02
60   */
61  public final class ConfigWriter extends ConfigHandler {
62      
63      /** Creates a new instance of ConfigWriter */
64      public ConfigWriter(Document d, File f) {
65          configDoc = d;
66          configFile = f;
67      }
68  
69      public void run() {
70          try {
71              sleep(5);
72              writeOutPanelData();
73          } catch (InterruptedException ex) {
74          }
75      }
76  
77      private void writeOutPanelData() {
78          Element root = configDoc.getDocumentElement();
79          NodeList firstChildren = root.getChildNodes();
80  
81          String[] genFields   = general.getAllFields();
82          boolean[] genChecks  = general.getCheckBoxes();
83          String[][] adminIDs  = general.getAdminIDs();
84          String filMaxSize    = filters.getMaxSize();
85          boolean[] filChecks  = filters.getCheckBoxValues();
86          String[] logFields   = logging.getFields();
87          boolean logStdErr    = logging.getStdErr();
88          String[] sysFields   = filesystem.getFields();
89          boolean secUseSSL    = security.isSSLEnabled();
90          String[][] secSSL    = security.getSSLValues();
91          String[][] secNet    = security.getNetworks();
92          String[][] conClient = connections.getClientPorts();
93          String[][] conServer = connections.getServerPorts();
94          String[] conFields   = connections.getFieldValues();
95          boolean conLegacy    = connections.getLegacy();
96          String[] ioFields    = inputOutput.getFieldValues();
97          boolean ioKarma      = inputOutput.getConfigureKarma();
98          String[] compFields  = components.getFieldValues();
99          boolean[] compUpdate = components.getUpdate();
100         String[][] compRooms = components.getConfRooms();
101 
102         String tagName = "";
103         NamedNodeMap attList;
104         Node attr;
105         String idAttr = "";
106         boolean[] logUpdated = { false, false };
107         boolean judChanged = false;
108         boolean confChanged = false;
109         String confID = "";
110 
111      for (int i = 0; i < firstChildren.getLength(); i++) {
112             Node child = firstChildren.item(i);
113             if (child instanceof Element) {
114                 // Manage first children
115                 tagName = child.getNodeName();
116                 if (tagName.equals("service")) {
117                     attList = child.getAttributes();
118                     for (int j = 0; j < attList.getLength(); j++) {
119                         attr = attList.item(j);
120                         if (!(attr.getNodeName().equals("id")))
121                             continue;
122                         idAttr = attr.getNodeValue();
123 
124                         if (idAttr.equals("sessions")) {
125                             simulateXPathGetNode(child, "/host/jabberd:cmdline").getFirstChild().setNodeValue(genFields[0]);
126                             simulateXPathGetNode(child, "/jsm/filter/max_size").getFirstChild().setNodeValue(filMaxSize);
127                             if (simulateXPathPathExists(child, "/jsm/filter/allow/conditions/ns")) {
128                                 if (!filChecks[0])
129                                     simulateXPathGetNode(child, "/jsm/filter/allow/conditions").removeChild(simulateXPathGetNode(child, "/jsm/filter/allow/conditions/ns"));
130                             } else {
131                                 if (filChecks[0]) {
132                                     Element nsElement = configDoc.createElement("ns");
133                                     simulateXPathGetNode(child, "/jsm/filter/allow/conditions").appendChild(nsElement);
134                                 }
135                             }
136                             if (simulateXPathPathExists(child, "/jsm/filter/allow/conditions/unavailable")) {
137                                 if (!filChecks[1])
138                                     simulateXPathGetNode(child, "/jsm/filter/allow/conditions").removeChild(simulateXPathGetNode(child, "/jsm/filter/allow/conditions/unavailable"));
139                             } else {
140                                 if (filChecks[1]) {
141                                     Element unavailableElement = configDoc.createElement("unavailable");
142                                     simulateXPathGetNode(child, "/jsm/filter/allow/conditions").appendChild(unavailableElement);
143                                 }
144                             }
145                             if (simulateXPathPathExists(child, "/jsm/filter/allow/conditions/from")) {
146                                 if (!filChecks[2])
147                                     simulateXPathGetNode(child, "/jsm/filter/allow/conditions").removeChild(simulateXPathGetNode(child, "/jsm/filter/allow/conditions/from"));
148                             } else {
149                                 if (filChecks[2]) {
150                                     Element fromElement = configDoc.createElement("from");
151                                     simulateXPathGetNode(child, "/jsm/filter/allow/conditions").appendChild(fromElement);
152                                 }
153                             }
154                             if (simulateXPathPathExists(child, "/jsm/filter/allow/conditions/resource")) {
155                                 if (!filChecks[3])
156                                     simulateXPathGetNode(child, "/jsm/filter/allow/conditions").removeChild(simulateXPathGetNode(child, "/jsm/filter/allow/conditions/resource"));
157                             } else {
158                                 if (filChecks[3]) {
159                                     Element resourceElement = configDoc.createElement("resource");
160                                     simulateXPathGetNode(child, "/jsm/filter/allow/conditions").appendChild(resourceElement);
161                                 }
162                             }
163                             if (simulateXPathPathExists(child, "/jsm/filter/allow/conditions/subject")) {
164                                 if (!filChecks[4])
165                                     simulateXPathGetNode(child, "/jsm/filter/allow/conditions").removeChild(simulateXPathGetNode(child, "/jsm/filter/allow/conditions/subject"));
166                             } else {
167                                 if (filChecks[4]) {
168                                     Element subjectElement = configDoc.createElement("subject");
169                                     simulateXPathGetNode(child, "/jsm/filter/allow/conditions").appendChild(subjectElement);
170                                 }
171                             }
172                             if (simulateXPathPathExists(child, "/jsm/filter/allow/conditions/body")) {
173                                 if (!filChecks[5])
174                                     simulateXPathGetNode(child, "/jsm/filter/allow/conditions").removeChild(simulateXPathGetNode(child, "/jsm/filter/allow/conditions/body"));
175                             } else {
176                                 if (filChecks[5]) {
177                                     Element bodyElement = configDoc.createElement("body");
178                                     simulateXPathGetNode(child, "/jsm/filter/allow/conditions").appendChild(bodyElement);
179                                 }
180                             }
181                             if (simulateXPathPathExists(child, "/jsm/filter/allow/conditions/show")) {
182                                 if (!filChecks[6])
183                                     simulateXPathGetNode(child, "/jsm/filter/allow/conditions").removeChild(simulateXPathGetNode(child, "/jsm/filter/allow/conditions/show"));
184                             } else {
185                                 if (filChecks[6]) {
186                                     Element showElement = configDoc.createElement("show");
187                                     simulateXPathGetNode(child, "/jsm/filter/allow/conditions").appendChild(showElement);
188                                 }
189                             }
190                             if (simulateXPathPathExists(child, "/jsm/filter/allow/conditions/type")) {
191                                 if (!filChecks[7])
192                                     simulateXPathGetNode(child, "/jsm/filter/allow/conditions").removeChild(simulateXPathGetNode(child, "/jsm/filter/allow/conditions/type"));
193                             } else {
194                                 if (filChecks[7]) {
195                                     Element typeElement = configDoc.createElement("type");
196                                     simulateXPathGetNode(child, "/jsm/filter/allow/conditions").appendChild(typeElement);
197                                 }
198                             }
199                             if (simulateXPathPathExists(child, "/jsm/filter/allow/conditions/roster")) {
200                                 if (!filChecks[8])
201                                     simulateXPathGetNode(child, "/jsm/filter/allow/conditions").removeChild(simulateXPathGetNode(child, "/jsm/filter/allow/conditions/roster"));
202                             } else {
203                                 if (filChecks[8]) {
204                                     Element rosterElement = configDoc.createElement("roster");
205                                     simulateXPathGetNode(child, "/jsm/filter/allow/conditions").appendChild(rosterElement);
206                                 }
207                             }
208                             if (simulateXPathPathExists(child, "/jsm/filter/allow/conditions/group")) {
209                                 if (!filChecks[9])
210                                     simulateXPathGetNode(child, "/jsm/filter/allow/conditions").removeChild(simulateXPathGetNode(child, "/jsm/filter/allow/conditions/group"));
211                             } else {
212                                 if (filChecks[9]) {
213                                     Element groupElement = configDoc.createElement("group");
214                                     simulateXPathGetNode(child, "/jsm/filter/allow/conditions").appendChild(groupElement);
215                                 }
216                             }
217                             if (simulateXPathPathExists(child, "/jsm/filter/allow/actions/error")) {
218                                 if (!filChecks[10])
219                                     simulateXPathGetNode(child, "/jsm/filter/allow/actions").removeChild(simulateXPathGetNode(child, "/jsm/filter/allow/actions/error"));
220                             } else {
221                                 if (filChecks[10]) {
222                                     Element errorElement = configDoc.createElement("error");
223                                     simulateXPathGetNode(child, "/jsm/filter/allow/actions").appendChild(errorElement);
224                                 }
225                             }
226                             if (simulateXPathPathExists(child, "/jsm/filter/allow/actions/offline")) {
227                                 if (!filChecks[11])
228                                     simulateXPathGetNode(child, "/jsm/filter/allow/actions").removeChild(simulateXPathGetNode(child, "/jsm/filter/allow/actions/offline"));
229                             } else {
230                                 if (filChecks[11]) {
231                                     Element offlineElement = configDoc.createElement("offline");
232                                     simulateXPathGetNode(child, "/jsm/filter/allow/actions").appendChild(offlineElement);
233                                 }
234                             }
235                             if (simulateXPathPathExists(child, "/jsm/filter/allow/actions/forward")) {
236                                 if (!filChecks[12])
237                                     simulateXPathGetNode(child, "/jsm/filter/allow/actions").removeChild(simulateXPathGetNode(child, "/jsm/filter/allow/actions/forward"));
238                             } else {
239                                 if (filChecks[12]) {
240                                     Element forwardElement = configDoc.createElement("forward");
241                                     simulateXPathGetNode(child, "/jsm/filter/allow/actions").appendChild(forwardElement);
242                                 }
243                             }
244                             if (simulateXPathPathExists(child, "/jsm/filter/allow/actions/reply")) {
245                                 if (!filChecks[13])
246                                     simulateXPathGetNode(child, "/jsm/filter/allow/actions").removeChild(simulateXPathGetNode(child, "/jsm/filter/allow/actions/reply"));
247                             } else {
248                                 if (filChecks[13]) {
249                                     Element replyElement = configDoc.createElement("reply");
250                                     simulateXPathGetNode(child, "/jsm/filter/allow/actions").appendChild(replyElement);
251                                 }
252                             }
253                             if (simulateXPathPathExists(child, "/jsm/filter/allow/actions/continue")) {
254                                 if (!filChecks[14])
255                                     simulateXPathGetNode(child, "/jsm/filter/allow/actions").removeChild(simulateXPathGetNode(child, "/jsm/filter/allow/actions/continue"));
256                             } else {
257                                 if (filChecks[14]) {
258                                     Element continueElement = configDoc.createElement("continue");
259                                     simulateXPathGetNode(child, "/jsm/filter/allow/actions").appendChild(continueElement);
260                                 }
261                             }
262                             if (simulateXPathPathExists(child, "/jsm/filter/allow/actions/settype")) {
263                                 if (!filChecks[15])
264                                     simulateXPathGetNode(child, "/jsm/filter/allow/actions").removeChild(simulateXPathGetNode(child, "/jsm/filter/allow/actions/settype"));
265                             } else {
266                                 if (filChecks[15]) {
267                                     Element settypeElement = configDoc.createElement("settype");
268                                     simulateXPathGetNode(child, "/jsm/filter/allow/actions").appendChild(settypeElement);
269                                 }
270                             }
271                             simulateXPathGetNode(child, "/jsm/vCard/FN").getFirstChild().setNodeValue(genFields[1]);
272                             simulateXPathGetNode(child, "/jsm/vCard/DESC").getFirstChild().setNodeValue(genFields[2]);
273                             simulateXPathGetNode(child, "/jsm/vCard/URL").getFirstChild().setNodeValue(genFields[3]);
274                             simulateXPathGetAttributeNode(child, "/jsm/register", "notify").setNodeValue(genChecks[1] ? "yes" : "no");
275                             simulateXPathGetNode(child, "/jsm/register/instructions").getFirstChild().setNodeValue(genFields[7]);
276                             // welcome message
277                             if (simulateXPathPathExists(child, "/jsm/welcome/subject")) {
278                                 if (genChecks[2]) {
279                                     simulateXPathGetNode(child, "/jsm/welcome/subject").getFirstChild().setNodeValue(genFields[8]);
280                                     simulateXPathGetNode(child, "/jsm/welcome/body").getFirstChild().setNodeValue(genFields[9]);
281                                 } else {
282                                     simulateXPathGetNode(child, "/jsm").removeChild(simulateXPathGetNode(child, "/jsm/welcome"));
283                                 }
284                             } else {
285                                 if (genChecks[2]) {
286                                     Element welcomeElement = configDoc.createElement("welcome");
287                                     Element welcomeSubjectElement = configDoc.createElement("subject");
288                                     Element welcomeBodyElement = configDoc.createElement("body");
289                                     welcomeSubjectElement.appendChild(configDoc.createTextNode(genFields[8]));
290                                     welcomeBodyElement.appendChild(configDoc.createTextNode(genFields[9]));
291                                     welcomeElement.appendChild(welcomeSubjectElement);
292                                     welcomeElement.appendChild(welcomeBodyElement);
293                                     Node nextNode;
294                                     if (simulateXPathPathExists(child, "/jsm/admin"))
295                                         nextNode = simulateXPathGetNode(child, "/jsm/admin");
296                                     if (simulateXPathPathExists(child, "/jsm/update"))
297                                         nextNode = simulateXPathGetNode(child, "/jsm/update");
298                                     if (simulateXPathPathExists(child, "/jsm/vcard2jud"))
299                                         nextNode = simulateXPathGetNode(child, "/jsm/vcard2jud");
300                                     else
301                                         nextNode = simulateXPathGetNode(child, "/jsm/browse");
302                                     simulateXPathGetNode(child, "/jsm").insertBefore(welcomeElement, nextNode);
303                                 }
304                             }
305                             if (simulateXPathPathExists(child, "/jsm/admin")) {
306                                 if (adminIDs.length > 0) {
307                                     Node adminNode = simulateXPathGetNode(child, "/jsm/admin");
308                                     //first remove all admins before adding new ones...
309                                     for (int k = 0; k < adminNode.getChildNodes().getLength(); k++) {
310                                         if (adminNode.getChildNodes().item(k).getNodeName().equals("read") || adminNode.getChildNodes().item(k).getNodeName().equals("write"))
311                                             adminNode.removeChild(adminNode.getChildNodes().item(k));
312                                     }
313                                     for (int k = 0; k < adminIDs.length; k++) {
314                                         Element admin = configDoc.createElement(adminIDs[k][1]);
315                                         admin.appendChild(configDoc.createTextNode(adminIDs[k][0]));
316                                         adminNode.appendChild(admin);
317                                     }
318                                     simulateXPathGetNode(child, "/jsm/admin/reply/subject").getFirstChild().setNodeValue(genFields[5]);
319                                     simulateXPathGetNode(child, "/jsm/admin/reply/body").getFirstChild().setNodeValue(genFields[6]);
320                                 } else {
321                                     // remove existing admin section...
322                                     simulateXPathGetNode(child, "/jsm").removeChild(simulateXPathGetNode(child, "/jsm/admin"));
323                                 }
324                             } else {
325                                 if (adminIDs.length > 0) {
326                                     Element adminElement = configDoc.createElement("admin");
327                                     Element adminAccessElement;
328                                     for (int k = 0; k < adminIDs.length; k++) {
329                                         adminAccessElement = configDoc.createElement(adminIDs[k][1]);
330                                         adminAccessElement.appendChild(configDoc.createTextNode(adminIDs[k][0]));
331                                         adminElement.appendChild(adminAccessElement);
332                                     }
333                                     Element adminReplyElement = configDoc.createElement("reply");
334                                     Element adminReplySubjectElement = configDoc.createElement("subject");
335                                     Element adminReplyBodyElement = configDoc.createElement("body");
336                                     adminReplySubjectElement.appendChild(configDoc.createTextNode(genFields[5]));
337                                     adminReplyBodyElement.appendChild(configDoc.createTextNode(genFields[6]));
338                                     adminReplyElement.appendChild(adminReplySubjectElement);
339                                     adminReplyElement.appendChild(adminReplyBodyElement);
340                                     adminElement.appendChild(adminReplyElement);
341                                 }
342                             }
343                             if (simulateXPathPathExists(child, "/jsm/update/jabberd:cmdline")) {
344                                 if (genChecks[0])
345                                     simulateXPathGetNode(child, "/jsm/update/jabberd:cmdline").getFirstChild().setNodeValue(genFields[4]);
346                                 else
347                                     simulateXPathGetNode(child, "/jsm").removeChild(simulateXPathGetNode(child, "/jsm/update"));
348                             } else {
349                                 if (genChecks[0]) {
350                                     // If the update node doesn't exist or is commented out.
351                                     Element updateElement = configDoc.createElement("update");
352                                     Element jabberdUpdateElement = configDoc.createElement("jabberd:cmdline");
353                                     jabberdUpdateElement.setAttribute("flag", "h");
354                                     updateElement.appendChild(jabberdUpdateElement);
355                                     Text jabberdUpdateText = configDoc.createTextNode(genFields[4]);
356                                     jabberdUpdateElement.appendChild(jabberdUpdateText);
357                                     // this rather long line test for the vcard2jud node. If found, update will
358                                     // be inserted before it. If not found, it will be inserted before the 
359                                     // browse node
360                                     simulateXPathGetNode(child, "/jsm").insertBefore(updateElement, ((simulateXPathPathExists(child, "/jsm/vcard2jud")) ? (simulateXPathGetNode(child, "/jsm/vcard2jud")) : (simulateXPathGetNode(child, "/jsm/browse"))));
361                                 }
362                             }
363                             if (simulateXPathPathExists(child, "/jsm/vcard2jud")) {
364                                 if (!compUpdate[0])
365                                     simulateXPathGetNode(child, "/jsm").removeChild(simulateXPathGetNode(child, "/jsm/vcard2jud"));
366                             } else {
367                                 if (compUpdate[0]) {
368                                     Element vcard2judElement = configDoc.createElement("vcard2jud");
369                                     simulateXPathGetNode(child, "/jsm").insertBefore(vcard2judElement, simulateXPathGetNode(child, "/jsm/browse"));
370                                 }
371                             }
372                             Node browseNode = simulateXPathGetNode(child, "/jsm/browse");
373                             boolean judModified = false;
374                             boolean confModified = false;
375                             for (int k = 0; k < browseNode.getChildNodes().getLength(); k++) {
376                                 if (!(browseNode.getChildNodes().item(k) instanceof Element)) continue;
377                                 Element serviceElement = (Element)browseNode.getChildNodes().item(k);
378                                 if (serviceElement.getNodeName().equals("service") && !judModified) {
379                                     if (serviceElement.getAttribute("type").equals("jud")) {
380                                         serviceElement.setAttribute("jid", compFields[1]);
381                                         serviceElement.setAttribute("name", compFields[0]);
382                                         judModified = true; // to modify only the first instance
383                                         //break;
384                                     }
385                                 } else if (serviceElement.getNodeName().equals("conference")) {
386                                     // get rid of conferencing
387                                     if (compFields[6].equals("")) {
388                                         confID = serviceElement.getAttribute("jid");
389                                         serviceElement.getParentNode().removeChild(serviceElement);
390                                         confModified = true;
391                                         continue;
392                                     }
393                                     serviceElement.setAttribute("type", compFields[7]);
394                                     // confID is used to find the service description if it already exists
395                                     confID = serviceElement.getAttribute("jid");
396                                     serviceElement.setAttribute("jid", compFields[9]);
397                                     serviceElement.setAttribute("name", compFields[6]);
398                                     confModified = true;
399                                 }
400                             }
401                             // so we don't have a jud entry...
402                             if (!judModified) {
403                                 Element judServiceElement = configDoc.createElement("service");
404                                 judServiceElement.setAttribute("type", "jud");
405                                 judServiceElement.setAttribute("jid", compFields[1]);
406                                 judServiceElement.setAttribute("name", compFields[0]);
407                                 Element judNS1Element = configDoc.createElement("ns");
408                                 judNS1Element.appendChild(configDoc.createTextNode("jabber:iq:search"));
409                                 judServiceElement.appendChild(judNS1Element);
410                                 Element judNS2Element = configDoc.createElement("ns");
411                                 judNS2Element.appendChild(configDoc.createTextNode("jabber:iq:search"));
412                                 judServiceElement.appendChild(judNS2Element);
413                                 browseNode.appendChild(judServiceElement);
414                             }
415                             // must create new conference entry...
416                             if (!confModified) {
417                                 Element confServiceElement = configDoc.createElement("conference");
418                                 confServiceElement.setAttribute("type", compFields[7]);
419                                 confServiceElement.setAttribute("jid", compFields[9]);
420                                 confServiceElement.setAttribute("name", compFields[6]);
421                                 browseNode.appendChild(confServiceElement);
422                             }
423                         } else if (idAttr.equals("c2s")) {
424                             simulateXPathGetNode(child, "/load/pthsock_client").getFirstChild().setNodeValue(conFields[1]);
425                             Node authtimeNode = simulateXPathGetNode(child, "/pthcsock/authtime");
426                             if (authtimeNode.hasChildNodes()) {
427                                 if (conFields[0].length() > 0)
428                                     authtimeNode.getFirstChild().setNodeValue(conFields[0]);
429                                 else
430                                     authtimeNode.removeChild(authtimeNode.getFirstChild());
431                             } else {
432                                 if (conFields[0].length() > 0)
433                                     authtimeNode.appendChild(configDoc.createTextNode(conFields[0]));
434                             }
435                             Node pthcsockNode = simulateXPathGetNode(child, "/pthcsock");
436                             if (conFields[2].length() > 0) {
437                                 if (simulateXPathPathExists(pthcsockNode, "/karma")) {
438                                     simulateXPathGetNode(pthcsockNode, "/karma/init").getFirstChild().setNodeValue(conFields[2]);
439                                     simulateXPathGetNode(pthcsockNode, "/karma/max").getFirstChild().setNodeValue(conFields[3]);
440                                     simulateXPathGetNode(pthcsockNode, "/karma/inc").getFirstChild().setNodeValue(conFields[4]);
441                                     simulateXPathGetNode(pthcsockNode, "/karma/dec").getFirstChild().setNodeValue(conFields[5]);
442                                     simulateXPathGetNode(pthcsockNode, "/karma/penalty").getFirstChild().setNodeValue(conFields[6]);
443                                     simulateXPathGetNode(pthcsockNode, "/karma/restore").getFirstChild().setNodeValue(conFields[7]);
444                                 } else {
445                                     Element cKarmaElement = configDoc.createElement("karma");
446                                     Element cKarmaInitElement = configDoc.createElement("init");
447                                     cKarmaInitElement.appendChild(configDoc.createTextNode(conFields[2]));
448                                     cKarmaElement.appendChild(cKarmaInitElement);
449                                     Element cKarmaMaxElement = configDoc.createElement("max");
450                                     cKarmaMaxElement.appendChild(configDoc.createTextNode(conFields[3]));
451                                     cKarmaElement.appendChild(cKarmaMaxElement);
452                                     Element cKarmaIncElement = configDoc.createElement("inc");
453                                     cKarmaIncElement.appendChild(configDoc.createTextNode(conFields[4]));
454                                     cKarmaElement.appendChild(cKarmaIncElement);
455                                     Element cKarmaDecElement = configDoc.createElement("dec");
456                                     cKarmaDecElement.appendChild(configDoc.createTextNode(conFields[5]));
457                                     cKarmaElement.appendChild(cKarmaDecElement);
458                                     Element cKarmaPenaltyElement = configDoc.createElement("penalty");
459                                     cKarmaPenaltyElement.appendChild(configDoc.createTextNode(conFields[6]));
460                                     cKarmaElement.appendChild(cKarmaPenaltyElement);
461                                     Element cKarmaRestoreElement = configDoc.createElement("restore");
462                                     cKarmaRestoreElement.appendChild(configDoc.createTextNode(conFields[7]));
463                                     cKarmaElement.appendChild(cKarmaRestoreElement);
464                                     pthcsockNode.appendChild(cKarmaElement);
465                                 }
466                             } else {
467                                 if (simulateXPathPathExists(pthcsockNode, "/karma"))
468                                     pthcsockNode.removeChild(simulateXPathGetNode(pthcsockNode, "/karma"));
469                             }
470                             // first remove all ip or ssl elements before doing anything else...
471                             if (simulateXPathPathExists(pthcsockNode, "/ip") || simulateXPathPathExists(pthcsockNode, "/ssl")) {
472                                 for (int k = 0; k < pthcsockNode.getChildNodes().getLength(); k++) {
473                                     if (pthcsockNode.getChildNodes().item(k).getNodeName().equals("ip") || pthcsockNode.getChildNodes().item(k).getNodeName().equals("ssl"))
474                                         pthcsockNode.removeChild(pthcsockNode.getChildNodes().item(k));
475                                 }
476                             }
477                             if (conClient.length > 0) {
478                                 for (int k = 0; k < conClient.length; k++) {
479                                     Element cPortElement = configDoc.createElement(conClient[k][2]);
480                                     cPortElement.setAttribute("port", conClient[k][0]);
481                                     if (conClient[k][1].length() > 0)
482                                         cPortElement.appendChild(configDoc.createTextNode(conClient[k][1]));
483                                     pthcsockNode.appendChild(cPortElement);
484                                 }
485                             }
486                         } else if (idAttr.equals("dnsrv")) {
487                             // to be implemented later
488                         } else if (idAttr.equals("s2s")) {
489                             simulateXPathGetNode(child, "/load/dialback").getFirstChild().setNodeValue(conFields[8]);
490                             if (conLegacy) {
491                                 if (simulateXPathPathExists(child, "/dialback/legacy"))
492                                     simulateXPathGetNode(child, "/dialback").removeChild(simulateXPathGetNode(child, "/dialback/legacy"));
493                             } else {
494                                 if (!simulateXPathPathExists(child, "/dialback/legacy")) {
495                                     Element legacyElement = configDoc.createElement("legacy");
496                                     simulateXPathGetNode(child, "/dialback").appendChild(legacyElement);
497                                 }
498                             }
499                             // first remove all ip elements before doing anything else...
500                             Node dialbackNode = simulateXPathGetNode(child, "/dialback");
501                             if (simulateXPathPathExists(dialbackNode, "/ip")) {
502                                 for (int k = 0; k < dialbackNode.getChildNodes().getLength(); k++) {
503                                     if (dialbackNode.getChildNodes().item(k).getNodeName().equals("ip"))
504                                         dialbackNode.removeChild(dialbackNode.getChildNodes().item(k));
505                                 }
506                             }
507                             if (conServer.length > 0) {
508                                 for (int k = 0; k < conServer.length; k++) {
509                                     Element ipElement = configDoc.createElement("ip");
510                                     ipElement.setAttribute("port", conServer[k][0]);
511                                     if (conClient[k][1].length() > 0)
512                                         ipElement.appendChild(configDoc.createTextNode(conServer[k][1]));
513                                     dialbackNode.appendChild(ipElement);
514                                 }
515                             }
516                             if (conFields[9].length() > 0) {
517                                 if (simulateXPathPathExists(dialbackNode, "/karma")) {
518                                     simulateXPathGetNode(dialbackNode, "/karma/init").getFirstChild().setNodeValue(conFields[9]);
519                                     simulateXPathGetNode(dialbackNode, "karma/max").getFirstChild().setNodeValue(conFields[10]);
520                                     simulateXPathGetNode(dialbackNode, "/karma/inc").getFirstChild().setNodeValue(conFields[11]);
521                                     simulateXPathGetNode(dialbackNode, "/karma/dec").getFirstChild().setNodeValue(conFields[12]);
522                                     simulateXPathGetNode(dialbackNode, "/karma/penalty").getFirstChild().setNodeValue(conFields[13]);
523                                     simulateXPathGetNode(dialbackNode, "/karma/restore").getFirstChild().setNodeValue(conFields[14]);
524                                 } else {
525                                     Element sKarmaElement = configDoc.createElement("karma");
526                                     Element sKarmaInitElement = configDoc.createElement("init");
527                                     sKarmaInitElement.appendChild(configDoc.createTextNode(conFields[9]));
528                                     sKarmaElement.appendChild(sKarmaInitElement);
529                                     Element sKarmaMaxElement = configDoc.createElement("max");
530                                     sKarmaMaxElement.appendChild(configDoc.createTextNode(conFields[10]));
531                                     sKarmaElement.appendChild(sKarmaMaxElement);
532                                     Element sKarmaIncElement = configDoc.createElement("inc");
533                                     sKarmaIncElement.appendChild(configDoc.createTextNode(conFields[11]));
534                                     sKarmaElement.appendChild(sKarmaIncElement);
535                                     Element sKarmaDecElement = configDoc.createElement("dec");
536                                     sKarmaDecElement.appendChild(configDoc.createTextNode(conFields[12]));
537                                     sKarmaElement.appendChild(sKarmaDecElement);
538                                     Element sKarmaPenaltyElement = configDoc.createElement("penalty");
539                                     sKarmaPenaltyElement.appendChild(configDoc.createTextNode(conFields[13]));
540                                     sKarmaElement.appendChild(sKarmaPenaltyElement);
541                                     Element sKarmaRestoreElement = configDoc.createElement("restore");
542                                     sKarmaRestoreElement.appendChild(configDoc.createTextNode(conFields[14]));
543                                     sKarmaElement.appendChild(sKarmaRestoreElement);
544                                     dialbackNode.appendChild(sKarmaElement);
545                                 }
546                             } else {
547                                 if (simulateXPathPathExists(dialbackNode, "/karma"))
548                                     dialbackNode.removeChild(simulateXPathGetNode(dialbackNode, "/karma"));
549                             }
550                         } else if (idAttr.equals("jud")) {
551                             simulateXPathGetNode(child, "/host").getFirstChild().setNodeValue(compFields[1]);
552                             simulateXPathGetNode(child, "/load/jud").getFirstChild().setNodeValue(compFields[2]);
553                             simulateXPathGetNode(child, "/jud/vCard/FN").getFirstChild().setNodeValue(compFields[3]);
554                             simulateXPathGetNode(child, "/jud/vCard/DESC").getFirstChild().setNodeValue(compFields[4]);
555                             simulateXPathGetNode(child, "/jud/vCard/URL").getFirstChild().setNodeValue(compFields[5]);
556                             judChanged = true;
557                         } else if (!confID.equals("") && idAttr.equals(confID)) { // conference service section
558                             // get rid of conferencing.
559                             if (compFields[6].equals("")) {
560                                 child.getParentNode().removeChild(child);
561                                 continue;
562                             }
563                             attr.setNodeValue(compFields[9]);
564                             simulateXPathGetNode(child, "/load/conference").getFirstChild().setNodeValue(compFields[10]);
565                             if (compFields[7].equals("private")) {
566                                 if (simulateXPathPathExists(child, "/public"))
567                                     simulateXPathGetNode(child, "/conference").replaceChild((Node)configDoc.createElement("private"), simulateXPathGetNode(child, "/public"));
568                                 else if (!simulateXPathPathExists(child, "/private"))
569                                     simulateXPathGetNode(child, "/conference").appendChild(configDoc.createElement("private"));
570                             } else {
571                                 if (simulateXPathPathExists(child, "/private"))
572                                     simulateXPathGetNode(child, "/conference").replaceChild((Node)configDoc.createElement("public"), simulateXPathGetNode(child, "/private"));
573                                 else if (!simulateXPathPathExists(child, "/public"))
574                                     simulateXPathGetNode(child, "/conference").appendChild(configDoc.createElement("public"));
575                             }
576                             if (simulateXPathPathExists(child, "/conference/history")) {
577                                 if (!compFields[8].equals(""))
578                                     simulateXPathGetNode(child, "/conference/history").getFirstChild().setNodeValue(compFields[8]);
579                                 else
580                                     simulateXPathGetNode(child, "/conference").removeChild(simulateXPathGetNode(child, "/conference/history"));
581                             } else {
582                                 if (!compFields[8].equals("")) {
583                                     Element confHistoryEl = configDoc.createElement("history");
584                                     confHistoryEl.appendChild(configDoc.createTextNode(compFields[8]));
585                                     simulateXPathGetNode(child, "/conference").insertBefore(confHistoryEl, simulateXPathGetNode(child, "/conference/vCard"));
586                                 }
587                             }
588                             simulateXPathGetNode(child, "/conference/vCard/FN").getFirstChild().setNodeValue(compFields[11]);
589                             simulateXPathGetNode(child, "/conference/vCard/DESC").getFirstChild().setNodeValue(compFields[12]);
590                             simulateXPathGetNode(child, "/conference/vCard/URL").getFirstChild().setNodeValue(compFields[13]);
591                             simulateXPathGetNode(child, "/conference/notice/join").getFirstChild().setNodeValue(compFields[14]);
592                             simulateXPathGetNode(child, "/conference/notice/leave").getFirstChild().setNodeValue(compFields[15]);
593                             simulateXPathGetNode(child, "/conference/notice/rename").getFirstChild().setNodeValue(compFields[16]);
594                             NodeList confChildren = simulateXPathGetNode(child, "/conference").getChildNodes();
595                             for (int k = 0; k < confChildren.getLength(); k++) {
596                                 if (confChildren.item(k).getNodeName().equals("room"))
597                                     simulateXPathGetNode(child, "/conference").removeChild(confChildren.item(k));
598                             }
599                             Node conferenceEl = simulateXPathGetNode(child, "/conference");
600                             for (int k = 0; k < compRooms.length; k++) {
601                                 Element confRoomEl = configDoc.createElement("room");
602                                 confRoomEl.setAttribute("jid", compRooms[k][1]);
603                                 Element confRoomNameEl = configDoc.createElement("name");
604                                 confRoomNameEl.appendChild(configDoc.createTextNode(compRooms[k][0]));
605                                 confRoomEl.appendChild(confRoomNameEl);
606                                 if (compRooms[k][2].equals("privacy")) {
607                                     Element confRoomPrivEl = configDoc.createElement("privacy");
608                                     confRoomEl.appendChild(confRoomPrivEl);
609                                 }
610                                 if (!compRooms[k][3].equals("")) {
611                                     Element confRoomSecrEl = configDoc.createElement("secret");
612                                     confRoomSecrEl.appendChild(configDoc.createTextNode(compRooms[k][3]));
613                                     confRoomEl.appendChild(confRoomSecrEl);
614                                 }
615                                 if (!compRooms[k][4].equals("")) {
616                                     Element confRoomNotEl = configDoc.createElement("notice");
617                                     Element confRoomJoinEl = configDoc.createElement("join");
618                                     confRoomJoinEl.appendChild(configDoc.createTextNode(compRooms[k][4]));
619                                     confRoomNotEl.appendChild(confRoomJoinEl);
620                                     Element confRoomLeavEl = configDoc.createElement("leave");
621                                     confRoomLeavEl.appendChild(configDoc.createTextNode(compRooms[k][5]));
622                                     confRoomNotEl.appendChild(confRoomLeavEl);
623                                     Element confRoomRenEl = configDoc.createElement("rename");
624                                     confRoomRenEl.appendChild(configDoc.createTextNode(compRooms[k][6]));
625                                     confRoomNotEl.appendChild(confRoomRenEl);
626                                     confRoomEl.appendChild(confRoomNotEl);
627                                 }
628                                 conferenceEl.appendChild(confRoomEl);
629                             }
630                             confChanged = true;
631                         }
632                     }
633 
634                 } else if (tagName.equals("xdb")) {
635                     simulateXPathGetNode(child, "/load/xdb_file").getFirstChild().setNodeValue(sysFields[2]);
636                     simulateXPathGetNode(child, "/xdb_file/spool/jabberd:cmdline").getFirstChild().setNodeValue(sysFields[1]);
637 
638                 } else if (tagName.equals("log")) {
639                     if (getAttributeValue(child, "id").equals("elogger")) {
640                         simulateXPathGetNode(child, "/format").getFirstChild().setNodeValue(logFields[0]);
641                         simulateXPathGetNode(child, "/file").getFirstChild().setNodeValue(logFields[1]);
642                         if (simulateXPathPathExists(child, "/stderr")) {
643                             if (!logStdErr)
644                                 child.removeChild(simulateXPathGetNode(child, "/stderr"));
645                         } else {
646                             if (logStdErr)
647                                 child.appendChild(configDoc.createElement("stderr"));
648                         }
649                         logUpdated[0] = true;
650                     } else if (getAttributeValue(child, "id").equals("rlogger")) {
651                         simulateXPathGetNode(child, "/format").getFirstChild().setNodeValue(logFields[2]);
652                         simulateXPathGetNode(child, "/file").getFirstChild().setNodeValue(logFields[3]);
653                         logUpdated[1] = true;
654                     }
655 
656                 } else if (tagName.equals("io")) {
657                     // let's remove the karma before we do anything else...
658                     if (simulateXPathPathExists(child, "/karma")) {
659                         Node ioKarmaNode = simulateXPathGetNode(child, "/karma");
660                         if (ioKarma) {
661                             simulateXPathGetNode(ioKarmaNode, "heartbeat").getFirstChild().setNodeValue(ioFields[0]);
662                             simulateXPathGetNode(ioKarmaNode, "init").getFirstChild().setNodeValue(ioFields[1]);
663                             simulateXPathGetNode(ioKarmaNode, "max").getFirstChild().setNodeValue(ioFields[2]);
664                             simulateXPathGetNode(ioKarmaNode, "inc").getFirstChild().setNodeValue(ioFields[3]);
665                             simulateXPathGetNode(ioKarmaNode, "dec").getFirstChild().setNodeValue(ioFields[4]);
666                             simulateXPathGetNode(ioKarmaNode, "penalty").getFirstChild().setNodeValue(ioFields[5]);
667                             simulateXPathGetNode(ioKarmaNode, "restore").getFirstChild().setNodeValue(ioFields[6]);
668                         } else
669                             child.removeChild(ioKarmaNode);
670                     } else {
671                         if (ioKarma) {
672                             Element ioKarmaElement = configDoc.createElement("karma");
673                             Element ioKarmaHeartbeatElement = configDoc.createElement("heartbeat");
674                             ioKarmaHeartbeatElement.appendChild(configDoc.createTextNode(ioFields[0]));
675                             ioKarmaElement.appendChild(ioKarmaHeartbeatElement);
676                             Element ioKarmaInitElement = configDoc.createElement("init");
677                             ioKarmaInitElement.appendChild(configDoc.createTextNode(ioFields[1]));
678                             ioKarmaElement.appendChild(ioKarmaInitElement);
679                             Element ioKarmaMaxElement = configDoc.createElement("max");
680                             ioKarmaMaxElement.appendChild(configDoc.createTextNode(ioFields[2]));
681                             ioKarmaElement.appendChild(ioKarmaMaxElement);
682                             Element ioKarmaIncElement = configDoc.createElement("inc");
683                             ioKarmaIncElement.appendChild(configDoc.createTextNode(ioFields[3]));
684                             ioKarmaElement.appendChild(ioKarmaIncElement);
685                             Element ioKarmaDecElement = configDoc.createElement("dec");
686                             ioKarmaDecElement.appendChild(configDoc.createTextNode(ioFields[4]));
687                             ioKarmaElement.appendChild(ioKarmaDecElement);
688                             Element ioKarmaPenaltyElement = configDoc.createElement("penalty");
689                             ioKarmaPenaltyElement.appendChild(configDoc.createTextNode(ioFields[5]));
690                             ioKarmaElement.appendChild(ioKarmaPenaltyElement);
691                             Element ioKarmaRestoreElement = configDoc.createElement("restore");
692                             ioKarmaRestoreElement.appendChild(configDoc.createTextNode(ioFields[6]));
693                             ioKarmaElement.appendChild(ioKarmaRestoreElement);
694                             child.appendChild(ioKarmaElement);
695                         }
696                     }
697                     Element ioRateElement = (Element)simulateXPathGetNode(child, "/rate");
698                     ioRateElement.setAttribute("points", ioFields[7]);
699                     ioRateElement.setAttribute("time", ioFields[8]);
700                     if (simulateXPathPathExists(child, "/ssl")) {
701                         Node sslNode = simulateXPathGetNode(child, "/ssl");
702                         if (secUseSSL) {
703                             // remove all existing ssl keys before adding new ones...
704                             for (int k = 0; k < sslNode.getChildNodes().getLength(); k++)
705                                 sslNode.removeChild(sslNode.getChildNodes().item(k));
706                             for (int k = 0; k < secSSL.length; k++) {
707                                 Element keyElement = configDoc.createElement("key");
708                                 keyElement.setAttribute("ip", secSSL[k][0]);
709                                 keyElement.appendChild(configDoc.createTextNode(secSSL[k][1]));
710                                 sslNode.appendChild(keyElement);
711                             }
712                         } else {
713                             child.removeChild(sslNode);
714                         }
715                     } else {
716                         if (secUseSSL) {
717                             Element sslElement = configDoc.createElement("ssl");
718                             for (int k = 0; k < secSSL.length; k++) {
719                                 Element keyElement = configDoc.createElement("key");
720                                 keyElement.setAttribute("ip", secSSL[k][0]);
721                                 keyElement.appendChild(configDoc.createTextNode(secSSL[k][1]));
722                                 sslElement.appendChild(keyElement);
723                             }
724                             child.appendChild(sslElement);
725                         }
726                     }
727                     if (simulateXPathPathExists(child, "/allow") || simulateXPathPathExists(child, "/deny")) {
728                         // remove all allow/deny elements before adding ours...
729                         for (int k = 0; k < child.getChildNodes().getLength(); k++) {
730                             if (child.getChildNodes().item(k).getNodeName().equals("allow") || child.getChildNodes().item(k).getNodeName().equals("deny"))
731                                 child.removeChild(child.getChildNodes().item(k));
732                         }
733                     }
734                     if (secNet.length > 0) {
735                         for (int k = 0; k < secNet.length; k++) {
736                             Element restrictElement = configDoc.createElement(secNet[k][0]);
737                             Element restrictIPElement = configDoc.createElement("ip");
738                             restrictIPElement.appendChild(configDoc.createTextNode(secNet[k][1]));
739                             restrictElement.appendChild(restrictIPElement);
740                             if (secNet[k][2].length() > 0) {
741                                 Element restrictMaskElement = configDoc.createElement("mask");
742                                 restrictMaskElement.appendChild(configDoc.createTextNode(secNet[k][2]));
743                                 restrictElement.appendChild(restrictMaskElement);
744                             }
745                             child.appendChild(restrictElement);
746                         }
747                     }
748 
749                 } else if (tagName.equals("pidfile")) {
750                     child.getFirstChild().setNodeValue(sysFields[0]);
751                 }
752 
753             }
754         }
755         // if log files are selected but do not appear in the current config file
756         if (!logUpdated[0] && (logFields[1].length() > 0)) {
757             Element eLogElement = configDoc.createElement("log");
758             eLogElement.setAttribute("id", "elogger");
759             eLogElement.appendChild(configDoc.createElement("host"));
760             eLogElement.appendChild(configDoc.createElement("logtype"));
761             Element eLogFormatElement = configDoc.createElement("format");
762             eLogFormatElement.appendChild(configDoc.createTextNode(logFields[0]));
763             eLogElement.appendChild(eLogFormatElement);
764             Element eLogFileElement = configDoc.createElement("file");
765             eLogFileElement.appendChild(configDoc.createTextNode(logFields[1]));
766             eLogElement.appendChild(eLogFileElement);
767             if (logStdErr)
768                 eLogElement.appendChild(configDoc.createElement("stderr"));
769             // this really belongs before service, id=dnsrv
770             // just insert before io to save checking all services
771             root.insertBefore(eLogElement, simulateXPathGetNode(root, "/io"));
772             logUpdated[0] = true;
773         }
774         if (!logUpdated[1] && (logFields[3].length() > 0)) {
775             Element rLogElement = configDoc.createElement("log");
776             rLogElement.setAttribute("id", "rlogger");
777             rLogElement.appendChild(configDoc.createElement("host"));
778             Element rLogLogtypeElement = configDoc.createElement("logtype");
779             rLogLogtypeElement.appendChild(configDoc.createTextNode("record"));
780             rLogElement.appendChild(rLogLogtypeElement);
781             Element rLogFormatElement = configDoc.createElement("format");
782             rLogFormatElement.appendChild(configDoc.createTextNode(logFields[2]));
783             rLogElement.appendChild(rLogFormatElement);
784             Element rLogFileElement = configDoc.createElement("file");
785             rLogFileElement.appendChild(configDoc.createTextNode(logFields[3]));
786             rLogElement.appendChild(rLogFileElement);
787             // this really belongs before service, id=dnsrv
788             // just insert before io to save checking all services
789             root.insertBefore(rLogElement, simulateXPathGetNode(root, "/io"));
790             logUpdated[1] = true;
791         }
792         // add a jud entry to services...
793         if (!compUpdate[1] && !judChanged) {
794             Element judServiceElement = configDoc.createElement("service");
795             judServiceElement.setAttribute("id", "jud");
796             Element judHostElement = configDoc.createElement("host");
797             judHostElement.appendChild(configDoc.createTextNode(compFields[1]));
798             judServiceElement.appendChild(judHostElement);
799             Element judLoadElement = configDoc.createElement("load");
800             Element judLoadJudElement = configDoc.createElement("jud");
801             judLoadJudElement.appendChild(configDoc.createTextNode(compFields[2]));
802             judLoadElement.appendChild(judLoadJudElement);
803             judServiceElement.appendChild(judLoadElement);
804             Element judJudElement = configDoc.createElement("jud");
805             judJudElement.setAttribute("xmlns", "jabber:config:jud");
806             Element judVCardElement = configDoc.createElement("vCard");
807             Element judFNElement = configDoc.createElement("FN");
808             judFNElement.appendChild(configDoc.createTextNode(compFields[3]));
809             judVCardElement.appendChild(judFNElement);
810             Element judDESCElement = configDoc.createElement("DESC");
811             judDESCElement.appendChild(configDoc.createTextNode(compFields[4]));
812             judVCardElement.appendChild(judDESCElement);
813             Element judURLElement = configDoc.createElement("URL");
814             judURLElement.appendChild(configDoc.createTextNode(compFields[5]));
815             judVCardElement.appendChild(judURLElement);
816             judJudElement.appendChild(judVCardElement);
817             judServiceElement.appendChild(judJudElement);
818             root.insertBefore(judServiceElement, simulateXPathGetNode(root, "io"));
819             judChanged = true;
820         }
821         // add conferencing to the list of services...
822         if (!compFields[6].equals("") && !confChanged) {
823             Element confServiceElement = configDoc.createElement("service");
824             confServiceElement.setAttribute("id", compFields[9]);
825             Element confLoadElement = configDoc.createElement("load");
826             Element confLoadConfElement = configDoc.createElement("conference");
827             confLoadConfElement.appendChild(configDoc.createTextNode(compFields[10]));
828             confLoadElement.appendChild(confLoadConfElement);
829             confServiceElement.appendChild(confLoadElement);
830             Element confConfElement = configDoc.createElement("conference");
831             confConfElement.setAttribute("xmlns", "jabberd:config:conference");
832             if (compFields[7].equals("private")) {
833                 Element confPrivateElement = configDoc.createElement("private");
834                 confConfElement.appendChild(confPrivateElement);
835             } else {
836                 Element confPublicElement = configDoc.createElement("public");
837                 confConfElement.appendChild(confPublicElement);
838             }
839             if (!compFields[8].equals("")) {
840                 Element confHistoryElement = configDoc.createElement("history");
841                 confHistoryElement.appendChild(configDoc.createTextNode(compFields[8]));
842                 confConfElement.appendChild(confHistoryElement);
843             }
844             Element confVCardElement = configDoc.createElement("vCard");
845             Element confFNElement = configDoc.createElement("FN");
846             confFNElement.appendChild(configDoc.createTextNode(compFields[11]));
847             confVCardElement.appendChild(confFNElement);
848             Element confDESCElement = configDoc.createElement("DESC");
849             confDESCElement.appendChild(configDoc.createTextNode(compFields[12]));
850             confVCardElement.appendChild(confDESCElement);
851             Element confURLElement = configDoc.createElement("URL");
852             confURLElement.appendChild(configDoc.createTextNode(compFields[13]));
853             confVCardElement.appendChild(confURLElement);
854             confConfElement.appendChild(confVCardElement);
855             Element confNoticeElement = configDoc.createElement("notice");
856             Element confJoinElement = configDoc.createElement("join");
857             confJoinElement.appendChild(configDoc.createTextNode(compFields[14]));
858             confNoticeElement.appendChild(confJoinElement);
859             Element confLeaveElement = configDoc.createElement("leave");
860             confLeaveElement.appendChild(configDoc.createTextNode(compFields[15]));
861             confNoticeElement.appendChild(confLeaveElement);
862             Element confRenameElement = configDoc.createElement("rename");
863             confRenameElement.appendChild(configDoc.createTextNode(compFields[16]));
864             confNoticeElement.appendChild(confRenameElement);
865             confConfElement.appendChild(confNoticeElement);
866 
867             for (int i = 0; i < compRooms.length; i++) {
868                 Element confRoomElement = configDoc.createElement("room");
869                 confRoomElement.setAttribute("jid", compRooms[i][1]);
870                 Element confRoomNameElement = configDoc.createElement("name");
871                 confRoomNameElement.appendChild(configDoc.createTextNode(compRooms[i][0]));
872                 confRoomElement.appendChild(confRoomNameElement);
873                 if (compRooms[i][2].equals("privacy")) {
874                     Element confRoomPrivElement = configDoc.createElement("privacy");
875                     confRoomElement.appendChild(confRoomPrivElement);
876                 }
877                 if (!compRooms[i][3].equals("")) {
878                     Element confRoomSecrElement = configDoc.createElement("secret");
879                     confRoomSecrElement.appendChild(configDoc.createTextNode(compRooms[i][3]));
880                     confRoomElement.appendChild(confRoomSecrElement);
881                 }
882                 if (!compRooms[i][4].equals("")) {
883                     Element confRoomNoticeElement = configDoc.createElement("notice");
884                     Element confRoomNotJoinElement = configDoc.createElement("join");
885                     confRoomNotJoinElement.appendChild(configDoc.createTextNode(compRooms[i][4]));
886                     confRoomNoticeElement.appendChild(confRoomNotJoinElement);
887                     Element confRoomNotLeavElement = configDoc.createElement("leave");
888                     confRoomNotLeavElement.appendChild(configDoc.createTextNode(compRooms[i][5]));
889                     confRoomNoticeElement.appendChild(confRoomNotLeavElement);
890                     Element confRoomRenElement = configDoc.createElement("rename");
891                     confRoomRenElement.appendChild(configDoc.createTextNode(compRooms[i][6]));
892                     confRoomNoticeElement.appendChild(confRoomRenElement);
893                 }
894             }
895             confServiceElement.appendChild(confConfElement);
896             root.insertBefore(confServiceElement, simulateXPathGetNode(root, "io"));
897         }
898 
899         try {
900             Transformer t = TransformerFactory.newInstance().newTransformer();
901             t.transform(new DOMSource(configDoc), new StreamResult(new FileOutputStream(configFile)));
902         } catch (IOException e) {
903             JOptionPane.showMessageDialog(parent, "IOException", "IOException: " + e.toString(), JOptionPane.ERROR_MESSAGE);
904         } catch (TransformerException e) {
905             JOptionPane.showMessageDialog(parent, "TransformerException", "TransformerException: " + e.toString(), JOptionPane.ERROR_MESSAGE);
906         }
907     }
908 
909     public void setParent(Jabbee j) {
910         parent = j;
911     }
912 
913     private Document configDoc;
914     private File configFile;
915     private Jabbee parent;
916 }