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

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