1
2
3
4
5 package com.jcabi.xml;
6
7 import java.io.File;
8 import java.io.FileNotFoundException;
9 import java.io.IOException;
10 import java.io.InputStream;
11 import java.net.URI;
12 import java.net.URL;
13 import java.nio.file.Path;
14 import java.util.Collection;
15 import javax.xml.transform.Source;
16 import lombok.EqualsAndHashCode;
17 import org.xml.sax.ErrorHandler;
18 import org.xml.sax.SAXParseException;
19
20
21
22
23
24
25
26
27
28
29
30
31
32 @Deprecated
33 @EqualsAndHashCode(of = "xsd")
34 public final class XSDDocument implements XSD {
35
36
37
38
39 private final transient String xsd;
40
41
42
43
44
45 public XSDDocument(final XML src) {
46 this(src.toString());
47 }
48
49
50
51
52
53 public XSDDocument(final String src) {
54 this.xsd = src;
55 }
56
57
58
59
60
61
62
63 public XSDDocument(final URL url) throws IOException {
64 this(new TextResource(url).toString());
65 }
66
67
68
69
70
71
72
73 public XSDDocument(final Path file) throws IOException {
74 this(file.toFile());
75 }
76
77
78
79
80
81
82
83 public XSDDocument(final File file) throws IOException {
84 this(new TextResource(file).toString());
85 }
86
87
88
89
90
91
92
93 public XSDDocument(final URI uri) throws IOException {
94 this(new TextResource(uri).toString());
95 }
96
97
98
99
100
101 public XSDDocument(final InputStream stream) {
102 this(new TextResource(stream).toString());
103 }
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121 @SuppressWarnings("PMD.ProhibitPublicStaticMethods")
122 public static XSD make(final InputStream stream) {
123 return new XSDDocument(stream);
124 }
125
126
127
128
129
130
131
132
133 @SuppressWarnings("PMD.ProhibitPublicStaticMethods")
134 public static XSD make(final URL url) {
135 try {
136 return new XSDDocument(url);
137 } catch (final IOException ex) {
138 throw new IllegalStateException(ex);
139 }
140 }
141
142 @Override
143 public String toString() {
144 return new XMLDocument(this.xsd).toString();
145 }
146
147 @Override
148 public Collection<SAXParseException> validate(final Source xml) {
149 return new XMLDocument(xml).validate(new XMLDocument(this.xsd));
150 }
151
152
153
154
155
156
157 static final class ValidationHandler implements ErrorHandler {
158
159
160
161 private final transient Collection<SAXParseException> errors;
162
163
164
165
166
167 ValidationHandler(final Collection<SAXParseException> errs) {
168 this.errors = errs;
169 }
170
171 @Override
172 public void warning(final SAXParseException error) {
173 this.errors.add(error);
174 }
175
176 @Override
177 public void error(final SAXParseException error) {
178 this.errors.add(error);
179 }
180
181 @Override
182 public void fatalError(final SAXParseException error) {
183 this.errors.add(error);
184 }
185 }
186
187 }