src/net/java/sip/communicator/impl/protocol/jabber/ServerStoredContactListJabberImpl.java
/**
     * Adds a new contact with the specified screenname to the list under the
     * specified group.
     * @param id the id of the contact to add.
     * @param parent the group under which we want the new contact placed.
     * @throws OperationFailedException if the contact already exist
     */
Adds a new contact with the specified screenname to the list under the
specified group.
@param id the id of the contact to add.
@param parent the group under which we want the new contact placed.
@throws OperationFailedException if the contact already exist
Adds a new contact with the specified screenname to the list under the specified group . @param id the id of the contact to add . @param parent the group under which we want the new contact placed . @throws OperationFailedException if the contact already exist
public void addContact(ContactGroup parent, String id)
        throws OperationFailedException
    {
        if (logger.isTraceEnabled())
            logger.trace("Adding contact " + id + " to parent=" + parent);
        final BareJid completeID = parseAddressString(id);
        ContactJabberImpl existingContact = findContactById(completeID);
        if( existingContact != null
            && existingContact.isPersistent() )
        {
            if(logger.isDebugEnabled())
                logger.debug("Contact " + completeID
                                + " already exists in group "
                                + findContactGroup(existingContact));
            throw new OperationFailedException(
                "Contact " + completeID + " already exists.",
                OperationFailedException.SUBSCRIPTION_ALREADY_EXISTS);
        }
        try
        {
            String[] parentNames = null;
            if(parent != null && parent != getRootGroup())
                parentNames = new String[]{parent.getGroupName()};
            StanzaListener presenceInterceptor = new StanzaListener()
            {
                @Override
                public void processStanza(Stanza packet)
                {
                    Presence presence = (Presence) packet;
                    if(presence.getType() == Presence.Type.subscribe
                        && completeID.equals(presence.getTo().asBareJid()))
                    {
                        Nick nicknameExt
                            = new Nick(
                                JabberActivator.getGlobalDisplayDetailsService()
                                    .getDisplayName(jabberProvider));
                        presence.addExtension(nicknameExt);
                    }
                }
            };
            jabberProvider.getConnection().addPacketInterceptor(
                presenceInterceptor, new StanzaTypeFilter(Presence.class));
            getParentProvider().getConnection().setReplyTimeout(
                ProtocolProviderServiceJabberImpl.SMACK_PACKET_REPLY_TIMEOUT);
            this.roster.createEntry(completeID, completeID.toString(), parentNames);
            getParentProvider().getConnection().setReplyTimeout(
                SmackConfiguration.getDefaultReplyTimeout());
            jabberProvider.getConnection().removePacketInterceptor(
                presenceInterceptor);
        }
        catch (XMPPErrorException ex)
        {
            String errTxt = "Error adding new jabber entry";
            logger.error(errTxt, ex);
            int errorCode = OperationFailedException.INTERNAL_ERROR;
            XMPPError err = ex.getXMPPError();
            if(err != null)
            {
                switch (err.getCondition())
                {
                    case forbidden:
                    case not_allowed:
                    case not_authorized:
                        errorCode = OperationFailedException.FORBIDDEN;
                        break;
                    default:
                        errorCode = OperationFailedException.INTERNAL_SERVER_ERROR;
                }
                errTxt = err.getConditionText();
            }
            throw new OperationFailedException(errTxt, errorCode, ex);
        }
        catch (InterruptedException
            | NotConnectedException
            | NoResponseException
            | NotLoggedInException e)
        {
            throw new OperationFailedException(
                    "Could not add contact",
                    OperationFailedException.INTERNAL_ERROR,
                    e);
        }
    }
public void addContact ( ContactGroup parent , String id ) throws OperationFailedException { if ( logger . isTraceEnabled ( ) ) logger . trace ( "Adding contact " + id + " to parent=" + parent ) ; final BareJid completeID = parseAddressString ( id ) ; ContactJabberImpl existingContact = findContactById ( completeID ) ; if ( existingContact != null && existingContact . isPersistent ( ) ) { if ( logger . isDebugEnabled ( ) ) logger . debug ( "Contact " + completeID + " already exists in group " + findContactGroup ( existingContact ) ) ; throw new OperationFailedException ( "Contact " + completeID + " already exists." , OperationFailedException . SUBSCRIPTION_ALREADY_EXISTS ) ; } try { String [ ] parentNames = null ; if ( parent != null && parent != getRootGroup ( ) ) parentNames = new String [ ] { parent . getGroupName ( ) } ; StanzaListener presenceInterceptor = new StanzaListener ( ) { @ Override public void processStanza ( Stanza packet ) { Presence presence = ( Presence ) packet ; if ( presence . getType ( ) == Presence . Type . subscribe && completeID . equals ( presence . getTo ( ) . asBareJid ( ) ) ) { Nick nicknameExt = new Nick ( JabberActivator . getGlobalDisplayDetailsService ( ) . getDisplayName ( jabberProvider ) ) ; presence . addExtension ( nicknameExt ) ; } } } ; jabberProvider . getConnection ( ) . addPacketInterceptor ( presenceInterceptor , new StanzaTypeFilter ( Presence . class ) ) ; getParentProvider ( ) . getConnection ( ) . setReplyTimeout ( ProtocolProviderServiceJabberImpl . SMACK_PACKET_REPLY_TIMEOUT ) ; this . roster . createEntry ( completeID , completeID . toString ( ) , parentNames ) ; getParentProvider ( ) . getConnection ( ) . setReplyTimeout ( SmackConfiguration . getDefaultReplyTimeout ( ) ) ; jabberProvider . getConnection ( ) . removePacketInterceptor ( presenceInterceptor ) ; } catch ( XMPPErrorException ex ) { String errTxt = "Error adding new jabber entry" ; logger . error ( errTxt , ex ) ; int errorCode = OperationFailedException . INTERNAL_ERROR ; XMPPError err = ex . getXMPPError ( ) ; if ( err != null ) { switch ( err . getCondition ( ) ) { case forbidden : case not_allowed : case not_authorized : errorCode = OperationFailedException . FORBIDDEN ; break ; default : errorCode = OperationFailedException . INTERNAL_SERVER_ERROR ; } errTxt = err . getConditionText ( ) ; } throw new OperationFailedException ( errTxt , errorCode , ex ) ; } catch ( InterruptedException | NotConnectedException | NoResponseException | NotLoggedInException e ) { throw new OperationFailedException ( "Could not add contact" , OperationFailedException . INTERNAL_ERROR , e ) ; } }
Adds a new contact with the specified screenname to the list under the
 specified group.
Adds a new contact with the specified screenname to the list under the specified group .
//if the contact is already in the contact list and is not volatile, //then only broadcast an event // modify our reply timeout because some XMPP may send "result" IQ // late (> 5 seconds).