001 /* 002 * Copyright 2011 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.kfs.sys.web; 017 018 import java.util.regex.Pattern; 019 020 import org.apache.commons.lang.StringUtils; 021 022 /** 023 * A utility class which holds functions that can be used as JSP functions. 024 */ 025 public class WebUtilities { 026 /** 027 * Converts a property name so that it is correct for the purposes of populating a business object 028 * in the maintenance framework - basically by changing "document.oldMaintainableObject.businessObject" to 029 * "document.oldMaintainableObject" and doing a similar operation for "document.newMaintainableObject.businessObject" 030 * @param propertyName the property name to fix 031 * @return the corrected version of the property name 032 */ 033 public static String renamePropertyForMaintenanceFramework(String propertyName) { 034 if (propertyName == null) { 035 return null; 036 } 037 Pattern oldMaintainablePattern = Pattern.compile("^document\\.oldMaintainableObject\\.businessObject\\."); 038 if (oldMaintainablePattern.matcher(propertyName).find()) { 039 return propertyName.replaceFirst("^document\\.oldMaintainableObject\\.businessObject\\.", "document.oldMaintainableObject."); 040 } 041 Pattern newMaintainablePattern = Pattern.compile("^document\\.newMaintainableObject\\.businessObject\\."); 042 if (newMaintainablePattern.matcher(propertyName).find()) { 043 return propertyName.replaceFirst("^document\\.newMaintainableObject\\.businessObject\\.", "document.newMaintainableObject."); 044 } 045 return propertyName; 046 } 047 048 /** 049 * Determines if the given value matches the given pattern 050 * @param value the value which is matching the pattern 051 * @param pattern the Java regular expression pattern to match against 052 * @return true if the value matches; false otherwise 053 * @see java.util.regex.Pattern 054 */ 055 public static boolean matchesPattern(String value, String pattern) { 056 return (StringUtils.isBlank(value)) ? false : value.matches(pattern); 057 } 058 }