01: /*
02: * Copyright (C) 2004 TiongHiang Lee
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: * Email: thlee@onemindsoft.org
19: */
20:
21: package org.onemind.jxp;
22:
23: import java.io.*;
24: import java.util.HashMap;
25: import java.util.Map;
26: import org.onemind.jxp.parser.AstJxpDocument;
27:
28: public class ByteArrayPageSource extends CachingPageSource {
29:
30: private Map _buffers = new HashMap();
31:
32: protected AstJxpDocument parseJxpDocument(JxpPage page)
33: throws JxpPageParseException {
34: // TODO Auto-generated method stub
35: return null;
36: }
37:
38: public void putPageBuffer(String id, byte[] buffer) {
39: _buffers.put(id, buffer);
40: }
41:
42: protected boolean isExpired(CachedJxpPage page) {
43: return false;
44: }
45:
46: protected boolean hasStream(String pageName) {
47: return _buffers.get(pageName) != null;
48: }
49:
50: protected InputStream loadStream(CachedJxpPage page)
51: throws IOException {
52: byte[] buffer = (byte[]) _buffers.get(page.getName());
53: if (buffer == null) {
54: throw new IOException("Page " + page.getName()
55: + " not found");
56: } else {
57: return new ByteArrayInputStream(buffer);
58: }
59: }
60: }
|