01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.mail.datasource;
18:
19: import java.io.IOException;
20: import java.io.InputStream;
21: import java.io.OutputStream;
22: import javax.activation.DataSource;
23:
24: import org.apache.avalon.framework.logger.AbstractLogEnabled;
25:
26: /**
27: * The AbstractDataSource class is a base class for other {@link DataSource}
28: * implementation.
29: *
30: * @version $Id: AbstractDataSource.java 469260 2006-10-30 20:28:11Z vgritsenko $
31: */
32: public abstract class AbstractDataSource extends AbstractLogEnabled
33: implements DataSource {
34:
35: private String name;
36: private String contentType;
37:
38: public AbstractDataSource() {
39: }
40:
41: /**
42: * @param name Name of the content part
43: * @param type Mime type of the content
44: */
45: public AbstractDataSource(String name, String type) {
46: this .name = name;
47: this .contentType = type;
48: if (isNullOrEmpty(this .name)) {
49: this .name = null;
50: }
51: if (isNullOrEmpty(this .contentType)) {
52: this .contentType = null;
53: }
54: }
55:
56: /**
57: * Check String for null or empty.
58: * @param str
59: * @return true if str is null, empty string, or equals "null"
60: */
61: protected static boolean isNullOrEmpty(String str) {
62: return str == null || "".equals(str) || "null".equals(str);
63: }
64:
65: /**
66: * Returns the name for this <code>DataSource</code> object.
67: */
68: public String getName() {
69: return this .name;
70: }
71:
72: public void setName(String name) {
73: this .name = name;
74: }
75:
76: /**
77: * @return The content type (mime type) of this <code>DataSource</code> object.
78: */
79: public String getContentType() {
80: return this .contentType;
81: }
82:
83: public void setContentType(String contentType) {
84: this .contentType = contentType;
85: }
86:
87: /**
88: * Get the <code>InputStream</code> for this DataSource.
89: */
90: public abstract InputStream getInputStream() throws IOException;
91:
92: /**
93: * Not implemented. Throws <code>IOException</code>.
94: * @throws java.io.IOException since unimplemented
95: */
96: public OutputStream getOutputStream() throws IOException {
97: throw new IOException("no data sink available");
98: }
99: }
|