Search in sources :

Example 1 with AdditionalFolderAtRoot

use of net.pms.external.AdditionalFolderAtRoot in project UniversalMediaServer by UniversalMediaServer.

the class RootFolder method getAdditionalFoldersAtRoot.

/**
 * Returns as many folders as plugins providing root folders are loaded
 * into memory (need to implement AdditionalFolder(s)AtRoot)
 */
private List<DLNAResource> getAdditionalFoldersAtRoot() {
    List<DLNAResource> res = new ArrayList<>();
    String[] legalPlugs = null;
    String tmp = configuration.getPlugins(tags);
    if (StringUtils.isNotBlank(tmp)) {
        legalPlugs = tmp.split(",");
    }
    for (ExternalListener listener : ExternalFactory.getExternalListeners()) {
        if (illegalPlugin(legalPlugs, listener.name())) {
            LOGGER.debug("plugin " + listener.name() + " is not legal for render");
            continue;
        }
        if (listener instanceof AdditionalFolderAtRoot) {
            AdditionalFolderAtRoot afar = (AdditionalFolderAtRoot) listener;
            try {
                DLNAResource resource = afar.getChild();
                LOGGER.debug("add ext list " + listener);
                if (resource == null) {
                    continue;
                }
                resource.setMasterParent(listener);
                for (DLNAResource r : resource.getChildren()) {
                    r.setMasterParent(listener);
                }
                res.add(resource);
            } catch (Throwable t) {
                LOGGER.error(String.format("Failed to append AdditionalFolderAtRoot with name=%s, class=%s", afar.name(), afar.getClass()), t);
            }
        } else if (listener instanceof AdditionalFoldersAtRoot) {
            Iterator<DLNAResource> folders = ((AdditionalFoldersAtRoot) listener).getChildren();
            while (folders.hasNext()) {
                DLNAResource resource = folders.next();
                resource.setMasterParent(listener);
                for (DLNAResource r : resource.getChildren()) {
                    r.setMasterParent(listener);
                }
                try {
                    res.add(resource);
                } catch (Throwable t) {
                    LOGGER.error(String.format("Failed to append AdditionalFolderAtRoots with class=%s for DLNAResource=%s", listener.getClass(), resource.getClass()), t);
                }
            }
        }
    }
    return res;
}
Also used : AdditionalFoldersAtRoot(net.pms.external.AdditionalFoldersAtRoot) ExternalListener(net.pms.external.ExternalListener) AdditionalFolderAtRoot(net.pms.external.AdditionalFolderAtRoot)

Aggregations

AdditionalFolderAtRoot (net.pms.external.AdditionalFolderAtRoot)1 AdditionalFoldersAtRoot (net.pms.external.AdditionalFoldersAtRoot)1 ExternalListener (net.pms.external.ExternalListener)1