@@ -160,51 +160,54 @@ class CLIConf(arguments: Array[String], stdout: PrintStream, stderr: PrintStream
160
160
override def argFormat (name : String ): String = " [" + name + " ]"
161
161
}
162
162
163
- implicit def validateConverter = singleArgConverter[ValidationMode .Type ]((s : String ) => {
164
- import ValidatorPatterns ._
165
- s match {
166
- case " on" => ValidationMode .Full
167
- case " limited" => ValidationMode .Limited
168
- case " off" => ValidationMode .Off
169
- case DefaultArgPattern (name, arg) if Validators .isRegistered(name) =>
170
- val config =
171
- if (arg.endsWith(" .conf" )) ConfigFactory .parseFile(new File (arg))
172
- else ConfigFactory .parseString(s " $name= $arg" )
173
- ValidationMode .Custom (Validators .get(name).make(config))
174
- case NoArgsPattern (name) if Validators .isRegistered(name) =>
175
- ValidationMode .Custom (Validators .get(name).make(ConfigFactory .empty))
176
- case _ =>
177
- throw new Exception (
178
- " Unrecognized ValidationMode %s. Must be 'on', 'limited', 'off', or name of spi validator."
179
- .format(s)
180
- )
181
- }
182
- })
163
+ implicit def validateConverter : ValueConverter [ValidationMode .Type ] =
164
+ singleArgConverter[ValidationMode .Type ]((s : String ) => {
165
+ import ValidatorPatterns ._
166
+ s match {
167
+ case " on" => ValidationMode .Full
168
+ case " limited" => ValidationMode .Limited
169
+ case " off" => ValidationMode .Off
170
+ case DefaultArgPattern (name, arg) if Validators .isRegistered(name) =>
171
+ val config =
172
+ if (arg.endsWith(" .conf" )) ConfigFactory .parseFile(new File (arg))
173
+ else ConfigFactory .parseString(s " $name= $arg" )
174
+ ValidationMode .Custom (Validators .get(name).make(config))
175
+ case NoArgsPattern (name) if Validators .isRegistered(name) =>
176
+ ValidationMode .Custom (Validators .get(name).make(ConfigFactory .empty))
177
+ case _ =>
178
+ throw new Exception (
179
+ " Unrecognized ValidationMode %s. Must be 'on', 'limited', 'off', or name of spi validator."
180
+ .format(s)
181
+ )
182
+ }
183
+ })
183
184
184
- implicit def infosetTypeConverter = singleArgConverter[InfosetType .Type ]((s : String ) => {
185
- try {
186
- InfosetType .withName(s.toLowerCase)
187
- } catch {
188
- case _ : NoSuchElementException =>
189
- throw new Exception (
190
- " Unrecognized infoset type: %s. Must be one of %s" .format(
191
- s,
192
- InfosetType .values.mkString(" , " )
185
+ implicit def infosetTypeConverter : ValueConverter [InfosetType .Type ] =
186
+ singleArgConverter[InfosetType .Type ]((s : String ) => {
187
+ try {
188
+ InfosetType .withName(s.toLowerCase)
189
+ } catch {
190
+ case _ : NoSuchElementException =>
191
+ throw new Exception (
192
+ " Unrecognized infoset type: %s. Must be one of %s" .format(
193
+ s,
194
+ InfosetType .values.mkString(" , " )
195
+ )
193
196
)
194
- )
195
- }
196
- })
197
+ }
198
+ })
197
199
198
- implicit def implementationConverter = singleArgConverter[TDMLImplementation ]((s : String ) => {
199
- val optImplementation = TDMLImplementation .optionStringToEnum(" implementation" , s)
200
- if (! optImplementation.isDefined) {
201
- throw new Exception (
202
- " Unrecognized TDML implementation '%s'. Must be one of %s"
203
- .format(s, TDMLImplementation .values.mkString(" , " ))
204
- )
205
- }
206
- optImplementation.get
207
- })
200
+ implicit def implementationConverter : ValueConverter [TDMLImplementation ] =
201
+ singleArgConverter[TDMLImplementation ]((s : String ) => {
202
+ val optImplementation = TDMLImplementation .optionStringToEnum(" implementation" , s)
203
+ if (! optImplementation.isDefined) {
204
+ throw new Exception (
205
+ " Unrecognized TDML implementation '%s'. Must be one of %s"
206
+ .format(s, TDMLImplementation .values.mkString(" , " ))
207
+ )
208
+ }
209
+ optImplementation.get
210
+ })
208
211
209
212
def qnameConvert (s : String ): RefQName = {
210
213
val eQN = QName .refQNameFromExtendedSyntax(s)
@@ -229,59 +232,61 @@ class CLIConf(arguments: Array[String], stdout: PrintStream, stderr: PrintStream
229
232
val argType = ArgType .SINGLE
230
233
}
231
234
232
- implicit def rootNSConverter = org.rogach.scallop.singleArgConverter[RefQName ](qnameConvert _)
233
-
234
- implicit def fileResourceURIConverter = singleArgConverter[URISchemaSource ]((s : String ) => {
235
- val optResolved =
236
- try {
237
- val uri =
238
- if (File .separatorChar == '/' || s.startsWith(" /" )) {
239
- // This is either a non-Windows system or a resource on the classpath. Either way we
240
- // assume it is a valid URI except for things like spaces, which this URI
241
- // constructor converts. We do not specify a schema since this might be a relative
242
- // path
243
- new URI (null , s, null )
244
- } else {
245
- // This is a Windows system, which has complex path resolution and paths that are
246
- // not valid URIs. Try to convert it to a relative URI where possible, otherwise we
247
- // settle for an absolute URI
248
- val p = Paths .get(s)
249
- if (p.isAbsolute() || s.startsWith(" \\ " )) {
250
- // if the Windows path is absolute (i.e. starts with a drive letter and colon) or
251
- // starts with a backslash (which resolves relative to the current drive instead
252
- // of the current working directory), then there is no valid relative URI
253
- // representation, so we just convert it to an absolute URI
254
- p.toUri
235
+ implicit def rootNSConverter : ValueConverter [RefQName ] =
236
+ org.rogach.scallop.singleArgConverter[RefQName ](qnameConvert _)
237
+
238
+ implicit def fileResourceURIConverter : ValueConverter [URISchemaSource ] =
239
+ singleArgConverter[URISchemaSource ]((s : String ) => {
240
+ val optResolved =
241
+ try {
242
+ val uri =
243
+ if (File .separatorChar == '/' || s.startsWith(" /" )) {
244
+ // This is either a non-Windows system or a resource on the classpath. Either way we
245
+ // assume it is a valid URI except for things like spaces, which this URI
246
+ // constructor converts. We do not specify a schema since this might be a relative
247
+ // path
248
+ new URI (null , s, null )
255
249
} else {
256
- // this Windows path is relative to the current working directory. We can convert
257
- // it to a relative URI by just switching all the path separators. We do not
258
- // specify a schema since this is a relative path
259
- new URI (null , s.replace('\\ ' , '/' ), null )
250
+ // This is a Windows system, which has complex path resolution and paths that are
251
+ // not valid URIs. Try to convert it to a relative URI where possible, otherwise we
252
+ // settle for an absolute URI
253
+ val p = Paths .get(s)
254
+ if (p.isAbsolute() || s.startsWith(" \\ " )) {
255
+ // if the Windows path is absolute (i.e. starts with a drive letter and colon) or
256
+ // starts with a backslash (which resolves relative to the current drive instead
257
+ // of the current working directory), then there is no valid relative URI
258
+ // representation, so we just convert it to an absolute URI
259
+ p.toUri
260
+ } else {
261
+ // this Windows path is relative to the current working directory. We can convert
262
+ // it to a relative URI by just switching all the path separators. We do not
263
+ // specify a schema since this is a relative path
264
+ new URI (null , s.replace('\\ ' , '/' ), null )
265
+ }
260
266
}
267
+ // At this point we have a valid URI, which could be absolute or relative, with relative
268
+ // URIs resolved from the current working directory. We create a fake contextPath that represents
269
+ // a fake file in the current working directory and pass that as the contextSource to the
270
+ // resolveSchemaLocation function to find the actual file or resource. This is necessary because
271
+ // resolveSchemaLocation expects a context that is a file for diagnostic purposes.
272
+ val contextPath = Paths .get(" fakeContext.dfdl.xsd" )
273
+ val contextSource = URISchemaSource (contextPath.toFile, contextPath.toUri)
274
+ XMLUtils .resolveSchemaLocation(uri.toString, Some (contextSource))
275
+ } catch {
276
+ case _ : Exception => throw new Exception (s " Could not find file or resource $s" )
277
+ }
278
+ optResolved match {
279
+ case Some ((uriSchemaSource, relToAbs)) => {
280
+ if (relToAbs) {
281
+ Logger .log.warn(s " Found relative path on classpath absolutely, did you mean / $s" )
261
282
}
262
- // At this point we have a valid URI, which could be absolute or relative, with relative
263
- // URIs resolved from the current working directory. We create a fake contextPath that represents
264
- // a fake file in the current working directory and pass that as the contextSource to the
265
- // resolveSchemaLocation function to find the actual file or resource. This is necessary because
266
- // resolveSchemaLocation expects a context that is a file for diagnostic purposes.
267
- val contextPath = Paths .get(" fakeContext.dfdl.xsd" )
268
- val contextSource = URISchemaSource (contextPath.toFile, contextPath.toUri)
269
- XMLUtils .resolveSchemaLocation(uri.toString, Some (contextSource))
270
- } catch {
271
- case _ : Exception => throw new Exception (s " Could not find file or resource $s" )
272
- }
273
- optResolved match {
274
- case Some ((uriSchemaSource, relToAbs)) => {
275
- if (relToAbs) {
276
- Logger .log.warn(s " Found relative path on classpath absolutely, did you mean / $s" )
283
+ uriSchemaSource
284
+ }
285
+ case None => {
286
+ throw new Exception (s " Could not find file or resource $s" )
277
287
}
278
- uriSchemaSource
279
- }
280
- case None => {
281
- throw new Exception (s " Could not find file or resource $s" )
282
288
}
283
- }
284
- })
289
+ })
285
290
286
291
printedName = " Apache Daffodil"
287
292
0 commit comments