Home | Trees | Indices | Help |
|
---|
|
1 # Copyright (C) 2012 Vaadin Ltd. 2 # Copyright (C) 2012 Richard Lincoln 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of 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, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 from muntjac.terminal.error_message import IErrorMessage 17 from muntjac.terminal.gwt.server.abstract_application_servlet import AbstractApplicationServlet 18 1921 """C{UserError} is a controlled error occurred in application. User 22 errors are occur in normal usage of the application and guide the user. 23 24 @author: Vaadin Ltd. 25 @author: Richard Lincoln 26 @version: 1.1.2 27 """ 28 29 #: Content mode, where the error contains only plain text. 30 CONTENT_TEXT = 0 31 32 #: Content mode, where the error contains preformatted text. 33 CONTENT_PREFORMATTED = 1 34 35 #: Formatted content mode, where the contents is XML restricted 36 # to the UIDL 1.0 formatting markups. 37 CONTENT_UIDL = 2 38 39 #: Content mode, where the error contains XHTML. 40 CONTENT_XHTML = 3 4114643 """Creates a error message with level and content mode. 44 45 @param message: 46 the error message. 47 @param contentMode: 48 the content Mode. 49 @param errorLevel: 50 the level of error (defaults to Error). 51 """ 52 # Content mode. 53 self._mode = self.CONTENT_TEXT 54 55 # Message in content mode. 56 self._msg = message 57 58 # Error level. 59 self._level = IErrorMessage.ERROR 60 61 if contentMode is not None: 62 # Check the parameters 63 if contentMode < 0 or contentMode > 2: 64 raise ValueError, 'Unsupported content mode: ' + contentMode 65 self._mode = contentMode 66 self._level = errorLevel67 68 71 72 75 76 79 80 83 84 87 88 91 9294 95 target.startTag('error') 96 97 # Error level 98 if self._level >= IErrorMessage.SYSTEMERROR: 99 target.addAttribute('level', 'system') 100 101 elif self._level >= IErrorMessage.CRITICAL: 102 target.addAttribute('level', 'critical') 103 104 elif self._level >= IErrorMessage.ERROR: 105 target.addAttribute('level', 'error') 106 107 elif self._level >= IErrorMessage.WARNING: 108 target.addAttribute('level', 'warning') 109 110 else: 111 target.addAttribute('level', 'info') 112 113 # Paint the message 114 if self._mode == self.CONTENT_TEXT: 115 escaped = AbstractApplicationServlet.safeEscapeForHtml(self._msg) 116 target.addText(escaped) 117 118 elif self._mode == self.CONTENT_UIDL: 119 target.addUIDL("<pre>" 120 + AbstractApplicationServlet.safeEscapeForHtml(self._msg) 121 + "</pre>") 122 123 elif self._mode == self.CONTENT_PREFORMATTED: 124 target.startTag('pre') 125 target.addText(self._msg) 126 target.endTag('pre') 127 128 target.endTag('error')129 130 133 134 137 138 141 142
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sat Apr 20 16:01:34 2013 | http://epydoc.sourceforge.net |