summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/utils/ModelUtils.java
blob: 6316dc5d3d153605d60649196062f3787593662a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.gitblit.utils;

import com.gitblit.IStoredSettings;

public class ModelUtils
{
    private static final String DEFAULT_USER_REPO_PREFIX = "~";

    private static String userRepoPrefix = DEFAULT_USER_REPO_PREFIX;



    public static void setUserRepoPrefix(IStoredSettings settings)
    {
        userRepoPrefix = settings.getString("repo.userPrefix", DEFAULT_USER_REPO_PREFIX);
    }


    public static String getUserRepoPrefix()
    {
        return userRepoPrefix;
    }


    public static String getPersonalPath(String username)
    {
        return userRepoPrefix + username.toLowerCase();
    }


    public static boolean isPersonalRepository(String name)
    {
        if ( name.startsWith(getUserRepoPrefix()) ) return true;
        return false;
    }


    public static boolean isUsersPersonalRepository(String username, String name)
    {
        if ( name.equalsIgnoreCase(getPersonalPath(username)) ) return true;
        return false;
    }


    public static String getUserNameFromRepoPath(String path)
    {
        if ( !isPersonalRepository(path) ) return "";
        
        return path.substring(getUserRepoPrefix().length());
    }

}