You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ErrorMessage.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal;
  5. import java.io.Serializable;
  6. /**
  7. * Interface for rendering error messages to terminal. All the visible errors
  8. * shown to user must implement this interface.
  9. *
  10. * @author Vaadin Ltd.
  11. * @since 3.0
  12. */
  13. public interface ErrorMessage extends Serializable {
  14. public enum ErrorLevel {
  15. /**
  16. * Error code for informational messages.
  17. */
  18. INFORMATION("info", 0),
  19. /**
  20. * Error code for warning messages.
  21. */
  22. WARNING("warning", 1),
  23. /**
  24. * Error code for regular error messages.
  25. */
  26. ERROR("error", 2),
  27. /**
  28. * Error code for critical error messages.
  29. */
  30. CRITICAL("critical", 3),
  31. /**
  32. * Error code for system errors and bugs.
  33. */
  34. SYSTEMERROR("system", 4);
  35. String text;
  36. int errorLevel;
  37. private ErrorLevel(String text, int errorLevel) {
  38. this.text = text;
  39. this.errorLevel = errorLevel;
  40. }
  41. /**
  42. * Textual representation for server-client communication of level
  43. *
  44. * @return String for error severity
  45. */
  46. public String getText() {
  47. return text;
  48. }
  49. /**
  50. * Integer representation of error severity for comparison
  51. *
  52. * @return integer for error severity
  53. */
  54. public int intValue() {
  55. return errorLevel;
  56. }
  57. @Override
  58. public String toString() {
  59. return text;
  60. }
  61. }
  62. /**
  63. * @deprecated from 7.0, use {@link ErrorLevel#SYSTEMERROR} instead    
  64. */
  65. @Deprecated
  66. public static final ErrorLevel SYSTEMERROR = ErrorLevel.SYSTEMERROR;
  67. /**
  68. * @deprecated from 7.0, use {@link ErrorLevel#CRITICAL} instead    
  69. */
  70. @Deprecated
  71. public static final ErrorLevel CRITICAL = ErrorLevel.CRITICAL;
  72. /**
  73. * @deprecated from 7.0, use {@link ErrorLevel#ERROR} instead    
  74. */
  75. @Deprecated
  76. public static final ErrorLevel ERROR = ErrorLevel.ERROR;
  77. /**
  78. * @deprecated from 7.0, use {@link ErrorLevel#WARNING} instead    
  79. */
  80. @Deprecated
  81. public static final ErrorLevel WARNING = ErrorLevel.WARNING;
  82. /**
  83. * @deprecated from 7.0, use {@link ErrorLevel#INFORMATION} instead    
  84. */
  85. @Deprecated
  86. public static final ErrorLevel INFORMATION = ErrorLevel.INFORMATION;
  87. /**
  88. * Gets the errors level.
  89. *
  90. * @return the level of error as an integer.
  91. */
  92. public ErrorLevel getErrorLevel();
  93. /**
  94. * Returns the HTML formatted message to show in as the error message on the
  95. * client.
  96. *
  97. * This method should perform any necessary escaping to avoid XSS attacks.
  98. *
  99. * TODO this API may still change to use a separate data transfer object
  100. *
  101. * @return HTML formatted string for the error message
  102. * @since 7.0
  103. */
  104. public String getFormattedHtmlMessage();
  105. }