1 /**
2 * Copyright 2010-2013 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.jdbc.supplier;
17
18 import org.kuali.common.util.Str;
19 import org.kuali.common.util.nullify.NullUtils;
20
21 public class LocationSupplierUtils {
22
23 /**
24 * Returns a location string with any prefix context information removed
25 *
26 * The expected form of the parameter string is: CONTEXT:LOCATION
27 *
28 * The return value of this method will return just the LOCATION token
29 *
30 * @param contextLocation
31 * the location string with prefixed context information
32 * @return a location string with no context prefix
33 */
34 public static String getLocationFromContextLocation(String contextLocation) {
35 // return every character after the first colon
36 return contextLocation.substring(contextLocation.indexOf(Str.COLON) + 1);
37 }
38
39 /**
40 * Return just the context information prefix of a context location string
41 *
42 * The expected form of the parameter string is: CONTEXT:LOCATION
43 *
44 * The return value of this method will return just the CONTEXT string
45 *
46 * @param contextLocation
47 * the location string with prefixed context information
48 * @return a context token
49 */
50 public static String getContextFromContextLocation(String contextLocation) {
51 return Str.split(contextLocation, Str.COLON, true)[0];
52 }
53
54 /**
55 * Build a "context location" from a context and a location
56 *
57 * The format of a context location is: CONTEXT:LOCATION
58 *
59 * If no applicable context information is defined, the CONTEXT token will be set to Constants.NONE
60 *
61 * @param context
62 * object containing context information
63 * @param location
64 * resource location string
65 * @return a formatted context location
66 */
67 public static String getContextLocation(LocationSupplierContext context, String location) {
68 String contextToken = context.getValue();
69
70 if (contextToken == null) {
71 contextToken = NullUtils.NONE;
72 }
73
74 return Str.getId(contextToken, location);
75 }
76 }