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 private boolean parsingError = false;
40
41 private List<SAXParseException> errors = new ArrayList<SAXParseException>();
42
43 private List<SAXParseException> fatalErrors = new ArrayList<SAXParseException>();
44
45 private List<SAXParseException> warnings = new ArrayList<SAXParseException>();
46
47 private boolean failOnValidationError;
48
49
50
51
52 public XmlValidationHandler( boolean failOnValidationError )
53 {
54 this.failOnValidationError = failOnValidationError;
55 }
56
57
58
59
60 public void error( SAXParseException excp )
61 throws SAXException
62 {
63 this.setErrorParsing( true );
64 this.errors.add( excp );
65 if ( this.failOnValidationError )
66 {
67 throw new SAXException( excp.getMessage(), excp );
68 }
69 }
70
71
72
73
74 public void fatalError( SAXParseException excp )
75 throws SAXException
76 {
77 this.fatalErrors.add( excp );
78 if ( this.failOnValidationError )
79 {
80 throw new SAXException( excp.getMessage(), excp );
81 }
82 }
83
84
85
86
87 public void warning( SAXParseException excp )
88 throws SAXException
89 {
90 this.warnings.add( excp );
91 }
92
93
94
95
96 public void startElement( String uri, String localName, String qName, Attributes attributes )
97 throws SAXException
98 {
99
100 }
101
102
103
104
105 public boolean isErrorParsing()
106 {
107 return this.parsingError;
108 }
109
110
111
112
113 public void setErrorParsing( boolean error )
114 {
115 this.parsingError = error;
116 }
117
118 public List<SAXParseException> getErrors()
119 {
120 return errors;
121 }
122
123 public void setErrors( List<SAXParseException> errors )
124 {
125 this.errors = errors;
126 }
127
128 public List<SAXParseException> getFatalErrors()
129 {
130 return fatalErrors;
131 }
132
133 public void setFatalErrors( List<SAXParseException> fatalErrors )
134 {
135 this.fatalErrors = fatalErrors;
136 }
137
138 public List<SAXParseException> getWarnings()
139 {
140 return warnings;
141 }
142
143 public void setWarnings( List<SAXParseException> warnings )
144 {
145 this.warnings = warnings;
146 }
147 }