From cb946fa57e9dd4ca0853f079331c73dc0331c1e7 Mon Sep 17 00:00:00 2001 From: Florian Zschocke Date: Wed, 10 Jul 2013 09:14:29 +0200 Subject: Refactor logic for user repository path into one class. Gather logic for building the path/name of a personal user repository into one class. --- src/main/java/com/gitblit/utils/ModelUtils.java | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/main/java/com/gitblit/utils/ModelUtils.java (limited to 'src/main/java/com/gitblit/utils/ModelUtils.java') 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()); + } + +} -- cgit v1.2.3