01: /*
02: * Copyright 2006 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.xml.client.impl;
17:
18: import com.google.gwt.xml.client.DOMException;
19:
20: /**
21: * Thrown when parse errors occur in the underlying implementation.
22: */
23: public class DOMParseException extends DOMException {
24:
25: /**
26: * Maximum size of error message in summary.
27: */
28: private static final int MAX_SUMMARY_LENGTH = 128;
29:
30: static String summarize(String text) {
31: return text.substring(0, Math.min(text.length(),
32: MAX_SUMMARY_LENGTH));
33: }
34:
35: private String contents;
36:
37: public DOMParseException() {
38: super (DOMException.SYNTAX_ERR, "Parse error");
39: }
40:
41: public DOMParseException(String contents) {
42: super (DOMException.SYNTAX_ERR, "Failed to parse: "
43: + summarize(contents));
44: this .contents = contents;
45: }
46:
47: public DOMParseException(String contents, Throwable e) {
48: super (DOMException.SYNTAX_ERR, "Failed to parse: "
49: + summarize(contents));
50: initCause(e);
51: this .contents = contents;
52: }
53:
54: public String getContents() {
55: return contents;
56: }
57: }
|