aboutsummaryrefslogtreecommitdiffstats
path: root/org.jacoco.report/src/org/jacoco/report/internal/html/HTMLDocument.java
blob: f1c45f244d478d7bfdbe45ac8e3e8710b9933aef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*******************************************************************************
 * Copyright (c) 2009, 2017 Mountainminds GmbH & Co. KG and Contributors
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Marc R. Hoffmann - initial API and implementation
 *    
 *******************************************************************************/
package org.jacoco.report.internal.html;

import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;

import org.jacoco.report.internal.xml.XMLDocument;

/**
 * {@link XMLDocument} that declares its content type to be XHTML 1.0 Strict and
 * produces {@link HTMLElement}s as children.
 */
public class HTMLDocument extends XMLDocument {

	private static final String ROOT = "html";

	private static final String PUBID = "-//W3C//DTD XHTML 1.0 Strict//EN";

	private static final String SYSTEM = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";

	private static final String XMLNS = "xmlns";

	private static final String XHTML_NAMESPACE_URL = "http://www.w3.org/1999/xhtml";

	/**
	 * Creates a new HTML document based on the given writer.
	 * 
	 * @param writer
	 *            writer for content output
	 * @param encoding
	 *            document encoding
	 * @throws IOException
	 *             in case of problems with the writer
	 */
	public HTMLDocument(final Writer writer, final String encoding)
			throws IOException {
		super(ROOT, PUBID, SYSTEM, encoding, false, writer);
		attr(XMLNS, XHTML_NAMESPACE_URL);
	}

	/**
	 * Creates a new HTML document based on the given stream.
	 * 
	 * @param output
	 *            stream for content output
	 * @param encoding
	 *            document encoding
	 * @throws IOException
	 *             in case of problems with the stream
	 */
	public HTMLDocument(final OutputStream output, final String encoding)
			throws IOException {
		super(ROOT, PUBID, SYSTEM, encoding, false, output);
		attr(XMLNS, XHTML_NAMESPACE_URL);
	}

	@Override
	public HTMLElement element(final String name) throws IOException {
		final HTMLElement element = new HTMLElement(writer, name);
		addChildElement(element);
		return element;
	}

	/**
	 * Creates a 'head' element.
	 * 
	 * @return 'head' element
	 * @throws IOException
	 *             in case of problems with the writer
	 */
	public HTMLElement head() throws IOException {
		return element("head");
	}

	/**
	 * Creates a 'body' element.
	 * 
	 * @return 'body' element
	 * @throws IOException
	 *             in case of problems with the writer
	 */
	public HTMLElement body() throws IOException {
		return element("body");
	}

}