Java Code Examples for org.tigris.subversion.svnclientadapter.SVNUrl#getPathSegments()

The following examples show how to use org.tigris.subversion.svnclientadapter.SVNUrl#getPathSegments() . 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: RepositoryFile.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public RepositoryFile(SVNUrl repositoryUrl, SVNUrl fileUrl, SVNRevision revision) {       
    this(repositoryUrl, revision);
    this.fileUrl = fileUrl;        
    repositoryRoot = fileUrl == null;   
    
    if(!repositoryRoot) {            
        String[] fileUrlSegments = fileUrl.getPathSegments();
        int fileSegmentsLength = fileUrlSegments.length;
        int repositorySegmentsLength = repositoryUrl.getPathSegments().length;
        pathSegments = new String[fileSegmentsLength - repositorySegmentsLength];
        StringBuffer sb = new StringBuffer();
        for (int i = repositorySegmentsLength; i < fileSegmentsLength; i++) {
            pathSegments[i-repositorySegmentsLength] = fileUrlSegments[i];
            sb.append(fileUrlSegments[i]);
            if(i-repositorySegmentsLength < pathSegments.length-1) {
                sb.append("/"); // NOI18N
            }
        }    
        path = sb.toString();
    }                
}
 
Example 2
Source File: SVNUrlUtils.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * get the common root url for given urls
 * @param url1
 * @param url2
 * @return the common root url for given urls
 */
public static SVNUrl getCommonRootUrl(SVNUrl url1, SVNUrl url2) {
    if ( (!url1.getProtocol().equals(url2.getProtocol())) ||
         (!url1.getHost().equals(url2.getHost())) ||
         (url1.getPort() != url2.getPort()) ) {
        return null;
    }
    String url = url1.getProtocol()+"://"+url1.getHost()+":"+url1.getPort(); 
    String[] segs1 = url1.getPathSegments();
    String[] segs2 = url2.getPathSegments();
    int minLength = segs1.length >= segs2.length ? segs2.length : segs1.length;
    for (int i = 0; i < minLength; i++) {
        if (!segs1[i].equals(segs2[i])) {
            break;
        }
        url+="/"+segs1[i];
    }
    try {
        return new SVNUrl(url);
    } catch (MalformedURLException e) {
        return null;
    }
}
 
Example 3
Source File: SvnCommand.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private String makeCliUrlString(SVNUrl url, boolean appendAtSign) {
    String cliUrlString = encodeUrl(url).toString();
    if (appendAtSign) {
        for (String pathSegment : url.getPathSegments()) {
            if (pathSegment.indexOf('@') != -1) {
                cliUrlString += '@';
                break;
            }
        }
    }
    return cliUrlString;
}
 
Example 4
Source File: RepositoryConnection.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void parseUrlString(String urlString) throws MalformedURLException {
    int idx = urlString.lastIndexOf('@');
    int hostIdx = urlString.indexOf("://");                         // NOI18N
    int firstSlashIdx = urlString.indexOf("/", hostIdx + 3);        // NOI18N
    if (urlString.contains("\\")) {
        throw new MalformedURLException(NbBundle.getMessage(Repository.class, "MSG_Repository_InvalidSvnUrl", urlString)); //NOI18N
    }
    if(idx < 0 || firstSlashIdx < 0 || idx < firstSlashIdx) {
        svnRevision = SVNRevision.HEAD;
    } else /*if (acceptRevision)*/ {
        if( idx + 1 < urlString.length()) {
            String revisionString = "";                             // NOI18N
            try {
                revisionString = urlString.substring(idx + 1);
                svnRevision = SvnUtils.getSVNRevision(revisionString);
            } catch (NumberFormatException ex) {
                throw new MalformedURLException(NbBundle.getMessage(Repository.class, "MSG_Repository_WrongRevision", revisionString));     // NOI18N
            }
        } else {
            svnRevision = SVNRevision.HEAD;
        }
        urlString = urlString.substring(0, idx);
    }
    SVNUrl normalizedUrl = removeEmptyPathSegments(new SVNUrl(urlString));
    if ("file".equals(normalizedUrl.getProtocol()) && normalizedUrl.getHost() != null //NOI18N
            && normalizedUrl.getPathSegments().length == 0) {
        throw new MalformedURLException(NbBundle.getMessage(Repository.class, "MSG_Repository_InvalidSvnUrl", SvnUtils.decodeToString(normalizedUrl))); //NOI18N
    }
    svnUrl = normalizedUrl;
}
 
Example 5
Source File: RepositoryConnection.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private SVNUrl removeEmptyPathSegments(SVNUrl url) throws MalformedURLException {
    String[] pathSegments = url.getPathSegments();
    StringBuffer urlString = new StringBuffer();
    urlString.append(url.getProtocol());
    urlString.append("://");                                                // NOI18N
    urlString.append(ripUserFromHost(url.getHost()));
    if(url.getPort() > 0) {
        urlString.append(":");                                              // NOI18N
        urlString.append(url.getPort());
    }
    boolean gotSegments = false;
    for (int i = 0; i < pathSegments.length; i++) {
        if(!pathSegments[i].trim().equals("")) {                            // NOI18N
            gotSegments = true;
            urlString.append("/");                                          // NOI18N
            urlString.append(pathSegments[i]);                
        }
    }
    try {
        if(gotSegments) {
            return new SVNUrl(urlString.toString());
        } else {
            return url;
        }
    } catch (MalformedURLException ex) {
        throw ex;
    }
}
 
Example 6
Source File: RemoteAnnotationStorage.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public IPath getFullPath() {
	ISVNRepositoryLocation location = file.getRepository();
	SVNUrl repositoryUrl = location.getRepositoryRoot();
	String[] segments = repositoryUrl.getPathSegments();
	
	IPath path = new Path(null, "/");
	for (int i = 0; i < segments.length; i++) {
		path = path.append(segments[i]);
	}
	
	path = path.setDevice(repositoryUrl.getHost() + IPath.DEVICE_SEPARATOR);
	path = path.append(file.getRepositoryRelativePath());
	return path;
}