diff options
-rw-r--r-- | sources/ch/epfl/lamp/util/HTMLRepresentation.java | 64 |
1 files changed, 46 insertions, 18 deletions
diff --git a/sources/ch/epfl/lamp/util/HTMLRepresentation.java b/sources/ch/epfl/lamp/util/HTMLRepresentation.java index 5894c9df07..debe5288bd 100644 --- a/sources/ch/epfl/lamp/util/HTMLRepresentation.java +++ b/sources/ch/epfl/lamp/util/HTMLRepresentation.java @@ -8,19 +8,24 @@ package ch.epfl.lamp.util; -/** This class contains properties of HTML document representation - * (see http://www.w3.org/TR/REC-html40/charset.html). +/** + * 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 type; + private final String doctype; /** The document character encoding */ - private final String encoding; + private final String docencoding; /** The document language */ private final String language; @@ -29,43 +34,66 @@ public class HTMLRepresentation { // Public Constructors /** Creates a new instance */ - public HTMLRepresentation(String type, String encoding, String language) { - this.type = type; - this.encoding = encoding; + public HTMLRepresentation(String doctype, String docencoding, String language) { + this.doctype = doctype; + this.docencoding = docencoding; this.language = language; } /** Creates a new instance */ - public HTMLRepresentation(String type, String encoding) { - this(type, encoding, "EN"); + public HTMLRepresentation(String doctype, String docencoding) { + this(doctype, docencoding, DEFAULT_DOCLANGUAGE); } /** Creates a new instance */ - public HTMLRepresentation(String type) { - this(type, "iso-8859-1", "EN"); + public HTMLRepresentation(String doctype) { + this(doctype, DEFAULT_DOCENCODING, DEFAULT_DOCLANGUAGE); } /** Creates a new instance */ public HTMLRepresentation() { - this("HTML 4.01 Transitional", "iso-8859-1", "EN"); + this(DEFAULT_DOCTYPE, DEFAULT_DOCENCODING, DEFAULT_DOCLANGUAGE); } //######################################################################## // Public Methods - Getting & Setting - /** Returns the underlying document type. */ + /** + * Returns the underlying document type. + */ public String getType() { - return type; + return doctype; } - /** Returns the underlying character encoding. */ + /** + * Returns the underlying character encoding. + */ public String getEncoding() { - return encoding; + return docencoding; } - /** Returns the underlying character encoding. */ + /** + * Returns the underlying document language. + * + * @ return the language name of the underlying document + */ public String getLanguage() { return language; } -}
\ No newline at end of file + /** + * 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.*"); + } + + //######################################################################## +} |