01: /*
02: * The contents of this file are subject to the
03: * Mozilla Public License Version 1.1 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
06: *
07: * Software distributed under the License is distributed on an "AS IS"
08: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
09: * 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: * Standard implementation of <code>PageRenderer</code> which will render
32: * XML using a XSLT to a given <code>OutputStream</code>
33: *
34: * @author Michael Bell
35: * @version $Revision: 1.3 $
36: *
37: */
38: public class StandardRenderer implements PageRenderer {
39:
40: /**
41: *
42: */
43: public StandardRenderer() {
44: super ();
45: }
46:
47: /* (non-Javadoc)
48: * @see org.openharmonise.rm.publishing.renderers.PageRenderer#render(org.openharmonise.commons.xml.XMLDocument, javax.xml.transform.Templates, java.io.OutputStream)
49: */
50: public void render(XMLDocument xdoc, Templates templates,
51: OutputStream out) throws RenderException {
52: try {
53: OutputStreamWriter outwriter = new OutputStreamWriter(out,
54: "UTF-8");
55:
56: Transformer trans = templates.newTransformer();
57:
58: DOMSource ds = new DOMSource(xdoc.getDocumentElement());
59:
60: StreamResult res = new StreamResult(outwriter);
61:
62: trans.transform(ds, res);
63: } catch (TransformerConfigurationException e) {
64: throw new RenderException(
65: "Error occured with configuration", e);
66: } catch (TransformerException e) {
67: throw new RenderException(
68: "Error occured with transformation", e);
69: } catch (UnsupportedEncodingException e) {
70: throw new RenderException("Unsupported encoding error", e);
71: }
72: }
73: }
|