[sip-comm-cvs] CVS update: /sip-communicator/src/net/java/sip/communicator/impl/contactlist/MclStorageManager.java

emcho at dev.java.net emcho at dev.java.net
Wed May 16 16:51:26 CEST 2007


User: emcho   
Date: 2007-05-16 14:51:26+0000
Log:
 Adding Ben's implementation of instant messaging for SIP (by Benoit Pradelle)
 
 make sure we create a new contactlist.xml document if we fail parsing the existing one.

File Changes:

Directory: /sip-communicator/src/net/java/sip/communicator/impl/contactlist/
============================================================================

File [changed]: MclStorageManager.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/contactlist/MclStorageManager.java?r1=1.18&r2=1.19
Delta lines:  +44 -30
---------------------
--- MclStorageManager.java	2007-04-17 12:12:38+0000	1.18
+++ MclStorageManager.java	2007-05-16 14:51:23+0000	1.19
@@ -12,7 +12,6 @@
 
 import org.osgi.framework.*;
 import org.w3c.dom.*;
-import org.xml.sax.*;
 import net.java.sip.communicator.service.configuration.*;
 import net.java.sip.communicator.service.contactlist.*;
 import net.java.sip.communicator.service.contactlist.event.*;
@@ -301,13 +300,25 @@
             }
             else
             {
+                try
+                {
                 contactListDocument = builder.parse(contactlistFile);
             }
-        }
-        catch (SAXException ex)
+                catch (Throwable ex)
         {
             logger.error("Error parsing configuration file", ex);
-            throw new XMLException(ex.getMessage(), ex);
+                    logger.error("Creating replacement file");
+
+                    //re-create and re-init the new document
+                    contactlistFile.delete();
+                    contactlistFile.createNewFile();
+                    contactListDocument = builder.newDocument();
+                    initVirginDocument(mclServiceImpl, contactListDocument);
+
+                    //write the contact list so that it is there for the parser
+                    storeContactList0();
+                }
+            }
         }
         catch (ParserConfigurationException ex)
         {
@@ -1410,31 +1421,34 @@
         switch (evt.getEventID())
         {
             case MetaContactGroupEvent.CONTACT_GROUP_REMOVED_FROM_META_GROUP:
-                Element protoGroupNode
-                    = XMLUtils.locateElement(
-                        mcGroupNode
-                        , PROTO_GROUP_NODE_NAME
-                        , UID_ATTR_NAME, evt.getSourceProtoGroup().getUID());
-
-                //remove the proto group from the node containing all proto
-                //groups for the corresponding meta contact group.
-                if(protoGroupNode != null)
-                    protoGroupNode.getParentNode().removeChild(protoGroupNode);
-                else
-                    logger.error("Hm ... strange ...");
-                break;
             case MetaContactGroupEvent.CONTACT_GROUP_ADDED_TO_META_GROUP:
-                Element newProtoGroupNode
-                    = createProtoContactGroupNode(evt.getSourceProtoGroup());
+                //the fact that a contact group was added or removed to a
+                //meta group may imply substantial changes in the child contacts
+                //and the layout of any possible subgroups, so
+                //to make things simple, we'll remove the existing meta contact
+                //group node and re-create it according to its current state.
+                Element parentNode = (Element)mcGroupNode.getParentNode();
 
-                Element protoGroupsNode = XMLUtils.findChild(
-                    mcGroupNode, PROTO_GROUPS_NODE_NAME);
-                //add the proto group to the node containing all proto
-                //groups for the corresponding meta contact group.
-                if(protoGroupsNode != null)
-                    protoGroupsNode.appendChild(newProtoGroupNode);
-                else
-                    logger.error("Hm ... strange ...");
+                parentNode.removeChild(mcGroupNode);
+
+                Element newGroupElement = createMetaContactGroupNode(
+                    evt.getSourceMetaContactGroup());
+
+                parentNode.appendChild(newGroupElement);
+
+                try
+                {
+                    scheduleContactListStorage();
+                }
+                catch (IOException ex)
+                {
+                    /**given we're being invoked from an event dispatch thread
+                     * that was proberly triggerred by a net operation - we
+                     * could not do much. so ... log and @todo one day we'll
+                     * have a global error dispatcher */
+                    logger.error("Writing CL failed after adding contact "
+                                 + evt.getSourceMetaContactGroup(), ex);
+                }
                 break;
             case MetaContactGroupEvent.META_CONTACT_GROUP_RENAMED:
                 mcGroupNode.setAttribute(




---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe at sip-communicator.dev.java.net
For additional commands, e-mail: cvs-help at sip-communicator.dev.java.net





More information about the commits mailing list