All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.day.jcr.vault.util.PathUtil Maven / Gradle / Ivy

/*************************************************************************
 *
 * ADOBE CONFIDENTIAL
 * __________________
 *
 *  Copyright 2011 Adobe Systems Incorporated
 *  All Rights Reserved.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Adobe Systems Incorporated and its suppliers,
 * if any.  The intellectual and technical concepts contained
 * herein are proprietary to Adobe Systems Incorporated and its
 * suppliers and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Adobe Systems Incorporated.
 *
 **************************************************************************/

package com.day.jcr.vault.util;

import java.io.File;

import javax.jcr.Node;
import javax.jcr.RepositoryException;

/**
 * PathUtil...
 *
 */
public class PathUtil {

    /**
     * make a canonical path. removes all /./ and /../ and multiple slashes.
     * @param parent the parent path (can be null)
     * @param path the path to resolve
     * @return the canonicalized path
     */
    public static String[] makePath(String[] parent, String path) {
        if (path == null || path.equals("") || path.equals(".")) {
            return parent;
        }
        // compose parent and path
        boolean isAbsolute = false;
        String[] composed = Text.explode(path, '/');
        if (path.charAt(0) == '/') {
            isAbsolute = true;
        } else {
            if (parent != null && parent.length > 0) {
                int off = 0;
                if (parent[0].equals("/")) {
                    isAbsolute = true;
                    off = 1;
                }
                String[] c = new String[parent.length - off + composed.length];
                System.arraycopy(parent, off, c, 0, parent.length - off);
                System.arraycopy(composed, 0, c, parent.length - off, composed.length);
                composed = c;
            }
        }
        // canonicalize
        int dst = 0;
        boolean startsWithParent = false;
        for (int i=0; i 0 && ret.charAt(ret.length()-1) != '/') {
            ret.append('/');
        }
        ret.append(relPath);
        return ret.toString();
    }
    
    public static int getDepth(String path) {
        // assume valid absolute path
        int len = path.length();
        if (len <=1) {
            return 0;
        }
        int depth = 1;
        for (int i=1; i 0) {
            if (path.endsWith("/")) {
                path += relPath;
            } else {
                path += "/" + relPath;
            }
        }
        return path;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy