Class Message

  • All Implemented Interfaces:
    Element, FullyQualifiedElement, MessageView, NamedElement, StanzaView, TopLevelStreamElement, XmlLangElement

    public final class Message
    extends MessageOrPresence<MessageBuilder>
    implements MessageView
    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​(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​(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​(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 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:
        XmppStringprepException - if 'to' is not a valid XMPP address.
      • Message

        @Deprecated
        public Message​(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.
      • 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.
      • 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
      • 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.
      • 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

        @Deprecated
        public Message clone()
        Deprecated.
        use asBuilder() instead.
        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.

        Overrides:
        clone in class java.lang.Object
        Returns:
        a clone of this message.