Commit 38c07285 by Amelin Konstantin

Add exception handler to Main.

parent c617955d
......@@ -37,10 +37,13 @@ object Main {
for (v <- Files.walk(Paths.get(args(0))).toArray; f = v.asInstanceOf[Path]; if !Files.isDirectory(f)) {
val fSourceName= f.getFileName.toString
val fOutputName = s"Converted_$fSourceName"
val now = LocalDateTime.now().toString
Try {
val sourceXml = XML.loadFile(f.toString)
val template = Template(sourceXml)
val outputXml = XML.loadString(p.format(template.render))
val now = LocalDateTime.now().toString
val sourceXmlValid = if (template.isStraight) nsdXmlValid else rtsXmlValid
val outputXmlValid = if (template.isStraight) rtsXmlValid else nsdXmlValid
......@@ -61,10 +64,23 @@ object Main {
XML.save(Paths.get(args(1), fOutputName).toString, outputXml, xmlDecl = true)
logString += template.info(s"$now\n$msgCheckSource\n$msgCheckOutput") + "\n\n"
template.info(s"$now\n$msgCheckSource\n$msgCheckOutput") + "\n\n"
} match {
case Success(ti) => logString += ti
case Failure(ex) => logString += s"'$now\nImpossible to convert'$fSourceName': ${ex.getMessage}\n\n"
}
}
Files.write(Paths.get(args(1), logFileName), logString.getBytes("utf-8"), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)
Try {
Files.write(
Paths.get(args(1), logFileName),
logString.getBytes("utf-8"),
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING)
} match {
case Success(_) => println(s"Work has finished. $logFileName located in ${args(1)}")
case Failure(ex) => println(s"Error. Work hasn`t finished: ${ex.getMessage}")
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment