01: /*
02: JSPWiki - a JSP-based WikiWiki clone.
03:
04: Copyright (C) 2001-2007 Janne Jalkanen (Janne.Jalkanen@iki.fi)
05:
06: This program is free software; you can redistribute it and/or modify
07: it under the terms of the GNU Lesser General Public License as published by
08: the Free Software Foundation; either version 2.1 of the License, or
09: (at your option) any later version.
10:
11: This program is distributed in the hope that it will be useful,
12: but WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: GNU Lesser General Public License for more details.
15:
16: You should have received a copy of the GNU Lesser General Public License
17: along with this program; if not, write to the Free Software
18: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20: package com.ecyrd.jspwiki.attachment;
21:
22: import com.ecyrd.jspwiki.WikiEngine;
23:
24: /**
25: * A DynamicAttachment is an attachment which does not really exist, but is
26: * created dynamically by a JSPWiki component.
27: * <p>
28: * Note that a DynamicAttachment might not be available before it is actually
29: * created by a component (e.g. plugin), and therefore trying to access it
30: * before that component has been invoked, might result in a surprising 404.
31: * <p>
32: * DynamicAttachments are not listed among regular attachments in the current
33: * version.
34: * <p>
35: * Usage:
36: *
37: * <pre>
38: *
39: * class MyDynamicComponent implements DynamicAttachmentProvider
40: * {
41: * ...
42: *
43: * DynamicAttachment destatt = mgr.getDynamicAttachment( destattname );
44: *
45: * if( destatt == null )
46: * {
47: * destatt = new DynamicAttachment( context.getEngine(),
48: * context.getPage().getName(),
49: * destfilename,
50: * this );
51: * destatt.setCacheable( false );
52: * }
53: *
54: * // This is used to check whether the attachment is modified or not
55: * // so don't forget to update this if your attachment source changes!
56: * // Else JSPWiki will be serving 304s to anyone who asks...
57: *
58: * destatt.setLastModified( context.getPage().getLastModified() );
59: * mgr.storeDynamicAttachment( context, destatt );
60: * ...
61: *
62: * public InputStream getAttachmentData( WikiContext context, Attachment att )
63: * throws IOException
64: * {
65: * byte[] bytes = "This is a test".getBytes();
66: *
67: * return new ByteArrayInputStream( bytes );
68: * }
69: * </pre>
70: *
71: * @author Janne Jalkanen
72: * @since 2.5.34
73: */
74: public class DynamicAttachment extends Attachment {
75: private DynamicAttachmentProvider m_provider = null;
76:
77: /**
78: * Creates a DynamicAttachment.
79: *
80: * @param engine The engine which owns this attachment
81: * @param parentPage The page which owns this attachment
82: * @param fileName The filename of the attachment
83: * @param provider The provider which will be used to generate the attachment.
84: */
85: public DynamicAttachment(WikiEngine engine, String parentPage,
86: String fileName, DynamicAttachmentProvider provider) {
87: super (engine, parentPage, fileName);
88: m_provider = provider;
89: }
90:
91: /**
92: * Returns the provider which is used to generate this attachment.
93: *
94: * @return A Provider component for this attachment.
95: */
96: public DynamicAttachmentProvider getProvider() {
97: return m_provider;
98: }
99: }
|