|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object examples.news.NewsFormatter
public class NewsFormatter
This is a simple example of how you can implement your own ResponseFormatter to suit your own needs. This class
implements the ResponseFormatter interface and requires an extra URL parameter called 'wires'.
It has a predefined set of possible values for wires and a default should the user specify an unrecognised wire.
The possible values for wires are:
Field Summary | |
---|---|
static String |
DEFAULT_WIRE_TYPE
Specifies the default value of 'wires' if the one supplied was invalid. |
static String[] |
POSSIBLE_WIRE_TYPES
Specifies the different types of 'wires' that are valid. |
static String[] |
POSSIBLE_WIRE_VALUES
Specifies the relevant response to each valid value for 'wires'. |
Constructor Summary | |
---|---|
NewsFormatter()
|
Method Summary | |
---|---|
String |
formatErrorResponse(javax.servlet.http.HttpServletRequest request,
String errorMessage)
This method records in the log than an error response is being returned and what the error was. |
String |
formatResponse(javax.servlet.http.HttpServletRequest request,
String token)
Implementation of the interface method. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String DEFAULT_WIRE_TYPE
Specifies the default value of 'wires' if the one supplied was invalid.
public static final String[] POSSIBLE_WIRE_TYPES
Specifies the different types of 'wires' that are valid.
public static final String[] POSSIBLE_WIRE_VALUES
Specifies the relevant response to each valid value for 'wires'.
Constructor Detail |
---|
public NewsFormatter()
Method Detail |
---|
public String formatResponse(javax.servlet.http.HttpServletRequest request, String token)
Implementation of the interface method. The method initialises a Map to hold all the different types of wire and each corresponding message.
This allows quick retrieval of the message as the parameter is used as the key. if the key ("wires") returns null then the default message is returned,
otherwise the corresponding message is returned.
formatResponse
in interface ResponseFormatter
request
- the HttpServletRequest object that contains the URL and parameters etc.token
- the generated token for this request.
public String formatErrorResponse(javax.servlet.http.HttpServletRequest request, String errorMessage)
This method records in the log than an error response is being returned and what the error was. It then returns the errorMessage.
formatErrorResponse
in interface ResponseFormatter
request
- A request object that was used to call the calling servlet.errorMessage
- A description of what has gone wrong.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |