1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.atlassian.theplugin.eclipse.view.popup;
18
19
20
21
22 public class RepositoryTaskHandleUtil {
23
24 public static final String HANDLE_DELIM = "-";
25
26 private static final String MISSING_REPOSITORY = "norepository";
27
28 public static String getHandle(String repositoryUrl, String taskId) {
29 if (!isValidTaskId(taskId)) {
30 throw new RuntimeException("invalid handle for task, can not contain: " + HANDLE_DELIM + ", was: " + taskId);
31 }
32
33 if (repositoryUrl == null) {
34 return MISSING_REPOSITORY + HANDLE_DELIM + taskId;
35 } else {
36 return repositoryUrl + HANDLE_DELIM + taskId;
37 }
38 }
39
40 public static String getRepositoryUrl(String taskHandle) {
41 int index = taskHandle.lastIndexOf(RepositoryTaskHandleUtil.HANDLE_DELIM);
42 String url = null;
43 if (index != -1) {
44 url = taskHandle.substring(0, index);
45 }
46 return url;
47 }
48
49 public static String getTaskId(String taskHandle) {
50 int index = taskHandle.lastIndexOf(HANDLE_DELIM);
51 if (index != -1) {
52 String id = taskHandle.substring(index + 1);
53 return id;
54 }
55 return null;
56 }
57
58 public static boolean isValidTaskId(String taskId) {
59 return !taskId.contains(HANDLE_DELIM);
60 }
61
62 }