001/* 002 * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. Oracle designates this 008 * particular file as subject to the "Classpath" exception as provided 009 * by Oracle in the LICENSE file that accompanied this code. 010 * 011 * This code is distributed in the hope that it will be useful, but WITHOUT 012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 014 * version 2 for more details (a copy is included in the LICENSE file that 015 * accompanied this code). 016 * 017 * You should have received a copy of the GNU General Public License version 018 * 2 along with this work; if not, write to the Free Software Foundation, 019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 020 * 021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 022 * or visit www.oracle.com if you need additional information or have any 023 * questions. 024 */ 025 026package org.jdrupes.mdoclet.internal.doclets.formats.html.markup; 027 028import java.io.IOException; 029import java.io.Writer; 030import java.util.ArrayList; 031import java.util.List; 032import java.util.Objects; 033 034import org.jdrupes.mdoclet.internal.doclets.toolkit.Content; 035 036/** 037 * Content for the {@code <body>} element. 038 * 039 * The content is a {@code <div>} element that contains a 040 * header that is always visible, and main content that 041 * can be scrolled if necessary. 042 */ 043public class BodyContents extends Content { 044 045 private final List<Content> mainContents = new ArrayList<>(); 046 private HtmlTree header = null; 047 private HtmlTree footer = null; 048 049 public BodyContents addMainContent(Content content) { 050 mainContents.add(content); 051 return this; 052 } 053 054 public BodyContents setHeader(HtmlTree header) { 055 this.header = Objects.requireNonNull(header); 056 return this; 057 } 058 059 public BodyContents setFooter(HtmlTree footer) { 060 this.footer = footer; 061 return this; 062 } 063 064 /** 065 * {@inheritDoc} 066 * 067 * @implSpec This implementation always returns {@code false}. 068 * 069 * @return {@code false} 070 */ 071 @Override 072 public boolean isEmpty() { 073 return false; 074 } 075 076 @Override 077 public boolean write(Writer out, String newline, boolean atNewline) 078 throws IOException { 079 return toContent().write(out, newline, atNewline); 080 } 081 082 /** 083 * Returns the HTML for the contents of the BODY element. 084 * 085 * @return the HTML 086 */ 087 private Content toContent() { 088 if (header == null) 089 throw new NullPointerException(); 090 091 HtmlTree flexHeader = header.addStyle(HtmlStyle.flexHeader); 092 093 var flexContent = HtmlTree.DIV(HtmlStyle.flexContent) 094 .add(HtmlTree.MAIN().add(mainContents)) 095 .add(footer == null ? Text.EMPTY : footer); 096 097 return HtmlTree.DIV(HtmlStyle.flexBox) 098 .add(flexHeader) 099 .add(flexContent); 100 } 101}