001: /*
002: * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/publishing/markups/TKMarkupParserException.java,v 1.7 2001/06/11 09:14:10 alex Exp $
003: *
004: */
005: package com.teamkonzept.publishing.markups;
006:
007: import com.teamkonzept.lib.*;
008:
009: public class TKMarkupParserException extends Exception {
010:
011: int pos;
012:
013: public TKMarkupParserException(String msg) {
014:
015: super (msg);
016:
017: this .pos = -1;
018: }
019:
020: public TKMarkupParserException(String msg, int pos) {
021:
022: super (msg);
023:
024: this .pos = pos;
025: }
026:
027: public void throwAgain() throws TKMarkupParserException {
028:
029: throwAgain((String) null, -1);
030: }
031:
032: public void throwAgain(int pos) throws TKMarkupParserException {
033:
034: throwAgain((String) null, pos);
035: }
036:
037: public void throwAgain(String msg, int pos)
038: throws TKMarkupParserException {
039:
040: if (this .pos >= 0)
041: pos = this .pos;
042:
043: throwAgain(this , msg, pos);
044: }
045:
046: public String getMsg() {
047:
048: return getMsg(null);
049: }
050:
051: public String getMsg(String prefix) {
052:
053: return (prefix == null ? "" : prefix)
054: + (pos < 0 ? "" : "Position " + pos + ": ")
055: + demandMsg(this );
056: }
057:
058: public TKVector handle(TKVector diagnostics) {
059:
060: if (diagnostics == null)
061: diagnostics = new TKVector();
062: diagnostics.addElement(getMsg());
063:
064: return diagnostics;
065: }
066:
067: private static int count = 0;
068:
069: private static synchronized int countUp() {
070:
071: return ++count;
072: }
073:
074: public static void throwAgain(Exception ex)
075: throws TKMarkupParserException {
076:
077: throwAgain(ex, (String) null, -1);
078: }
079:
080: public static void throwAgain(Exception ex, int pos)
081: throws TKMarkupParserException {
082:
083: throwAgain(ex, (String) null, pos);
084: }
085:
086: public static void throwAgain(Exception ex, String msg, int pos)
087: throws TKMarkupParserException {
088:
089: String old = demandMsg(ex);
090:
091: if (msg == null)
092: throw new TKMarkupParserException(old, pos);
093: else
094: throw new TKMarkupParserException(msg + ": " + old, pos);
095: }
096:
097: public static String demandMsg(Exception ex) {
098:
099: String msg = ex.getMessage();
100:
101: if (msg == null) {
102:
103: int id = countUp();
104: msg = "Unbekannter Fehler #" + id + " (siehe Logfile)";
105: }
106:
107: return msg;
108: }
109:
110: public static TKVector handle(Exception ex, TKVector diagnostics) {
111:
112: if (diagnostics == null)
113: diagnostics = new TKVector();
114: diagnostics.addElement(demandMsg(ex));
115:
116: return diagnostics;
117: }
118: }
|