1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.camel.processor.validation; |
18 |
|
|
19 |
|
import java.util.ArrayList; |
20 |
|
import java.util.List; |
21 |
|
|
22 |
|
import javax.xml.transform.dom.DOMResult; |
23 |
|
import javax.xml.validation.Schema; |
24 |
|
|
25 |
|
import org.apache.commons.logging.Log; |
26 |
|
import org.apache.commons.logging.LogFactory; |
27 |
|
import org.xml.sax.SAXException; |
28 |
|
import org.xml.sax.SAXParseException; |
29 |
|
|
30 |
|
import org.apache.camel.Exchange; |
31 |
|
import org.apache.camel.ValidationException; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
0 |
public class DefaultValidationErrorHandler implements ValidatorErrorHandler { |
39 |
0 |
private static final transient Log log = LogFactory.getLog(DefaultValidationErrorHandler.class); |
40 |
0 |
private List<SAXParseException> warnings = new ArrayList<SAXParseException>(); |
41 |
0 |
private List<SAXParseException> errors = new ArrayList<SAXParseException>(); |
42 |
0 |
private List<SAXParseException> fatalErrors = new ArrayList<SAXParseException>(); |
43 |
|
|
44 |
|
public void warning(SAXParseException e) throws SAXException { |
45 |
0 |
if (log.isDebugEnabled()) { |
46 |
0 |
log.debug("warning: " + e, e); |
47 |
|
} |
48 |
0 |
warnings.add(e); |
49 |
0 |
} |
50 |
|
|
51 |
|
public void error(SAXParseException e) throws SAXException { |
52 |
0 |
if (log.isDebugEnabled()) { |
53 |
0 |
log.debug("error: " + e, e); |
54 |
|
} |
55 |
0 |
errors.add(e); |
56 |
0 |
} |
57 |
|
|
58 |
|
public void fatalError(SAXParseException e) throws SAXException { |
59 |
0 |
if (log.isDebugEnabled()) { |
60 |
0 |
log.debug("fatalError: " + e, e); |
61 |
|
} |
62 |
0 |
fatalErrors.add(e); |
63 |
0 |
} |
64 |
|
|
65 |
|
public void reset() { |
66 |
0 |
} |
67 |
|
|
68 |
|
public boolean isValid() { |
69 |
0 |
return errors.isEmpty() && fatalErrors.isEmpty(); |
70 |
|
} |
71 |
|
|
72 |
|
public void handleErrors(Exchange exchange, Schema schema, DOMResult result) throws ValidationException { |
73 |
0 |
if (!isValid()) { |
74 |
0 |
throw new SchemaValidationException(exchange, schema, fatalErrors, errors, warnings); |
75 |
|
} |
76 |
0 |
} |
77 |
|
|
78 |
|
public void handleErrors(Exchange exchange, Object schema) throws ValidationException { |
79 |
0 |
if (!isValid()) { |
80 |
0 |
throw new SchemaValidationException(exchange, schema, fatalErrors, errors, warnings); |
81 |
|
} |
82 |
0 |
} |
83 |
|
} |