Created
December 19, 2018 19:11
-
-
Save jesusjavierdediego/b2a44ed9ce89c3349fc804bc714b1d55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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