View Javadoc

1   /**
2    * Copyright (C) 2008 Atlassian
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.atlassian.theplugin.eclipse.view.popup;
18  
19  /**
20   * @author Mik Kersten
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  }