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