Search in sources :

Example 1 with FileResource

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;
}
Also used : ArrayList(java.util.ArrayList) FileResource(com.eden.orchid.api.resources.resource.FileResource) File(java.io.File)

Example 2 with FileResource

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;
}
Also used : OrchidResource(com.eden.orchid.api.resources.resource.OrchidResource) ArrayList(java.util.ArrayList) FileResource(com.eden.orchid.api.resources.resource.FileResource) Collection(java.util.Collection) File(java.io.File)

Aggregations

FileResource (com.eden.orchid.api.resources.resource.FileResource)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 OrchidResource (com.eden.orchid.api.resources.resource.OrchidResource)1 Collection (java.util.Collection)1