OSDN Git Service

add comment for Serializable private field warning
[jindolf/JinParser.git] / src / main / java / jp / osdn / jindolf / parser / HtmlParseException.java
1 /*
2  * html parse exception
3  *
4  * License : The MIT License
5  * Copyright(c) 2009 olyutorskii
6  */
7
8 package jp.osdn.jindolf.parser;
9
10 /**
11  * XHTMLパースの異常系情報。
12  * {@link HtmlParser}の各ハンドラは、この例外をスローすることで
13  * パース処理の即時停止を{@link HtmlParser}に指示することができる。
14  * パース対象({@link jp.osdn.jindolf.parser.content.DecodedContent})
15  * 内のパース中断位置を保持することができる。
16  * 中断位置が不明な場合は負の値が設定される。
17  */
18 @SuppressWarnings("serial")
19 public class HtmlParseException extends Exception{
20
21     /** パース中段位置。 */
22     private final int charPos;
23
24     /**
25      * コンストラクタ。
26      */
27     public HtmlParseException(){
28         this(null, -1);
29         return;
30     }
31
32     /**
33      * コンストラクタ。
34      * @param message メッセージ
35      */
36     public HtmlParseException(String message){
37         this(message, -1);
38         return;
39     }
40
41     /**
42      * コンストラクタ。
43      * @param charPos パース中断位置
44      */
45     public HtmlParseException(int charPos){
46         this(null, charPos);
47         return;
48     }
49
50     /**
51      * コンストラクタ。
52      * @param message メッセージ
53      * @param charPos パース中断位置
54      */
55     public HtmlParseException(String message, int charPos){
56         super(message);
57         this.charPos = charPos;
58         return;
59     }
60
61     /**
62      * パース中断位置を返す。
63      * @return パース中断位置
64      */
65     public int getCharPos(){
66         return this.charPos;
67     }
68
69     /**
70      * {@inheritDoc}
71      * @return {@inheritDoc}
72      */
73     @Override
74     public String getMessage(){
75         StringBuilder result = new StringBuilder();
76
77         String message = super.getMessage();
78         if(message != null && message.length() > 0){
79             result.append(message).append(' ');
80         }
81
82         result.append("charPos=").append(this.charPos);
83
84         return result.toString();
85     }
86
87 }