Projects tigase _server server-core Commits 74a97f30
ctrl k
  • Bug #431 fix, corrected the way roster item name is now properly uuencoded and uudecoded during processing, fixes #431

  • Loading...
  • Artur Hefczyc committed 1 decade ago
    74a97f30
    1 parent 4c4ae708
  • src/main/java/tigase/xmpp/impl/JabberIqRoster.java
    ■ ■ ■ ■ ■ ■
    skipped 1 lines
    2 2   * JabberIqRoster.java
    3 3   *
    4 4   * Tigase Jabber/XMPP Server
    5  - * Copyright (C) 2004-2012 "Artur Hefczyc" <artur.hefczyc@tigase.org>
     5 + * Copyright (C) 2004-2013 "Tigase, Inc." <office@tigase.com>
    6 6   *
    7 7   * This program is free software: you can redistribute it and/or modify
    8 8   * it under the terms of the GNU Affero General Public License as published by
    skipped 71 lines
    80 80   implements XMPPProcessorIfc, XMPPStopListenerIfc {
    81 81   /** Field description */
    82 82   public static final String ANON = "anon";
    83  - private static final String[] ELEMENTS = { "query", "query" };
     83 + private static final String[] ELEMENTS = { Iq.QUERY_NAME, Iq.QUERY_NAME };
    84 84   
    85 85   /**
    86 86   * Private logger for class instance.
    skipped 594 lines
    681 681   results.offer(
    682 682   Authorization.FEATURE_NOT_IMPLEMENTED.getResponseMessage(
    683 683   packet,
    684  - "You cannot modify this contact. It is controlled by an external service.",
    685  - true));
     684 + "You cannot modify this contact. It is controlled by an " +
     685 + "external service.", true));
    686 686   
    687 687   return;
    688 688   }
    skipped 57 lines
    746 746   roster_util.removeBuddy(session, buddy);
    747 747   roster_util.updateBuddyChange(session, results, it);
    748 748   } else {
    749  - String name = item.getAttributeStaticStr("name");
    750 749   
    751  - // if (name == null) {
    752  - // name = buddy;
    753  - // } // end of if (name == null)
     750 + // We are adding a new roster element here
     751 + String name = item.getAttributeStaticStr("name");
    754 752   List<Element> groups = item.getChildren();
    755 753   String[] gr = null;
    756 754   
    skipped 106 lines
    863 861   JID buddy = JID.jidInstanceNS(nitem.getAttribute("jid"));
    864 862   String name = nitem.getAttribute("name");
    865 863   String subscrStr = nitem.getAttribute("subscription");
    866  - RosterAbstract.SubscriptionType subscr = subscrStr == null ? null : RosterAbstract.SubscriptionType.valueOf(subscrStr);
     864 + RosterAbstract.SubscriptionType subscr =
     865 + subscrStr == null ? null :
     866 + RosterAbstract.SubscriptionType.valueOf(subscrStr);
    867 867   String[] groups = null;
    868 868   List<Element> ngroups = nitem.getChildren();
    869 869   if (ngroups != null && !ngroups.isEmpty()) {
    870 870   int i = 0;
    871 871   groups = new String[ngroups.size()];
    872 872   for (Element group : nitem.getChildren()) {
    873  - groups[i++] = group.getCData() == null ? "" : group.getCData();
     873 + groups[i++] =
     874 + group.getCData() == null ? "" : group.getCData();
    874 875   }
    875 876   }
    876 877   roster_util.addBuddy(session, buddy, name, groups, null);
    skipped 30 lines
    907 908  // ~ Formatted by Jindent --- http://www.jindent.com
    908 909   
    909 910   
    910  -//~ Formatted in Tigase Code Convention on 13/02/20
     911 +//~ Formatted in Tigase Code Convention on 13/02/28
    911 912   
  • src/main/java/tigase/xmpp/impl/roster/RosterElement.java
    ■ ■ ■ ■ ■ ■
    skipped 1 lines
    2 2   * RosterElement.java
    3 3   *
    4 4   * Tigase Jabber/XMPP Server
    5  - * Copyright (C) 2004-2012 "Artur Hefczyc" <artur.hefczyc@tigase.org>
     5 + * Copyright (C) 2004-2013 "Tigase, Inc." <office@tigase.com>
    6 6   *
    7 7   * This program is free software: you can redistribute it and/or modify
    8 8   * it under the terms of the GNU Affero General Public License as published by
    skipped 66 lines
    75 75   
    76 76   //~--- fields ---------------------------------------------------------------
    77 77   
    78  - // ~--- fields ---------------------------------------------------------------
    79 78   private String[] groups = null;
    80 79   private JID jid = null;
    81 80   private String name = null;
    skipped 13 lines
    95 94   private boolean modified = false;
    96 95   
    97 96   //~--- constructors ---------------------------------------------------------
    98  - 
    99  - // ~--- constructors ---------------------------------------------------------
    100 97   
    101 98   /**
    102 99   * Creates a new <code>RosterElement</code> instance.
    skipped 20 lines
    123 120   String grps = roster_el.getAttributeStaticStr(GRP_ATT);
    124 121   
    125 122   if ((grps != null) &&!grps.trim().isEmpty()) {
    126  - groups = grps.split(",");
     123 + setGroups(grps.split(","));
    127 124   }
    128 125   
    129 126   String other_data = roster_el.getAttributeStaticStr(OTHER_ATT);
    skipped 50 lines
    180 177   this.session = session;
    181 178   setJid(jid);
    182 179   setName(name);
    183  - this.groups = groups;
     180 + setGroups(groups);
    184 181   this.subscription = SubscriptionType.none;
    185 182   }
    186 183   
    187 184   //~--- methods --------------------------------------------------------------
    188  - 
    189  - // ~--- methods --------------------------------------------------------------
    190 185   
    191 186   /**
    192 187   * Method description
    skipped 4 lines
    197 192   public void addGroups(String[] groups) {
    198 193   if (groups != null) {
    199 194   if (this.groups == null) {
    200  - this.groups = groups;
     195 + setGroups(groups);
    201 196   } else {
    202 197   
    203 198   // Groups names must be unique
    skipped 5 lines
    209 204   for (String group : groups) {
    210 205   groupsSet.add(group);
    211 206   }
    212  - this.groups = groupsSet.toArray(new String[groupsSet.size()]);
     207 + setGroups(groupsSet.toArray(new String[groupsSet.size()]));
    213 208   }
    214 209   }
    215 210   
    skipped 1 lines
    217 212   }
    218 213   
    219 214   //~--- get methods ----------------------------------------------------------
    220  - 
    221  - // ~--- get methods ----------------------------------------------------------
    222 215   
    223 216   /**
    224 217   * Method description
    skipped 44 lines
    269 262   public Element getRosterElement() {
    270 263   Element elem = new Element(ELEM_NAME, new String[] { JID_ATT, SUBS_ATT, NAME_ATT,
    271 264   STRINGPREP_ATT }, new String[] { jid.toString(), subscription.toString(),
    272  - name, "" + stringpreped });
     265 + XMLUtils.escape(name), "" + stringpreped });
    273 266   
    274 267   if ((groups != null) && (groups.length > 0)) {
    275 268   String grps = "";
    276 269   
    277 270   for (String group : groups) {
    278  - grps += group + ",";
     271 + grps += XMLUtils.escape(group) + ",";
    279 272   }
    280 273   grps = grps.substring(0, grps.length() - 1);
    281 274   elem.setAttribute(GRP_ATT, grps);
    skipped 49 lines
    331 324   *
    332 325   * @return
    333 326   */
     327 + @Override
    334 328   public String toString() {
    335 329   return getRosterItem().toString();
    336 330   }
    skipped 42 lines
    379 373   
    380 374   //~--- set methods ----------------------------------------------------------
    381 375   
    382  - // ~--- set methods ----------------------------------------------------------
    383  - 
    384 376   /**
    385 377   * Method description
    386 378   *
    387 379   *
    388 380   * @param groups
    389 381   */
    390  - public void setGroups(String[] groups) {
    391  - this.groups = groups;
    392  - modified = true;
    393  - 
    394  - // item = null;
     382 + public final void setGroups(String[] groups) {
     383 + if ((groups != null) && (groups.length > 0)) {
     384 + this.groups = new String[groups.length];
     385 + for (int i = 0; i < groups.length; i++) {
     386 + this.groups[i] = XMLUtils.unescape(groups[i]);
     387 + }
     388 + modified = true;
     389 + }
    395 390   }
    396 391   
    397 392   /**
    skipped 2 lines
    400 395   *
    401 396   * @param name
    402 397   */
    403  - public void setName(String name) {
     398 + public final void setName(String name) {
     399 + String old_name = this.name;
     400 + 
    404 401   if (name == null) {
    405 402   this.name = this.jid.getLocalpart();
    406 403   if ((this.name == null) || this.name.trim().isEmpty()) {
    407 404   this.name = this.jid.getBareJID().toString();
    408 405   }
     406 + } else {
     407 + this.name = XMLUtils.unescape(name);
     408 + }
     409 + if (!this.name.equals(old_name)) {
    409 410   modified = true;
    410  - } else {
    411  - this.name = name;
    412 411   }
    413 412   }
    414 413   
    skipped 152 lines
    567 566  }
    568 567   
    569 568   
    570  -//~ Formatted in Tigase Code Convention on 13/02/20
     569 +//~ Formatted in Tigase Code Convention on 13/02/28
    571 570   
  • src/main/java/tigase/xmpp/impl/roster/RosterFlat.java
    ■ ■ ■ ■ ■ ■
    1 1  /*
     2 + * RosterFlat.java
     3 + *
    2 4   * Tigase Jabber/XMPP Server
    3  - * Copyright (C) 2004-2012 "Artur Hefczyc" <artur.hefczyc@tigase.org>
     5 + * Copyright (C) 2004-2013 "Tigase, Inc." <office@tigase.com>
    4 6   *
    5 7   * This program is free software: you can redistribute it and/or modify
    6 8   * it under the terms of the GNU Affero General Public License as published by
    7  - * the Free Software Foundation, either version 3 of the License.
     9 + * the Free Software Foundation, either version 3 of the License,
     10 + * or (at your option) any later version.
    8 11   *
    9 12   * This program is distributed in the hope that it will be useful,
    10 13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    skipped 4 lines
    15 18   * along with this program. Look for COPYING file in the top folder.
    16 19   * If not, see http://www.gnu.org/licenses/.
    17 20   *
    18  - * $Rev$
    19  - * Last modified by $Author$
    20  - * $Date$
    21 21   */
     22 + 
     23 + 
    22 24   
    23 25  package tigase.xmpp.impl.roster;
    24 26   
    skipped 15 lines
    40 42   
    41 43  import java.util.Arrays;
    42 44  import java.util.Comparator;
     45 +import java.util.concurrent.ConcurrentHashMap;
    43 46  import java.util.Date;
    44 47  import java.util.LinkedList;
    45 48  import java.util.List;
    46  -import java.util.Map;
    47  -import java.util.Queue;
    48  -import java.util.concurrent.ConcurrentHashMap;
    49 49  import java.util.logging.Level;
    50 50  import java.util.logging.Logger;
    51  - 
    52  -//~--- classes ----------------------------------------------------------------
     51 +import java.util.Map;
     52 +import java.util.Queue;
    53 53   
    54 54  /**
    55 55   * Describe class RosterFlat here.
    skipped 4 lines
    60 60   * @author <a href="mailto:artur.hefczyc@tigase.org">Artur Hefczyc</a>
    61 61   * @version $Rev$
    62 62   */
    63  -public class RosterFlat extends RosterAbstract {
    64  - 
     63 +public class RosterFlat
     64 + extends RosterAbstract {
    65 65   /**
    66 66   * Private logger for class instances.
    67 67   */
    68  - private static final Logger log = Logger.getLogger(RosterFlat.class.getName());
     68 + private static final Logger log = Logger.getLogger(RosterFlat.class.getName());
    69 69   private static final SimpleParser parser = SingletonFactory.getParserInstance();
    70  - private static int maxRosterSize = new Long(Runtime.getRuntime().maxMemory() / 250000L)
    71  - .intValue();
     70 + private static int maxRosterSize = new Long(Runtime.getRuntime().maxMemory() /
     71 + 250000L).intValue();
     72 + 
     73 + //~--- methods --------------------------------------------------------------
    72 74   
    73 75   // ~--- methods --------------------------------------------------------------
    74 76   
    skipped 6 lines
    81 83   *
    82 84   * @return
    83 85   */
    84  - public static boolean addBuddy(RosterElement relem, Map<BareJID, RosterElement> roster) {
     86 + public static boolean addBuddy(RosterElement relem,
     87 + Map<BareJID, RosterElement> roster) {
    85 88   if (roster.size() < maxRosterSize) {
    86 89   roster.put(relem.getJid().getBareJID(), relem);
    87 90   
    skipped 3 lines
    91 94   return false;
    92 95   }
    93 96   
     97 + /**
     98 + * Method description
     99 + *
     100 + *
     101 + * @param buddy
     102 + * @param session
     103 + *
     104 + * @return
     105 + *
     106 + * @throws NotAuthorizedException
     107 + * @throws TigaseDBException
     108 + */
    94 109   public RosterElement addTempBuddy(JID buddy, XMPPResourceConnection session)
    95  - throws NotAuthorizedException, TigaseDBException {
     110 + throws NotAuthorizedException, TigaseDBException {
    96 111   RosterElement relem = getRosterElementInstance(buddy, null, null, session);
     112 + 
    97 113   relem.setPersistent(false);
    98 114   addBuddy(relem, getUserRoster(session));
     115 + 
    99 116   return relem;
    100 117   }
    101 118   
    skipped 8 lines
    110 127   * @return
    111 128   */
    112 129   public static boolean parseRosterUtil(String roster_str,
    113  - Map<BareJID, RosterElement> roster, XMPPResourceConnection session) {
    114  - boolean result = false;
     130 + Map<BareJID, RosterElement> roster, XMPPResourceConnection session) {
     131 + boolean result = false;
    115 132   DomBuilderHandler domHandler = new DomBuilderHandler();
    116 133   
    117 134   parser.parse(domHandler, roster_str.toCharArray(), 0, roster_str.length());
    skipped 6 lines
    124 141   RosterElement relem = new RosterElement(elem, session);
    125 142   
    126 143   result |= relem.isModified();
    127  - 
    128 144   if (!addBuddy(relem, roster)) {
    129 145   break;
    130 146   }
    skipped 21 lines
    152 168   */
    153 169   @Override
    154 170   public void addBuddy(XMPPResourceConnection session, JID buddy, String name,
    155  - String[] groups, String otherData) throws NotAuthorizedException, TigaseDBException {
     171 + String[] groups, String otherData)
     172 + throws NotAuthorizedException, TigaseDBException {
    156 173   
    157 174   // String buddy = JIDUtils.getNodeID(jid);
    158 175   RosterElement relem = getRosterElement(session, buddy);
    skipped 3 lines
    162 179   
    163 180   relem = getRosterElementInstance(buddy, name, groups, session);
    164 181   relem.setOtherData(otherData);
    165  - 
     182 + if (log.isLoggable(Level.FINEST)) {
     183 + log.log(Level.FINEST, "1. Added buddy to roster: {0}, name: {1}, item: {2}",
     184 + new Object[] { relem.getJid(),
     185 + relem.getName(), relem.getRosterItem() });
     186 + }
    166 187   if (addBuddy(relem, roster)) {
    167 188   saveUserRoster(session);
    168 189   } else {
    169 190   throw new TigaseDBException("Too many elements in the user roster.");
    170 191   }
    171  - 
    172 192   if (log.isLoggable(Level.FINEST)) {
    173  - log.log(Level.FINEST, "Added buddy to roster: {0}", buddy);
     193 + log.log(Level.FINEST, "2. Added buddy to roster: {0}, name: {1}, item: {2}",
     194 + new Object[] { relem.getJid(),
     195 + relem.getName(), relem.getRosterItem() });
    174 196   }
    175 197   } else {
    176  - if ((name != null) && !name.isEmpty()) {
     198 + if ((name != null) &&!name.isEmpty()) {
    177 199   relem.setName(name);
    178 200   }
    179 201   
    skipped 6 lines
    186 208   
    187 209   // }
    188 210   saveUserRoster(session);
    189  - 
    190 211   if (log.isLoggable(Level.FINEST)) {
    191 212   log.log(Level.FINEST, "Updated buddy in roster: {0}", buddy);
    192 213   }
    skipped 14 lines
    207 228   * @throws TigaseDBException
    208 229   */
    209 230   @Override
    210  - public boolean
    211  - addBuddyGroup(XMPPResourceConnection session, JID buddy, String[] groups)
     231 + public boolean addBuddyGroup(XMPPResourceConnection session, JID buddy, String[] groups)
    212 232   throws NotAuthorizedException, TigaseDBException {
    213 233   RosterElement relem = getRosterElement(session, buddy);
    214 234   
    skipped 24 lines
    239 259   */
    240 260   @Override
    241 261   public boolean containsBuddy(XMPPResourceConnection session, JID buddy)
    242  - throws NotAuthorizedException, TigaseDBException {
     262 + throws NotAuthorizedException, TigaseDBException {
    243 263   RosterElement relem = getRosterElement(session, buddy);
    244  - return relem != null && relem.isPersistent();
     264 + 
     265 + return (relem != null) && relem.isPersistent();
    245 266   }
     267 + 
     268 + //~--- get methods ----------------------------------------------------------
    246 269   
    247 270   // ~--- get methods ----------------------------------------------------------
    248 271   
    skipped 9 lines
    258 281   * @throws TigaseDBException
    259 282   */
    260 283   @Override
     284 + 
    261 285   // public String[] getBuddies(XMPPResourceConnection session,
    262 286   // boolean onlineOnly)
    263  - public
    264  - JID[] getBuddies(XMPPResourceConnection session) throws NotAuthorizedException,
    265  - TigaseDBException {
     287 + public JID[] getBuddies(XMPPResourceConnection session)
     288 + throws NotAuthorizedException, TigaseDBException {
    266 289   Map<BareJID, RosterElement> roster = getUserRoster(session);
    267 290   
    268 291   if (roster.size() == 0) {
    skipped 1 lines
    270 293   }
    271 294   
    272 295   JID[] result = new JID[roster.size()];
    273  - int idx = 0;
     296 + int idx = 0;
    274 297   
    275 298   for (RosterElement rosterElement : roster.values()) {
    276 299   result[idx++] = rosterElement.getJid();
    277 300   }
     301 + 
    278 302   // TODO: this sorting should be optional as it may impact performance
    279 303   Arrays.sort(result, new RosterElemComparator(roster));
    280 304   
    skipped 25 lines
    306 330   */
    307 331   @Override
    308 332   public String[] getBuddyGroups(XMPPResourceConnection session, JID buddy)
    309  - throws NotAuthorizedException, TigaseDBException {
     333 + throws NotAuthorizedException, TigaseDBException {
    310 334   RosterElement relem = getRosterElement(session, buddy);
    311 335   
    312 336   if (relem == null) {
    skipped 29 lines
    342 366   */
    343 367   @Override
    344 368   public Element getBuddyItem(final XMPPResourceConnection session, JID buddy)
    345  - throws NotAuthorizedException, TigaseDBException {
     369 + throws NotAuthorizedException, TigaseDBException {
    346 370   RosterElement relem = getRosterElement(session, buddy);
    347 371   
    348 372   if (relem == null) {
    skipped 17 lines
    366 390   */
    367 391   @Override
    368 392   public String getBuddyName(XMPPResourceConnection session, JID buddy)
    369  - throws NotAuthorizedException, TigaseDBException {
     393 + throws NotAuthorizedException, TigaseDBException {
    370 394   RosterElement relem = getRosterElement(session, buddy);
    371 395   
    372 396   if (relem == null) {
    skipped 17 lines
    390 414   */
    391 415   @Override
    392 416   public SubscriptionType getBuddySubscription(XMPPResourceConnection session, JID buddy)
    393  - throws NotAuthorizedException, TigaseDBException {
     417 + throws NotAuthorizedException, TigaseDBException {
    394 418   RosterElement relem = getRosterElement(session, buddy);
    395 419   
    396 420   if (relem == null) {
    skipped 17 lines
    414 438   * @return
    415 439   */
    416 440   public RosterElement getRosterElementInstance(JID buddy, String name, String[] groups,
    417  - XMPPResourceConnection session) {
     441 + XMPPResourceConnection session) {
    418 442   return new RosterElement(buddy, name, groups, session);
    419 443   }
    420 444   
    skipped 10 lines
    431 455   */
    432 456   @Override
    433 457   public List<Element> getRosterItems(XMPPResourceConnection session)
    434  - throws NotAuthorizedException, TigaseDBException {
    435  - LinkedList<Element> items = new LinkedList<Element>();
     458 + throws NotAuthorizedException, TigaseDBException {
     459 + LinkedList<Element> items = new LinkedList<Element>();
    436 460   Map<BareJID, RosterElement> roster = getUserRoster(session);
    437 461   
    438 462   for (RosterElement relem : roster.values()) {
    skipped 3 lines
    442 466   if (relem.isPersistent()) {
    443 467   items.add(getBuddyItem(relem));
    444 468   }
    445  - 
    446 469   }
    447 470   
    448 471   return items;
    skipped 13 lines
    462 485   */
    463 486   @Override
    464 487   public boolean isOnline(XMPPResourceConnection session, JID buddy)
    465  - throws NotAuthorizedException, TigaseDBException {
     488 + throws NotAuthorizedException, TigaseDBException {
    466 489   RosterElement relem = getRosterElement(session, buddy);
    467 490   
    468 491   return (relem != null) && relem.isOnline();
    469 492   }
     493 + 
     494 + //~--- methods --------------------------------------------------------------
    470 495   
    471 496   // ~--- methods --------------------------------------------------------------
    472 497   
    skipped 8 lines
    481 506   * @return
    482 507   */
    483 508   public boolean parseRoster(String roster_str, Map<BareJID, RosterElement> roster,
    484  - XMPPResourceConnection session) {
     509 + XMPPResourceConnection session) {
    485 510   return parseRosterUtil(roster_str, roster, session);
    486 511   }
    487 512   
    skipped 11 lines
    499 524   */
    500 525   @Override
    501 526   public boolean presenceSent(XMPPResourceConnection session, JID buddy)
    502  - throws NotAuthorizedException, TigaseDBException {
     527 + throws NotAuthorizedException, TigaseDBException {
    503 528   RosterElement relem = getRosterElement(session, buddy);
    504 529   
    505 530   return (relem != null) && relem.isPresence_sent();
    skipped 13 lines
    519 544   */
    520 545   @Override
    521 546   public boolean removeBuddy(XMPPResourceConnection session, JID jid)
    522  - throws NotAuthorizedException, TigaseDBException {
     547 + throws NotAuthorizedException, TigaseDBException {
    523 548   Map<BareJID, RosterElement> roster = getUserRoster(session);
    524 549   
    525 550   if (log.isLoggable(Level.FINEST)) {
    526 551   log.log(Level.FINEST, "Removing roster buddy: {0}, before removal: {1}",
    527  - new Object[] { jid, roster });
     552 + new Object[] { jid,
     553 + roster });
    528 554   }
    529 555   roster.remove(jid.getBareJID());
    530 556   if (log.isLoggable(Level.FINEST)) {
    531 557   log.log(Level.FINEST, "Removing roster buddy: {0}, after removal: {1}",
    532  - new Object[] { jid, roster });
     558 + new Object[] { jid,
     559 + roster });
    533 560   }
    534 561   saveUserRoster(session);
    535 562   
    536 563   return true;
    537 564   }
    538 565   
     566 + //~--- set methods ----------------------------------------------------------
     567 + 
    539 568   // ~--- set methods ----------------------------------------------------------
    540 569   
    541 570   /**
    skipped 9 lines
    551 580   */
    552 581   @Override
    553 582   public void setBuddyName(XMPPResourceConnection session, JID buddy, String name)
    554  - throws NotAuthorizedException, TigaseDBException {
     583 + throws NotAuthorizedException, TigaseDBException {
    555 584   RosterElement relem = getRosterElement(session, buddy);
    556 585   
    557 586   if (relem != null) {
    558 587   if (log.isLoggable(Level.FINEST)) {
    559  - log.log(Level.FINEST, "Setting name: ''{0}'' for buddy: {1}", new Object[] {
    560  - name, buddy });
     588 + log.log(Level.FINEST, "Setting name: ''{0}'' for buddy: {1}", new Object[] { name,
     589 + buddy });
    561 590   }
    562  - 
    563  - if ((name != null) && !name.isEmpty()) {
     591 + if ((name != null) &&!name.isEmpty()) {
    564 592   relem.setName(name);
    565 593   }
    566  - 
    567 594   saveUserRoster(session);
    568 595   } else {
    569 596   log.log(Level.WARNING, "Setting buddy name for non-existen contact: {0}", buddy);
    skipped 13 lines
    583 610   */
    584 611   @Override
    585 612   public void setBuddySubscription(XMPPResourceConnection session,
    586  - SubscriptionType subscription, JID buddy) throws NotAuthorizedException,
    587  - TigaseDBException {
     613 + SubscriptionType subscription, JID buddy)
     614 + throws NotAuthorizedException, TigaseDBException {
    588 615   RosterElement relem = getRosterElement(session, buddy);
    589 616   
    590 617   if (relem != null) {
    skipped 17 lines
    608 635   */
    609 636   @Override
    610 637   public void setOnline(XMPPResourceConnection session, JID buddy, boolean online)
    611  - throws NotAuthorizedException, TigaseDBException {
     638 + throws NotAuthorizedException, TigaseDBException {
    612 639   RosterElement relem = getRosterElement(session, buddy);
    613 640   
    614 641   if (relem == null) {
    615 642   relem = addTempBuddy(buddy, session);
    616 643   }
    617  - 
    618 644   relem.setOnline(buddy.getResource(), online);
    619 645   }
    620 646   
    skipped 10 lines
    631 657   */
    632 658   @Override
    633 659   public void setPresenceSent(XMPPResourceConnection session, JID buddy, boolean sent)
    634  - throws NotAuthorizedException, TigaseDBException {
     660 + throws NotAuthorizedException, TigaseDBException {
    635 661   RosterElement relem = getRosterElement(session, buddy);
    636 662   
    637 663   if (relem == null) {
    skipped 1 lines
    639 665   }
    640 666   relem.setPresence_sent(sent);
    641 667   }
     668 + 
     669 + //~--- get methods ----------------------------------------------------------
    642 670   
    643 671   // ~--- get methods ----------------------------------------------------------
    644 672   
     673 + /**
     674 + * Method description
     675 + *
     676 + *
     677 + * @param session
     678 + * @param buddy
     679 + *
     680 + * @return
     681 + *
     682 + * @throws NotAuthorizedException
     683 + * @throws TigaseDBException
     684 + */
    645 685   public RosterElement getRosterElement(XMPPResourceConnection session, JID buddy)
    646  - throws NotAuthorizedException, TigaseDBException {
     686 + throws NotAuthorizedException, TigaseDBException {
    647 687   Map<BareJID, RosterElement> roster = getUserRoster(session);
    648 688   
    649 689   return roster.get(buddy.getBareJID());
    650 690   }
    651 691   
     692 + /**
     693 + * Method description
     694 + *
     695 + *
     696 + * @param session
     697 + *
     698 + * @return
     699 + *
     700 + * @throws NotAuthorizedException
     701 + * @throws TigaseDBException
     702 + */
    652 703   @SuppressWarnings({ "unchecked" })
    653 704   protected Map<BareJID, RosterElement> getUserRoster(XMPPResourceConnection session)
    654  - throws NotAuthorizedException, TigaseDBException {
     705 + throws NotAuthorizedException, TigaseDBException {
    655 706   Map<BareJID, RosterElement> roster = null;
    656 707   
    657 708   // The method can be called from different plugins concurrently.
    skipped 1 lines
    659 710   // access problems
    660 711   synchronized (session) {
    661 712   roster = (Map<BareJID, RosterElement>) session.getCommonSessionData(ROSTER);
    662  - 
    663 713   if (roster == null) {
    664 714   roster = loadUserRoster(session);
    665 715   }
    skipped 2 lines
    668 718   return roster;
    669 719   }
    670 720   
     721 + //~--- methods --------------------------------------------------------------
     722 + 
    671 723   // ~--- methods --------------------------------------------------------------
    672 724   
     725 + /**
     726 + * Method description
     727 + *
     728 + *
     729 + * @param session
     730 + *
     731 + * @throws NotAuthorizedException
     732 + * @throws TigaseDBException
     733 + */
    673 734   protected void saveUserRoster(XMPPResourceConnection session)
    674  - throws NotAuthorizedException, TigaseDBException {
     735 + throws NotAuthorizedException, TigaseDBException {
    675 736   Map<BareJID, RosterElement> roster = getUserRoster(session);
    676  - StringBuilder sb = new StringBuilder(5000);
     737 + StringBuilder sb = new StringBuilder(5000);
    677 738   
    678 739   for (RosterElement relem : roster.values()) {
    679 740   if (relem.isPersistent()) {
    680 741   sb.append(relem.getRosterElement().toString());
    681 742   }
    682 743   }
    683  - 
    684 744   if (log.isLoggable(Level.FINEST)) {
    685 745   log.log(Level.FINEST, "Saving user roster: {0}", sb);
    686 746   }
    687  - 
    688 747   session.setData(null, ROSTER, sb.toString());
    689 748   }
    690 749   
    691 750   private Map<BareJID, RosterElement> loadUserRoster(XMPPResourceConnection session)
    692  - throws NotAuthorizedException, TigaseDBException {
     751 + throws NotAuthorizedException, TigaseDBException {
    693 752   
    694 753   // In most times we just read from this data structure
    695 754   // From time to time there might be some modification, posibly concurrent
    696 755   // very unlikely by more than one thread
    697  - Map<BareJID, RosterElement> roster =
    698  - new ConcurrentHashMap<BareJID, RosterElement>(100, 0.25f, 1);
     756 + Map<BareJID, RosterElement> roster = new ConcurrentHashMap<BareJID,
     757 + RosterElement>(100, 0.25f, 1);
    699 758   
    700 759   session.putCommonSessionData(ROSTER, roster);
    701 760   
    skipped 2 lines
    704 763   if (log.isLoggable(Level.FINEST)) {
    705 764   log.log(Level.FINEST, "Loaded user roster: {0}", roster_str);
    706 765   }
    707  - 
    708  - if ((roster_str != null) && !roster_str.isEmpty()) {
     766 + if ((roster_str != null) &&!roster_str.isEmpty()) {
    709 767   updateRosterHash(roster_str, session);
    710 768   
    711 769   boolean modified = parseRoster(roster_str, roster, session);
    skipped 6 lines
    718 776   // Try to load a roster from the 'old' style roster storage and
    719 777   // convert it the the flat roster storage
    720 778   Roster oldRoster = new Roster();
    721  - JID[] buddies = oldRoster.getBuddies(session);
     779 + JID[] buddies = oldRoster.getBuddies(session);
    722 780   
    723 781   if ((buddies != null) && (buddies.length > 0)) {
    724 782   for (JID buddy : buddies) {
    725  - String name = oldRoster.getBuddyName(session, buddy);
     783 + String name = oldRoster.getBuddyName(session, buddy);
    726 784   SubscriptionType subscr = oldRoster.getBuddySubscription(session, buddy);
    727  - String[] groups = oldRoster.getBuddyGroups(session, buddy);
    728  - RosterElement relem = getRosterElementInstance(buddy, name, groups, session);
     785 + String[] groups = oldRoster.getBuddyGroups(session, buddy);
     786 + RosterElement relem = getRosterElementInstance(buddy, name, groups,
     787 + session);
    729 788   
    730 789   relem.setSubscription(subscr);
    731  - 
    732 790   if (!addBuddy(relem, roster)) {
    733 791   break;
    734 792   }
    735 793   }
    736  - 
    737 794   saveUserRoster(session);
    738 795   }
    739 796   }
    skipped 1 lines
    741 798   return roster;
    742 799   }
    743 800   
    744  - // @Override
    745  - // public void setBuddyOnline(XMPPResourceConnection session, String buddy,
    746  - // boolean online)
    747  - // throws NotAuthorizedException, TigaseDBException {
    748  - // RosterElement relem = getRosterElement(session, buddy);
    749  - // if (relem != null) {
    750  - // relem.setOnline(online);
    751  - // }
    752  - // }
    753  - //
    754  - // @Override
    755  - // public boolean isBuddyOnline(XMPPResourceConnection session, String buddy)
    756  - // throws NotAuthorizedException, TigaseDBException {
    757  - // RosterElement relem = getRosterElement(session, buddy);
    758  - // if (relem != null) {
    759  - // return relem.isOnline();
    760  - // }
    761  - // return false;
    762  - // }
     801 + //~--- get methods ----------------------------------------------------------
    763 802   
    764  - private class RosterElemComparator implements Comparator<JID> {
    765  - 
    766  - private Map<BareJID, RosterElement> roster = null;
    767  - 
    768  - private RosterElemComparator(Map<BareJID, RosterElement> roster) {
    769  - this.roster = roster;
    770  - }
    771  - 
    772  - /*
    773  - * (non-Javadoc)
    774  - *
    775  - * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
    776  - */
    777  - @Override
    778  - public int compare(JID arg0, JID arg1) {
    779  - double w0 = roster.get(arg0.getBareJID()).getWeight();
    780  - double w1 = roster.get(arg1.getBareJID()).getWeight();
    781  - return Double.compare(w0, w1);
    782  - }
    783  - 
    784  - }
    785  - 
     803 + /**
     804 + * Method description
     805 + *
     806 + *
     807 + * @param session
     808 + * @param buddy
     809 + *
     810 + * @return
     811 + *
     812 + * @throws NotAuthorizedException
     813 + * @throws TigaseDBException
     814 + */
    786 815   public String getCustomStatus(XMPPResourceConnection session, JID buddy)
    787  - throws NotAuthorizedException, TigaseDBException {
     816 + throws NotAuthorizedException, TigaseDBException {
    788 817   RosterElement rel = getRosterElement(session, buddy);
    789  - String result = null;
     818 + String result = null;
     819 + 
    790 820   if (rel != null) {
    791 821   if (rel.getLastSeen() > RosterElement.INITIAL_LAST_SEEN_VAL) {
    792  - result =
    793  - "Buddy last seen on: " + new Date(rel.getLastSeen()) + ", weight: "
    794  - + rel.getWeight();
     822 + result = "Buddy last seen on: " + new Date(rel.getLastSeen()) + ", weight: " +
     823 + rel.getWeight();
    795 824   } else {
    796 825   result = "Never seen";
    797 826   }
    798 827   }
     828 + 
    799 829   return result;
    800 830   }
     831 + 
     832 + //~--- methods --------------------------------------------------------------
    801 833   
    802 834   /*
    803 835   * (non-Javadoc)
    804 836   *
    805 837   * @see tigase.xmpp.impl.roster.RosterAbstract#logout()
    806 838   */
     839 + 
     840 + /**
     841 + * Method description
     842 + *
     843 + *
     844 + * @param session
     845 + */
    807 846   @Override
    808 847   public void logout(XMPPResourceConnection session) {
    809 848   try {
    skipped 1 lines
    811 850   saveUserRoster(session);
    812 851   }
    813 852   } catch (NotAuthorizedException ex) {
     853 + 
    814 854   // TODO Auto-generated catch block
    815 855   ex.printStackTrace();
    816 856   } catch (TigaseDBException ex) {
     857 + 
    817 858   // TODO Auto-generated catch block
    818 859   ex.printStackTrace();
    819 860   }
    820 861   }
    821 862   
     863 + //~--- get methods ----------------------------------------------------------
     864 + 
    822 865   /**
    823 866   * @param session
    824 867   * @return
    skipped 1 lines
    826 869   * @throws NotAuthorizedException
    827 870   */
    828 871   public boolean isModified(XMPPResourceConnection session)
    829  - throws NotAuthorizedException, TigaseDBException {
     872 + throws NotAuthorizedException, TigaseDBException {
    830 873   Map<BareJID, RosterElement> roster = getUserRoster(session);
    831  - boolean result = false;
     874 + boolean result = false;
     875 + 
    832 876   if (roster != null) {
    833 877   for (RosterElement rel : roster.values()) {
    834 878   result |= rel.isModified();
    835 879   }
    836 880   }
     881 + 
    837 882   return result;
    838 883   }
    839 884   
    840  -} // RosterFlat
     885 + //~--- inner classes --------------------------------------------------------
     886 + 
     887 + // @Override
     888 + // public void setBuddyOnline(XMPPResourceConnection session, String buddy,
     889 + // boolean online)
     890 + // throws NotAuthorizedException, TigaseDBException {
     891 + // RosterElement relem = getRosterElement(session, buddy);
     892 + // if (relem != null) {
     893 + // relem.setOnline(online);
     894 + // }
     895 + // }
     896 + //
     897 + // @Override
     898 + // public boolean isBuddyOnline(XMPPResourceConnection session, String buddy)
     899 + // throws NotAuthorizedException, TigaseDBException {
     900 + // RosterElement relem = getRosterElement(session, buddy);
     901 + // if (relem != null) {
     902 + // return relem.isOnline();
     903 + // }
     904 + // return false;
     905 + // }
     906 + private class RosterElemComparator
     907 + implements Comparator<JID> {
     908 + private Map<BareJID, RosterElement> roster = null;
     909 + 
     910 + //~--- constructors -------------------------------------------------------
     911 + 
     912 + private RosterElemComparator(Map<BareJID, RosterElement> roster) {
     913 + this.roster = roster;
     914 + }
     915 + 
     916 + //~--- methods ------------------------------------------------------------
     917 + 
     918 + /*
     919 + * (non-Javadoc)
     920 + *
     921 + * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
     922 + */
     923 + 
     924 + /**
     925 + * Method description
     926 + *
     927 + *
     928 + * @param arg0
     929 + * @param arg1
     930 + *
     931 + * @return
     932 + */
     933 + @Override
     934 + public int compare(JID arg0, JID arg1) {
     935 + double w0 = roster.get(arg0.getBareJID()).getWeight();
     936 + double w1 = roster.get(arg1.getBareJID()).getWeight();
     937 + 
     938 + return Double.compare(w0, w1);
     939 + }
     940 + }
     941 +} // RosterFlat
     942 + 
     943 + 
    841 944   
    842 945  // ~ Formatted in Sun Code Convention
    843 946   
    844 947  // ~ Formatted by Jindent --- http://www.jindent.com
    845 948   
     949 + 
     950 +//~ Formatted in Tigase Code Convention on 13/02/28
     951 + 
Please wait...
Page is in error, reload to recover