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 *******************************************************************************/
12package org.jacoco.report.html;
13
14import java.io.IOException;
15import java.io.OutputStream;
16import java.io.Writer;
17
18import org.jacoco.report.xml.XMLDocument;
19
20/**
21 * {@link XMLDocument} that declares its content type to be XHTML 1.0 Strict and
22 * produces {@link HTMLElement}s as children.
23 *
24 *
25 * @author Marc R. Hoffmann
26 * @version 0.4.1.20101007204400
27 */
28public class HTMLDocument extends XMLDocument {
29
30 private static final String ROOT = "html";
31
32 private static final String PUBID = "-//W3C//DTD XHTML 1.0 Strict//EN";
33
34 private static final String SYSTEM = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";
35
36 private static final String XMLNS = "xmlns";
37
38 private static final String XHTML_NAMESPACE_URL = "http://www.w3.org/1999/xhtml";
39
40 /**
41 * Creates a new HTML document based on the given writer.
42 *
43 * @param writer
44 * writer for content output
45 * @param encoding
46 * document encoding
47 * @throws IOException
48 * in case of problems with the writer
49 */
50 public HTMLDocument(final Writer writer, final String encoding)
51 throws IOException {
52 super(ROOT, PUBID, SYSTEM, encoding, false, writer);
53 attr(XMLNS, XHTML_NAMESPACE_URL);
54 }
55
56 /**
57 * Creates a new HTML document based on the given stream.
58 *
59 * @param output
60 * stream for content output
61 * @param encoding
62 * document encoding
63 * @throws IOException
64 * in case of problems with the stream
65 */
66 public HTMLDocument(final OutputStream output, final String encoding)
67 throws IOException {
68 super(ROOT, PUBID, SYSTEM, encoding, false, output);
69 attr(XMLNS, XHTML_NAMESPACE_URL);
70 }
71
72 @Override
73 public HTMLElement element(final String name) throws IOException {
74 final HTMLElement element = new HTMLElement(writer, name);
75 addChildElement(element);
76 return element;
77 }
78
79 /**
80 * Creates a 'head' element.
81 *
82 * @return 'head' element
83 * @throws IOException
84 * in case of problems with the writer
85 */
86 public HTMLElement head() throws IOException {
87 return element("head");
88 }
89
90 /**
91 * Creates a 'body' element.
92 *
93 * @return 'body' element
94 * @throws IOException
95 * in case of problems with the writer
96 */
97 public HTMLElement body() throws IOException {
98 return element("body");
99 }
100
101}