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