Package muntjac :: Package terminal :: Module user_error
[hide private]
[frames] | no frames]

Source Code for Module muntjac.terminal.user_error

  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   
 19   
20 -class UserError(IErrorMessage):
21 """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 41
42 - def __init__(self, message, contentMode=None, errorLevel=None):
43 """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 = errorLevel
67 68
69 - def getErrorLevel(self):
70 return self._level
71 72
73 - def addListener(self, listener, iface=None):
74 pass
75 76
77 - def addCallback(self, callback, eventType=None, *args):
78 pass
79 80
81 - def removeListener(self, listener, iface=None):
82 pass
83 84
85 - def removeCallback(self, callback, eventType=None):
86 pass
87 88
89 - def requestRepaint(self):
90 pass
91 92
93 - def paint(self, target):
94 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
131 - def requestRepaintRequests(self):
132 pass
133 134
135 - def __str__(self):
136 return self._msg
137 138
139 - def getDebugId(self):
140 return None
141 142
143 - def setDebugId(self, idd):
144 raise NotImplementedError, \ 145 'Setting testing id for this Paintable is not implemented'
146