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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright 2011 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.server;
  17. import java.io.Serializable;
  18. /**
  19. * Interface for rendering error messages to terminal. All the visible errors
  20. * shown to user must implement this interface.
  21. *
  22. * @author Vaadin Ltd.
  23. * @since 3.0
  24. */
  25. public interface ErrorMessage extends Serializable {
  26. public enum ErrorLevel {
  27. /**
  28. * Error code for informational messages.
  29. */
  30. INFORMATION("info", 0),
  31. /**
  32. * Error code for warning messages.
  33. */
  34. WARNING("warning", 1),
  35. /**
  36. * Error code for regular error messages.
  37. */
  38. ERROR("error", 2),
  39. /**
  40. * Error code for critical error messages.
  41. */
  42. CRITICAL("critical", 3),
  43. /**
  44. * Error code for system errors and bugs.
  45. */
  46. SYSTEMERROR("system", 4);
  47. String text;
  48. int errorLevel;
  49. private ErrorLevel(String text, int errorLevel) {
  50. this.text = text;
  51. this.errorLevel = errorLevel;
  52. }
  53. /**
  54. * Textual representation for server-client communication of level
  55. *
  56. * @return String for error severity
  57. */
  58. public String getText() {
  59. return text;
  60. }
  61. /**
  62. * Integer representation of error severity for comparison
  63. *
  64. * @return integer for error severity
  65. */
  66. public int intValue() {
  67. return errorLevel;
  68. }
  69. @Override
  70. public String toString() {
  71. return text;
  72. }
  73. }
  74. /**
  75. * @deprecated As of 7.0, use {@link ErrorLevel#SYSTEMERROR} instead    
  76. */
  77. @Deprecated
  78. public static final ErrorLevel SYSTEMERROR = ErrorLevel.SYSTEMERROR;
  79. /**
  80. * @deprecated As of 7.0, use {@link ErrorLevel#CRITICAL} instead    
  81. */
  82. @Deprecated
  83. public static final ErrorLevel CRITICAL = ErrorLevel.CRITICAL;
  84. /**
  85. * @deprecated As of 7.0, use {@link ErrorLevel#ERROR} instead    
  86. */
  87. @Deprecated
  88. public static final ErrorLevel ERROR = ErrorLevel.ERROR;
  89. /**
  90. * @deprecated As of 7.0, use {@link ErrorLevel#WARNING} instead    
  91. */
  92. @Deprecated
  93. public static final ErrorLevel WARNING = ErrorLevel.WARNING;
  94. /**
  95. * @deprecated As of 7.0, use {@link ErrorLevel#INFORMATION} instead    
  96. */
  97. @Deprecated
  98. public static final ErrorLevel INFORMATION = ErrorLevel.INFORMATION;
  99. /**
  100. * Gets the errors level.
  101. *
  102. * @return the level of error as an integer.
  103. */
  104. public ErrorLevel getErrorLevel();
  105. /**
  106. * Returns the HTML formatted message to show in as the error message on the
  107. * client.
  108. *
  109. * This method should perform any necessary escaping to avoid XSS attacks.
  110. *
  111. * TODO this API may still change to use a separate data transfer object
  112. *
  113. * @return HTML formatted string for the error message
  114. * @since 7.0
  115. */
  116. public String getFormattedHtmlMessage();
  117. }