diff options
-rw-r--r-- | sources/ch/epfl/lamp/util/HTMLPrinter.java | 54 | ||||
-rw-r--r-- | sources/ch/epfl/lamp/util/XHTMLPrinter.java | 33 |
2 files changed, 69 insertions, 18 deletions
diff --git a/sources/ch/epfl/lamp/util/HTMLPrinter.java b/sources/ch/epfl/lamp/util/HTMLPrinter.java index 33e78326bd..df2866fcc1 100644 --- a/sources/ch/epfl/lamp/util/HTMLPrinter.java +++ b/sources/ch/epfl/lamp/util/HTMLPrinter.java @@ -36,18 +36,29 @@ public class HTMLPrinter { //######################################################################## // Private Fields - /** The underlying code printer */ + /** + * The underlying code printer. + */ private final CodePrinter printer; - /** The document title */ + /** + * The document title. + */ private final String title; //######################################################################## // Protected Fields - /** The document representation */ + /** + * The document representation. + */ protected final HTMLRepresentation representation; + /** + * The document stylesheet. + */ + protected final String stylesheet; + //######################################################################## // Public Constructors @@ -57,11 +68,26 @@ public class HTMLPrinter { * @param writer * @param title * @param representation + * @param stylesheet */ - public HTMLPrinter(Writer writer, String title, HTMLRepresentation representation) { + public HTMLPrinter(Writer writer, String title, HTMLRepresentation representation, + String stylesheet) + { this.printer = new CodePrinter(writer, " "); this.title = title; this.representation = representation; + this.stylesheet = stylesheet; + } + + /** + * Creates a new instance. + * + * @param writer + * @param title + * @param representation + */ + public HTMLPrinter(Writer writer, String title, HTMLRepresentation representation) { + this(writer, title, representation, DEFAULT_STYLESHEET); } /** @@ -71,10 +97,12 @@ public class HTMLPrinter { * @param title * @param encoding */ - public HTMLPrinter(Writer writer, String title, String encoding) { - this.printer = new CodePrinter(writer, " "); - this.title = title; - this.representation = new HTMLRepresentation("HTML 4.01 Transitional", encoding); + public HTMLPrinter(Writer writer, String title, String docencoding) { + this( + writer, + title, + new HTMLRepresentation(HTMLRepresentation.DEFAULT_DOCTYPE, docencoding) + ); } /** @@ -84,7 +112,7 @@ public class HTMLPrinter { * @param title */ public HTMLPrinter(Writer writer, String title) { - this(writer, title, "iso-8859-1"); + this(writer, title, HTMLRepresentation.DEFAULT_DOCENCODING); } //######################################################################## @@ -630,9 +658,9 @@ public class HTMLPrinter { * Prints the HTML preamble of the current page. */ protected void printPreamble() { - println("<!DOCTYPE html PUBLIC \"-//W3C//DTD " + - representation.getType() + "//" + representation.getLanguage() + "\">"); - printlnOTag("html").line(); + println("<!DOCTYPE html PUBLIC \"-//W3C//DTD " + + representation.getType() + "//" + representation.getLanguage() + "\">"); + printlnOTag("html").line(); } /** @@ -715,7 +743,7 @@ public class HTMLPrinter { * @param generator */ public void printHeader(XMLAttribute[] metaAttrs, String generator) { - printHeader(metaAttrs, generator, DEFAULT_STYLESHEET); + printHeader(metaAttrs, generator, stylesheet); } /** diff --git a/sources/ch/epfl/lamp/util/XHTMLPrinter.java b/sources/ch/epfl/lamp/util/XHTMLPrinter.java index 1b7707acff..9600817b06 100644 --- a/sources/ch/epfl/lamp/util/XHTMLPrinter.java +++ b/sources/ch/epfl/lamp/util/XHTMLPrinter.java @@ -26,10 +26,24 @@ public class XHTMLPrinter extends HTMLPrinter { * * @param writer * @param title + * @param representation + * @param stylesheet + */ + public XHTMLPrinter(Writer writer, String title, HTMLRepresentation representation, + String stylesheet) + { + super(writer, title, representation, stylesheet); + } + + /** + * Creates a new instance. + * + * @param writer + * @param title * @param repr */ - public XHTMLPrinter(Writer writer, String title, HTMLRepresentation repr) { - super(writer, title, repr); + public XHTMLPrinter(Writer writer, String title, HTMLRepresentation representation) { + this(writer, title, representation, DEFAULT_STYLESHEET); } /** @@ -37,10 +51,10 @@ public class XHTMLPrinter extends HTMLPrinter { * * @param writer * @param title - * @param encoding + * @param docencoding */ - public XHTMLPrinter(Writer writer, String title, String encoding) { - this(writer, title, new HTMLRepresentation("XHTML 1.0 Transitional", encoding)); + public XHTMLPrinter(Writer writer, String title, String docencoding) { + this(writer, title, new HTMLRepresentation("XHTML 1.0 Transitional", docencoding)); } /** @@ -60,6 +74,7 @@ public class XHTMLPrinter extends HTMLPrinter { * Prints text <code>text</code> in bold followed by a new line. * * @param text + * @return the current HTML printer */ public HTMLPrinter printlnBold(String text) { return printlnTag("span", @@ -69,6 +84,8 @@ public class XHTMLPrinter extends HTMLPrinter { /** * Prints an horizontal line separator followed by a new line. + * + * @return the current HTML printer */ public HTMLPrinter printlnHLine() { printOTag("div", new XMLAttribute[] { @@ -84,6 +101,7 @@ public class XHTMLPrinter extends HTMLPrinter { * Prints text <code>text</code> in bold. * * @param text + * @return the current HTML printer */ public HTMLPrinter printBold(String text) { return printTag("span", @@ -93,6 +111,8 @@ public class XHTMLPrinter extends HTMLPrinter { /** * Prints an horizontal line separator + * + * @return the current HTML printer */ public HTMLPrinter printHLine() { printOTag("div", new XMLAttribute[] { @@ -105,6 +125,7 @@ public class XHTMLPrinter extends HTMLPrinter { * Prints an horizontal line separator with attributes <code>attrs</code>. * * @param attrs + * @return the current HTML printer */ public HTMLPrinter printHLine(XMLAttribute[] attrs) { return printHLine(); @@ -115,6 +136,7 @@ public class XHTMLPrinter extends HTMLPrinter { * followed by a new line. * * @param attrs + * @return the current HTML printer */ public HTMLPrinter printlnMeta(XMLAttribute[] attrs) { return printlnSTag("meta", attrs); @@ -125,6 +147,7 @@ public class XHTMLPrinter extends HTMLPrinter { * followed by a new line. * * @param attrs + * @return the current HTML printer */ public HTMLPrinter printlnLink(XMLAttribute[] attrs) { return printlnSTag("link", attrs); |