KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > xml > client > impl > DOMParseException


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * 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, 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 JavaDoc summarize(String JavaDoc text) {
31     return text.substring(0, Math.min(text.length(), MAX_SUMMARY_LENGTH));
32   }
33
34   private String JavaDoc contents;
35
36   public DOMParseException() {
37     super(DOMException.SYNTAX_ERR, "Parse error");
38   }
39
40   public DOMParseException(String JavaDoc contents) {
41     super(DOMException.SYNTAX_ERR, "Failed to parse: " + summarize(contents));
42     this.contents = contents;
43   }
44
45   public DOMParseException(String JavaDoc contents, Throwable JavaDoc e) {
46     super(DOMException.SYNTAX_ERR, "Failed to parse: " + summarize(contents));
47     initCause(e);
48     this.contents = contents;
49   }
50
51   public String JavaDoc getContents() {
52     return contents;
53   }
54 }
55
Popular Tags