HTMLDocument.java
1/*******************************************************************************
2 * Copyright (c) 2009, 2010 Mountainminds GmbH & Co. KG and Contributors
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Marc R. Hoffmann - initial API and implementation
10 *
11 * $Id: $
12 *******************************************************************************/
13package org.jacoco.report.html;
14
15import java.io.IOException;
16import java.io.OutputStream;
17import java.io.Writer;
18
19import org.jacoco.report.xml.XMLDocument;
20
21/**
22 * {@link XMLDocument} that declares its content type to be XHTML 1.0 Strict and
23 * produces {@link HTMLElement}s as children.
24 *
25 *
26 * @author Marc R. Hoffmann
27 * @version $Revision: $
28 */
29public class HTMLDocument extends XMLDocument {
30
31 private static final String ROOT = "html";
32
33 private static final String PUBID = "-//W3C//DTD XHTML 1.0 Strict//EN";
34
35 private static final String SYSTEM = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";
36
37 private static final String XMLNS = "xmlns";
38
39 private static final String XHTML_NAMESPACE_URL = "http://www.w3.org/1999/xhtml";
40
41 /**
42 * Creates a new HTML document based on the given writer.
43 *
44 * @param writer
45 * writer for content output
46 * @param encoding
47 * document encoding
48 * @throws IOException
49 * in case of problems with the writer
50 */
51 public HTMLDocument(final Writer writer, final String encoding)
52 throws IOException {
53 super(ROOT, PUBID, SYSTEM, encoding, false, writer);
54 attr(XMLNS, XHTML_NAMESPACE_URL);
55 }
56
57 /**
58 * Creates a new HTML document based on the given stream.
59 *
60 * @param output
61 * stream for content output
62 * @param encoding
63 * document encoding
64 * @throws IOException
65 * in case of problems with the stream
66 */
67 public HTMLDocument(final OutputStream output, final String encoding)
68 throws IOException {
69 super(ROOT, PUBID, SYSTEM, encoding, false, output);
70 attr(XMLNS, XHTML_NAMESPACE_URL);
71 }
72
73 @Override
74 public HTMLElement element(final String name) throws IOException {
75 final HTMLElement element = new HTMLElement(writer, name);
76 addChildElement(element);
77 return element;
78 }
79
80 /**
81 * Creates a 'head' element.
82 *
83 * @return 'head' element
84 * @throws IOException
85 * in case of problems with the writer
86 */
87 public HTMLElement head() throws IOException {
88 return element("head");
89 }
90
91 /**
92 * Creates a 'body' element.
93 *
94 * @return 'body' element
95 * @throws IOException
96 * in case of problems with the writer
97 */
98 public HTMLElement body() throws IOException {
99 return element("body");
100 }
101
102}