jetbrains.buildServer.controllers
Class ActionMessages

java.lang.Object
  extended by jetbrains.buildServer.controllers.ActionMessages

public class ActionMessages
extends java.lang.Object

Storage for various messages (success messages, information messages and so on). The stored messages can be shown in JSP with help of <bs:messages/> tag where bs prefix is bounded to /WEB-INF/tags URI. The messages are stored in the session, once the message is shown it is deleted automatically after the request processing is finished.

ActionMessages class is responsible for proper messages XML escaping. If the client wants to pass a raw HTML there, he/she should be using addRawMessage(String, String, String...) explicitly. In this case the responsibility is passed to the client.

See Also:
ActionMessage

Constructor Summary
ActionMessages()
          Creates a new storage
 
Method Summary
 void addMessage(ActionMessage message)
          Adds a message with specified key to the storage.
 void addMessage(java.lang.String key, java.lang.String message)
          Adds a message with specified key to the storage.
 void addMessage(java.lang.String key, java.lang.String message, java.lang.String... parameters)
          Adds a message with specified key to the storage.
 void addRawMessage(java.lang.String key, java.lang.String message, java.lang.String... parameters)
          Adds a message with specified key to the storage.
 void clearMessages()
          Removes all currently stored messages
 void clearReadMessages()
          Removes all read messages from the storage.
 ActionMessage getActionMessage(java.lang.String key)
          Returns a message with specified key and marks this message as read.
 java.lang.String getMessage(java.lang.String key)
          Returns a string message with specified key and marks this message as read.
 java.util.Collection<ActionMessage> getMessages()
          Returns all messages and all of them as read.
static ActionMessages getMessages(javax.servlet.http.HttpServletRequest request)
          Obtains ActionMessages object from the specified request.
static ActionMessages getOrCreateMessages(javax.servlet.http.HttpServletRequest request)
          Obtains ActionMessages object from the specified request or creates a new one if there is no such object.
 boolean hasMessage(java.lang.String key)
          Returns true if this storage contains a message with specified key
 boolean hasMessages()
           
 void removeMessage(java.lang.String key)
          Removes the message with the specified key from the storage.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ActionMessages

public ActionMessages()
Creates a new storage

Method Detail

getOrCreateMessages

@NotNull
public static ActionMessages getOrCreateMessages(@NotNull
                                                         javax.servlet.http.HttpServletRequest request)
Obtains ActionMessages object from the specified request or creates a new one if there is no such object.

Parameters:
request - request
Returns:
ActionMessages object

getMessages

@Nullable
public static ActionMessages getMessages(@NotNull
                                                  javax.servlet.http.HttpServletRequest request)
Obtains ActionMessages object from the specified request.

Parameters:
request - request
Returns:
ActionMessages object or null

addMessage

public void addMessage(@NotNull
                       ActionMessage message)
Adds a message with specified key to the storage.

Parameters:
message - message

addMessage

public void addMessage(@NotNull
                       java.lang.String key,
                       @NotNull
                       java.lang.String message)
Adds a message with specified key to the storage.

The caller cannot pass raw HTML message using this method, as the message will be escaped.

Parameters:
key - message key
message - message

addMessage

public void addMessage(@NotNull
                       java.lang.String key,
                       @NotNull
                       java.lang.String message,
                       @NotNull
                       java.lang.String... parameters)
Adds a message with specified key to the storage. Message can contain placeholders for parameters.

The caller cannot pass raw HTML message using this method, as the message will be escaped.

Parameters:
key - message key
message - message
parameters - if specified then substrings like {0}, {1}, {2} and so on will be replaced with parameter with corresponding index. Each parameter will be passed through WebUtil.escapeXml(String) function before inserted into the resulting message.
See Also:
addRawMessage(String, String, String...)

addRawMessage

public void addRawMessage(@NotNull
                          java.lang.String key,
                          @NotNull
                          java.lang.String message,
                          @NotNull
                          java.lang.String... parameters)
Adds a message with specified key to the storage. Message can contain placeholders for parameters.

The caller is allowed to use raw HTML in a message (and thus is responsible of escaping of any untrusted user data there). The parameters are escaped, no HTML can be passed there.

Parameters:
key - message key
message - message
parameters - if specified then substrings like {0}, {1}, {2} and so on will be replaced with parameter with corresponding index. Each parameter will be passed through WebUtil.escapeXml(String) function before inserted into the resulting message.
Since:
7.1
See Also:
addMessage(String, String, String...)

removeMessage

public void removeMessage(@NotNull
                          java.lang.String key)
Removes the message with the specified key from the storage.

Parameters:
key - message key
Since:
8.0

getMessage

@Nullable
public java.lang.String getMessage(@NotNull
                                            java.lang.String key)
Returns a string message with specified key and marks this message as read.

Parameters:
key - message key
Returns:
a message with specified key

getActionMessage

@Nullable
public ActionMessage getActionMessage(@NotNull
                                               java.lang.String key)
Returns a message with specified key and marks this message as read.

Parameters:
key - message key
Returns:
a message with specified key

getMessages

@NotNull
public java.util.Collection<ActionMessage> getMessages()
Returns all messages and all of them as read.

Returns:
collection of messages

hasMessage

public boolean hasMessage(@NotNull
                          java.lang.String key)
Returns true if this storage contains a message with specified key

Parameters:
key - message key
Returns:
true if this storage contains a message with specified key

clearReadMessages

public void clearReadMessages()
Removes all read messages from the storage.


hasMessages

public boolean hasMessages()
Returns:
true if this storage contains at least one message.

clearMessages

public void clearMessages()
Removes all currently stored messages


toString

@NonNls
public java.lang.String toString()
Overrides:
toString in class java.lang.Object