Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def getListOfDiagramFilesFromDirectory(dir: String): Array[Option[Elem]] = {
val canonicalPath = getClass.getResource("/".concat(dir))
var listOfFiles: ArrayBuffer[Option[Elem]] = ArrayBuffer[Option[Elem]]()
if (canonicalPath.getProtocol().equals("jar")) {
val jarPath: String = canonicalPath.getPath().substring(5, canonicalPath.getPath().indexOf("!"))
val jar: JarFile = new JarFile(URLDecoder.decode(jarPath, "UTF-8"))
val entries = jar.entries()
while(entries.hasMoreElements){
val entry = entries.nextElement()
if (entry.isDirectory()) {
logger.debug(s"Directory: '${entry}'")
} else {
logger.debug(s"File: '${entry}'")
if(entry.getName.contains(dir)){
if(entry.getName.contains(".bpmn")){
listOfFiles += getDiagramFile(entry.getName)
}
}
}
}
}
listOfFiles.toArray
}
def getDiagramFile(fileInJar: String): Option[Elem] = {
import java.net.URL
var result: Option[Elem] = None
try {
val u: URL = this.getClass().getResource(fileInJar)
val f: InputStream = u.openStream()
result = Some(XML.load(f))
} catch {
case e: NullPointerException => {
logger.error(s"The file '${fileInJar}' is not loaded.")
}
}
result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.