![JAR search and dependency download from the Maven repository](/logo.png)
net.sourceforge.plantuml.FileSystem Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plantuml-mit Show documentation
Show all versions of plantuml-mit Show documentation
PlantUML is a component that allows to quickly write diagrams from text.
// THIS FILE HAS BEEN GENERATED BY A PREPROCESSOR.
package net.sourceforge.plantuml;
import java.io.IOException;
import net.sourceforge.plantuml.security.SFile;
import net.sourceforge.plantuml.security.SecurityUtils;
import net.sourceforge.plantuml.utils.Log;
public class FileSystem {
// ::remove file when __HAXE__
private final static FileSystem singleton = new FileSystem();
private ThreadLocal currentDir = new ThreadLocal<>();
private FileSystem() {
reset();
}
public static FileSystem getInstance() {
return singleton;
}
public void setCurrentDir(SFile dir) {
if (dir == null) {
this.currentDir.set(null);
} else {
Log.info("Setting current dir: " + dir.getAbsolutePath());
this.currentDir.set(dir.getAbsolutePath());
}
}
public SFile getCurrentDir() {
// ::comment when __CORE__
final String path = this.currentDir.get();
if (path != null)
return new SFile(path);
return null;
}
public SFile getFile(String nameOrPath) throws IOException {
// ::uncomment when __CORE__
// return null;
// ::comment when __CORE__
if (isAbsolute(nameOrPath)) {
final SFile result = new SFile(nameOrPath);
Log.info("Trying " + result.getAbsolutePath());
return result.getCanonicalFile();
}
final SFile dir = getCurrentDir();
SFile filecurrent = null;
if (dir != null) {
filecurrent = dir.getAbsoluteFile().file(nameOrPath);
Log.info("Current dir is " + dir.getAbsolutePath() + " so trying " + filecurrent.getAbsolutePath());
if (filecurrent.exists())
return filecurrent.getCanonicalFile();
}
for (SFile d : SecurityUtils.getPath(SecurityUtils.PATHS_INCLUDES)) {
assert d.isDirectory();
final SFile file = d.file(nameOrPath);
if (file.exists())
return file.getCanonicalFile();
}
for (SFile d : SecurityUtils.getPath(SecurityUtils.PATHS_CLASSES)) {
assert d.isDirectory();
final SFile file = d.file(nameOrPath);
if (file.exists())
return file.getCanonicalFile();
}
if (dir == null) {
assert filecurrent == null;
return new SFile(nameOrPath).getCanonicalFile();
}
assert filecurrent != null;
return filecurrent;
}
// ::comment when __CORE__
private boolean isAbsolute(String nameOrPath) {
final SFile f = new SFile(nameOrPath);
return f.isAbsolute();
}
public void reset() {
setCurrentDir(new SFile("."));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy