KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jpublish > view > raw > RawViewRenderer


1 /*--
2
3  Copyright (C) 2001-2003 Aetrion LLC.
4  All rights reserved.
5  
6  Redistribution and use in source and binary forms, with or without
7  modification, are permitted provided that the following conditions
8  are met:
9  
10  1. Redistributions of source code must retain the above copyright
11     notice, this list of conditions, and the following disclaimer.
12  
13  2. Redistributions in binary form must reproduce the above copyright
14     notice, this list of conditions, and the disclaimer that follows
15     these conditions in the documentation and/or other materials
16     provided with the distribution.
17
18  3. The name "JPublish" must not be used to endorse or promote products
19     derived from this software without prior written permission. For
20     written permission, please contact info@aetrion.com.
21  
22  4. Products derived from this software may not be called "JPublish", nor
23     may "JPublish" appear in their name, without prior written permission
24     from Aetrion LLC (info@aetrion.com).
25  
26  In addition, the authors of this software request (but do not require)
27  that you include in the end-user documentation provided with the
28  redistribution and/or in the software itself an acknowledgement equivalent
29  to the following:
30      "This product includes software developed by
31       Aetrion LLC (http://www.aetrion.com/)."
32
33  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
34  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
35  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
36  DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
37  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
38  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
39  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
41  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
42  IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43  POSSIBILITY OF SUCH DAMAGE.
44
45  For more information on JPublish, please see <http://www.jpublish.org/>.
46  
47  */

48
49 package org.jpublish.view.raw;
50
51 import java.io.*;
52
53 import com.anthonyeden.lib.config.Configuration;
54 import com.anthonyeden.lib.config.ConfigurationException;
55 import com.anthonyeden.lib.util.IOUtilities;
56 import org.jpublish.RequestContext;
57 import org.jpublish.view.AbstractViewRenderer;
58 import org.jpublish.view.ContentSource;
59 import org.jpublish.view.ViewRenderException;
60
61 /**
62  * ViewRenderer which renders the data directly to the output stream with no template engine.
63  *
64  * @author Anthony Eden
65  * @since 2.0
66  */

67
68 public class RawViewRenderer extends AbstractViewRenderer {
69
70     /**
71      * Render the view.
72      *
73      * @param context The RequestContext
74      * @param path The path to the template
75      * @param out The Writer to write the rendered view
76      * @throws IOException
77      * @throws ViewRenderException
78      */

79
80     public void render(RequestContext context, String JavaDoc path, Writer out)
81             throws IOException, ViewRenderException {
82         ContentSource contentSource = siteContext.getContentSource(path);
83         InputStream in = null;
84         try {
85             in = contentSource.getInputStream();
86             int c = -1;
87             while ((c = in.read()) != -1) {
88                 out.write((char) c);
89             }
90         } finally {
91             IOUtilities.close(in);
92         }
93     }
94
95     /**
96      * Render the view.
97      *
98      * @param context The RequestContext
99      * @param path The path to the template
100      * @param out The OutputStream to write the rendered view
101      * @throws IOException
102      * @throws ViewRenderException
103      */

104
105     public void render(RequestContext context, String JavaDoc path, OutputStream out)
106             throws IOException, ViewRenderException {
107         render(context, path, new OutputStreamWriter(out));
108     }
109
110     /**
111      * Render the view.
112      *
113      * @param context The RequestContext
114      * @param path The path to the content
115      * @param in The Reader providing the raw content
116      * @param out The Writer to write the rendered view
117      * @throws IOException
118      * @throws ViewRenderException
119      */

120
121     public void render(RequestContext context, String JavaDoc path, Reader in,
122             Writer out) throws IOException, ViewRenderException {
123         int c = -1;
124         while ((c = in.read()) != -1) {
125             out.write((char) c);
126         }
127     }
128
129     /**
130      * Render the view.
131      *
132      * @param context The RequestContext
133      * @param path The path to the content
134      * @param in The InputStream providing the raw content
135      * @param out The OutputStream to write the rendered view
136      * @throws IOException
137      * @throws ViewRenderException
138      */

139
140     public void render(RequestContext context, String JavaDoc path, InputStream in,
141             OutputStream out) throws IOException, ViewRenderException {
142         render(context, path, new InputStreamReader(in),
143                 new OutputStreamWriter(out));
144     }
145
146     /**
147      * Load the configuration for the view.
148      *
149      * @param configuration The configuration object
150      */

151
152     public void loadConfiguration(Configuration configuration)
153             throws ConfigurationException {
154
155     }
156
157 }
158
Popular Tags