diff options
author | Florian Zschocke <florian.zschocke@cycos.com> | 2013-07-10 09:14:29 +0200 |
---|---|---|
committer | Florian Zschocke <florian.zschocke@cycos.com> | 2013-08-26 12:30:53 +0200 |
commit | cb946fa57e9dd4ca0853f079331c73dc0331c1e7 (patch) | |
tree | 50c94e40a79dbff7bc0c2e3420bc4d5220f66d70 /src/main/java/com/gitblit/utils/ModelUtils.java | |
parent | 8eaf843d60983d433435ac2a89e1a63b8de02338 (diff) | |
download | gitblit-cb946fa57e9dd4ca0853f079331c73dc0331c1e7.tar.gz gitblit-cb946fa57e9dd4ca0853f079331c73dc0331c1e7.zip |
Refactor logic for user repository path into one class.
Gather logic for building the path/name of a personal user repository into one class.
Diffstat (limited to 'src/main/java/com/gitblit/utils/ModelUtils.java')
-rw-r--r-- | src/main/java/com/gitblit/utils/ModelUtils.java | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/main/java/com/gitblit/utils/ModelUtils.java b/src/main/java/com/gitblit/utils/ModelUtils.java new file mode 100644 index 00000000..6316dc5d --- /dev/null +++ b/src/main/java/com/gitblit/utils/ModelUtils.java @@ -0,0 +1,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()); + } + +} |