Skip to content

Instantly share code, notes, and snippets.

@cmaggiulli
Last active March 17, 2022 19:24
Show Gist options
  • Select an option

  • Save cmaggiulli/3e260e13c723925c11f437c8d45e8fa1 to your computer and use it in GitHub Desktop.

Select an option

Save cmaggiulli/3e260e13c723925c11f437c8d45e8fa1 to your computer and use it in GitHub Desktop.
Parse KTR
import groovy.io.FileType
import groovy.xml.*
def dirStr = "C:\\integration\\Pentaho\\Projects\\content\\public"
def dir = new File(dirStr)
def slurper = new XmlSlurper()
def connFileMap = [:]
File outputFile = new File("c:\\Users\\CMaggiul\\connections.csv")
dir.eachFileRecurse(FileType.FILES) { file ->
xmlFile = file.path
xmlFileName = file.name
connList = []
def csv = ""
if( file.name.endsWith('ktr') ) {
xml = new XmlParser().parse(xmlFile)
csv += "${xmlFileName},${xmlFile}"
xml.connection.each {
connName = it.name.text()
if( connName ) {
csv += ",${connName}"
connList.add( connName )
}
}
outputFile.withWriterAppend{ out ->
out.println csv
}
connFileMap.put(xmlFileName, connList)
} else if ( file.name.endsWith('kjb') ) {
// Do Nothing For Now
}
}
print connFileMap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment