001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.html;
014
015/**
016 * Defines the interface for rendering the contents of an HTML page produced by the {@link HtmlDocSerializer}
017 * serializer.
018 * 
019 * <p>
020 * The HTML doc serializer produces the following document structure with the typical contents:
021 * <p class='bcode'>
022 *    <xt>&lt;html&gt;
023 *       &lt;head&gt;
024 *          &lt;style&gt;
025 *             <xv>CSS styles and links to stylesheets</xv>
026 *          &lt;/style&gt;
027 *          &lt;script&gt;
028 *             <xv>Javascript</xv>
029 *          &lt;/script&gt;
030 *       &lt;/head&gt;
031 *       &lt;body&gt;
032 *          &lt;header&gt;
033 *             &lt;h1&gt;<xv>Page title</xv>&lt;/h1&gt;
034 *             &lt;h2&gt;<xv>Page description</xv>&lt;/h2&gt;
035 *             <xv>Arbitrary page branding</xv>
036 *          &lt;/header&gt;
037 *          &lt;nav&gt;
038 *             <xv>Page links</xv>
039 *          &lt;/nav&gt;
040 *          &lt;aside&gt;
041 *             <xv>Side-bar page links</xv>
042 *          &lt;/aside&gt;
043 *          &lt;article&gt;
044 *             <xv>Contents of serialized object</xv>
045 *          &lt;/article&gt;
046 *          &lt;footer&gt;
047 *             <xv>Footer message</xv>
048 *          &lt;/footer&gt;
049 *       &lt;/body&gt;
050 *    &lt;/html&gt;</xt>
051 * </p>
052 * 
053 * <p>
054 * This interface allows you to control how these sections get rendered.
055 */
056public interface HtmlDocTemplate {
057
058   /**
059    * Renders the contents of the <code><xt>&lt;head&gt;</xt></code> element.
060    * 
061    * @param session The current serializer session.
062    * @param w The writer being written to.
063    * @param o The object being serialized.
064    * @throws Exception Any exception can be thrown.
065    */
066   public void head(HtmlDocSerializerSession session, HtmlWriter w, Object o) throws Exception;
067
068   /**
069    * Renders the contents of the <code><xt>&lt;head&gt;</xt>/<xt>&lt;style&gt;</xt></code> element.
070    * 
071    * @param session The current serializer session.
072    * @param w The writer being written to.
073    * @param o The object being serialized.
074    * @throws Exception Any exception can be thrown.
075    */
076   public void style(HtmlDocSerializerSession session, HtmlWriter w, Object o) throws Exception;
077
078   /**
079    * Renders the contents of the <code><xt>&lt;head&gt;</xt>/<xt>&lt;script&gt;</xt></code> element.
080    * 
081    * @param session The current serializer session.
082    * @param w The writer being written to.
083    * @param o The object being serialized.
084    * @throws Exception Any exception can be thrown.
085    */
086   public void script(HtmlDocSerializerSession session, HtmlWriter w, Object o) throws Exception;
087
088   /**
089    * Renders the contents of the <code><xt>&lt;body&gt;</xt></code> element.
090    * 
091    * @param session The current serializer session.
092    * @param w The writer being written to.
093    * @param o The object being serialized.
094    * @throws Exception Any exception can be thrown.
095    */
096   public void body(HtmlDocSerializerSession session, HtmlWriter w, Object o) throws Exception;
097
098   /**
099    * Renders the contents of the <code><xt>&lt;body&gt;</xt>/<xt>&lt;header&gt;</xt></code> element.
100    * 
101    * @param session The current serializer session.
102    * @param w The writer being written to.
103    * @param o The object being serialized.
104    * @throws Exception Any exception can be thrown.
105    */
106   public void header(HtmlDocSerializerSession session, HtmlWriter w, Object o) throws Exception;
107
108   /**
109    * Renders the contents of the <code><xt>&lt;body&gt;</xt>/<xt>&lt;nav&gt;</xt></code> element.
110    * 
111    * @param session The current serializer session.
112    * @param w The writer being written to.
113    * @param o The object being serialized.
114    * @throws Exception Any exception can be thrown.
115    */
116   public void nav(HtmlDocSerializerSession session, HtmlWriter w, Object o) throws Exception;
117
118   /**
119    * Renders the contents of the <code><xt>&lt;body&gt;</xt>/<xt>&lt;article&gt;</xt></code> element.
120    * 
121    * @param session The current serializer session.
122    * @param w The writer being written to.
123    * @param o The object being serialized.
124    * @throws Exception Any exception can be thrown.
125    */
126   public void article(HtmlDocSerializerSession session, HtmlWriter w, Object o) throws Exception;
127
128   /**
129    * Renders the contents of the <code><xt>&lt;body&gt;</xt>/<xt>&lt;aside&gt;</xt></code> element.
130    * 
131    * @param session The current serializer session.
132    * @param w The writer being written to.
133    * @param o The object being serialized.
134    * @throws Exception Any exception can be thrown.
135    */
136   public void aside(HtmlDocSerializerSession session, HtmlWriter w, Object o) throws Exception;
137
138   /**
139    * Renders the contents of the <code><xt>&lt;body&gt;</xt>/<xt>&lt;footer&gt;</xt></code> element.
140    * 
141    * @param session The current serializer session.
142    * @param w The writer being written to.
143    * @param o The object being serialized.
144    * @throws Exception Any exception can be thrown.
145    */
146   public void footer(HtmlDocSerializerSession session, HtmlWriter w, Object o) throws Exception;
147
148   /**
149    * Returns <jk>true</jk> if this page should render a <code><xt>&lt;head&gt;</xt>/<xt>&lt;style&gt;</xt></code> element.
150    * 
151    * @param session The current serializer session.
152    * @return A boolean flag.
153    */
154   public boolean hasStyle(HtmlDocSerializerSession session);
155
156   /**
157    * Returns <jk>true</jk> if this page should render a <code><xt>&lt;head&gt;</xt>/<xt>&lt;script&gt;</xt></code> element.
158    * 
159    * @param session The current serializer session.
160    * @return A boolean flag.
161    */
162   public boolean hasScript(HtmlDocSerializerSession session);
163
164   /**
165    * Returns <jk>true</jk> if this page should render a <code><xt>&lt;body&gt;</xt>/<xt>&lt;header&gt;</xt></code>
166    * element.
167    * 
168    * @param session The current serializer session.
169    * @return A boolean flag.
170    */
171   public boolean hasHeader(HtmlDocSerializerSession session);
172
173   /**
174    * Returns <jk>true</jk> if this page should render a <code><xt>&lt;body&gt;</xt>/<xt>&lt;nav&gt;</xt></code>
175    * element.
176    * 
177    * @param session The current serializer session.
178    * @return A boolean flag.
179    */
180   public boolean hasNav(HtmlDocSerializerSession session);
181
182   /**
183    * Returns <jk>true</jk> if this page should render a <code><xt>&lt;body&gt;</xt>/<xt>&lt;aside&gt;</xt></code>
184    * element.
185    * 
186    * @param session The current serializer session.
187    * @return A boolean flag.
188    */
189   public boolean hasAside(HtmlDocSerializerSession session);
190
191   /**
192    * Returns <jk>true</jk> if this page should render a <code><xt>&lt;body&gt;</xt>/<xt>&lt;footer&gt;</xt></code>
193    * element.
194    * 
195    * @param session The current serializer session.
196    * @return A boolean flag.
197    */
198   public boolean hasFooter(HtmlDocSerializerSession session);
199}