Skip to content

Instantly share code, notes, and snippets.

@jesusjavierdediego
Created December 19, 2018 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesusjavierdediego/b2a44ed9ce89c3349fc804bc714b1d55 to your computer and use it in GitHub Desktop.
Save jesusjavierdediego/b2a44ed9ce89c3349fc804bc714b1d55 to your computer and use it in GitHub Desktop.
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