KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > go > teaservlet > TemplateError


1 /* ====================================================================
2  * TeaServlet - Copyright (c) 1999-2000 Walt Disney Internet Group
3  * ====================================================================
4  * The Tea Software License, Version 1.1
5  *
6  * Copyright (c) 2000 Walt Disney Internet Group. All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Walt Disney Internet Group (http://opensource.go.com/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Tea", "TeaServlet", "Kettle", "Trove" and "BeanDoc" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact opensource@dig.com.
31  *
32  * 5. Products derived from this software may not be called "Tea",
33  * "TeaServlet", "Kettle" or "Trove", nor may "Tea", "TeaServlet",
34  * "Kettle", "Trove" or "BeanDoc" appear in their name, without prior
35  * written permission of the Walt Disney Internet Group.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE WALT DISNEY INTERNET GROUP OR ITS
41  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
42  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
43  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
44  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
45  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48  * ====================================================================
49  *
50  * For more information about Tea, please see http://opensource.go.com/.
51  */

52
53 package com.go.teaservlet;
54
55 import com.go.tea.compiler.ErrorEvent;
56
57 /******************************************************************************
58  *
59  * @author Reece Wilton
60  * @version
61  * <!--$$Revision:--> 16 <!-- $-->, <!--$$JustDate:--> 9/07/00 <!-- $-->
62  */

63 public class TemplateError {
64     private String JavaDoc mErrorMessage;
65     private String JavaDoc mDetailedErrorMessage;
66     private String JavaDoc mSourceInfoMessage;
67     private String JavaDoc mSourceLine;
68     private int mErrorStartPos;
69     private int mDetailPos;
70     private int mErrorEndPos;
71     
72     public TemplateError(ErrorEvent errorEvent, String JavaDoc sourceLine,
73                          int errorStartPos, int detailPos, int errorEndPos) {
74         mErrorMessage = errorEvent.getErrorMessage();
75         mSourceInfoMessage = errorEvent.getSourceInfoMessage();
76         mDetailedErrorMessage = errorEvent.getDetailedErrorMessage();
77         mSourceLine = sourceLine;
78
79         int length = sourceLine.length();
80         if ((mErrorStartPos = errorStartPos) > length) {
81             mErrorStartPos = length - 1;
82         }
83         if ((mDetailPos = detailPos) > length) {
84             mDetailPos = length - 1;
85         }
86         if ((mErrorEndPos = errorEndPos) > length) {
87             mErrorEndPos = length - 1;
88         }
89     }
90
91     public String JavaDoc getErrorMessage() {
92         return mErrorMessage;
93     }
94
95     public String JavaDoc getDetailedErrorMessage() {
96         return mDetailedErrorMessage;
97     }
98
99     public String JavaDoc getSourceInfoMessage() {
100         return mSourceInfoMessage;
101     }
102
103     public String JavaDoc getSourceLine() {
104         return mSourceLine;
105     }
106
107     public String JavaDoc getLineStart() {
108         try {
109             return mSourceLine.substring(0, mErrorStartPos);
110         }
111         catch (IndexOutOfBoundsException JavaDoc e) {
112             return "";
113         }
114     }
115     
116     public String JavaDoc getErrorStart() {
117         try {
118             return mSourceLine.substring(mErrorStartPos, mDetailPos);
119         }
120         catch (IndexOutOfBoundsException JavaDoc e) {
121             return "";
122         }
123     }
124     
125     public String JavaDoc getDetail() {
126         try {
127             return mSourceLine.substring(mDetailPos, mDetailPos + 1);
128         }
129         catch (IndexOutOfBoundsException JavaDoc e) {
130             return "";
131         }
132     }
133     
134     public String JavaDoc getErrorEnd() {
135         try {
136             return mSourceLine.substring(mDetailPos + 1, mErrorEndPos + 1);
137         }
138         catch (IndexOutOfBoundsException JavaDoc e) {
139             return "";
140         }
141     }
142     
143     public String JavaDoc getLineEnd() {
144         try {
145             return mSourceLine.substring
146                 (mErrorEndPos + 1, mSourceLine.length());
147         }
148         catch (IndexOutOfBoundsException JavaDoc e) {
149             return "";
150         }
151     }
152 }
153
Popular Tags