1 package org.apache.maven.api.services.xml;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.InputStream;
23 import java.io.Reader;
24 import java.net.URL;
25 import java.nio.file.Path;
26
27 import org.apache.maven.api.annotations.Experimental;
28 import org.apache.maven.api.annotations.Immutable;
29 import org.apache.maven.api.annotations.Nonnull;
30 import org.apache.maven.api.annotations.NotThreadSafe;
31
32
33
34
35
36
37 @Experimental
38 @Immutable
39 public interface XmlReaderRequest
40 {
41
42 Path getPath();
43
44 URL getURL();
45
46 InputStream getInputStream();
47
48 Reader getReader();
49
50 Transformer getTransformer();
51
52 boolean isStrict();
53
54 String getModelId();
55
56 String getLocation();
57
58 boolean isAddDefaultEntities();
59
60 interface Transformer
61 {
62
63
64
65
66
67
68
69
70 String transform( String source, String fieldName );
71 }
72
73 @Nonnull
74 static XmlReaderRequestBuilder builder()
75 {
76 return new XmlReaderRequestBuilder();
77 }
78
79 @NotThreadSafe
80 class XmlReaderRequestBuilder
81 {
82 Path path;
83 URL url;
84 InputStream inputStream;
85 Reader reader;
86 Transformer transformer;
87 boolean strict;
88 String modelId;
89 String location;
90 boolean addDefaultEntities = true;
91
92 public XmlReaderRequestBuilder path( Path path )
93 {
94 this.path = path;
95 return this;
96 }
97
98 public XmlReaderRequestBuilder url( URL url )
99 {
100 this.url = url;
101 return this;
102 }
103
104 public XmlReaderRequestBuilder inputStream( InputStream inputStream )
105 {
106 this.inputStream = inputStream;
107 return this;
108 }
109
110 public XmlReaderRequestBuilder reader( Reader reader )
111 {
112 this.reader = reader;
113 return this;
114 }
115
116 public XmlReaderRequestBuilder transformer( Transformer transformer )
117 {
118 this.transformer = transformer;
119 return this;
120 }
121
122 public XmlReaderRequestBuilder strict( boolean strict )
123 {
124 this.strict = strict;
125 return this;
126 }
127
128 public XmlReaderRequestBuilder modelId( String modelId )
129 {
130 this.modelId = modelId;
131 return this;
132 }
133
134 public XmlReaderRequestBuilder location( String location )
135 {
136 this.location = location;
137 return this;
138 }
139
140 public XmlReaderRequestBuilder addDefaultEntities( boolean addDefaultEntities )
141 {
142 this.addDefaultEntities = addDefaultEntities;
143 return this;
144 }
145
146 public XmlReaderRequest build()
147 {
148 return new DefaultXmlReaderRequest( path, url, inputStream, reader, transformer, strict,
149 modelId, location, addDefaultEntities );
150 }
151
152 private static class DefaultXmlReaderRequest implements XmlReaderRequest
153 {
154 final Path path;
155 final URL url;
156 final InputStream inputStream;
157 final Reader reader;
158 final Transformer transformer;
159 final boolean strict;
160 final String modelId;
161 final String location;
162 final boolean addDefaultEntities;
163
164 @SuppressWarnings( "checkstyle:ParameterNumber" )
165 DefaultXmlReaderRequest( Path path, URL url, InputStream inputStream, Reader reader,
166 Transformer transformer, boolean strict,
167 String modelId, String location,
168 boolean addDefaultEntities )
169 {
170 this.path = path;
171 this.url = url;
172 this.inputStream = inputStream;
173 this.reader = reader;
174 this.transformer = transformer;
175 this.strict = strict;
176 this.modelId = modelId;
177 this.location = location;
178 this.addDefaultEntities = addDefaultEntities;
179 }
180
181 @Override
182 public Path getPath()
183 {
184 return path;
185 }
186
187 @Override
188 public URL getURL()
189 {
190 return null;
191 }
192
193 @Override
194 public InputStream getInputStream()
195 {
196 return inputStream;
197 }
198
199 public Reader getReader()
200 {
201 return reader;
202 }
203
204 @Override
205 public Transformer getTransformer()
206 {
207 return transformer;
208 }
209
210 @Override
211 public boolean isStrict()
212 {
213 return strict;
214 }
215
216 @Override
217 public String getModelId()
218 {
219 return modelId;
220 }
221
222 @Override
223 public String getLocation()
224 {
225 return location;
226 }
227
228 @Override
229 public boolean isAddDefaultEntities()
230 {
231 return addDefaultEntities;
232 }
233 }
234 }
235
236 }