1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.millscript.commons.xml.alerts;
22
23 import org.millscript.commons.alert.Alert;
24 import org.millscript.commons.xml.api.Name;
25
26 /**
27 * This class implements an Alert for use in situations like where an XML error
28 * is encountered.
29 */
30 public class XmlErrorAlert extends Alert {
31
32 /**
33 * This is the ID from the first release for future compatibility.
34 */
35 private static final long serialVersionUID = -870690901509964165L;
36
37 /**
38 * Constructs a new XML error alert with no explanation.
39 */
40 public XmlErrorAlert() {
41 this( null );
42 }
43
44 /**
45 * Constructs a new XML error alert with the specified explanation.
46 *
47 * @param exp the explanation for the alert
48 */
49 public XmlErrorAlert( final String exp ) {
50 this( "XML error", exp );
51 }
52
53 /**
54 * Constructs a new alert with the specified complaint and explanation.
55 * This constructor is for private use, to allow us to provide an exception
56 * hierarchy.
57 *
58 * @param comp the complaint
59 * @param exp the complaints explanation
60 */
61 protected XmlErrorAlert( final String comp, final String exp ) {
62 super( comp, exp );
63 }
64
65 /**
66 * Adds the specifed <code>char</code> as a culprit to this alert.
67 *
68 * @param ch the <code>char</code> to add as a culprit
69 * @return this alert
70 */
71 public XmlErrorAlert culpritChar( final char ch ) {
72 return (XmlErrorAlert) this.culprit(
73 "character",
74 new Character( ch )
75 ).culprit(
76 "hex char code",
77 Integer.toHexString( ch )
78 );
79 }
80
81 /**
82 * Adds the specifed <code>char</code> as a culprit to this alert.
83 *
84 * @param ch the <code>char</code> to add as a culprit
85 * @return this alert
86 */
87 public XmlErrorAlert culpritChar( final int ch ) {
88 return (XmlErrorAlert) this.culprit(
89 "character",
90 new Character( (char) ch )
91 ).culprit(
92 "hex char code",
93 Integer.toHexString( ch )
94 );
95 }
96
97 /**
98 * Adds the specifed end tag <code>Name</code> as a culprit to this alert.
99 *
100 * @param name the end tag <code>Name</code> to add as a culprit
101 * @return this alert
102 */
103 public XmlErrorAlert culpritETag( final Name name ) {
104 return (XmlErrorAlert) this.culprit( "end tag name", name );
105 }
106
107 /**
108 * Adds the specifed empty element tag <code>Name</code> as a culprit to
109 * this alert.
110 *
111 * @param name the empty element tag <code>Name</code> to add as a culprit
112 * @return this alert
113 */
114 public XmlErrorAlert culpritEmptyElemTag( final Name name ) {
115 return (XmlErrorAlert) this.culprit( "empty element tag name", name );
116 }
117
118 /**
119 * Adds the specifed start tag <code>Name</code> as a culprit to this
120 * alert.
121 *
122 * @param name the start tag <code>Name</code> to add as a culprit
123 * @return this alert
124 */
125 public XmlErrorAlert culpritSTag( final Name name ) {
126 return (XmlErrorAlert) this.culprit( "start tag name", name );
127 }
128
129 /**
130 * Adds the specifed token as a culprit to this alert.
131 *
132 * @param token the token to add as a culprit
133 * @return this alert
134 */
135 public XmlErrorAlert culpritToken( final String token ) {
136 return (XmlErrorAlert) this.culprit( "token", token );
137 }
138
139 }