Skip to content
Snippets Groups Projects
Commit 5f38d208 authored by Sebastian Ebert's avatar Sebastian Ebert
Browse files

improved cmdl interfacing

parent e7d9e50b
No related branches found
No related tags found
No related merge requests found
package de.tudresden.inf.st.pnml.base.util;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
public class FileUtils {
public static File resolveTemplate(String path) {
// Get the ClassLoader
ClassLoader classLoader = FileUtils.class.getClassLoader();
// Get the URL to the resource
URL resourceURL = classLoader.getResource(path);
if (resourceURL != null) {
try {
// If the resource is inside the JAR (URL starts with "jar:file:")
if (resourceURL.getProtocol().equals("jar")) {
// If the resource is inside the JAR, copy it to a temporary file
InputStream inputStream = resourceURL.openStream();
Path tempFile = Files.createTempFile("template_", ".pnml");
try (OutputStream outputStream = Files.newOutputStream(tempFile)) {
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
}
return tempFile.toFile(); // Return the temporary File
} else {
// If the resource is not inside a JAR, it is a regular file on the filesystem
return new File(resourceURL.getFile()); // Return File for IDE usage
}
} catch (IOException e) {
System.out.println("Error reading resource: " + e.getMessage());
return null;
}
} else {
System.out.println("Resource not found");
return null;
}
}
}
import de.tudresden.inf.st.pnml.jastadd.model.PetriNet; import de.tudresden.inf.st.pnml.jastadd.model.PetriNet;
import de.tudresden.inf.st.pnml.base.util.FileUtils;
import fr.lip6.move.pnml.framework.hlapi.HLAPIRootClass; import fr.lip6.move.pnml.framework.hlapi.HLAPIRootClass;
import fr.lip6.move.pnml.framework.utils.ModelRepository; import fr.lip6.move.pnml.framework.utils.ModelRepository;
import fr.lip6.move.pnml.framework.utils.PNMLUtils; import fr.lip6.move.pnml.framework.utils.PNMLUtils;
...@@ -32,20 +33,21 @@ aspect PnmlParser { ...@@ -32,20 +33,21 @@ aspect PnmlParser {
return tempFile; return tempFile;
} }
public static List<PetriNet> parsePnml(String path, boolean useTemp) {
Path file = null; public static List<PetriNet> parsePnml(String path, boolean isExternal) {
if(useTemp){ File file = null;
file = toTempPath(path);
} else { if(isExternal){
file = Paths.get(path); file = Paths.get(path).toFile();
} } else {
file = FileUtils.resolveTemplate(path);
}
HLAPIRootClass document = null; HLAPIRootClass document = null;
try { try {
document = PNMLUtils.importPnmlDocument(file.toFile(), false); document = PNMLUtils.importPnmlDocument(file, false);
//logger.info(document.toPNML()); //logger.info(document.toPNML());
} catch (ImportException | InvalidIDException e) { } catch (ImportException | InvalidIDException e) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment