diff --git a/src/net/java/sip/communicator/impl/protocol/yahoo/ContactGroupYahooImpl.java b/src/net/java/sip/communicator/impl/protocol/yahoo/ContactGroupYahooImpl.java index a183c1898..6813fc3ba 100644 --- a/src/net/java/sip/communicator/impl/protocol/yahoo/ContactGroupYahooImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/yahoo/ContactGroupYahooImpl.java @@ -179,7 +179,8 @@ public Contact getContact(String id) public String getGroupName() { if(isResolved) - return yahooGroup.getName(); + return ServerStoredContactListYahooImpl + .replaceIllegalChars(yahooGroup.getName()); else return tempId; } diff --git a/src/net/java/sip/communicator/impl/protocol/yahoo/ServerStoredContactListYahooImpl.java b/src/net/java/sip/communicator/impl/protocol/yahoo/ServerStoredContactListYahooImpl.java index c973d0c41..6b0b67301 100644 --- a/src/net/java/sip/communicator/impl/protocol/yahoo/ServerStoredContactListYahooImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/yahoo/ServerStoredContactListYahooImpl.java @@ -43,7 +43,8 @@ public class ServerStoredContactListYahooImpl /** * The root contagroup. The container for all yahoo buddies and groups. */ - private RootContactGroupYahooImpl rootGroup = new RootContactGroupYahooImpl(); + private RootContactGroupYahooImpl rootGroup + = new RootContactGroupYahooImpl(); /** * The operation set that created us and that we could use when dispatching @@ -120,7 +121,8 @@ public ContactGroup getRootGroup() /** * Registers the specified group listener so that it would receive events * on group modification/creation/destruction. - * @param listener the ServerStoredGroupListener to register for group events + * @param listener the ServerStoredGroupListener to register for group + * events */ void addGroupListener(ServerStoredGroupListener listener) { @@ -251,11 +253,12 @@ ProtocolProviderServiceYahooImpl getParentProvider() * group was found. *

* @param name the name of the group we're looking for. - * @return a reference to the ContactGroupYahooImpl instance we're looking for - * or null if no such group was found. + * @return a reference to the ContactGroupYahooImpl instance we're looking + * for or null if no such group was found. */ public ContactGroupYahooImpl findContactGroup(String name) { + String nameToLookFor = replaceIllegalChars(name); Iterator contactGroups = rootGroup.subgroups(); while(contactGroups.hasNext()) @@ -263,7 +266,7 @@ public ContactGroupYahooImpl findContactGroup(String name) ContactGroupYahooImpl contactGroup = (ContactGroupYahooImpl) contactGroups.next(); - if (contactGroup.getGroupName().equals(name)) + if (contactGroup.getGroupName().equals(nameToLookFor)) return contactGroup; } @@ -386,7 +389,8 @@ public void addContact(final ContactGroupYahooImpl parent, String id) try { - yahooSession.addFriend(YahooSession.getYahooUserID(id), parent.getGroupName()); + yahooSession.addFriend(YahooSession.getYahooUserID(id), + parent.getGroupName()); } catch(IOException ex) { @@ -579,7 +583,8 @@ public void removeGroup(ContactGroupYahooImpl groupToRemove) */ void removeContact(ContactYahooImpl contactToRemove) { - logger.trace("Removing yahoo contact " + contactToRemove.getSourceContact()); + logger.trace("Removing yahoo contact " + + contactToRemove.getSourceContact()); if(contactToRemove.isVolatile()) { @@ -621,7 +626,8 @@ public void renameGroup(ContactGroupYahooImpl groupToRename, String newName) logger.info("Cannot rename group " + groupToRename); } - fireGroupEvent(groupToRename, ServerStoredGroupEvent.GROUP_RENAMED_EVENT); + fireGroupEvent(groupToRename, + ServerStoredGroupEvent.GROUP_RENAMED_EVENT); */ } @@ -871,7 +877,8 @@ void processAuthorizationRequest(SessionAuthorizationEvent ev) private class ContactListModListenerImpl extends SessionAdapter { - private Hashtable waitMove = new Hashtable(); + private Hashtable waitMove + = new Hashtable(); public void waitForMove(String id, String oldParent) { @@ -912,8 +919,9 @@ public void friendAddedReceived(SessionFriendEvent ev) // as new one will be created if(contactToAdd != null && contactToAdd.isVolatile()) { - ContactGroupYahooImpl parent = - (ContactGroupYahooImpl)contactToAdd.getParentContactGroup(); + ContactGroupYahooImpl parent + = (ContactGroupYahooImpl)contactToAdd + .getParentContactGroup(); parent.removeContact(contactToAdd); fireContactRemoved(parent, contactToAdd); @@ -1023,8 +1031,10 @@ public void friendRemovedReceived(SessionFriendEvent ev) if(waitForMoveObj != null && waitForMoveObj instanceof YahooGroup) { // first get the group - oldParent - ContactGroupYahooImpl oldParent = findContactGroup(ev.getGroup()); - ContactYahooImpl contactToRemove = oldParent.findContact(contactID); + ContactGroupYahooImpl oldParent + = findContactGroup(ev.getGroup()); + ContactYahooImpl contactToRemove + = oldParent.findContact(contactID); oldParent.removeContact(contactToRemove); waitMove.remove(contactID); @@ -1043,7 +1053,8 @@ public void friendRemovedReceived(SessionFriendEvent ev) return; ContactGroupYahooImpl parentGroup = - (ContactGroupYahooImpl)contactToRemove.getParentContactGroup(); + (ContactGroupYahooImpl)contactToRemove. + getParentContactGroup(); parentGroup.removeContact(contactToRemove); fireContactRemoved(parentGroup, contactToRemove); @@ -1052,7 +1063,8 @@ public void friendRemovedReceived(SessionFriendEvent ev) if(findGroup(ev.getGroup()) == null) { rootGroup.removeSubGroup(parentGroup); - fireGroupEvent(parentGroup, ServerStoredGroupEvent.GROUP_REMOVED_EVENT); + fireGroupEvent(parentGroup, + ServerStoredGroupEvent.GROUP_REMOVED_EVENT); } } @@ -1107,7 +1119,8 @@ public void contactRejectionReceived(SessionEvent ev) ContactYahooImpl contact = findContactById(ev.getFrom()); AuthorizationResponse resp = - new AuthorizationResponse(AuthorizationResponse.REJECT, ev.getMessage()); + new AuthorizationResponse(AuthorizationResponse.REJECT, + ev.getMessage()); handler.processAuthorizationResponse(resp, contact); } @@ -1175,7 +1188,8 @@ else if(ev.isAuthorizationDenied()) } else if(ev.isAuthorizationRequest()) { - logger.trace("authorizationRequestReceived from " + ev.getFrom()); + logger.trace("authorizationRequestReceived from " + + ev.getFrom()); processAuthorizationRequest(ev); } } @@ -1192,4 +1206,20 @@ void setYahooSession(YahooSession session) session.addSessionListener(contactListModListenerImpl); initList(); } + + /** + * It seems that ymsg (or the Yahoo! service itself as the problem also + * appears with libpurple) would return illegal chars for names that were + * entered in cyrillic. We use this method to translate their names into + * something that we could actually display and store here. + * + * @param ymsgString the String containing illegal chars. + * + * @return a String where all illegal chars are converted into human + * readable ones + */ + static String replaceIllegalChars(String ymsgString) + { + return ymsgString.replace((char)26, '?'); + } } diff --git a/src/net/java/sip/communicator/util/xml/XMLUtils.java b/src/net/java/sip/communicator/util/xml/XMLUtils.java index df8b60e99..039bb3f9d 100644 --- a/src/net/java/sip/communicator/util/xml/XMLUtils.java +++ b/src/net/java/sip/communicator/util/xml/XMLUtils.java @@ -7,6 +7,7 @@ package net.java.sip.communicator.util.xml; import java.io.*; +import java.nio.charset.*; import java.util.*; import javax.xml.transform.*; @@ -250,13 +251,13 @@ public static void writeXML(Document document, { DOMSource domSource = new DOMSource(document); TransformerFactory tf = TransformerFactory.newInstance(); - + // not working for jdk 1.4 try { tf.setAttribute("indent-number", 4); }catch(Exception e){} - + Transformer serializer = tf.newTransformer(); if(doctypeSystem != null) serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, @@ -266,7 +267,6 @@ public static void writeXML(Document document, doctypePublic); // not working for jdk 1.5 serializer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "4"); - serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.transform(domSource, streamResult); @@ -295,14 +295,13 @@ public static void indentedWriteXML(Document doc, OutputStream out) { try { -// Writer wri = new OutputStreamWriter(out, "UTF-8"); + Writer wri = new OutputStreamWriter(out, "UTF-8"); // wri.write(""+lSep); // (new DOMElementWriter()).write(rootElement, wri, 0, " "); // wri.flush(); // wri.close(); writeXML(doc - , new StreamResult( - out) + , new StreamResult(wri) , null , null); out.close(); @@ -392,11 +391,11 @@ public static Element findChild(Element parent, String tagName) return null; } - + /** * Returns the children elements with the specified tagName for the * specified parent element. - * + * * @param parent The parent whose children we're looking for. * @param tagName the name of the child to find * @return List of the children with the specified name @@ -474,11 +473,11 @@ public static Element locateElement(Element root, return null; } - + /** * Looks through all child elements of the specified root (recursively) and * returns the elements that corresponds to all parameters. - * + * * @param root the Element where the search should begin * @param tagName the name of the node we're looking for * @param keyAttributeName the name of an attribute that the node has to