1 /* 2 * Copyright 2008 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.ole.sys.web; 17 18 import java.util.regex.Pattern; 19 20 import org.apache.commons.lang.StringUtils; 21 22 /** 23 * A utility class which holds functions that can be used as JSP functions. 24 */ 25 public class WebUtilities { 26 /** 27 * Converts a property name so that it is correct for the purposes of populating a business object 28 * in the maintenance framework - basically by changing "document.oldMaintainableObject.businessObject" to 29 * "document.oldMaintainableObject" and doing a similar operation for "document.newMaintainableObject.businessObject" 30 * @param propertyName the property name to fix 31 * @return the corrected version of the property name 32 */ 33 public static String renamePropertyForMaintenanceFramework(String propertyName) { 34 if (propertyName == null) { 35 return null; 36 } 37 Pattern oldMaintainablePattern = Pattern.compile("^document\\.oldMaintainableObject\\.businessObject\\."); 38 if (oldMaintainablePattern.matcher(propertyName).find()) { 39 return propertyName.replaceFirst("^document\\.oldMaintainableObject\\.businessObject\\.", "document.oldMaintainableObject."); 40 } 41 Pattern newMaintainablePattern = Pattern.compile("^document\\.newMaintainableObject\\.businessObject\\."); 42 if (newMaintainablePattern.matcher(propertyName).find()) { 43 return propertyName.replaceFirst("^document\\.newMaintainableObject\\.businessObject\\.", "document.newMaintainableObject."); 44 } 45 return propertyName; 46 } 47 48 /** 49 * Determines if the given value matches the given pattern 50 * @param value the value which is matching the pattern 51 * @param pattern the Java regular expression pattern to match against 52 * @return true if the value matches; false otherwise 53 * @see java.util.regex.Pattern 54 */ 55 public static boolean matchesPattern(String value, String pattern) { 56 return (StringUtils.isBlank(value)) ? false : value.matches(pattern); 57 } 58 }