001: /* *************************************************************************
002:
003: Millstone(TM)
004: Open Sourced User Interface Library for
005: Internet Development with Java
006:
007: Millstone is a registered trademark of IT Mill Ltd
008: Copyright (C) 2000-2005 IT Mill Ltd
009:
010: *************************************************************************
011:
012: This library is free software; you can redistribute it and/or
013: modify it under the terms of the GNU Lesser General Public
014: license version 2.1 as published by the Free Software Foundation.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: *************************************************************************
026:
027: For more information, contact:
028:
029: IT Mill Ltd phone: +358 2 4802 7180
030: Ruukinkatu 2-4 fax: +358 2 4802 7181
031: 20540, Turku email: info@itmill.com
032: Finland company www: www.itmill.com
033:
034: Primary source for MillStone information and releases: www.millstone.org
035:
036: ********************************************************************** */
037:
038: package org.millstone.base.terminal;
039:
040: /** User error is a controlled error occurred in application. User errors
041: * are occur in normal usage of the application and guide the user.
042: *
043: * @author IT Mill Ltd.
044: * @version 3.1.1
045: * @since 3.0
046: */
047: public class UserError implements ErrorMessage {
048:
049: /** Content mode, where the error contains only plain text.
050: */
051: public static final int CONTENT_TEXT = 0;
052:
053: /** Content mode, where the error contains preformatted text.
054: */
055: public static final int CONTENT_PREFORMATTED = 1;
056:
057: /** Formatted content mode, where the contents is XML restricted to the
058: * UIDL 1.0 formatting markups.
059: */
060: public static final int CONTENT_UIDL = 2;
061:
062: /** Content mode */
063: private int mode = CONTENT_TEXT;
064:
065: /** Message in content mode */
066: private String msg;
067:
068: /** Error level */
069: private int level = ErrorMessage.ERROR;
070:
071: /** Create a textual error message of level ERROR.
072: *
073: * @param textErrorMessage The text of the error message.
074: */
075: public UserError(String textErrorMessage) {
076: this .msg = textErrorMessage;
077: }
078:
079: /** Create error message with level and content mode.
080: */
081: public UserError(String message, int contentMode, int errorLevel) {
082:
083: // Check the parameters
084: if (contentMode < 0 || contentMode > 2)
085: throw new java.lang.IllegalArgumentException(
086: "Unsupported content mode: " + contentMode);
087:
088: this .msg = message;
089: this .mode = contentMode;
090: this .level = errorLevel;
091: }
092:
093: /* Documenten in interface */
094: public int getErrorLevel() {
095: return level;
096: }
097:
098: /* Documenten in interface */
099: public void addListener(RepaintRequestListener listener) {
100: }
101:
102: /* Documenten in interface */
103: public void removeListener(RepaintRequestListener listener) {
104: }
105:
106: /* Documenten in interface */
107: public void requestRepaint() {
108: }
109:
110: /* Documenten in interface */
111: public void paint(PaintTarget target) throws PaintException {
112:
113: target.startTag("error");
114:
115: // Error level
116: if (level >= ErrorMessage.SYSTEMERROR)
117: target.addAttribute("level", "system");
118: else if (level >= ErrorMessage.CRITICAL)
119: target.addAttribute("level", "critical");
120: else if (level >= ErrorMessage.ERROR)
121: target.addAttribute("level", "error");
122: else if (level >= ErrorMessage.WARNING)
123: target.addAttribute("level", "warning");
124: else
125: target.addAttribute("level", "info");
126:
127: // Paint the message
128: switch (mode) {
129: case CONTENT_TEXT:
130: target.addText(msg);
131: break;
132: case CONTENT_UIDL:
133: target.addUIDL(msg);
134: break;
135: case CONTENT_PREFORMATTED:
136: target.startTag("pre");
137: target.addText(msg);
138: target.endTag("pre");
139: }
140:
141: target.endTag("error");
142: }
143:
144: /* Documenten in interface */
145: public void requestRepaintRequests() {
146: }
147:
148: /* Documented in superclass */
149: public String toString() {
150: return msg;
151: }
152:
153: }
|