1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.aggregator.impl;
18
19 import java.io.CharArrayWriter;
20 import java.io.PrintWriter;
21
22 import org.apache.jetspeed.aggregator.PortletContent;
23 import org.apache.jetspeed.aggregator.PortletRenderer;
24 import org.apache.jetspeed.cache.ContentCacheKey;
25
26
27 public class PortletContentImpl implements PortletContent
28 {
29 private CharArrayWriter cw;
30 private PrintWriter writer;
31 private boolean complete = false;
32 private ContentCacheKey cacheKey;
33 private int expiration = 0;
34 private String title;
35 private PortletRenderer renderer = null;
36
37 PortletContentImpl()
38 {
39 init();
40 }
41
42 PortletContentImpl(PortletRenderer renderer, ContentCacheKey cacheKey, int expiration, String title)
43 {
44 this.renderer = renderer;
45 this.cacheKey = cacheKey;
46 this.expiration = expiration;
47 this.title = title;
48 init();
49 }
50
51 PortletContentImpl(PortletRenderer renderer, ContentCacheKey cacheKey, int expiration)
52 {
53 this(renderer, cacheKey, expiration,"no title");
54 }
55
56 public PrintWriter getWriter()
57 {
58 return writer;
59 }
60
61 public void init()
62 {
63 cw = new CharArrayWriter();
64 writer = new PrintWriter(cw);
65 }
66
67 public void release()
68 {
69 writer.close();
70 }
71
72 public String toString()
73 {
74 writer.flush();
75 return cw.toString();
76 }
77
78 public void writeTo( java.io.Writer out ) throws java.io.IOException
79 {
80 writer.flush();
81 cw.writeTo(out);
82 }
83
84 public char[] toCharArray()
85 {
86 writer.flush();
87 return cw.toCharArray();
88 }
89
90 public boolean isComplete()
91 {
92 return complete;
93 }
94
95 void setComplete(boolean state, boolean notify)
96 {
97 if (renderer != null && notify)
98 renderer.notifyContentComplete(this);
99 this.complete = state;
100 }
101
102 public String getContent()
103 {
104 return toString();
105 }
106 /***
107 * <p>
108 * complete
109 * </p>
110 *
111 * @see org.apache.jetspeed.aggregator.PortletContent#complete()
112 *
113 */
114 public void complete()
115 {
116 setComplete(true, true);
117 }
118
119
120 public void completeWithError()
121 {
122 setComplete(true, false);
123 }
124
125 public ContentCacheKey getCacheKey()
126 {
127 return cacheKey;
128 }
129
130 public int getExpiration()
131 {
132 return expiration;
133 }
134
135 public void setExpiration(int expiration)
136 {
137 this.expiration = expiration;
138 }
139
140 public String getTitle()
141 {
142 return title;
143 }
144
145 public void setTitle(String title)
146 {
147 this.title = title;
148 }
149
150 }