diff options
Diffstat (limited to 'sources/ch')
-rw-r--r-- | sources/ch/epfl/lamp/util/CodePrinter.java | 277 | ||||
-rw-r--r-- | sources/ch/epfl/lamp/util/ForwardingMap.java | 97 | ||||
-rw-r--r-- | sources/ch/epfl/lamp/util/HTMLPrinter.java | 886 | ||||
-rw-r--r-- | sources/ch/epfl/lamp/util/HTMLRepresentation.java | 99 | ||||
-rw-r--r-- | sources/ch/epfl/lamp/util/Pair.java | 27 | ||||
-rw-r--r-- | sources/ch/epfl/lamp/util/XHTMLPrinter.java | 189 | ||||
-rw-r--r-- | sources/ch/epfl/lamp/util/XMLAttribute.java | 31 |
7 files changed, 0 insertions, 1606 deletions
diff --git a/sources/ch/epfl/lamp/util/CodePrinter.java b/sources/ch/epfl/lamp/util/CodePrinter.java deleted file mode 100644 index 7bce133a43..0000000000 --- a/sources/ch/epfl/lamp/util/CodePrinter.java +++ /dev/null @@ -1,277 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package ch.epfl.lamp.util; - -import java.io.Writer; -import java.io.StringWriter; -import java.io.IOException; - -/** - * This class provides methods for printing code. It has support for - * indentation and spacing. - */ -public class CodePrinter { - - //######################################################################## - // Public Constants - - /** The default indentation string */ - public static final String STEP = " "; - - /** The line separator */ - public static final String LINE = System.getProperty("line.separator"); - - //######################################################################## - // Private Fields - - /** The underlying writer */ - private final Writer writer; - - /** The indentation string */ - private String step; - - /** The indentation level */ - private int level; - - /** Do we need to align? */ - private boolean align; - - /** Do we need to print a white space? */ - private boolean space; - - /** Is there already a empty line? */ - private boolean line; - - //######################################################################## - // Public Constructors - - /** Creates a new instance. */ - public CodePrinter() { - this(new StringWriter()); - } - - /** Creates a new instance. */ - public CodePrinter(String step) { - this(new StringWriter(), step); - } - - /** Creates a new instance. */ - public CodePrinter(Writer writer) { - this(writer, STEP); - } - - /** Creates a new instance. */ - public CodePrinter(Writer writer, String step) { - this.writer = writer; - this.step = step; - this.level = 0; - this.align = true; - this.space = false; - this.line = false; - } - - //######################################################################## - // Public Methods - Getting & Setting - - /** Returns the underlying writer. */ - public Writer getWriter() { - return writer; - } - - /** Returns the indentation level. */ - public int getIndentLevel() { - return level; - } - - /** Returns the indentation width. */ - public int getIndentWidth() { - return step == null ? -1 : step.length(); - } - - /** Returns the indentation string. */ - public String getIndentString() { - return step; - } - - /** Sets the indentation level. */ - public CodePrinter setIndentLevel(int level) { - this.level = level; - return this; - } - - /** Sets the indentation width. */ - public CodePrinter setIndentWidth(int width) { - StringBuffer buffer = new StringBuffer(width); - for (int i = 0; i < width; i++) buffer.append(' '); - return setIndentString(buffer.toString()); - } - - /** Sets the indentation string. */ - public CodePrinter setIndentString(String step) { - this.step = step; - return this; - } - - //######################################################################## - // Public Methods - Formating - - /** Increases the indentation level by one. */ - public CodePrinter indent() { - level++; - return this; - } - - /** Decreases the indentation level by one. */ - public CodePrinter undent() { - level--; - return this; - } - - /** Inserts a new line. */ - public CodePrinter line() { - if (step == null) return space(); - if (line) return this; - write(LINE); - line = align; - align = true; - space = false; - return this; - } - - /** Inserts a white space. */ - public CodePrinter space() { - space = !align; - return this; - } - - //######################################################################## - // Public Methods - Printing - - /** Prints a new line. */ - public CodePrinter println() { - return line(); - } - - /** Prints the boolean value followed by a new line. */ - public CodePrinter println(boolean value) { - return print(value).line(); - } - - /** Prints the byte value followed by a new line. */ - public CodePrinter println(byte value) { - return print(value).line(); - } - - /** Prints the short value followed by a new line. */ - public CodePrinter println(short value) { - return print(value).line(); - } - - /** Prints the char value followed by a new line. */ - public CodePrinter println(char value) { - return print(value).line(); - } - - /** Prints the int value followed by a new line. */ - public CodePrinter println(int value) { - return print(value).line(); - } - - /** Prints the long value followed by a new line. */ - public CodePrinter println(long value) { - return print(value).line(); - } - - /** Prints the float value followed by a new line. */ - public CodePrinter println(float value) { - return print(value).line(); - } - - /** Prints the double value followed by a new line. */ - public CodePrinter println(double value) { - return print(value).line(); - } - - /** Prints the string followed by a new line. */ - public CodePrinter println(String value) { - return print(value).line(); - } - - /** Prints the boolean value. */ - public CodePrinter print(boolean value) { - return print(String.valueOf(value)); - } - - /** Prints the byte value. */ - public CodePrinter print(byte value) { - return print(String.valueOf(value)); - } - - /** Prints the short value. */ - public CodePrinter print(short value) { - return print(String.valueOf(value)); - } - - /** Prints the char value. */ - public CodePrinter print(char value) { - return print(String.valueOf(value)); - } - - /** Prints the int value. */ - public CodePrinter print(int value) { - return print(String.valueOf(value)); - } - - /** Prints the long value. */ - public CodePrinter print(long value) { - return print(String.valueOf(value)); - } - - /** Prints the float value. */ - public CodePrinter print(float value) { - return print(String.valueOf(value)); - } - - /** Prints the long value. */ - public CodePrinter print(double value) { - return print(String.valueOf(value)); - } - - /** Prints the string. */ - public CodePrinter print(String value) { - if (align) for (int i = 0; i < level; i++) write(step); - if (space) write(" "); - write(value); - align = false; - space = false; - line = false; - return this; - } - - //######################################################################## - // Public Methods - Converting - - /** Returns the string representation of this printer. */ - public String toString() { - return writer.toString(); - } - - //######################################################################## - // Private Methods - - private void write(String string) { - try { - writer.write(string); - } catch (IOException exception) { - throw new Error(exception); - } - } - - //######################################################################## -} diff --git a/sources/ch/epfl/lamp/util/ForwardingMap.java b/sources/ch/epfl/lamp/util/ForwardingMap.java deleted file mode 100644 index 7efc3627b0..0000000000 --- a/sources/ch/epfl/lamp/util/ForwardingMap.java +++ /dev/null @@ -1,97 +0,0 @@ -package ch.epfl.lamp.util; - -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -/** - * This class implements the interface Map by forwarding all its - * operations to an underlying instance of Map. - */ -public class ForwardingMap implements Map { - - //######################################################################## - // Protected Fields - - protected final Map delegate; - - //######################################################################## - // Public Constructors - - public ForwardingMap(Map delegate) { - this.delegate = delegate; - } - - //######################################################################## - // Public Methods - Query operations - - public int size() { - return delegate.size(); - } - - public boolean isEmpty() { - return delegate.isEmpty(); - } - - public boolean containsKey(Object key) { - return delegate.containsKey(key); - } - - public boolean containsValue(Object value) { - return delegate.containsValue(value); - } - - public Object get(Object key) { - return delegate.get(key); - } - - //######################################################################## - // Public Methods - Modification operations - - public Object put(Object key, Object value) { - return delegate.put(key, value); - } - - public Object remove(Object key) { - return delegate.remove(key); - } - - //######################################################################## - // Public Methods - Bulk operations - - public void putAll(Map map) { - delegate.putAll(map); - } - - public void clear() { - delegate.clear(); - } - - //######################################################################## - // Public Methods - Views - - public Set keySet() { - return delegate.keySet(); - } - - public Collection values() { - return delegate.values(); - } - - public Set entrySet() { - return delegate.entrySet(); - } - - //######################################################################## - // Public Methods - Comparison and hashing - - public boolean equals(Object that) { - return delegate.equals(that); - } - - public int hashCode() { - return delegate.hashCode(); - } - - //######################################################################## -} diff --git a/sources/ch/epfl/lamp/util/HTMLPrinter.java b/sources/ch/epfl/lamp/util/HTMLPrinter.java deleted file mode 100644 index bc1afcd441..0000000000 --- a/sources/ch/epfl/lamp/util/HTMLPrinter.java +++ /dev/null @@ -1,886 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package ch.epfl.lamp.util; - -import java.io.Writer; - -/** - * This class provides methods to print HTML document. - * - * @author Stephane Micheloud - * @version 1.1 - */ -public class HTMLPrinter { - - public static final String DEFAULT_STYLESHEET = "style.css"; - public static final String DEFAULT_JAVASCRIPT = "script.js"; - - //######################################################################## - // Private Constants - - /* - * The characters which must be HTML encoded - */ - private static final Character AMP = new Character('&'); - private static final Character GT = new Character('>'); - private static final Character LT = new Character('<'); - private static final Character QUOT = new Character('"'); - - //######################################################################## - // Private Fields - - /** - * The underlying code printer. - */ - private final CodePrinter printer; - - /** - * The document title. - */ - private final String title; - - //######################################################################## - // Protected Fields - - /** - * The document representation. - */ - protected final HTMLRepresentation representation; - - /** - * The document stylesheet. - */ - protected final String stylesheet; - - /** - * The document script. - */ - protected final String script; - - //######################################################################## - // Public Constructors - - /** - * Creates a new instance. - * - * @param writer - * @param title - * @param representation - * @param stylesheet - * @param script - */ - public HTMLPrinter(Writer writer, String title, HTMLRepresentation representation, - String stylesheet, String script) - { - this.printer = new CodePrinter(writer, " "); - this.title = title; - this.representation = representation; - this.stylesheet = stylesheet; - this.script = script; - } - - /** - * Creates a new instance. - * - * @param writer - * @param title - * @param representation - * @param stylesheet - */ - public HTMLPrinter(Writer writer, String title, HTMLRepresentation representation, - String stylesheet) - { - this(writer, title, representation, stylesheet, DEFAULT_JAVASCRIPT); - } - - /** - * Creates a new instance. - * - * @param writer - * @param title - * @param representation - */ - public HTMLPrinter(Writer writer, String title, HTMLRepresentation representation) { - this(writer, title, representation, DEFAULT_STYLESHEET); - } - - /** - * Creates a new instance with "HTML 4.01 Transitional" as default - * document type. - * - * @param writer - * @param title - * @param encoding - */ - public HTMLPrinter(Writer writer, String title, String docencoding) { - this( - writer, - title, - new HTMLRepresentation(HTMLRepresentation.DEFAULT_DOCTYPE, docencoding) - ); - } - - /** - * Creates a new instance with "iso-8859-1" as default character encoding. - * - * @param writer - * @param title - */ - public HTMLPrinter(Writer writer, String title) { - this(writer, title, HTMLRepresentation.DEFAULT_DOCENCODING); - } - - //######################################################################## - // Public Methods - Getting & Setting - - /** - * Returns the underlying code printer. - */ - public CodePrinter getCodePrinter() { - return printer; - } - - /** - * Returns the underlying title. - */ - public String getTitle() { - return title; - } - - //######################################################################## - // Public Methods - Character encoding - - /** - * Encodes the special character <code>ch</code> to its - * corresponding HTML encoding. - * - * @param ch - */ - public static String encode(Character ch) { - if (AMP.compareTo(ch) == 0) return "&"; - else if (GT.compareTo(ch) == 0) return ">"; - else if (LT.compareTo(ch) == 0) return "<"; - else if (QUOT.compareTo(ch) == 0) return """; - else return ch.toString(); - } - - /** - * Encodes the special characters to their corresponding HTML encodings. - * - * @param text - */ - public static String encode(String text) { - return text; - } - - //######################################################################## - // Public Methods - Formatting - - /** - * Increases the indentation level by one. - */ - public HTMLPrinter indent() { - printer.indent(); - return this; - } - - /** Decreases the indentation level by one. */ - public HTMLPrinter undent() { - printer.undent(); - return this; - } - - /** Inserts a new line. */ - public HTMLPrinter line() { - printer.line(); - return this; - } - - /** Inserts a white space. */ - public HTMLPrinter space() { - printer.space(); - return this; - } - - //######################################################################## - // Public Methods - Printing simple values followed by a new line - - /** Prints a new line. */ - public HTMLPrinter println() { - printer.println(); - return this; - } - - /** Prints the boolean value followed by a new line. */ - public HTMLPrinter println(boolean value) { - printer.println(value); - return this; - } - - /** Prints the byte value followed by a new line. */ - public HTMLPrinter println(byte value) { - printer.println(value); - return this; - } - - /** Prints the short value followed by a new line. */ - public HTMLPrinter println(short value) { - printer.println(value); - return this; - } - - /** Prints the char value followed by a new line. */ - public HTMLPrinter println(char value) { - printer.println(value); - return this; - } - - /** Prints the int value followed by a new line. */ - public HTMLPrinter println(int value) { - printer.println(value); - return this; - } - - /** Prints the long value followed by a new line. */ - public HTMLPrinter println(long value) { - printer.println(value); - return this; - } - - /** Prints the float value followed by a new line. */ - public HTMLPrinter println(float value) { - printer.println(value); - return this; - } - - /** Prints the double value followed by a new line. */ - public HTMLPrinter println(double value) { - printer.println(value); - return this; - } - - /** Prints the string followed by a new line. */ - public HTMLPrinter println(String value) { - printer.println(value); - return this; - } - - /** Prints the opening HTML tag followed by a new line. */ - public HTMLPrinter printlnOTag(String label) { - printer.print("<"); - printer.print(label); - printer.println(">"); - return this; - } - - /** Prints the HTML tag with attributes followed by a new line. */ - public HTMLPrinter printlnOTag(String label, XMLAttribute[] attrs) { - printer.print("<"); - printer.print(label); - printer.print(" "); - printer.print(StringOf.object.array(attrs, "", " ", "")); - printer.println(">"); - return this; - } - - /** Prints the closing HTML tag followed by a new line. */ - public HTMLPrinter printlnCTag(String label) { - printer.print("</"); - printer.print(label); - printer.println(">"); - return this; - } - - /** - * Prints HTML tag with label and contents followed by a new line. - * - * @param label - * @param text - */ - public HTMLPrinter printlnTag(String label, String text) { - printlnOTag(label); - print(text); - return printlnCTag(label); - } - - /** - * Prints the HTML tag <code>label</code> with attributes <code>attrs</code> - * and contents <code>text</code> followed by a new line. - * - * @param label - * @param attrs - * @param text - */ - public HTMLPrinter printlnTag(String label, XMLAttribute[] attrs, String text) { - printOTag(label, attrs); - print(text); - return printlnCTag(label); - } - - /** - * Prints the short HTML tag followed by a new line. - * - * @param label - */ - public HTMLPrinter printlnSTag(String label) { - printer.print("<"); - printer.print(label); - printer.println("/>"); - return this; - } - - /** - * Prints the short HTML tag with attributes <code>attrs</code> - * followed by a new line. - * - * @param label - * @param attrs - */ - public HTMLPrinter printlnSTag(String label, XMLAttribute[] attrs) { - printer.print("<"); - printer.print(label); - printer.print(" "); - printer.print(StringOf.object.array(attrs, "", " ", "")); - printer.println("/>"); - return this; - } - - /** - * Prints <A HREF=link> text </a> tag followed by a new line. - * - * @param dest - * @param text - */ - public HTMLPrinter printlnAhref(String dest, String text) { - printOTag("a", new XMLAttribute[]{ new XMLAttribute("href", dest) }); - print(text); - return printlnCTag("a"); - } - - /** - * Prints <A HREF=dest TARGET=target> text </a> tag followed by a new line. - * - * @param dest - * @param target - * @param text - */ - public HTMLPrinter printlnAhref(String dest, String target, String text) { - printOTag("a", new XMLAttribute[]{ - new XMLAttribute("href", dest), - new XMLAttribute("target", target)}); - print(text); - return printlnCTag("a"); - } - - /** - * Prints <A NAME=name> text </a> tag followed by a new line. - * - * @param anchor - * @param text - */ - public HTMLPrinter printlnAname(String anchor, String text) { - printOTag("a", new XMLAttribute[]{new XMLAttribute("name", anchor)}); - print(text); - return printlnCTag("a"); - } - - /** - * Prints text <code>text</code> in bold followed by a new line. - * - * @param text - */ - public HTMLPrinter printlnBold(String text) { - return printlnTag("b", text); - } - - /** - * Prints text <code>text</code> in color <code>color</code> followed by a new line. - * - * @param color - * @param text - */ - public HTMLPrinter printlnFontColor(String color, String text) { - return printlnTag( - "font", - new XMLAttribute[]{ new XMLAttribute("color", color)}, - text); - } - - /** - * Prints comment with contents <code>text</code> followed by a new line. - * - * @param text - */ - public HTMLPrinter printlnComment(String text) { - printer.print("<!--"); - printer.print(text); - printer.println("-->"); - return this; - } - - /** - * Prints script followed by a new line. - * - * @param script - */ - public HTMLPrinter printlnScript(String script) { - printOTag("script", new XMLAttribute[]{ - new XMLAttribute("type", "text/javascript"), - new XMLAttribute("src", script) - }); - return printlnCTag("script"); - } - - /** - * Prints <code>n</code> HTML blank spaces followed by a new line. - * - * @param n The parameter <code>n</code> gives the number - * of printed blank spaces - */ - public HTMLPrinter printlnNbsp(int n) { - return printNbsp(n).line(); - } - - /** - * Prints an horizontal line separator followed by a new line. - */ - public HTMLPrinter printlnHLine() { - return printlnOTag("hr"); - } - - /** - * Prints an horizontal line separator with attributes <code>attrs</code>. - * - * @param attrs - */ - public HTMLPrinter printlnHLine(XMLAttribute[] attrs) { - return printlnOTag("hr", attrs); - } - - /** - * Prints the <meta> tag with attributes 'attrs' followed by a new line. - * - * @param attrs - */ - public HTMLPrinter printlnMeta(XMLAttribute[] attrs) { - return printlnOTag("meta", attrs); - } - - /** - * Prints the <link> tag with attributes 'attrs' followed by a new line. - * - * @param attrs - */ - public HTMLPrinter printlnLink(XMLAttribute[] attrs) { - return printlnOTag("link", attrs); - } - - //######################################################################## - // Public Methods - Printing simple values - - /** Prints the boolean value. */ - public HTMLPrinter print(boolean value) { - printer.print(value); - return this; - } - - /** Prints the byte value. */ - public HTMLPrinter print(byte value) { - printer.print(value); - return this; - } - - /** Prints the short value. */ - public HTMLPrinter print(short value) { - printer.print(value); - return this; - } - - /** Prints the char value. */ - public HTMLPrinter print(char value) { - printer.print(value); - return this; - } - - /** Prints the int value. */ - public HTMLPrinter print(int value) { - printer.print(value); - return this; - } - - /** Prints the long value. */ - public HTMLPrinter print(long value) { - printer.print(value); - return this; - } - - /** Prints the float value. */ - public HTMLPrinter print(float value) { - printer.print(value); - return this; - } - - /** Prints the long value. */ - public HTMLPrinter print(double value) { - printer.print(value); - return this; - } - - /** Prints the string. */ - public HTMLPrinter print(String value) { - printer.print(value); - return this; - } - - /** Prints the opening HTML tag. */ - public HTMLPrinter printOTag(String label) { - printer.print("<"); - printer.print(label); - printer.print(">"); - return this; - } - - /** Prints the opening HTML tag 'label' with attributes 'attrs'. */ - public HTMLPrinter printOTag(String label, XMLAttribute[] attrs) { - printer.print("<"); - printer.print(label); - printer.print(" "); - printer.print(StringOf.object.array(attrs, "", " ", "")); - printer.print(">"); - return this; - } - - /** Prints the closing HTML tag 'label'. */ - public HTMLPrinter printCTag(String label) { - printer.print("</"); - printer.print(label); - printer.print(">"); - return this; - } - - /** - * Prints the HTML tag <code>label</code> with contents <code>text</code>. - * - * @param label - * @param text - */ - public HTMLPrinter printTag(String label, String text) { - printOTag(label); - print(text); - return printCTag(label); - } - - /** Prints the HTML tag 'label' with attributes 'attrs' and contents 'text'. */ - public HTMLPrinter printTag(String label, XMLAttribute[] attrs, String text) { - printOTag(label, attrs); - print(text); - printCTag(label); - return this; - } - - /** Prints the short HTML tag 'label'. */ - public HTMLPrinter printSTag(String label) { - printer.print("<"); - printer.print(label); - printer.print("/>"); - return this; - } - - /** Prints <A HREF=link> text </a> tag. */ - public HTMLPrinter printAhref(String dest, String text) { - printOTag("a", new XMLAttribute[]{ new XMLAttribute("href", dest) }); - print(text); - return printCTag("a"); - } - - /** Prints <A HREF=dest TARGET=target> text </a> tag. */ - public HTMLPrinter printAhref(String dest, String target, String text) { - printOTag("a", new XMLAttribute[]{ - new XMLAttribute("href", dest), - new XMLAttribute("target", target)}); - print(text); - return printCTag("a"); - } - - /** Prints <A NAME=name> text </a> tag. */ - public HTMLPrinter printAname(String anchor, String text) { - printOTag("a", new XMLAttribute[]{ new XMLAttribute("name", anchor) }); - print(text); - return printCTag("a"); - } - - /** - * Prints text <code>text</code> in bold. - * - * @param text - */ - public HTMLPrinter printBold(String text) { - return printTag("b", text); - } - - /** - * Prints text <code>text</code> in color <code>color</code>. - * - * @param color - * @param text - */ - public HTMLPrinter printFontColor(String color, String text) { - return printTag("font", new XMLAttribute[]{ new XMLAttribute("color", color) }, text); - } - - /** - * Prints comment with contents <code>text</code>. - * - * @param text - */ - public HTMLPrinter printComment(String text) { - printer.print("<!-- "); - printer.print(text); - printer.print(" -->"); - return this; - } - - /** - * Prints <code>n</code> HTML blank spaces. - * - * @param n The parameter <code>n</code> gives the number - * of printed blank spaces - */ - public HTMLPrinter printNbsp(int n) { - while (n > 0) { - print(" "); - n--; - } - return this; - } - - /** - * Prints an horizontal line separator. - */ - public HTMLPrinter printHLine() { - return printOTag("hr"); - } - - /** - * Prints an horizontal line separator with attributes <code>attrs</code>. - * - * @param attrs - */ - public HTMLPrinter printHLine(XMLAttribute[] attrs) { - return printOTag("hr", attrs); - } - - //######################################################################## - // Public Methods - Converting - - /** - * Returns the string representation of this printer. - */ - public String toString() { - return printer.toString(); - } - - //######################################################################## - - /** - * Prints the HTML preamble of the current page. - */ - protected void printPreamble() { - println("<!DOCTYPE html PUBLIC \"-//W3C//DTD " + - representation.getType() + "//" + representation.getLanguage() + "\">"); - printlnOTag("html").line(); - } - - /** - * Prints HTML meta informations. - * - * @param metaAttrs - */ - protected void printMetaInfo(XMLAttribute[] metaAttrs) { - printlnMeta(new XMLAttribute[]{ - new XMLAttribute("http-equiv", "content-type"), - new XMLAttribute("content", - "text/html; charset=" + representation.getEncoding())}); - for (int i = 0; i < metaAttrs.length; i++) { - printlnMeta(new XMLAttribute[]{ - new XMLAttribute("name", metaAttrs[i].name), - new XMLAttribute("content", metaAttrs[i].value)}); - } - } - - /** - * Prints HTML link information for the given stylesheet. - * - * @param stylesheet The stylesheet to be linked - * to the current HTML document - */ - protected void printlnStyle(String stylesheet) { - printlnLink(new XMLAttribute[]{ - new XMLAttribute("rel", "stylesheet"), - new XMLAttribute("type", "text/css"), - new XMLAttribute("href", stylesheet)}); - } - - /** - * Prints HTML header section of the current page. - * - * @param metaAttrs - * @param generator - * @param stylesheets - */ - public void printHeader(XMLAttribute[] metaAttrs, - String[] comments, String[] stylesheets, String[] scripts) - { - printPreamble(); - printlnOTag("head").indent(); - printlnTag("title", title); - for (int i = 0; i < comments.length; i++) - printlnComment(comments[i]); - printMetaInfo(metaAttrs); - for (int i = 0; i < stylesheets.length; i++) - printlnStyle(stylesheets[i]); - for (int i = 0; i < scripts.length; i++) - printlnScript(scripts[i]); - undent().printlnCTag("head").line(); - } - - /** - * Prints HTML header section. - * - * @param metaXMLAttributes - * @param generator - * @param stylesheet - */ - public void printHeader(XMLAttribute[] metaAttrs, String comment, - String stylesheet, String script) - { - printHeader(metaAttrs, - new String[]{ comment }, - new String[]{ stylesheet }, - new String[]{ script }); - } - - /** - * Prints HTML header section. - * - * @param metaXMLAttributes - * @param generator - * @param stylesheet - */ - public void printHeader(XMLAttribute[] metaAttrs, String comment, - String stylesheet) - { - printHeader(metaAttrs, comment, stylesheet, script); - } - - /** - * Prints HTML header section. - * - * @param metaXMLAttributes - * @param generator - */ - public void printHeader(XMLAttribute[] metaAttrs, String comment) { - printHeader(metaAttrs, comment, stylesheet); - } - - /** - * Prints the header section of the current page. - * - * @param metaXMLAttributes - */ - public void printHeader(XMLAttribute[] metaAttrs) { - printHeader(metaAttrs, null); - } - - /** - * Open the body section of the current page. - */ - public void printOpenBody(XMLAttribute[] attrs) { - printlnOTag("body", attrs).indent(); - } - - /** - * Open the body section of the current page. - */ - public void printOpenBody() { - printlnOTag("body").indent(); - } - - /** - * Prints the HTML footer of the current page. - */ - public void printFootpage() { - undent().printlnCTag("body"); - printlnCTag("html"); - } - - //######################################################################## -} - - -/** - * Map from Object to String. - */ -public abstract class StringOf { - - /** - * Gives the string representation of an object. - * - * @param o - */ - public abstract String element(Object o); - - /** - * Gives the string representation of an array of objects. - * Return delimiters for empty arrays depending on "delimWhenEmpty". - * - * @param objects - * @param open - * @param sep - * @param close - * @param delimWhenEmpty - */ - public String array(Object[] objects, String open, String sep, String close, boolean delimWhenEmpty) { - if ((objects.length == 0) && !delimWhenEmpty) - return ""; - else { - StringBuffer str = new StringBuffer(); - str.append(open); - if (objects.length > 0) { - str.append(element(objects[0])); - for(int i = 1; i < objects.length; i++) - str.append(sep + element(objects[i])); - } - str.append(close); - return str.toString(); - } - } - - /** - * Returns always delimiters. - * - * @param objects - * @param open - * @param sep - * @param close - */ - public String array(Object[] objects, String open, String sep, String close) { - return array(objects, open, sep, close, true); - } - - /** - * Basic map. - */ - public static StringOf object = new StringOf() { - public String element(Object o) { - return o.toString(); - } - }; - -} diff --git a/sources/ch/epfl/lamp/util/HTMLRepresentation.java b/sources/ch/epfl/lamp/util/HTMLRepresentation.java deleted file mode 100644 index debe5288bd..0000000000 --- a/sources/ch/epfl/lamp/util/HTMLRepresentation.java +++ /dev/null @@ -1,99 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package ch.epfl.lamp.util; - -/** - * This class contains properties of HTML document representation - * (see http://www.w3.org/TR/REC-html40/charset.html). - */ -public class HTMLRepresentation { - - public static final String DEFAULT_DOCTYPE = "HTML 4.01 Transitional"; - public static final String DEFAULT_DOCENCODING = "iso-8859-1"; - public static final String DEFAULT_DOCLANGUAGE = "EN"; - - //######################################################################## - // Private Fields - - /** The document type */ - private final String doctype; - - /** The document character encoding */ - private final String docencoding; - - /** The document language */ - private final String language; - - //######################################################################## - // Public Constructors - - /** Creates a new instance */ - public HTMLRepresentation(String doctype, String docencoding, String language) { - this.doctype = doctype; - this.docencoding = docencoding; - this.language = language; - } - - /** Creates a new instance */ - public HTMLRepresentation(String doctype, String docencoding) { - this(doctype, docencoding, DEFAULT_DOCLANGUAGE); - } - - /** Creates a new instance */ - public HTMLRepresentation(String doctype) { - this(doctype, DEFAULT_DOCENCODING, DEFAULT_DOCLANGUAGE); - } - - /** Creates a new instance */ - public HTMLRepresentation() { - this(DEFAULT_DOCTYPE, DEFAULT_DOCENCODING, DEFAULT_DOCLANGUAGE); - } - - //######################################################################## - // Public Methods - Getting & Setting - - /** - * Returns the underlying document type. - */ - public String getType() { - return doctype; - } - - /** - * Returns the underlying character encoding. - */ - public String getEncoding() { - return docencoding; - } - - /** - * Returns the underlying document language. - * - * @ return the language name of the underlying document - */ - public String getLanguage() { - return language; - } - - /** - * Returns <code>true</code> if the document type is HTML. - */ - public boolean isHTMLType() { - return doctype.toLowerCase().matches("^html\\p{Space}\\d\\.\\d.*"); - } - - /** - * Returns <code>true</code> if the document type is XHTML. - */ - public boolean isXHTMLType() { - return doctype.toLowerCase().matches("^xhtml\\p{Space}\\d\\.\\d.*"); - } - - //######################################################################## -} diff --git a/sources/ch/epfl/lamp/util/Pair.java b/sources/ch/epfl/lamp/util/Pair.java deleted file mode 100644 index 1b755ca18a..0000000000 --- a/sources/ch/epfl/lamp/util/Pair.java +++ /dev/null @@ -1,27 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package ch.epfl.lamp.util; - -/** - * Pairs of values. - * - * @author Michel Schinz - * @version 1.0 - */ - -public class Pair { - public final Object fst, snd; - public Pair(Object fst, Object snd) { - this.fst = fst; - this.snd = snd; - } - public String toString() { - return "Pair(" + fst + ", " + snd + ")"; - } -} diff --git a/sources/ch/epfl/lamp/util/XHTMLPrinter.java b/sources/ch/epfl/lamp/util/XHTMLPrinter.java deleted file mode 100644 index be76c45023..0000000000 --- a/sources/ch/epfl/lamp/util/XHTMLPrinter.java +++ /dev/null @@ -1,189 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package ch.epfl.lamp.util; - -import java.io.Writer; - -/** - * This class provides methods to print XHTML document. - * - * @author Stephane Micheloud - * @version 1.1 - */ -public class XHTMLPrinter extends HTMLPrinter { - - //######################################################################## - // Public Constructors - - /** - * Creates a new instance. - * - * @param writer - * @param title - * @param representation - * @param stylesheet - * @param script - */ - public XHTMLPrinter(Writer writer, String title, HTMLRepresentation representation, - String stylesheet, String script) - { - super(writer, title, representation, stylesheet, script); - } - - /** - * Creates a new instance. - * - * @param writer - * @param title - * @param representation - * @param stylesheet - */ - public XHTMLPrinter(Writer writer, String title, HTMLRepresentation representation, - String stylesheet) - { - this(writer, title, representation, stylesheet, DEFAULT_JAVASCRIPT); - } - - /** - * Creates a new instance. - * - * @param writer - * @param title - * @param repr - */ - public XHTMLPrinter(Writer writer, String title, HTMLRepresentation representation) { - this(writer, title, representation, DEFAULT_STYLESHEET); - } - - /** - * Creates a new instance with "XHTML 1.0 Transitional" as default document type. - * - * @param writer - * @param title - * @param docencoding - */ - public XHTMLPrinter(Writer writer, String title, String docencoding) { - this(writer, title, new HTMLRepresentation("XHTML 1.0 Transitional", docencoding)); - } - - /** - * Creates a new instance with "utf-8" as default character encoding. - * - * @param writer - * @param title - */ - public XHTMLPrinter(Writer writer, String title) { - this(writer, title, "utf-8"); - } - - //######################################################################## - // Public Methods - Printing simple values followed by a new line - - /** - * 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", - new XMLAttribute[]{ new XMLAttribute("style", "font-weight:bold;") }, - text); - } - - /** - * Prints an horizontal line separator followed by a new line. - * - * @return the current HTML printer - */ - public HTMLPrinter printlnHLine() { - printOTag("div", new XMLAttribute[] { - new XMLAttribute("style", "border:1px solid #aaaaaa; " + - "margin:10px 0px 5px 0px;height:1px;") }); - return printlnCTag("div"); - } - - //######################################################################## - // Public Methods - Printing simple values - - /** - * Prints text <code>text</code> in bold. - * - * @param text - * @return the current HTML printer - */ - public HTMLPrinter printBold(String text) { - return printTag("span", - new XMLAttribute[]{ new XMLAttribute("style", "font-weight:bold;") }, - text); - } - - /** - * Prints an horizontal line separator - * - * @return the current HTML printer - */ - public HTMLPrinter printHLine() { - printOTag("div", new XMLAttribute[] { - new XMLAttribute("style", "border:1px solid #aaaaaa; " + - "margin:10px 0px 5px 0px;height:1px;") }); - return printCTag("div"); - } - - /** - * Prints an horizontal line separator with attributes <code>attrs</code>. - * - * @param attrs - * @return the current HTML printer - */ - public HTMLPrinter printHLine(XMLAttribute[] attrs) { - return printHLine(); - } - - /** - * Prints the <meta/> tag with attributes <code>attrs</code> - * followed by a new line. - * - * @param attrs - * @return the current HTML printer - */ - public HTMLPrinter printlnMeta(XMLAttribute[] attrs) { - return printlnSTag("meta", attrs); - } - - /** - * Prints the <link> tag with attributes <code>attrs</code> - * followed by a new line. - * - * @param attrs - * @return the current HTML printer - */ - public HTMLPrinter printlnLink(XMLAttribute[] attrs) { - return printlnSTag("link", attrs); - } - - //######################################################################## - - /** - * Prints XHTML preamble. - */ - protected void printPreamble() { - println("<!--"); - println("< ?xml version=\"1.0\" encoding=\"" + - representation.getEncoding() + "\"?>"); - println("//-->"); - println("<!DOCTYPE html PUBLIC \"-//W3C//DTD " + - representation.getType() + "//" + representation.getLanguage() + - "\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"); - println("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"" + - representation.getLanguage() + "\">").line(); - } - - //######################################################################## -} diff --git a/sources/ch/epfl/lamp/util/XMLAttribute.java b/sources/ch/epfl/lamp/util/XMLAttribute.java deleted file mode 100644 index 309a4cc621..0000000000 --- a/sources/ch/epfl/lamp/util/XMLAttribute.java +++ /dev/null @@ -1,31 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package ch.epfl.lamp.util; - -/** An XML attribute. - */ -public class XMLAttribute { - - /** Name of the attribute. - */ - public String name; - - /** Value of the attribute. - */ - public String value; - - public XMLAttribute(String name, String value) { - this.name = name; - this.value = value; - } - - public String toString() { - return name + "=\"" + value + "\""; - } -}
\ No newline at end of file |