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.

SystemError.java 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal;
  5. import com.vaadin.terminal.gwt.server.AbstractApplicationServlet;
  6. /**
  7. * <code>SystemError</code> is an error message for a problem caused by error in
  8. * system, not the user application code. The system error can contain technical
  9. * information such as stack trace and exception.
  10. *
  11. * SystemError does not support HTML in error messages or stack traces. If HTML
  12. * messages are required, use {@link UserError} or a custom implementation of
  13. * {@link ErrorMessage}.
  14. *
  15. * @author Vaadin Ltd.
  16. * @since 3.0
  17. */
  18. @SuppressWarnings("serial")
  19. public class SystemError extends AbstractErrorMessage {
  20. /**
  21. * Constructor for SystemError with error message specified.
  22. *
  23. * @param message
  24. * the Textual error description.
  25. */
  26. public SystemError(String message) {
  27. super(message);
  28. setErrorLevel(ErrorLevel.SYSTEMERROR);
  29. setMode(ContentMode.XHTML);
  30. setMessage(getHtmlMessage());
  31. }
  32. /**
  33. * Constructor for SystemError with causing exception and error message.
  34. *
  35. * @param message
  36. * the Textual error description.
  37. * @param cause
  38. * the throwable causing the system error.
  39. */
  40. public SystemError(String message, Throwable cause) {
  41. this(message);
  42. addCause(AbstractErrorMessage.getErrorMessageForException(cause));
  43. }
  44. /**
  45. * Constructor for SystemError with cause.
  46. *
  47. * @param cause
  48. * the throwable causing the system error.
  49. */
  50. public SystemError(Throwable cause) {
  51. this(null, cause);
  52. }
  53. /**
  54. * Returns the message of the error in HTML.
  55. *
  56. * Note that this API may change in future versions.
  57. */
  58. protected String getHtmlMessage() {
  59. // TODO wrapping div with namespace? See the old code:
  60. // target.addXMLSection("div", message,
  61. // "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd");
  62. StringBuilder sb = new StringBuilder();
  63. if (getMessage() != null) {
  64. sb.append("<h2>");
  65. sb.append(AbstractApplicationServlet
  66. .safeEscapeForHtml(getMessage()));
  67. sb.append("</h2>");
  68. }
  69. return sb.toString();
  70. }
  71. }