Java Code Examples for org.red5.server.api.scope.IScope#getParent()

The following examples show how to use org.red5.server.api.scope.IScope#getParent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScopeUtils.java    From red5-server-common with Apache License 2.0 5 votes vote down vote up
/**
 * Resolves scope for specified scope and path.
 *
 * @param from
 *            Scope to use as context (to start from)
 * @param path
 *            Path to resolve
 * @return Resolved scope
 */
public static IScope resolveScope(IScope from, String path) {
    log.debug("resolveScope from: {} path: {}", from.getName(), path);
    IScope current = from;
    if (path.startsWith(SLASH)) {
        current = ScopeUtils.findRoot(current);
        path = path.substring(1, path.length());
    }
    if (path.endsWith(SLASH)) {
        path = path.substring(0, path.length() - 1);
    }
    log.trace("Current: {}", current);
    String[] parts = path.split(SLASH);
    if (log.isTraceEnabled()) {
        log.trace("Parts: {}", Arrays.toString(parts));
    }
    for (String part : parts) {
        log.trace("Part: {}", part);
        if (part.equals(".")) {
            continue;
        }
        if (part.equals("..")) {
            if (!current.hasParent()) {
                return null;
            }
            current = current.getParent();
            continue;
        }
        if (!current.hasChildScope(part)) {
            return null;
        }
        current = current.getScope(part);
        log.trace("Current: {}", current);
    }
    return current;
}
 
Example 2
Source File: ScopeUtils.java    From red5-server-common with Apache License 2.0 5 votes vote down vote up
/**
 * Finds root scope for specified scope object. Root scope is the top level scope among scope's parents.
 *
 * @param from
 *            Scope to find root for
 * @return Root scope object
 */
public static IScope findRoot(IScope from) {
    IScope current = from;
    while (current.hasParent()) {
        current = current.getParent();
    }
    return current;
}
 
Example 3
Source File: DefaultStreamFilenameGenerator.java    From red5-server-common with Apache License 2.0 4 votes vote down vote up
/**
 * Generate stream directory based on relative scope path. The base directory is
 * 
 * <pre>
 * streams
 * </pre>
 * 
 * , e.g. a scope
 * 
 * <pre>
 * /application/one/two/
 * </pre>
 * 
 * will generate a directory
 * 
 * <pre>
 * /streams/one/two/
 * </pre>
 * 
 * inside the application.
 * 
 * @param scope
 *            Scope
 * @return Directory based on relative scope path
 */
private String getStreamDirectory(IScope scope) {
    final StringBuilder result = new StringBuilder();
    final IScope app = ScopeUtils.findApplication(scope);
    final String prefix = "streams/";
    while (scope != null && scope != app) {
        result.insert(0, scope.getName() + "/");
        scope = scope.getParent();
    }
    if (result.length() == 0) {
        return prefix;
    } else {
        result.insert(0, prefix).append('/');
        return result.toString();
    }
}
 
Example 4
Source File: ScopeUtils.java    From red5-server-common with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the application scope for specified scope. Application scope has depth of 1 and has no parent.
 *
 * See
 * 
 * <pre>
 * isApp
 * </pre>
 * 
 * method for details.
 *
 * @param from
 *            Scope to find application for
 * @return Application scope.
 */
public static IScope findApplication(IScope from) {
    IScope current = from;
    while (current.hasParent() && !current.getType().equals(ScopeType.APPLICATION)) {
        current = current.getParent();
    }
    return current;
}