001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.portals.gems.util;
018:
019: import java.io.CharArrayWriter;
020: import java.io.PrintWriter;
021:
022: import org.apache.jetspeed.aggregator.PortletContent;
023: import org.apache.jetspeed.cache.ContentCacheKey;
024:
025: public class PortletContentImpl implements PortletContent {
026: private CharArrayWriter cw;
027: private PrintWriter writer;
028: private boolean complete = false;
029: private String cacheKey;
030: private ContentCacheKey ccKey;
031: private int expiration = 0;
032: private String title;
033:
034: public PortletContentImpl() {
035: init();
036: }
037:
038: PortletContentImpl(ContentCacheKey ccKey, int expiration,
039: String title, boolean complete) {
040: this .ccKey = ccKey;
041: this .expiration = expiration;
042: this .title = title;
043: this .complete = complete;
044: init();
045: }
046:
047: PortletContentImpl(String cacheKey, int expiration, String title,
048: boolean complete) {
049: this .cacheKey = cacheKey;
050: this .expiration = expiration;
051: this .title = title;
052: this .complete = complete;
053: init();
054: }
055:
056: PortletContentImpl(String cacheKey, int expiration) {
057: this (cacheKey, expiration, "no title", false);
058: }
059:
060: public PrintWriter getWriter() {
061: return writer;
062: }
063:
064: public void init() {
065: cw = new CharArrayWriter();
066: writer = new PrintWriter(cw);
067: }
068:
069: public void release() {
070: writer.close();
071: }
072:
073: public String toString() {
074: writer.flush();
075: return cw.toString();
076: }
077:
078: public void writeTo(java.io.Writer out) throws java.io.IOException {
079: writer.flush();
080: cw.writeTo(out);
081: }
082:
083: public char[] toCharArray() {
084: writer.flush();
085: return cw.toCharArray();
086: }
087:
088: public boolean isComplete() {
089: return complete;
090: }
091:
092: // error case, don't notify
093: public void completeWithError() {
094: setComplete(true);
095: }
096:
097: void setComplete(boolean state) {
098: this .complete = state;
099: }
100:
101: public String getContent() {
102: return toString();
103: }
104:
105: /**
106: * <p>
107: * complete
108: * </p>
109: *
110: * @see org.apache.jetspeed.aggregator.PortletContent#complete()
111: *
112: */
113: public void complete() {
114: setComplete(true);
115: }
116:
117: public ContentCacheKey getCacheKey() {
118: return ccKey;
119: }
120:
121: public String getStringCacheKey() {
122: return cacheKey;
123: }
124:
125: public int getExpiration() {
126: return expiration;
127: }
128:
129: public void setExpiration(int e) {
130: this .expiration = e;
131: }
132:
133: public String getTitle() {
134: return title;
135: }
136:
137: public void setTitle(String title) {
138: this.title = title;
139: }
140:
141: }
|