001: /**********************************************************************************
002: * $URL: $
003: * $Id: $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2006, 2007 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.content.impl;
021:
022: import java.io.InputStream;
023: import java.io.UnsupportedEncodingException;
024: import java.util.Hashtable;
025: import java.util.List;
026: import java.util.Map;
027:
028: import org.sakaiproject.content.api.ContentEntity;
029: import org.sakaiproject.content.api.ResourceToolAction;
030: import org.sakaiproject.content.api.ResourceToolActionPipe;
031:
032: public class BasicResourceToolActionPipe implements
033: ResourceToolActionPipe {
034: protected byte[] content;
035: protected ContentEntity contentEntity;
036: protected InputStream contentInputStream;
037: protected String contentType;
038: protected String initializationId;
039: protected Map propertyValues = new Hashtable();
040: protected Map revisedPropertyValues = new Hashtable();
041: protected byte[] revisedContent;
042: protected InputStream revisedContentStream;
043: protected String revisedContentType;
044: protected String helperId;
045: protected ResourceToolAction action;
046: protected boolean actionCompleted;
047: protected String errorMessage;
048: protected boolean actionCanceled;
049: protected boolean errorEncountered;
050: protected String fileName;
051: protected Object revisedListItem;
052:
053: /**
054: * @return the helperId
055: */
056: public String getHelperId() {
057: return this .helperId;
058: }
059:
060: /**
061: * @param helperId the helperId to set
062: */
063: public void setHelperId(String helperId) {
064: this .helperId = helperId;
065: }
066:
067: public BasicResourceToolActionPipe(String interactionId,
068: ResourceToolAction action) {
069: this .initializationId = interactionId;
070: this .action = action;
071: }
072:
073: public byte[] getContent() {
074: return this .content;
075: }
076:
077: public ContentEntity getContentEntity() {
078: return this .contentEntity;
079: }
080:
081: public InputStream getContentStream() {
082: return this .contentInputStream;
083: }
084:
085: public String getMimeType() {
086: return this .contentType;
087: }
088:
089: public String getInitializationId() {
090: return this .initializationId;
091: }
092:
093: public Object getPropertyValue(String name) {
094: return (String) this .propertyValues.get(name);
095: }
096:
097: public byte[] getRevisedContent() {
098: return this .revisedContent;
099: }
100:
101: public InputStream getRevisedContentStream() {
102: return this .revisedContentStream;
103: }
104:
105: public String getRevisedMimeType() {
106: return this .revisedContentType;
107: }
108:
109: public Map getRevisedResourceProperties() {
110: return this .revisedPropertyValues;
111: }
112:
113: public void setContent(byte[] content) {
114: this .content = content;
115: }
116:
117: public void setContentEntity(ContentEntity entity) {
118: this .contentEntity = entity;
119: }
120:
121: public void setContentStream(InputStream ostream) {
122: this .contentInputStream = ostream;
123: }
124:
125: public void setMimeType(String type) {
126: this .contentType = type;
127: }
128:
129: public void setInitializationId(String id) {
130: this .initializationId = id;
131: }
132:
133: public void setResourceProperty(String name, String value) {
134: if (value == null) {
135: this .propertyValues.remove(name);
136: } else {
137: this .propertyValues.put(name, value);
138: }
139: }
140:
141: public void setRevisedContent(byte[] content) {
142: this .revisedContent = content;
143: }
144:
145: public void setRevisedContentStream(InputStream istream) {
146: this .revisedContentStream = istream;
147: }
148:
149: public void setRevisedMimeType(String type) {
150: this .revisedContentType = type;
151: }
152:
153: public void setRevisedResourceProperty(String name, String value) {
154: if (value == null) {
155: this .revisedPropertyValues.remove(name);
156: } else {
157: this .revisedPropertyValues.put(name, value);
158: }
159: }
160:
161: public boolean isActionCanceled() {
162: return this .actionCanceled;
163: }
164:
165: public boolean isErrorEncountered() {
166: return this .errorEncountered;
167: }
168:
169: public void setActionCanceled(boolean actionCanceled) {
170: this .actionCanceled = actionCanceled;
171: }
172:
173: public void setErrorEncountered(boolean errorEncountered) {
174: this .errorEncountered = errorEncountered;
175: }
176:
177: public void setResourceProperty(String key, List list) {
178: this .propertyValues.put(key, list);
179: }
180:
181: public ResourceToolAction getAction() {
182: return this .action;
183: }
184:
185: public void setRevisedResourceProperty(String name, List list) {
186: this .revisedPropertyValues.put(name, list);
187: }
188:
189: public boolean isActionCompleted() {
190: return this .actionCompleted;
191: }
192:
193: public void setActionCompleted(boolean actionCompleted) {
194: this .actionCompleted = actionCompleted;
195: }
196:
197: public String getErrorMessage() {
198: return this .errorMessage;
199: }
200:
201: public void setErrorMessage(String msg) {
202: this .errorMessage = msg;
203: }
204:
205: /* (non-Javadoc)
206: * @see org.sakaiproject.content.api.ResourceToolActionPipe#getContentstring()
207: */
208: public String getContentstring() {
209: String rv = null;
210: byte[] content = getContent();
211: if (content != null) {
212: rv = new String(content);
213: // try
214: // {
215: // rv = new String( content, "UTF-8" );
216: // }
217: // catch(UnsupportedEncodingException e)
218: // {
219: // rv = new String( content );
220: // }
221: }
222: return rv;
223: }
224:
225: /* (non-Javadoc)
226: * @see org.sakaiproject.content.api.ResourceToolActionPipe#getFileName()
227: */
228: public String getFileName() {
229: return this .fileName;
230: }
231:
232: /* (non-Javadoc)
233: * @see org.sakaiproject.content.api.ResourceToolActionPipe#getFileUploadSize()
234: */
235: public int getFileUploadSize() {
236: int rv = 0;
237: if (this .revisedContent != null) {
238: rv = this .revisedContent.length;
239: }
240: return rv;
241: }
242:
243: /* (non-Javadoc)
244: * @see org.sakaiproject.content.api.ResourceToolActionPipe#setFileName(java.lang.String)
245: */
246: public void setFileName(String fileName) {
247: this .fileName = fileName;
248: }
249:
250: public void setRevisedListItem(Object item) {
251: this .revisedListItem = item;
252: }
253:
254: public Object getRevisedListItem() {
255: return revisedListItem;
256: }
257:
258: }
|