1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.rest.handler;
23
24 import java.io.*;
25
26 import com.opensymphony.xwork2.ActionInvocation;
27
28 /***
29 * Handles transferring content to and from objects for a specific content type
30 */
31 public interface ContentTypeHandler {
32
33 /***
34 * Populates an object using data from the input stream
35 * @param in The input stream, usually the body of the request
36 * @param target The target, usually the action class
37 */
38 void toObject(Reader in, Object target) throws IOException;
39
40 /***
41 * Writes content to the stream
42 *
43 * @param obj The object to write to the stream, usually the Action class
44 * @param resultCode The original result code
45 * @param stream The output stream, usually the response
46 * @return The new result code
47 * @throws IOException If unable to write to the output stream
48 */
49 String fromObject(Object obj, String resultCode, Writer stream) throws IOException;
50
51 /***
52 * Gets the content type for this handler
53 *
54 * @return The mime type
55 */
56 String getContentType();
57
58 /***
59 * Gets the extension this handler supports
60 *
61 * @return The extension
62 */
63 String getExtension();
64 }