001    /**
002     * Copyright 2010-2013 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.common.jdbc.supplier;
017    
018    import org.kuali.common.util.Str;
019    import org.kuali.common.util.nullify.NullUtils;
020    
021    public class LocationSupplierUtils {
022    
023            /**
024             * Returns a location string with any prefix context information removed
025             * 
026             * The expected form of the parameter string is: CONTEXT:LOCATION
027             * 
028             * The return value of this method will return just the LOCATION token
029             * 
030             * @param contextLocation
031             *            the location string with prefixed context information
032             * @return a location string with no context prefix
033             */
034            public static String getLocationFromContextLocation(String contextLocation) {
035                    // return every character after the first colon
036                    return contextLocation.substring(contextLocation.indexOf(Str.COLON) + 1);
037            }
038    
039            /**
040             * Return just the context information prefix of a context location string
041             * 
042             * The expected form of the parameter string is: CONTEXT:LOCATION
043             * 
044             * The return value of this method will return just the CONTEXT string
045             * 
046             * @param contextLocation
047             *            the location string with prefixed context information
048             * @return a context token
049             */
050            public static String getContextFromContextLocation(String contextLocation) {
051                    return Str.split(contextLocation, Str.COLON, true)[0];
052            }
053    
054            /**
055             * Build a "context location" from a context and a location
056             * 
057             * The format of a context location is: CONTEXT:LOCATION
058             * 
059             * If no applicable context information is defined, the CONTEXT token will be set to Constants.NONE
060             * 
061             * @param context
062             *            object containing context information
063             * @param location
064             *            resource location string
065             * @return a formatted context location
066             */
067            public static String getContextLocation(LocationSupplierContext context, String location) {
068                    String contextToken = context.getValue();
069    
070                    if (contextToken == null) {
071                            contextToken = NullUtils.NONE;
072                    }
073    
074                    return Str.getId(contextToken, location);
075            }
076    }