View Javadoc

1   /**
2    * Copyright 2005-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.rice.kim.util;
17  
18  import org.apache.commons.beanutils.PropertyUtils;
19  import org.kuali.rice.kim.api.KimConstants;
20  import org.kuali.rice.krad.service.KRADServiceLocator;
21  
22  /**
23   * This is a description of what this class does - bhargavp don't forget to fill
24   * this in.
25   *
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   *
28   */
29  public final class KimCommonUtilsInternal {
30      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KimCommonUtilsInternal.class);
31  
32  	private KimCommonUtilsInternal() {
33  		throw new UnsupportedOperationException("do not call");
34  	}
35  
36      public static void copyProperties(Object targetToCopyTo, Object sourceToCopyFrom){
37  		if(targetToCopyTo!=null && sourceToCopyFrom!=null)
38  		try{
39  			PropertyUtils.copyProperties(targetToCopyTo, sourceToCopyFrom);
40  		} catch(Exception ex){
41  			throw new RuntimeException("Failed to copy from source object: "+sourceToCopyFrom.getClass()+" to target object: "+targetToCopyTo,ex);
42  		}
43  	}
44  
45  	public static String getKimBasePath(){
46  		String kimBaseUrl = KRADServiceLocator.getKualiConfigurationService().getPropertyValueAsString(
47                  KimConstants.KimUIConstants.KIM_URL_KEY);
48  		if (!kimBaseUrl.endsWith(KimConstants.KimUIConstants.URL_SEPARATOR)) {
49  			kimBaseUrl = kimBaseUrl + KimConstants.KimUIConstants.URL_SEPARATOR;
50  		}
51  		return kimBaseUrl;
52  	}
53  
54  	public static String getPathWithKimContext(String path, String kimActionName){
55  		String kimContext = KimConstants.KimUIConstants.KIM_APPLICATION+KimConstants.KimUIConstants.URL_SEPARATOR;
56  		String kimContextParameterized = KimConstants.KimUIConstants.KIM_APPLICATION+KimConstants.KimUIConstants.PARAMETERIZED_URL_SEPARATOR;
57      	if(path.contains(kimActionName) && !path.contains(kimContext + kimActionName)
58      			&& !path.contains(kimContextParameterized + kimActionName))
59      		path = path.replace(kimActionName, kimContext+kimActionName);
60      	return path;
61  	}
62  }