01: /****************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one *
03: * or more contributor license agreements. See the NOTICE file *
04: * distributed with this work for additional information *
05: * regarding copyright ownership. The ASF licenses this file *
06: * to you under the Apache License, Version 2.0 (the *
07: * "License"); you may not use this file except in compliance *
08: * with the License. You may obtain a copy of the License at *
09: * *
10: * http://www.apache.org/licenses/LICENSE-2.0 *
11: * *
12: * Unless required by applicable law or agreed to in writing, *
13: * software distributed under the License is distributed on an *
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15: * KIND, either express or implied. See the License for the *
16: * specific language governing permissions and limitations *
17: * under the License. *
18: ****************************************************************/package org.apache.james.mailrepository;
19:
20: import org.apache.avalon.cornerstone.services.store.StreamRepository;
21: import org.apache.james.core.MimeMessageSource;
22:
23: import java.io.IOException;
24: import java.io.InputStream;
25:
26: public class MimeMessageAvalonSource extends MimeMessageSource {
27:
28: //Define how to get to the data
29:
30: /**
31: * The stream repository used by this data source.
32: */
33: StreamRepository sr = null;
34:
35: /**
36: * The name of the repository
37: */
38: String repositoryName = null;
39:
40: /**
41: * The key for the particular stream in the stream repository
42: * to be used by this data source.
43: */
44: String key = null;
45:
46: private long size = -1;
47:
48: public MimeMessageAvalonSource(StreamRepository sr,
49: String repositoryName, String key) {
50: this .sr = sr;
51: this .repositoryName = repositoryName;
52: this .key = key;
53: }
54:
55: /**
56: * Returns a unique String ID that represents the location from where
57: * this source is loaded. This will be used to identify where the data
58: * is, primarily to avoid situations where this data would get overwritten.
59: *
60: * @return the String ID
61: */
62: public String getSourceId() {
63: StringBuffer sourceIdBuffer = new StringBuffer(128).append(
64: repositoryName).append("/").append(key);
65: return sourceIdBuffer.toString();
66: }
67:
68: public InputStream getInputStream() throws IOException {
69: return sr.get(key);
70: }
71:
72: public long getMessageSize() throws IOException {
73: if (size == -1) {
74: if (sr instanceof org.apache.james.mailrepository.filepair.File_Persistent_Stream_Repository) {
75: size = ((org.apache.james.mailrepository.filepair.File_Persistent_Stream_Repository) sr)
76: .getSize(key);
77: } else
78: size = super.getMessageSize();
79: }
80: return size;
81: }
82: }
|