KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > rm > publishing > renderers > impl > StandardRenderer


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.rm.publishing.renderers.impl;
20
21 import java.io.*;
22
23 import javax.xml.transform.*;
24 import javax.xml.transform.dom.*;
25 import javax.xml.transform.stream.*;
26
27 import org.openharmonise.commons.xml.*;
28 import org.openharmonise.rm.publishing.renderers.*;
29
30
31
32 /**
33  * Standard implementation of <code>PageRenderer</code> which will render
34  * XML using a XSLT to a given <code>OutputStream</code>
35  *
36  * @author Michael Bell
37  * @version $Revision: 1.3 $
38  *
39  */

40 public class StandardRenderer implements PageRenderer {
41
42     /**
43      *
44      */

45     public StandardRenderer() {
46         super();
47     }
48
49     /* (non-Javadoc)
50      * @see org.openharmonise.rm.publishing.renderers.PageRenderer#render(org.openharmonise.commons.xml.XMLDocument, javax.xml.transform.Templates, java.io.OutputStream)
51      */

52     public void render(XMLDocument xdoc, Templates templates, OutputStream out)
53         throws RenderException {
54         try {
55             OutputStreamWriter outwriter = new OutputStreamWriter(out,"UTF-8");
56             
57             Transformer trans = templates.newTransformer();
58             
59             DOMSource ds = new DOMSource(xdoc.getDocumentElement());
60             
61             StreamResult res = new StreamResult(outwriter);
62             
63             trans.transform(ds, res);
64         } catch (TransformerConfigurationException e) {
65             throw new RenderException("Error occured with configuration",e);
66         } catch (TransformerException e) {
67             throw new RenderException("Error occured with transformation",e);
68         } catch (UnsupportedEncodingException e) {
69             throw new RenderException("Unsupported encoding error",e);
70         }
71     }
72 }
73
Popular Tags