use of com.eden.orchid.api.resources.resource.FileResource in project Orchid by JavaEden.
the class OrchidResources method findClosestFile.
public OrchidResource findClosestFile(String filename, boolean strict, int maxIterations) {
if (!EdenUtils.isEmpty(context.query("options.resourcesDir"))) {
String resourceDir = context.query("options.resourcesDir").toString();
File folder = new File(resourceDir);
while (true) {
if (folder.isDirectory()) {
List<File> files = new ArrayList<>(FileUtils.listFiles(folder, null, false));
for (File file : files) {
if (!strict) {
if (FilenameUtils.removeExtension(file.getName()).equalsIgnoreCase(filename)) {
return new FileResource(context, file);
}
} else {
if (file.getName().equals(filename)) {
return new FileResource(context, file);
}
}
}
}
// set the folder to its own parent and search again
if (folder.getParentFile() != null && maxIterations > 0) {
folder = folder.getParentFile();
maxIterations--;
} else // there is no more parent to search, exit the loop
{
break;
}
}
}
return null;
}
use of com.eden.orchid.api.resources.resource.FileResource in project Orchid by JavaEden.
the class LocalResourceSource method getResourceEntries.
@Override
public List<OrchidResource> getResourceEntries(String path, String[] fileExtensions, boolean recursive) {
List<OrchidResource> entries = new ArrayList<>();
String fullPath = getDirectory() + "/" + path;
File file = new File(fullPath);
if (file.exists() && file.isDirectory()) {
Collection newFiles = FileUtils.listFiles(file, fileExtensions, recursive);
if (!EdenUtils.isEmpty(newFiles)) {
for (Object object : newFiles) {
File newFile = (File) object;
if (shouldAddEntry(newFile.getName())) {
FileResource entry = new FileResource(context, newFile);
entry.setPriority(getPriority());
entries.add(entry);
}
}
}
}
return entries;
}
Aggregations