import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** * static helper methods to make creating CS * 318-course-style-standard HTML5 pages from servlets * less tedious/error-prone * * @author Sharon Tuttle * @version 3-25-13 */ public class Html318Helpers { /** * send to outStream the HTML5 expected for the beginning * part of an HTML5 page meeting CS 318 course style * standards; assumes NO external css file is involved * * @param outStream the output stream set up for the calling * Java servlet's response object * @param pageTitle the desired title for the HTML5 page being * begun */ public static void beginHtml(ServletOutputStream outStream, String pageTitle) throws IOException { outStream.println("<!DOCTYPE html>"); outStream.println("<html>"); outStream.println("<head>"); outStream.println(" <title> " + pageTitle + " </title>"); outStream.println(" <meta charset=\"utf-8\" />"); outStream.println("</head>"); outStream.println(""); outStream.println("<body>"); } /** * send to outStream the HTML5 expected for the beginning * part of an HTML5 page meeting CS 318 course style * standards when there's also an external CSS to include * * @param outStream the output stream set up for the calling * Java servlet's response object * @param pageTitle the desired title for the HTML5 page being * begun * @param whichCss the external CSS to link to in the head tag */ public static void beginHtmlCss(ServletOutputStream outStream, String pageTitle, String whichCss) throws IOException { outStream.println("<!DOCTYPE html>"); outStream.println("<html>"); outStream.println("<head>"); outStream.println(" <title> " + pageTitle + " </title>"); outStream.println(" <link rel=\"stylesheet\" type=\"text/css\" "); outStream.println(" href=\"" + whichCss + "\" />"); outStream.println(" <meta charset=\"utf-8\" />"); outStream.println("</head>"); outStream.println(""); outStream.println("<body>"); } /** * send to outStream the HTML5 expected for the bottom * part of an HTML5 page meeting CS 318 course style * standards * * @param outStream the output stream set up for the calling * Java servlet's response object */ public static void endHtml(ServletOutputStream outStream) throws IOException { outStream.println(" <hr /> "); outStream.println(""); outStream.println(" <p>"); outStream.println(" <a href=\"http://validator.w3.org/check/referer\">"); outStream.println(" Validate this HTML5 page"); outStream.println(" </a>"); outStream.println(" </p>"); outStream.println(""); outStream.println(" <p>"); outStream.println(" For full credit, this page must also pass the tests at"); outStream.println(" <a href=\"http://lint.brihten.com/html\">"); outStream.println(" http://lint.brihten.com/html/ </a> when its URL is"); outStream.println(" entered (and without modifying the default options)."); outStream.println(" </p>"); outStream.println(""); outStream.println(" <p>"); outStream.println(" <a href=\"http://jigsaw.w3.org/css-validator/check/referer?profile=css3\">"); outStream.println(" <img src=\"http://jigsaw.w3.org/css-validator/images/vcss\" "); outStream.println(" alt=\"Valid CSS3!\" height=\"31\" width=\"88\" />"); outStream.println(" </a>"); outStream.println(" </p>"); outStream.println(""); outStream.println("</body>"); outStream.println("</html>"); } }