| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kns.util; |
| 17 | |
|
| 18 | |
import java.lang.reflect.Constructor; |
| 19 | |
import java.text.NumberFormat; |
| 20 | |
import java.util.ArrayList; |
| 21 | |
import java.util.List; |
| 22 | |
|
| 23 | |
import org.apache.commons.lang.StringUtils; |
| 24 | |
import org.kuali.rice.core.util.type.KualiDecimal; |
| 25 | |
import org.kuali.rice.core.xml.dto.AttributeSet; |
| 26 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
| 27 | |
import org.kuali.rice.kns.service.KualiModuleService; |
| 28 | |
import org.kuali.rice.kns.service.ModuleService; |
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
public final class KNSUtils { |
| 40 | |
private static KualiModuleService kualiModuleService; |
| 41 | |
|
| 42 | 0 | private KNSUtils() { |
| 43 | 0 | throw new UnsupportedOperationException("do not call"); |
| 44 | |
} |
| 45 | |
|
| 46 | |
public final static String getBusinessTitleForClass(Class<? extends Object> clazz) { |
| 47 | 0 | if (clazz == null) { |
| 48 | 0 | throw new IllegalArgumentException("The getBusinessTitleForClass method of KNSUtils requires a non-null class"); |
| 49 | |
} |
| 50 | 0 | String className = clazz.getSimpleName(); |
| 51 | |
|
| 52 | 0 | StringBuffer label = new StringBuffer(className.substring(0, 1)); |
| 53 | 0 | for (int i = 1; i < className.length(); i++) { |
| 54 | 0 | if (Character.isLowerCase(className.charAt(i))) { |
| 55 | 0 | label.append(className.charAt(i)); |
| 56 | |
} else { |
| 57 | 0 | label.append(" ").append(className.charAt(i)); |
| 58 | |
} |
| 59 | |
} |
| 60 | 0 | return label.toString().trim(); |
| 61 | |
} |
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
public final static List<String> getFileNameFromPath(List<String> fullFileNames) { |
| 67 | 0 | List<String> fileNameList = new ArrayList<String>(); |
| 68 | |
|
| 69 | 0 | for (String fullFileName : fullFileNames) { |
| 70 | 0 | if (StringUtils.contains(fullFileName, "/")) { |
| 71 | 0 | fileNameList.add(StringUtils.substringAfterLast(fullFileName, "/")); |
| 72 | |
} |
| 73 | |
else { |
| 74 | 0 | fileNameList.add(StringUtils.substringAfterLast(fullFileName, "\\")); |
| 75 | |
} |
| 76 | |
} |
| 77 | |
|
| 78 | 0 | return fileNameList; |
| 79 | |
} |
| 80 | |
|
| 81 | 0 | private static final KualiDecimal ONE_HUNDRED = new KualiDecimal("100.00"); |
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
public final static String convertDecimalIntoInteger(KualiDecimal decimalNumber) { |
| 89 | 0 | KualiDecimal decimalAmount = decimalNumber.multiply(ONE_HUNDRED); |
| 90 | 0 | NumberFormat formatter = NumberFormat.getIntegerInstance(); |
| 91 | 0 | String formattedAmount = formatter.format(decimalAmount); |
| 92 | |
|
| 93 | 0 | return StringUtils.replace(formattedAmount, ",", ""); |
| 94 | |
} |
| 95 | |
|
| 96 | |
public static Integer getIntegerValue(String numberStr){ |
| 97 | 0 | Integer numberInt = null; |
| 98 | |
try{ |
| 99 | 0 | numberInt = new Integer(numberStr); |
| 100 | 0 | } catch(NumberFormatException nfe){ |
| 101 | 0 | Double numberDbl = new Double(numberStr); |
| 102 | 0 | numberInt = new Integer(numberDbl.intValue()); |
| 103 | 0 | } |
| 104 | 0 | return numberInt; |
| 105 | |
} |
| 106 | |
|
| 107 | |
public static Object createObject(Class<?> clazz, Class<?>[] argumentClasses, Object[] argumentValues) { |
| 108 | 0 | if(clazz==null) |
| 109 | 0 | return null; |
| 110 | |
try { |
| 111 | 0 | Constructor<?> constructor = clazz.getConstructor(argumentClasses); |
| 112 | 0 | return constructor.newInstance(argumentValues); |
| 113 | 0 | } catch (Exception e) { |
| 114 | 0 | return null; |
| 115 | |
} |
| 116 | |
} |
| 117 | |
|
| 118 | |
public static String joinWithQuotes(List<String> list){ |
| 119 | 0 | if(list==null || list.size()==0) return ""; |
| 120 | |
|
| 121 | 0 | return KNSConstants.SINGLE_QUOTE+ |
| 122 | |
StringUtils.join(list.iterator(), KNSConstants.SINGLE_QUOTE+","+KNSConstants.SINGLE_QUOTE)+ |
| 123 | |
KNSConstants.SINGLE_QUOTE; |
| 124 | |
} |
| 125 | |
|
| 126 | |
private static KualiModuleService getKualiModuleService() { |
| 127 | 0 | if (kualiModuleService == null) { |
| 128 | 0 | kualiModuleService = KNSServiceLocatorWeb.getKualiModuleService(); |
| 129 | |
} |
| 130 | 0 | return kualiModuleService; |
| 131 | |
} |
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
public static String getNamespaceCode(Class<? extends Object> clazz) { |
| 140 | 0 | ModuleService moduleService = getKualiModuleService().getResponsibleModuleService(clazz); |
| 141 | 0 | if (moduleService == null) { |
| 142 | 0 | return KNSConstants.DEFAULT_NAMESPACE; |
| 143 | |
} |
| 144 | 0 | return moduleService.getModuleConfiguration().getNamespaceCode(); |
| 145 | |
} |
| 146 | |
|
| 147 | |
public static AttributeSet getNamespaceAndComponentSimpleName( Class<? extends Object> clazz) { |
| 148 | 0 | AttributeSet attributeSet = new AttributeSet(); |
| 149 | 0 | attributeSet.put(KNSConstants.NAMESPACE_CODE, getNamespaceCode(clazz)); |
| 150 | 0 | attributeSet.put(KNSConstants.COMPONENT_NAME, getComponentSimpleName(clazz)); |
| 151 | 0 | return attributeSet; |
| 152 | |
} |
| 153 | |
|
| 154 | |
public static AttributeSet getNamespaceAndComponentFullName( Class<? extends Object> clazz) { |
| 155 | 0 | AttributeSet attributeSet = new AttributeSet(); |
| 156 | 0 | attributeSet.put(KNSConstants.NAMESPACE_CODE, getNamespaceCode(clazz)); |
| 157 | 0 | attributeSet.put(KNSConstants.COMPONENT_NAME, getComponentFullName(clazz)); |
| 158 | 0 | return attributeSet; |
| 159 | |
} |
| 160 | |
|
| 161 | |
public static AttributeSet getNamespaceAndActionClass( Class<? extends Object> clazz) { |
| 162 | 0 | AttributeSet attributeSet = new AttributeSet(); |
| 163 | 0 | attributeSet.put(KNSConstants.NAMESPACE_CODE, getNamespaceCode(clazz)); |
| 164 | 0 | attributeSet.put(KNSConstants.ACTION_CLASS, clazz.getName()); |
| 165 | 0 | return attributeSet; |
| 166 | |
} |
| 167 | |
|
| 168 | |
private static String getComponentSimpleName(Class<? extends Object> clazz) { |
| 169 | 0 | return clazz.getSimpleName(); |
| 170 | |
} |
| 171 | |
|
| 172 | |
private static String getComponentFullName(Class<? extends Object> clazz) { |
| 173 | 0 | return clazz.getName(); |
| 174 | |
} |
| 175 | |
} |