View Javadoc
1   /**
2    * Copyright 2010-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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  package org.kuali.common.util.config;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.commons.lang3.StringUtils;
22  import org.springframework.util.Assert;
23  
24  /**
25   * @deprecated
26   */
27  @Deprecated
28  public class ConfigUtils {
29  
30  	public static final String DELIMITER = ":";
31  
32  	public static List<ProjectConfig> getProjectConfigs(List<String> configIds) {
33  		List<ProjectConfig> requests = new ArrayList<ProjectConfig>();
34  		for (String configId : configIds) {
35  			ProjectConfig request = ConfigUtils.getProjectConfig(configId);
36  			requests.add(request);
37  		}
38  		return requests;
39  	}
40  
41  	public static String getConfigId(ProjectConfig config) {
42  		return getConfigId(config.getGroupId(), config.getArtifactId(), config.getContextId());
43  	}
44  
45  	public static String getConfigId(String groupId, String artifactId, String contextId) {
46  		Assert.hasText(groupId, "groupId is blank");
47  		Assert.hasText(artifactId, "artifactId is blank");
48  		StringBuilder sb = new StringBuilder();
49  		sb.append(StringUtils.trimToEmpty(groupId));
50  		sb.append(DELIMITER);
51  		sb.append(StringUtils.trimToEmpty(artifactId));
52  		if (!StringUtils.isBlank(contextId)) {
53  			sb.append(DELIMITER);
54  			sb.append(StringUtils.trimToEmpty(contextId));
55  		}
56  		return sb.toString();
57  	}
58  
59  	public static ProjectConfig getProjectConfig(String configId) {
60  
61  		// Split the id up into tokens
62  		String[] tokens = StringUtils.split(configId, DELIMITER);
63  
64  		// A config id with less than 2 tokens is invalid
65  		// In other words, groupId + artifactId are required
66  		Assert.isTrue(tokens.length > 1, "2 tokens are required");
67  
68  		// Extract each portion into an explicit variable
69  		String groupId = tokens[0];
70  		String artifactId = tokens[1];
71  		String contextId = getContextId(tokens);
72  
73  		// Store the variable inside an object
74  		DefaultProjectConfig config = new DefaultProjectConfig();
75  		config.setGroupId(groupId);
76  		config.setArtifactId(artifactId);
77  		config.setContextId(contextId);
78  		return config;
79  	}
80  
81  	protected static String getContextId(String[] tokens) {
82  		if (tokens.length < 3) {
83  			return null;
84  		}
85  		StringBuilder sb = new StringBuilder();
86  		for (int i = 2; i < tokens.length; i++) {
87  			if (i != 2) {
88  				sb.append(DELIMITER);
89  			}
90  			sb.append(tokens[i]);
91  		}
92  		return sb.toString();
93  	}
94  
95  }