FileDocCategorySizeDatePackage
Path.javaAPI Docmp4parser 1.0-RC-173894Wed Dec 19 20:10:37 GMT 2012com.googlecode.mp4parser.util

Path

public class Path extends Object

Fields Summary
static Pattern
component
Constructors Summary
private Path()

    
Methods Summary
public static java.lang.StringcreatePath(com.coremedia.iso.boxes.Box box)


         
        return createPath(box, "");
    
private static java.lang.StringcreatePath(com.coremedia.iso.boxes.Box box, java.lang.String path)

        if (box instanceof IsoFile) {
            return path;
        } else {
            List<?> boxesOfBoxType = box.getParent().getBoxes(box.getClass());
            int index = boxesOfBoxType.indexOf(box);
            path = String.format("/%s[%d]", box.getType(), index) + path;

            return createPath(box.getParent(), path);
        }
    
public static com.coremedia.iso.boxes.BoxgetPath(com.coremedia.iso.boxes.Box box, java.lang.String path)

        List<? extends Box> all = getPaths(box, path);
        return all.isEmpty() ? null : all.get(0);
    
public static java.util.ListgetPaths(com.coremedia.iso.boxes.Box box, java.lang.String path)

        if (path.startsWith("/")) {
            Box isoFile = box;
            while (isoFile.getParent() != null) {
                isoFile = isoFile.getParent();
            }
            assert isoFile instanceof IsoFile : isoFile.getType() + " has no parent";
            return getPaths(isoFile, path.substring(1));
        } else if (path.isEmpty()) {
            return Collections.singletonList(box);
        } else {
            String later;
            String now;
            if (path.contains("/")) {
                later = path.substring(path.indexOf('/") + 1);
                now = path.substring(0, path.indexOf('/"));
            } else {
                now = path;
                later = "";
            }

            Matcher m = component.matcher(now);
            if (m.matches()) {
                String type = m.group(1);
                if ("..".equals(type)) {
                    return getPaths(box.getParent(), later);
                } else {
                    int index = -1;
                    if (m.group(2) != null) {
                        // we have a specific index
                        String indexString = m.group(3);
                        index = Integer.parseInt(indexString);
                    }
                    List<Box> children = new LinkedList<Box>();
                    int currentIndex = 0;
                    for (Box box1 : ((ContainerBox) box).getBoxes()) {
                        if (box1.getType().matches(type)) {
                            if (index == -1 || index == currentIndex) {
                                children.addAll(getPaths(box1, later));
                            }
                            currentIndex++;
                        }
                    }
                    return children;
                }
            } else {
                throw new RuntimeException(now + " is invalid path.");
            }
        }

    
public static booleanisContained(com.coremedia.iso.boxes.Box box, java.lang.String path)

        assert path.startsWith("/") : "Absolute path required";
        return getPaths(box, path).contains(box);