1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.imixs.workflow.jaxrs;
29
30 import java.io.BufferedWriter;
31 import java.io.IOException;
32 import java.io.OutputStream;
33 import java.io.OutputStreamWriter;
34 import java.lang.annotation.Annotation;
35 import java.lang.reflect.Type;
36
37 import javax.ws.rs.Produces;
38 import javax.ws.rs.WebApplicationException;
39 import javax.ws.rs.core.MediaType;
40 import javax.ws.rs.core.MultivaluedMap;
41 import javax.ws.rs.ext.MessageBodyWriter;
42 import javax.ws.rs.ext.Provider;
43
44 import org.imixs.workflow.xml.EntityCollection;
45 import org.imixs.workflow.xml.XMLItemCollection;
46
47
48
49
50
51
52
53 @Provider
54 @Produces("text/html")
55 public class EntityCollectionWriter implements MessageBodyWriter<EntityCollection> {
56
57 public boolean isWriteable(Class<?> type, Type genericType,
58 Annotation[] annotations, MediaType mediaType) {
59 return EntityCollection.class.isAssignableFrom(type);
60 }
61
62 public void writeTo(EntityCollection entityCollection, Class<?> type, Type genericType,
63 Annotation[] annotations, MediaType mediaType,
64 MultivaluedMap<String, Object> httpHeaders,
65 OutputStream entityStream) throws IOException,
66 WebApplicationException {
67 BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
68 entityStream));
69
70
71
72 bw.write("<html>");
73 XMLItemCollectionWriter.printHead(bw);
74 bw.write("<body>");
75 try {
76 bw.write("<h1>EntityCollection</h1>");
77 bw.write("<h2>" + entityCollection.getEntity().length + " Entries</h2>");
78
79 for (XMLItemCollection xmlworkItem : entityCollection.getEntity()) {
80 XMLItemCollectionWriter.printXMLItemCollectionHTML(bw, xmlworkItem);
81
82 }
83 } catch (Exception e) {
84 bw.write("ERROR<br>");
85
86 }
87
88
89 bw.write("</body>");
90 bw.write("</html>");
91
92 bw.flush();
93 }
94
95 public long getSize(EntityCollection arg0, Class<?> arg1, Type arg2,
96 Annotation[] arg3, MediaType arg4) {
97 return -1;
98 }
99
100
101
102
103
104
105
106
107 }