01: /*
02: JSPWiki - a JSP-based WikiWiki clone.
03:
04: Copyright (C) 2001-2006 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.render;
21:
22: import java.io.IOException;
23: import java.io.StringWriter;
24:
25: import org.jdom.output.Format;
26: import org.jdom.output.XMLOutputter;
27:
28: import com.ecyrd.jspwiki.WikiContext;
29: import com.ecyrd.jspwiki.parser.WikiDocument;
30:
31: /**
32: * Implements a WikiRendered that outputs XHTML. Because the internal DOM
33: * representation is in XHTML already, this just basically dumps out everything
34: * out in a non-prettyprinted format.
35: *
36: * @author jalkanen
37: * @since 2.4
38: */
39: public class XHTMLRenderer extends WikiRenderer {
40: private static final String LINEBREAK = "\n";
41:
42: public XHTMLRenderer(WikiContext context, WikiDocument doc) {
43: super (context, doc);
44: }
45:
46: public String getString() throws IOException {
47: m_document.setContext(m_context);
48:
49: XMLOutputter output = new XMLOutputter();
50:
51: StringWriter out = new StringWriter();
52:
53: Format fmt = Format.getRawFormat();
54: fmt.setExpandEmptyElements(false);
55: fmt.setLineSeparator(LINEBREAK);
56:
57: output.setFormat(fmt);
58: output.outputElementContent(m_document.getRootElement(), out);
59:
60: return out.toString();
61: }
62: }
|