src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java
/**
     * Requests the provider to enter into a status corresponding to the
     * specified parameters.
     *
     * @param status the PresenceStatus as returned by
     *   getRequestableStatusSet
     * @param statusMessage the message that should be set as the reason to
     *   enter that status
     * @throws IllegalArgumentException if the status requested is not a
     *   valid PresenceStatus supported by this provider.
     * @throws IllegalStateException if the provider is not currently
     *   registered.
     * @throws OperationFailedException with code NETWORK_FAILURE if
     *   publishing the status fails due to a network error.
     */
Requests the provider to enter into a status corresponding to the
specified parameters.

@param status the PresenceStatus as returned by
getRequestableStatusSet
@param statusMessage the message that should be set as the reason to
enter that status
@throws IllegalArgumentException if the status requested is not a
valid PresenceStatus supported by this provider.
@throws IllegalStateException if the provider is not currently
registered.
@throws OperationFailedException with code NETWORK_FAILURE if
publishing the status fails due to a network error.
Requests the provider to enter into a status corresponding to the specified parameters . @param status the PresenceStatus as returned by getRequestableStatusSet @param statusMessage the message that should be set as the reason to enter that status @throws IllegalArgumentException if the status requested is not a valid PresenceStatus supported by this provider . @throws IllegalStateException if the provider is not currently registered . @throws OperationFailedException with code NETWORK_FAILURE if publishing the status fails due to a network error .
public void publishPresenceStatus(PresenceStatus status,
                                      String statusMessage)
        throws IllegalArgumentException,
               IllegalStateException,
               OperationFailedException
    {
        assertConnected();
        JabberStatusEnum jabberStatusEnum =
            parentProvider.getJabberStatusEnum();
        boolean isValidStatus = false;
        for (Iterator<PresenceStatus> supportedStatusIter
                        = jabberStatusEnum.getSupportedStatusSet();
             supportedStatusIter.hasNext();)
        {
            if (supportedStatusIter.next().equals(status))
            {
                isValidStatus = true;
                break;
            }
        }
        if (!isValidStatus)
            throw new IllegalArgumentException(status
                + " is not a valid Jabber status");
        synchronized(ssContactList.getRosterInitLock())
        {
            if(!ssContactList.isRosterInitialized())
            {
                ssContactList.setInitialStatus(status);
                ssContactList.setInitialStatusMessage(statusMessage);
                return;
            }
        }
        if (status.equals(jabberStatusEnum.getStatus(JabberStatusEnum.OFFLINE)))
        {
            parentProvider.unregister();
            clearLocalContactResources();
        }
        else
        {
            Presence presence = new Presence(Presence.Type.available);
            currentPresence = presence;
            presence.setMode(presenceStatusToJabberMode(status));
            presence.setPriority(
                getPriorityForPresenceStatus(status.getStatusName()));
            if(status.equals(jabberStatusEnum.getStatus(
                    JabberStatusEnum.ON_THE_PHONE)))
            {
                presence.setStatus(JabberStatusEnum.ON_THE_PHONE);
            }
            else if(status.equals(jabberStatusEnum.getStatus(
                JabberStatusEnum.IN_A_MEETING)))
            {
                presence.setStatus(JabberStatusEnum.IN_A_MEETING);
            }
            else
            {
                presence.setStatus(statusMessage);
            }
            try
            {
                parentProvider.getConnection().sendStanza(presence);
            }
            catch (NotConnectedException | InterruptedException e)
            {
                throw new OperationFailedException(
                    "Could not send new presense status",
                    OperationFailedException.GENERAL_ERROR,
                    e
                );
            }
            if(localContact != null)
                updateResource(localContact,
                    parentProvider.getOurJID().asFullJidIfPossible(), presence);
        }
        fireProviderStatusChangeEvent(currentStatus, status);
        String oldStatusMessage = getCurrentStatusMessage();
        /*
         * XXX Use StringUtils.isEquals instead of String.equals to avoid a
         * NullPointerException.
         */
        if(!java.util.Objects.equals(oldStatusMessage, statusMessage))
        {
            currentStatusMessage = statusMessage;
            fireProviderStatusMessageChangeEvent(
                    oldStatusMessage,
                    getCurrentStatusMessage());
        }
    }
public void publishPresenceStatus ( PresenceStatus status , String statusMessage ) throws IllegalArgumentException , IllegalStateException , OperationFailedException { assertConnected ( ) ; JabberStatusEnum jabberStatusEnum = parentProvider . getJabberStatusEnum ( ) ; boolean isValidStatus = false ; for ( Iterator < PresenceStatus > supportedStatusIter = jabberStatusEnum . getSupportedStatusSet ( ) ; supportedStatusIter . hasNext ( ) ; ) { if ( supportedStatusIter . next ( ) . equals ( status ) ) { isValidStatus = true ; break ; } } if ( ! isValidStatus ) throw new IllegalArgumentException ( status + " is not a valid Jabber status" ) ; synchronized ( ssContactList . getRosterInitLock ( ) ) { if ( ! ssContactList . isRosterInitialized ( ) ) { ssContactList . setInitialStatus ( status ) ; ssContactList . setInitialStatusMessage ( statusMessage ) ; return ; } } if ( status . equals ( jabberStatusEnum . getStatus ( JabberStatusEnum . OFFLINE ) ) ) { parentProvider . unregister ( ) ; clearLocalContactResources ( ) ; } else { Presence presence = new Presence ( Presence . Type . available ) ; currentPresence = presence ; presence . setMode ( presenceStatusToJabberMode ( status ) ) ; presence . setPriority ( getPriorityForPresenceStatus ( status . getStatusName ( ) ) ) ; if ( status . equals ( jabberStatusEnum . getStatus ( JabberStatusEnum . ON_THE_PHONE ) ) ) { presence . setStatus ( JabberStatusEnum . ON_THE_PHONE ) ; } else if ( status . equals ( jabberStatusEnum . getStatus ( JabberStatusEnum . IN_A_MEETING ) ) ) { presence . setStatus ( JabberStatusEnum . IN_A_MEETING ) ; } else { presence . setStatus ( statusMessage ) ; } try { parentProvider . getConnection ( ) . sendStanza ( presence ) ; } catch ( NotConnectedException | InterruptedException e ) { throw new OperationFailedException ( "Could not send new presense status" , OperationFailedException . GENERAL_ERROR , e ) ; } if ( localContact != null ) updateResource ( localContact , parentProvider . getOurJID ( ) . asFullJidIfPossible ( ) , presence ) ; } fireProviderStatusChangeEvent ( currentStatus , status ) ; String oldStatusMessage = getCurrentStatusMessage ( ) ; /*
         * XXX Use StringUtils.isEquals instead of String.equals to avoid a
         * NullPointerException.
         */ if ( ! java . util . Objects . equals ( oldStatusMessage , statusMessage ) ) { currentStatusMessage = statusMessage ; fireProviderStatusMessageChangeEvent ( oldStatusMessage , getCurrentStatusMessage ( ) ) ; } }
Requests the provider to enter into a status corresponding to the
 specified parameters.
Requests the provider to enter into a status corresponding to the specified parameters .
// if we got publish presence and we are still in a process of // initializing the roster, just save the status and we will dispatch // it when we are ready with the roster as sending initial presence // is recommended to be done after requesting the roster, but we want // to also dispatch it // store it // on the phone is a special status which is away // with custom status message