1 | |
package org.apache.maven.plugin.changes.schema; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.util.ArrayList; |
23 | |
import java.util.List; |
24 | |
|
25 | |
import org.xml.sax.Attributes; |
26 | |
import org.xml.sax.SAXException; |
27 | |
import org.xml.sax.SAXParseException; |
28 | |
import org.xml.sax.helpers.DefaultHandler; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
public class XmlValidationHandler |
36 | |
extends DefaultHandler |
37 | |
{ |
38 | |
|
39 | 3 | private boolean parsingError = false; |
40 | |
|
41 | 3 | private List errors = new ArrayList(); |
42 | |
|
43 | 3 | private List fatalErrors = new ArrayList(); |
44 | |
|
45 | 3 | private List warnings = new ArrayList(); |
46 | |
|
47 | |
private boolean failOnValidationError; |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
public XmlValidationHandler( boolean failOnValidationError ) |
53 | 3 | { |
54 | 3 | this.failOnValidationError = failOnValidationError; |
55 | 3 | } |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
public void error( SAXParseException excp ) |
61 | |
throws SAXException |
62 | |
{ |
63 | 2 | this.setErrorParsing( true ); |
64 | 2 | this.errors.add( excp ); |
65 | 2 | if ( this.failOnValidationError ) |
66 | |
{ |
67 | 1 | throw new SAXException( excp.getMessage(), excp ); |
68 | |
} |
69 | 1 | } |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
public void fatalError( SAXParseException excp ) |
75 | |
throws SAXException |
76 | |
{ |
77 | 0 | this.fatalErrors.add( excp ); |
78 | 0 | if ( this.failOnValidationError ) |
79 | |
{ |
80 | 0 | throw new SAXException( excp.getMessage(), excp ); |
81 | |
} |
82 | 0 | } |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
public void warning( SAXParseException excp ) |
88 | |
throws SAXException |
89 | |
{ |
90 | 0 | this.warnings.add( excp ); |
91 | 0 | } |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
public void startElement( String uri, String localName, String qName, Attributes attributes ) |
97 | |
throws SAXException |
98 | |
{ |
99 | |
|
100 | 0 | } |
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
public boolean isErrorParsing() |
106 | |
{ |
107 | 0 | return this.parsingError; |
108 | |
} |
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
public void setErrorParsing( boolean error ) |
114 | |
{ |
115 | 2 | this.parsingError = error; |
116 | 2 | } |
117 | |
|
118 | |
public List getErrors() |
119 | |
{ |
120 | 3 | return errors; |
121 | |
} |
122 | |
|
123 | |
public void setErrors( List errors ) |
124 | |
{ |
125 | 0 | this.errors = errors; |
126 | 0 | } |
127 | |
|
128 | |
public List getFatalErrors() |
129 | |
{ |
130 | 0 | return fatalErrors; |
131 | |
} |
132 | |
|
133 | |
public void setFatalErrors( List fatalErrors ) |
134 | |
{ |
135 | 0 | this.fatalErrors = fatalErrors; |
136 | 0 | } |
137 | |
|
138 | |
public List getWarnings() |
139 | |
{ |
140 | 0 | return warnings; |
141 | |
} |
142 | |
|
143 | |
public void setWarnings( List warnings ) |
144 | |
{ |
145 | 0 | this.warnings = warnings; |
146 | 0 | } |
147 | |
} |