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