From bfec2b7d0fff8fcce1f583b88541b85d88731529 Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Sat, 19 Sep 2009 22:11:41 +0000 Subject: [PATCH] Applies minor formatting to better conform to our coding convention. --- ...etServerStoredContactInfoFacebookImpl.java | 87 ++++++++++++------- 1 file changed, 55 insertions(+), 32 deletions(-) diff --git a/src/net/java/sip/communicator/impl/protocol/facebook/OperationSetServerStoredContactInfoFacebookImpl.java b/src/net/java/sip/communicator/impl/protocol/facebook/OperationSetServerStoredContactInfoFacebookImpl.java index 2831fb5e2..5307232ea 100644 --- a/src/net/java/sip/communicator/impl/protocol/facebook/OperationSetServerStoredContactInfoFacebookImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/facebook/OperationSetServerStoredContactInfoFacebookImpl.java @@ -54,6 +54,7 @@ protected OperationSetServerStoredContactInfoFacebookImpl( { this.parentProvider = provider; } + /** * Returns the user details from the specified class or its descendants * the class is one from the @@ -65,21 +66,19 @@ protected OperationSetServerStoredContactInfoFacebookImpl( * @return Iterator */ public Iterator getDetailsAndDescendants( - Contact contact, - Class detailClass) + Contact contact, + Class detailClass) { List details = getContactDetails(contact.getAddress()); List result = new LinkedList(); - if(details == null) + if (details == null) return result.iterator(); for (GenericDetail item : details) - { //the class AND its descendants - if(detailClass.isInstance(item)) + if (detailClass.isInstance(item)) result.add(item); - } return result.iterator(); } @@ -93,21 +92,19 @@ public Iterator getDetailsAndDescendants( * @return Iterator */ public Iterator getDetails( - Contact contact, - Class detailClass) + Contact contact, + Class detailClass) { List details = getContactDetails(contact.getAddress()); List result = new LinkedList(); - if(details == null) + if (details == null) return result.iterator(); for (GenericDetail item : details) - { //exactly that class not its descendants - if(detailClass.equals(item.getClass())) + if (detailClass.equals(item.getClass())) result.add(item); - } return result.iterator(); } @@ -140,7 +137,7 @@ private List getContactDetails(String contactAddress) { List result = retreivedDetails.get(contactAddress); - if((result == null) + if ((result == null) || !detailsRetreivedAddresses.contains(contactAddress)) { result = new LinkedList(); @@ -170,7 +167,8 @@ private List getContactDetails(String contactAddress) ContactFacebookImpl contact = (ContactFacebookImpl)presenceOS.findContactByID(contactAddress); //avatar, name, first name - if(contact != null){ + if(contact != null) + { /** * TODO fixme "Avatar" should be loaded from resources.properties */ @@ -185,14 +183,21 @@ private List getContactDetails(String contactAddress) tmpValueStr = metaInfo.name; if(tmpValueStr != null) - result.add(new ServerStoredDetails.DisplayNameDetail(tmpValueStr)); + result + .add( + new ServerStoredDetails.DisplayNameDetail( + tmpValueStr)); tmpValueStr = metaInfo.firstName; if(tmpValueStr != null) - result.add(new ServerStoredDetails.FirstNameDetail(tmpValueStr)); + result + .add( + new ServerStoredDetails.FirstNameDetail( + tmpValueStr)); } - String profilePage = adapter.getProfilePage(contactAddress); + String profilePage + = adapter.getSession().getProfilePage(contactAddress); if(profilePage == null) throw new Exception("Failed to load profile page"); @@ -212,7 +217,8 @@ private List getContactDetails(String contactAddress) String tmpPrefix = "
"; int beginPos = profilePage.indexOf(tmpPrefix); - if(beginPos >= 0){ + if(beginPos >= 0) + { //do something beginPos += tmpPrefix.length(); if(beginPos >= profilePage.length()) @@ -221,9 +227,11 @@ private List getContactDetails(String contactAddress) String tmpLabelStr; int tmpLeft = profilePage.indexOf("
", beginPos); int tmpRight = 0; - while(tmpLeft >= 0 && tmpLeft < profilePage.length()){ + while(tmpLeft >= 0 && tmpLeft < profilePage.length()) + { tmpRight = profilePage.indexOf("
", tmpLeft); - if(tmpRight >= 0){ + if(tmpRight >= 0) + { tmpLabelStr = profilePage.substring(tmpLeft + 4, tmpRight); tmpLabelStr = getText(tmpLabelStr); if(tmpLabelStr.endsWith(":")) @@ -231,11 +239,14 @@ private List getContactDetails(String contactAddress) //label done! tmpLeft = profilePage.indexOf("
", tmpRight); - if(tmpLeft >= 0){ + if(tmpLeft >= 0) + { tmpRight = profilePage.indexOf("
", tmpLeft); - if(tmpRight >= 0){ + if(tmpRight >= 0) + { tmpValueStr = profilePage.substring(tmpLeft + 4, tmpRight); - if(tmpValueStr.startsWith("")){ + if(tmpValueStr.startsWith("")) + { // tmpValueStr = tmpValueStr.substring(10, tmpValueStr.length() - 11); //"http://static.ak.fbcdn.net" @@ -243,16 +254,21 @@ private List getContactDetails(String contactAddress) if(imageBytes != null && imageBytes.length > 0) result.add(new ServerStoredDetails.ImageDetail( tmpLabelStr, imageBytes)); - } else { + } + else + { tmpValueStr = getText(tmpValueStr); //value done! result.add(new ServerStoredDetails.StringDetail(tmpLabelStr, tmpValueStr)); } - } else + } + else break; - } else + } + else break; - } else + } + else break; tmpLeft = profilePage.indexOf("
", tmpRight + 5); } @@ -326,28 +342,33 @@ public OperationSetPersistentPresenceFacebookImpl getParentPresenceOperationSet( return (OperationSetPersistentPresenceFacebookImpl) parentProvider .getOperationSet(OperationSetPersistentPresence.class); } + /** * Get text from html formatted string * * @param srcStr the html formatted string * @return the plain text */ - public static String getText(String srcStr){ + public static String getText(String srcStr) + { String text = ""; int left = 0; int cur = srcStr.indexOf("<", left); - while(cur >= 0){ + while(cur >= 0) + { text += srcStr.substring(left, cur); left = srcStr.indexOf(">", cur); if(left < 0) break; left++; - if(left < srcStr.length()){ + if(left < srcStr.length()) + { cur = srcStr.indexOf("<", left); continue; - } else + } + else break; } if(left >= 0) @@ -375,7 +396,9 @@ public static String getText(String srcStr){ return text; } - public static byte[] getImage(String urlStr){ + + public static byte[] getImage(String urlStr) + { ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream(); try {