From: Jens Jansson Date: Thu, 1 Dec 2011 13:20:19 +0000 (+0200) Subject: Converted UserError content type to an enum. There is probably other places where... X-Git-Tag: 7.0.0.alpha1~232^2~1^2~9 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=742b69e08ed04d31bb02ccc97eb5f82ffb9749d7;p=vaadin-framework.git Converted UserError content type to an enum. There is probably other places where we will have Text/UIDL/XHTML enum and this should be merged with the main one down the road. --- diff --git a/src/com/vaadin/terminal/UserError.java b/src/com/vaadin/terminal/UserError.java index 8f16a690b4..f2879f45bf 100644 --- a/src/com/vaadin/terminal/UserError.java +++ b/src/com/vaadin/terminal/UserError.java @@ -18,31 +18,39 @@ import com.vaadin.terminal.gwt.server.AbstractApplicationServlet; @SuppressWarnings("serial") public class UserError implements ErrorMessage { - /** - * Content mode, where the error contains only plain text. - */ - public static final int CONTENT_TEXT = 0; - - /** - * Content mode, where the error contains preformatted text. - */ - public static final int CONTENT_PREFORMATTED = 1; - - /** - * Formatted content mode, where the contents is XML restricted to the UIDL - * 1.0 formatting markups. - */ - public static final int CONTENT_UIDL = 2; + public enum ContentMode { + /** + * Content mode, where the error contains only plain text. + */ + TEXT, + /** + * Content mode, where the error contains preformatted text. + */ + PREFORMATTED, + /** + * Formatted content mode, where the contents is XML restricted to the + * UIDL 1.0 formatting markups. + */ + UIDL, + /** + * Content mode, where the error contains XHTML. + */ + XHTML; + } - /** - * Content mode, where the error contains XHTML. - */ - public static final int CONTENT_XHTML = 3; + @Deprecated + public static final ContentMode CONTENT_TEXT = ContentMode.TEXT; + @Deprecated + public static final ContentMode CONTENT_PREFORMATTED = ContentMode.PREFORMATTED; + @Deprecated + public static final ContentMode CONTENT_UIDL = ContentMode.UIDL; + @Deprecated + public static final ContentMode CONTENT_XHTML = ContentMode.XHTML; /** * Content mode. */ - private int mode = CONTENT_TEXT; + private ContentMode mode = ContentMode.TEXT; /** * Message in content mode. @@ -73,21 +81,24 @@ public class UserError implements ErrorMessage { * the content Mode. * @param errorLevel * the level of error. - * @deprecated use {link - * {@link #UserError(String, int, com.vaadin.terminal.ErrorMessage.ErrorLevel)} + * @deprecated use {link {@link #UserError(String, ContentMode, ErrorLevel)} * instead. */ @Deprecated public UserError(String message, int contentMode, int errorLevel) { - // Check the parameters - if (contentMode < 0 || contentMode > 2) { + // TODO should XHTML be also a supported mode? + if (contentMode == 0) { + mode = ContentMode.TEXT; + } else if (contentMode == 1) { + mode = ContentMode.PREFORMATTED; + } else if (contentMode == 2) { + mode = ContentMode.UIDL; + } else { throw new java.lang.IllegalArgumentException( "Unsupported content mode: " + contentMode); } - msg = message; - mode = contentMode; if (errorLevel == ErrorLevel.INFORMATION.ordinal()) { level = ErrorLevel.INFORMATION; } else if (errorLevel == ErrorLevel.WARNING.ordinal()) { @@ -101,14 +112,8 @@ public class UserError implements ErrorMessage { } } - public UserError(String message, int contentMode, ErrorLevel errorLevel) { - - // Check the parameters - if (contentMode < 0 || contentMode > 2) { - throw new java.lang.IllegalArgumentException( - "Unsupported content mode: " + contentMode); - } - + public UserError(String message, ContentMode contentMode, + ErrorLevel errorLevel) { msg = message; mode = contentMode; level = errorLevel; @@ -139,22 +144,21 @@ public class UserError implements ErrorMessage { // Paint the message switch (mode) { - case CONTENT_TEXT: + case TEXT: target.addText(AbstractApplicationServlet.safeEscapeForHtml(msg)); break; - case CONTENT_UIDL: + case UIDL: target.addUIDL(msg); break; - case CONTENT_PREFORMATTED: + case PREFORMATTED: target.addText("
"
                     + AbstractApplicationServlet.safeEscapeForHtml(msg)
                     + "
"); break; - case CONTENT_XHTML: + case XHTML: target.addText(msg); break; } - target.endTag("error"); }