Class Message

  • All Implemented Interfaces:
    java.lang.Cloneable, Element, FullyQualifiedElement, MessageView, NamedElement, StanzaView, TopLevelStreamElement, XmlLangElement, TypedCloneable<Message>

    public final class Message
    extends MessageOrPresence<MessageBuilder>
    implements MessageView, TypedCloneable<Message>
    Represents XMPP message packets. A message can be one of several types:
    • Message.Type.NORMAL -- (Default) a normal text message used in email like interface.
    • Message.Type.CHAT -- a typically short text message used in line-by-line chat interfaces.
    • Message.Type.GROUP_CHAT -- a chat message sent to a groupchat server for group chats.
    • Message.Type.HEADLINE -- a text message to be displayed in scrolling marquee displays.
    • Message.Type.ERROR -- indicates a messaging error.
    For each message type, different message fields are typically used as follows:
    Message Types
     Message type
    FieldNormalChatGroup ChatHeadlineXMPPError
    subject SHOULDSHOULD NOTSHOULD NOTSHOULD NOTSHOULD NOT
    thread OPTIONALSHOULDOPTIONALOPTIONALSHOULD NOT
    body SHOULDSHOULDSHOULDSHOULDSHOULD NOT
    error MUST NOTMUST NOTMUST NOTMUST NOTMUST
    • Constructor Detail

      • Message

        @Deprecated
        public Message()
        Deprecated.
        use StanzaBuilder, preferable via StanzaFactory, instead.
        Creates a new, "normal" message.
      • Message

        @Deprecated
        public Message​(org.jxmpp.jid.Jid to)
        Deprecated.
        use StanzaBuilder, preferable via StanzaFactory, instead.
        Creates a new "normal" message to the specified recipient.
        Parameters:
        to - the recipient of the message.
      • Message

        @Deprecated
        public Message​(org.jxmpp.jid.Jid to,
                       Message.Type type)
        Deprecated.
        use StanzaBuilder, preferable via StanzaFactory, instead.
        Creates a new message of the specified type to a recipient.
        Parameters:
        to - the user to send the message to.
        type - the message type.
      • Message

        @Deprecated
        public Message​(org.jxmpp.jid.Jid to,
                       java.lang.String body)
        Deprecated.
        use StanzaBuilder, preferable via StanzaFactory, instead.
        Creates a new message to the specified recipient and with the specified body.
        Parameters:
        to - the user to send the message to.
        body - the body of the message.
      • Message

        @Deprecated
        public Message​(java.lang.String to,
                       java.lang.String body)
                throws org.jxmpp.stringprep.XmppStringprepException
        Deprecated.
        use StanzaBuilder, preferable via StanzaFactory, instead.
        Creates a new message to the specified recipient and with the specified body.
        Parameters:
        to - the user to send the message to.
        body - the body of the message.
        Throws:
        org.jxmpp.stringprep.XmppStringprepException - if 'to' is not a valid XMPP address.
      • Message

        @Deprecated
        public Message​(org.jxmpp.jid.Jid to,
                       ExtensionElement extensionElement)
        Deprecated.
        use StanzaBuilder, preferable via StanzaFactory, instead.
        Creates a new message with the specified recipient and extension element.
        Parameters:
        to - TODO javadoc me please
        extensionElement - TODO javadoc me please
        Since:
        4.2
      • Message

        public Message​(Message other)
        Copy constructor.

        This does not perform a deep clone, as extension elements are shared between the new and old instance.

        Parameters:
        other - TODO javadoc me please
    • Method Detail

      • setType

        @Deprecated
        public void setType​(Message.Type type)
        Deprecated.
        use StanzaBuilder instead.
        Sets the type of the message.
        Parameters:
        type - the type of the message.
      • getSubject

        public java.lang.String getSubject()
        Returns the default subject of the message, or null if the subject has not been set. The subject is a short description of message contents.

        The default subject of a message is the subject that corresponds to the message's language. (see Stanza.getLanguage()) or if no language is set to the applications default language (see Stanza.getDefaultLanguage()).

        Returns:
        the subject of the message.
      • getSubject

        public java.lang.String getSubject​(java.lang.String language)
        Returns the subject corresponding to the language. If the language is null, the method result will be the same as getSubject(). Null will be returned if the language does not have a corresponding subject.
        Parameters:
        language - the language of the subject to return.
        Returns:
        the subject related to the passed in language.
      • getSubjects

        public java.util.Set<Message.Subject> getSubjects()
        Returns a set of all subjects in this Message, including the default message subject accessible from getSubject().
        Returns:
        a collection of all subjects in this message.
      • setSubject

        @Deprecated
        public void setSubject​(java.lang.String subject)
        Deprecated.
        use StanzaBuilder instead.
        Sets the subject of the message. The subject is a short description of message contents.
        Parameters:
        subject - the subject of the message.
      • addSubject

        @Deprecated
        public Message.Subject addSubject​(java.lang.String language,
                                          java.lang.String subject)
        Deprecated.
        Adds a subject with a corresponding language.
        Parameters:
        language - the language of the subject being added.
        subject - the subject being added to the message.
        Returns:
        the new Message.Subject
        Throws:
        java.lang.NullPointerException - if the subject is null, a null pointer exception is thrown
      • removeSubject

        @Deprecated
        public boolean removeSubject​(java.lang.String language)
        Deprecated.
        Removes the subject with the given language from the message.
        Parameters:
        language - the language of the subject which is to be removed
        Returns:
        true if a subject was removed and false if it was not.
      • removeSubject

        @Deprecated
        public boolean removeSubject​(Message.Subject subject)
        Deprecated.
        Removes the subject from the message and returns true if the subject was removed.
        Parameters:
        subject - the subject being removed from the message.
        Returns:
        true if the subject was successfully removed and false if it was not.
      • getSubjectLanguages

        public java.util.List<java.lang.String> getSubjectLanguages()
        Returns all the languages being used for the subjects, not including the default subject.
        Returns:
        the languages being used for the subjects.
      • getBody

        public java.lang.String getBody()
        Returns the default body of the message, or null if the body has not been set. The body is the main message contents.

        The default body of a message is the body that corresponds to the message's language. (see Stanza.getLanguage()) or if no language is set to the applications default language (see Stanza.getDefaultLanguage()).

        Returns:
        the body of the message.
      • getBody

        public java.lang.String getBody​(java.lang.String language)
        Returns the body corresponding to the language. If the language is null, the method result will be the same as getBody(). Null will be returned if the language does not have a corresponding body.
        Parameters:
        language - the language of the body to return.
        Returns:
        the body related to the passed in language.
        Since:
        3.0.2
      • getBodies

        public java.util.Set<Message.Body> getBodies()
        Returns a set of all bodies in this Message, including the default message body accessible from getBody().
        Returns:
        a collection of all bodies in this Message.
        Since:
        3.0.2
      • setBody

        @Deprecated
        public void setBody​(java.lang.CharSequence body)
        Deprecated.
        use StanzaBuilder instead.
        Sets the body of the message.
        Parameters:
        body - the body of the message.
        Since:
        4.2
        See Also:
        setBody(String)
      • setBody

        @Deprecated
        public void setBody​(java.lang.String body)
        Deprecated.
        use StanzaBuilder instead.
        Sets the body of the message. The body is the main message contents.
        Parameters:
        body - the body of the message.
      • addBody

        @Deprecated
        public Message.Body addBody​(java.lang.String language,
                                    java.lang.String body)
        Deprecated.
        use StanzaBuilder instead.
        Adds a body with a corresponding language.
        Parameters:
        language - the language of the body being added.
        body - the body being added to the message.
        Returns:
        the new Message.Body
        Throws:
        java.lang.NullPointerException - if the body is null, a null pointer exception is thrown
        Since:
        3.0.2
      • removeBody

        @Deprecated
        public boolean removeBody​(java.lang.String language)
        Deprecated.
        use StanzaBuilder instead.
        Removes the body with the given language from the message.
        Parameters:
        language - the language of the body which is to be removed
        Returns:
        true if a body was removed and false if it was not.
      • removeBody

        @Deprecated
        public boolean removeBody​(Message.Body body)
        Deprecated.
        use StanzaBuilder instead.
        Removes the body from the message and returns true if the body was removed.
        Parameters:
        body - the body being removed from the message.
        Returns:
        true if the body was successfully removed and false if it was not.
        Since:
        3.0.2
      • getBodyLanguages

        public java.util.List<java.lang.String> getBodyLanguages()
        Returns all the languages being used for the bodies, not including the default body.
        Returns:
        the languages being used for the bodies.
        Since:
        3.0.2
      • getThread

        public java.lang.String getThread()
        Returns the thread id of the message, which is a unique identifier for a sequence of "chat" messages. If no thread id is set, null will be returned.
        Returns:
        the thread id of the message, or null if it doesn't exist.
      • setThread

        @Deprecated
        public void setThread​(java.lang.String thread)
        Deprecated.
        use StanzaBuilder instead.
        Sets the thread id of the message, which is a unique identifier for a sequence of "chat" messages.
        Parameters:
        thread - the thread id of the message.
      • getElementName

        public java.lang.String getElementName()
        Description copied from interface: NamedElement
        Returns the root element name.
        Specified by:
        getElementName in interface NamedElement
        Returns:
        the element name.
      • toString

        public java.lang.String toString()
        Description copied from class: Stanza
        Returns a short String describing the Stanza. This method is suited for log purposes.
        Specified by:
        toString in class Stanza
      • clone

        public Message clone()
        Creates and returns a copy of this message stanza.

        This does not perform a deep clone, as extension elements are shared between the new and old instance.

        Specified by:
        clone in interface TypedCloneable<Message>
        Overrides:
        clone in class java.lang.Object
        Returns:
        a clone of this message.