01: /*
02: * ContentComponent.java February 2001
03: *
04: * Copyright (C) 2001, Niall Gallagher <niallg@users.sf.net>
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: * GNU Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General
16: * Public License along with this library; if not, write to the
17: * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18: * Boston, MA 02111-1307 USA
19: */
20:
21: package simple.http.serve;
22:
23: import java.io.OutputStream;
24: import java.io.IOException;
25:
26: /**
27: * The <code>ContentComponent</code> object is used to provide a
28: * resource that delegates to the <code>Context</code> for acquiring
29: * content. The performance of a content resource is dependant on
30: * the provided context implementation as all resources within the
31: * host file system will be taken from the provided instance. For
32: * high performance the <code>CacheContext</code> is recommended.
33: * <p>
34: * This is also an <code>IndexedComponent</code>, which means all
35: * meta data related to the target can be acquired. This provides
36: * information such as the locale, file length, path, and other
37: * such useful information. It the content for a required resource
38: * cannot be acquired a <code>ContentException</code> is thrown.
39: *
40: * @author Niall Gallagher
41: *
42: * @see simple.http.serve.CacheContext
43: */
44: abstract class ContentComponent extends IndexedComponent {
45:
46: /**
47: * Constructor for the <code>ContentComponent</code> object. This
48: * requires the context to locate the resource and the name of
49: * the target that this instance is to emit. The target name is
50: * given to the context to acquire the <code>Content</code>.
51: *
52: * @param target the HTTP request URI that represents this
53: * @param context this is the root context of the resource
54: */
55: protected ContentComponent(Context context, String target) {
56: super (context, target);
57: }
58:
59: /**
60: * This method is provided so that subclasses can write content
61: * easily. This will acquire the targeted <code>Content</code>
62: * object and use its <code>write</code> method to emit it. If
63: * the content for the target resource cannot be acquired then
64: * a <code>ContentException</code> will be thrown.
65: *
66: * @param out this is the output stream to the content to
67: *
68: * @exception IOException thrown if there is a I/O error
69: */
70: protected void write(OutputStream out) throws IOException {
71: context.getContent(target).write(out);
72: }
73: }
|