Clover Coverage Report
Coverage timestamp: Sa Aug 2 2008 13:56:27 CEST
../../../../../img/srcFileCovDistChart0.png 88% of files have more coverage
9   174   9   1
0   51   1   9
9     1  
1    
 
  XmlSyntaxException       Line # 32 9 9 0% 0.0
 
No Tests
 
1    /* $Id: XmlSyntaxException.java,v 1.1 2008/07/26 08:00:52 m31 Exp $
2    *
3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
4    *
5    * Copyright 2000-2008, Michael Meyling <mime@qedeq.org>.
6    *
7    * "Hilbert II" is free software; you can redistribute
8    * it and/or modify it under the terms of the GNU General Public
9    * License as published by the Free Software Foundation; either
10    * version 2 of the License, or (at your option) any later version.
11    *
12    * This program is distributed in the hope that it will be useful,
13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15    * GNU General Public License for more details.
16    */
17   
18    package org.qedeq.kernel.xml.common;
19   
20    import org.qedeq.kernel.common.QedeqException;
21    import org.qedeq.kernel.common.SourcePosition;
22   
23   
24    /**
25    * Exception that occurs during XML parsing. It specifies an syntactical error.
26    * It can also mark a lack of inner consistence of something.
27    * Also a programming error can lead to this exception.
28    *
29    * @version $Revision: 1.1 $
30    * @author Michael Meyling
31    */
 
32    public final class XmlSyntaxException extends QedeqException {
33   
34    /** Error code for Exceptions thrown by the SAXParser. */
35    public static final int SAX_PARSER_EXCEPTION = 9001;
36   
37    /** Error code for unexpected tag. */
38    public static final int UNEXPECTED_TAG_CODE = 9002;
39   
40    /** Unexpected tag message text. */
41    public static final String UNEXPECTED_TAG_TEXT = "Unexpected tag: ";
42   
43    /** Error code for unexpected character data. */
44    public static final int UNEXPECTED_DATA_CODE = 9003;
45   
46    /** Unexpected tag message text, part one. */
47    public static final String UNEXPECTED_DATA_TEXT = "Unexpected character data in tag: ";
48   
49    /** Error code for missing attribute. */
50    public static final int MISSING_ATTRIBUTE_CODE = 9004;
51   
52    /** Missing attribute text. */
53    public static final String MISSING_ATTRIBUTE_TEXT_1 = "Missing attribute: ";
54   
55    /** Missing attribute, part two. */
56    public static final String MISSING_ATTRIBUTE_TEXT_2 = " in tag: ";
57   
58    /** Error code for empty attribute. */
59    public static final int EMPTY_ATTRIBUTE_CODE = 9004;
60   
61    /** Missing attribute text. */
62    public static final String EMPTY_ATTRIBUTE_TEXT_1 = "Missing attribute: ";
63   
64    /** Missing attribute, part two. */
65    public static final String EMPTY_ATTRIBUTE_TEXT_2 = " in tag: ";
66   
67    /** Error code for a programming error. */
68    public static final int PROGRAMMING_ERROR_CODE = 9999;
69   
70    /** Unexpected tag message text, part one. */
71    public static final String PROGRAMMING_ERROR_TEXT = "A programming error occurred.";
72   
73    /** Error location. */
74    private SourcePosition position;
75   
76    /**
77    * Constructor.
78    *
79    * @param code Error code.
80    * @param message Error message.
81    */
 
82  0 toggle private XmlSyntaxException(final int code, final String message) {
83  0 super(code, message);
84    }
85   
86    /**
87    * Constructor.
88    *
89    * @param code Error code.
90    * @param message Error message.
91    * @param e Error cause.
92    */
 
93  0 toggle private XmlSyntaxException(final int code, final String message, final RuntimeException e) {
94  0 super(code, message, e);
95    }
96   
97    /**
98    * Get error position.
99    *
100    * @return Error position.
101    */
 
102  0 toggle public final SourcePosition getErrorPosition() {
103  0 return position;
104    }
105   
106   
107    /**
108    * Set error position.
109    *
110    * @param position Error position.
111    */
 
112  0 toggle public final void setErrorPosition(final SourcePosition position) {
113  0 this.position = position;
114    }
115   
116    /**
117    * Create exception for unexpected tag.
118    *
119    * @param name Tag name.
120    * @return Exception.
121    */
 
122  0 toggle public static final XmlSyntaxException createUnexpectedTagException(final String name) {
123  0 return new XmlSyntaxException(UNEXPECTED_TAG_CODE, UNEXPECTED_TAG_TEXT + name);
124    }
125   
126    /**
127    * Create exception for unexpected text data within a tag.
128    *
129    * @param name Tag name.
130    * @param value Data found.
131    * @return Exception.
132    */
 
133  0 toggle public static final XmlSyntaxException createUnexpectedTextDataException(final String name,
134    final String value) {
135  0 return new XmlSyntaxException(UNEXPECTED_DATA_CODE, UNEXPECTED_DATA_TEXT + name);
136    }
137   
138    /**
139    * Create exception for missing attribute within a tag.
140    *
141    * @param name Tag name.
142    * @param attribute Attribute name.
143    * @return Exception.
144    */
 
145  0 toggle public static final XmlSyntaxException createMissingAttributeException(final String name,
146    final String attribute) {
147  0 return new XmlSyntaxException(MISSING_ATTRIBUTE_CODE, MISSING_ATTRIBUTE_TEXT_1 + attribute
148    + MISSING_ATTRIBUTE_TEXT_2 + name);
149    }
150   
151    /**
152    * Create exception for empty attribute within a tag.
153    *
154    * @param name Tag name.
155    * @param attribute Attribute name.
156    * @return Exception.
157    */
 
158  0 toggle public static final XmlSyntaxException createEmptyAttributeException(final String name,
159    final String attribute) {
160  0 return new XmlSyntaxException(EMPTY_ATTRIBUTE_CODE, EMPTY_ATTRIBUTE_TEXT_1 + attribute
161    + EMPTY_ATTRIBUTE_TEXT_2 + name);
162    }
163   
164    /**
165    * Create exception for a programming error.
166    *
167    * @param e Exception.
168    * @return Created exception.
169    */
 
170  0 toggle public static final XmlSyntaxException createByRuntimeException(final RuntimeException e) {
171  0 return new XmlSyntaxException(PROGRAMMING_ERROR_CODE, PROGRAMMING_ERROR_TEXT, e);
172    }
173   
174    }