1 12 package org.displaytag.properties; 13 14 import java.io.IOException ; 15 import java.util.Enumeration ; 16 import java.util.HashMap ; 17 import java.util.Locale ; 18 import java.util.Map ; 19 import java.util.MissingResourceException ; 20 import java.util.Properties ; 21 import java.util.ResourceBundle ; 22 23 import javax.servlet.http.HttpServletRequest ; 24 import javax.servlet.jsp.PageContext ; 25 import javax.servlet.jsp.tagext.Tag ; 26 27 import org.apache.commons.lang.ClassUtils; 28 import org.apache.commons.lang.StringUtils; 29 import org.apache.commons.lang.UnhandledException; 30 import org.apache.commons.logging.Log; 31 import org.apache.commons.logging.LogFactory; 32 import org.displaytag.Messages; 33 import org.displaytag.decorator.DecoratorFactory; 34 import org.displaytag.decorator.DefaultDecoratorFactory; 35 import org.displaytag.exception.FactoryInstantiationException; 36 import org.displaytag.exception.TablePropertiesLoadException; 37 import org.displaytag.localization.I18nResourceProvider; 38 import org.displaytag.localization.LocaleResolver; 39 import org.displaytag.util.DefaultRequestHelperFactory; 40 import org.displaytag.util.ReflectHelper; 41 import org.displaytag.util.RequestHelperFactory; 42 43 44 59 public final class TableProperties implements Cloneable 60 { 61 62 65 public static final String DEFAULT_FILENAME = "displaytag.properties"; 67 71 public static final String LOCAL_PROPERTIES = "displaytag"; 73 76 public static final String PROPERTY_STRING_EXPORTBANNER = "export.banner"; 78 81 public static final String PROPERTY_STRING_EXPORTBANNER_SEPARATOR = "export.banner.sepchar"; 83 86 public static final String PROPERTY_BOOLEAN_EXPORTDECORATED = "export.decorated"; 88 91 public static final String PROPERTY_STRING_EXPORTAMOUNT = "export.amount"; 93 96 public static final String PROPERTY_STRING_SORTAMOUNT = "sort.amount"; 98 101 public static final String PROPERTY_BOOLEAN_SHOWHEADER = "basic.show.header"; 103 106 public static final String PROPERTY_STRING_EMPTYLIST_MESSAGE = "basic.msg.empty_list"; 108 111 public static final String PROPERTY_STRING_EMPTYLISTROW_MESSAGE = "basic.msg.empty_list_row"; 113 116 public static final String PROPERTY_BOOLEAN_EMPTYLIST_SHOWTABLE = "basic.empty.showtable"; 118 121 public static final String PROPERTY_STRING_BANNER_PLACEMENT = "paging.banner.placement"; 123 126 public static final String PROPERTY_STRING_PAGING_INVALIDPAGE = "error.msg.invalid_page"; 128 131 public static final String PROPERTY_STRING_PAGING_ITEM_NAME = "paging.banner.item_name"; 133 136 public static final String PROPERTY_STRING_PAGING_ITEMS_NAME = "paging.banner.items_name"; 138 141 public static final String PROPERTY_STRING_PAGING_NOITEMS = "paging.banner.no_items_found"; 143 146 public static final String PROPERTY_STRING_PAGING_FOUND_ONEITEM = "paging.banner.one_item_found"; 148 151 public static final String PROPERTY_STRING_PAGING_FOUND_ALLITEMS = "paging.banner.all_items_found"; 153 156 public static final String PROPERTY_STRING_PAGING_FOUND_SOMEITEMS = "paging.banner.some_items_found"; 158 161 public static final String PROPERTY_INT_PAGING_GROUPSIZE = "paging.banner.group_size"; 163 166 public static final String PROPERTY_STRING_PAGING_BANNER_ONEPAGE = "paging.banner.onepage"; 168 171 public static final String PROPERTY_STRING_PAGING_BANNER_FIRST = "paging.banner.first"; 173 176 public static final String PROPERTY_STRING_PAGING_BANNER_LAST = "paging.banner.last"; 178 181 public static final String PROPERTY_STRING_PAGING_BANNER_FULL = "paging.banner.full"; 183 186 public static final String PROPERTY_STRING_PAGING_PAGE_LINK = "paging.banner.page.link"; 188 191 public static final String PROPERTY_STRING_PAGING_PAGE_SELECTED = "paging.banner.page.selected"; 193 196 public static final String PROPERTY_STRING_PAGING_PAGE_SPARATOR = "paging.banner.page.separator"; 198 201 public static final String PROPERTY_CLASS_REQUESTHELPERFACTORY = "factory.requestHelper"; 203 206 public static final String PROPERTY_CLASS_DECORATORFACTORY = "factory.decorator"; 208 211 public static final String PROPERTY_CLASS_LOCALEPROVIDER = "locale.provider"; 213 216 public static final String PROPERTY_CLASS_LOCALERESOLVER = "locale.resolver"; 218 222 public static final String PROPERTY_CSS_TR_EVEN = "css.tr.even"; 224 227 public static final String PROPERTY_CSS_TR_ODD = "css.tr.odd"; 229 233 public static final String PROPERTY_CSS_TABLE = "css.table"; 235 239 public static final String PROPERTY_CSS_TH_SORTABLE = "css.th.sortable"; 241 245 public static final String PROPERTY_CSS_TH_SORTED = "css.th.sorted"; 247 251 public static final String PROPERTY_CSS_TH_SORTED_ASCENDING = "css.th.ascending"; 253 257 public static final String PROPERTY_CSS_TH_SORTED_DESCENDING = "css.th.descending"; 259 263 public static final String PROPERTY_EXPORT_PREFIX = "export"; 265 269 public static final String PROPERTY_EXPORT_DECORATOR_SUFFIX = "decorator"; 271 274 public static final String PROPERTY_EXPORTTYPES = "export.types"; 276 279 public static final String EXPORTPROPERTY_STRING_LABEL = "label"; 281 284 public static final String EXPORTPROPERTY_STRING_CLASS = "class"; 286 289 public static final String EXPORTPROPERTY_BOOLEAN_EXPORTHEADER = "include_header"; 291 294 public static final String EXPORTPROPERTY_STRING_FILENAME = "filename"; 296 300 public static final String PROPERTY_STRING_PAGINATION_SORT_PARAM = "pagination.sort.param"; 302 306 public static final String PROPERTY_STRING_PAGINATION_SORT_DIRECTION_PARAM = "pagination.sortdirection.param"; 308 312 public static final String PROPERTY_STRING_PAGINATION_PAGE_NUMBER_PARAM = "pagination.pagenumber.param"; 314 318 public static final String PROPERTY_STRING_PAGINATION_SEARCH_ID_PARAM = "pagination.searchid.param"; 320 324 public static final String PROPERTY_STRING_PAGINATION_ASC_VALUE = "pagination.sort.asc.value"; 326 330 public static final String PROPERTY_STRING_PAGINATION_DESC_VALUE = "pagination.sort.desc.value"; 332 338 public static final String PROPERTY_BOOLEAN_PAGINATION_SKIP_PAGE_NUMBER_IN_SORT = "pagination.sort.skippagenumber"; 340 342 345 private static final char SEP = '.'; 346 347 350 private static Log log = LogFactory.getLog(TableProperties.class); 351 352 356 private static Properties userProperties = new Properties (); 357 358 362 private static I18nResourceProvider resourceProvider; 363 364 367 private static LocaleResolver localeResolver; 368 369 372 private static Map prototypes = new HashMap (); 373 374 377 private Properties properties; 378 379 382 private Locale locale; 383 384 387 private Map objectCache = new HashMap (); 388 389 394 protected static void setResourceProvider(I18nResourceProvider provider) 395 { 396 resourceProvider = provider; 397 } 398 399 404 protected static void setLocaleResolver(LocaleResolver resolver) 405 { 406 localeResolver = resolver; 407 } 408 409 414 private static Properties loadBuiltInProperties() throws TablePropertiesLoadException 415 { 416 Properties defaultProperties = new Properties (); 417 418 try 419 { 420 defaultProperties.load(TableProperties.class.getResourceAsStream(DEFAULT_FILENAME)); 421 } 422 catch (IOException e) 423 { 424 throw new TablePropertiesLoadException(TableProperties.class, DEFAULT_FILENAME, e); 425 } 426 427 return defaultProperties; 428 } 429 430 436 private static ResourceBundle loadUserProperties(Locale locale) 437 { 438 ResourceBundle bundle = null; 439 try 440 { 441 bundle = ResourceBundle.getBundle(LOCAL_PROPERTIES, locale); 442 } 443 catch (MissingResourceException e) 444 { 445 try 447 { 448 bundle = ResourceBundle.getBundle(LOCAL_PROPERTIES, locale, Thread 449 .currentThread() 450 .getContextClassLoader()); 451 } 452 catch (MissingResourceException mre) 453 { 454 if (log.isDebugEnabled()) 455 { 456 log.debug(Messages.getString("TableProperties.propertiesnotfound", new Object []{mre.getMessage()})); 458 } 459 } 460 } 461 462 return bundle; 463 } 464 465 470 public static LocaleResolver getLocaleResolverInstance() throws TablePropertiesLoadException 471 { 472 473 if (localeResolver == null) 474 { 475 476 String className = null; 478 479 ResourceBundle defaultUserProperties = loadUserProperties(Locale.getDefault()); 480 481 if (defaultUserProperties != null) 483 { 484 try 485 { 486 className = defaultUserProperties.getString(PROPERTY_CLASS_LOCALERESOLVER); 487 } 488 catch (MissingResourceException e) 489 { 490 } 492 } 493 494 if (className == null) 496 { 497 Properties defaults = loadBuiltInProperties(); 498 className = defaults.getProperty(PROPERTY_CLASS_LOCALERESOLVER); 499 } 500 501 if (className != null) 502 { 503 try 504 { 505 Class classProperty = ReflectHelper.classForName(className); 506 localeResolver = (LocaleResolver) classProperty.newInstance(); 507 508 log.info(Messages.getString("TableProperties.classinitializedto", new Object []{ClassUtils.getShortClassName(LocaleResolver.class), className})); 510 } 511 catch (Throwable e) 512 { 513 log.warn(Messages.getString("TableProperties.errorloading", new Object []{ 515 ClassUtils.getShortClassName(LocaleResolver.class), 516 e.getClass().getName(), 517 e.getMessage()})); 518 } 519 } 520 else 521 { 522 log.info(Messages.getString("TableProperties.noconfigured", new Object []{ClassUtils.getShortClassName(LocaleResolver.class)})); 524 } 525 526 if (localeResolver == null) 528 { 529 localeResolver = new LocaleResolver() 531 { 532 533 public Locale resolveLocale(HttpServletRequest request) 534 { 535 return request.getLocale(); 536 } 537 }; 538 } 539 } 540 541 return localeResolver; 542 } 543 544 550 private TableProperties(Locale myLocale) throws TablePropertiesLoadException 551 { 552 this.locale = myLocale; 553 Properties defaultProperties = loadBuiltInProperties(); 555 556 properties = new Properties (defaultProperties); 557 addProperties(myLocale); 558 559 Enumeration keys = userProperties.keys(); 562 while (keys.hasMoreElements()) 563 { 564 String key = (String ) keys.nextElement(); 565 if (key != null) 566 { 567 properties.setProperty(key, (String ) userProperties.get(key)); 568 } 569 } 570 } 571 572 577 private void addProperties(Locale userLocale) 578 { 579 ResourceBundle bundle = loadUserProperties(userLocale); 580 581 if (bundle != null) 582 { 583 Enumeration keys = bundle.getKeys(); 584 while (keys.hasMoreElements()) 585 { 586 String key = (String ) keys.nextElement(); 587 properties.setProperty(key, bundle.getString(key)); 588 } 589 } 590 } 591 592 596 protected Object clone() 597 { 598 TableProperties twin; 599 try 600 { 601 twin = (TableProperties) super.clone(); 602 } 603 catch (CloneNotSupportedException e) 604 { 605 throw new UnhandledException(e); 607 } 608 twin.properties = (Properties ) this.properties.clone(); 609 return twin; 610 } 611 612 617 public static TableProperties getInstance(HttpServletRequest request) 618 { 619 Locale locale; 620 if (request != null) 621 { 622 locale = getLocaleResolverInstance().resolveLocale(request); 623 } 624 else 625 { 626 locale = Locale.getDefault(); 628 } 629 630 TableProperties props = (TableProperties) prototypes.get(locale); 631 if (props == null) 632 { 633 TableProperties lprops = new TableProperties(locale); 634 prototypes.put(locale, lprops); 635 props = lprops; 636 } 637 return (TableProperties) props.clone(); 638 } 639 640 644 public static void clearProperties() 645 { 646 prototypes.clear(); 647 } 648 649 656 public static void setUserProperties(Properties overrideProperties) 657 { 658 Enumeration keys = overrideProperties.keys(); 661 while (keys.hasMoreElements()) 662 { 663 String key = (String ) keys.nextElement(); 664 if (key != null) 665 { 666 userProperties.setProperty(key, (String ) overrideProperties.get(key)); 667 } 668 } 669 } 670 671 675 public Locale getLocale() 676 { 677 return locale; 678 } 679 680 684 public String getPagingInvalidPage() 685 { 686 return getProperty(PROPERTY_STRING_PAGING_INVALIDPAGE); 687 } 688 689 693 public String getPagingItemName() 694 { 695 return getProperty(PROPERTY_STRING_PAGING_ITEM_NAME); 696 } 697 698 702 public String getPagingItemsName() 703 { 704 return getProperty(PROPERTY_STRING_PAGING_ITEMS_NAME); 705 } 706 707 711 public String getPagingFoundNoItems() 712 { 713 return getProperty(PROPERTY_STRING_PAGING_NOITEMS); 714 } 715 716 720 public String getPagingFoundOneItem() 721 { 722 return getProperty(PROPERTY_STRING_PAGING_FOUND_ONEITEM); 723 } 724 725 729 public String getPagingFoundAllItems() 730 { 731 return getProperty(PROPERTY_STRING_PAGING_FOUND_ALLITEMS); 732 } 733 734 738 public String getPagingFoundSomeItems() 739 { 740 return getProperty(PROPERTY_STRING_PAGING_FOUND_SOMEITEMS); 741 } 742 743 747 public int getPagingGroupSize() 748 { 749 return getIntProperty(PROPERTY_INT_PAGING_GROUPSIZE, 8); 751 } 752 753 757 public String getPagingBannerOnePage() 758 { 759 return getProperty(PROPERTY_STRING_PAGING_BANNER_ONEPAGE); 760 } 761 762 766 public String getPagingBannerFirst() 767 { 768 return getProperty(PROPERTY_STRING_PAGING_BANNER_FIRST); 769 } 770 771 775 public String getPagingBannerLast() 776 { 777 return getProperty(PROPERTY_STRING_PAGING_BANNER_LAST); 778 } 779 780 784 public String getPagingBannerFull() 785 { 786 return getProperty(PROPERTY_STRING_PAGING_BANNER_FULL); 787 } 788 789 793 public String getPagingPageLink() 794 { 795 return getProperty(PROPERTY_STRING_PAGING_PAGE_LINK); 796 } 797 798 802 public String getPagingPageSelected() 803 { 804 return getProperty(PROPERTY_STRING_PAGING_PAGE_SELECTED); 805 } 806 807 811 public String getPagingPageSeparator() 812 { 813 return getProperty(PROPERTY_STRING_PAGING_PAGE_SPARATOR); 814 } 815 816 821 public boolean getAddExport(MediaTypeEnum exportType) 822 { 823 return getBooleanProperty(PROPERTY_EXPORT_PREFIX + SEP + exportType.getName()); 824 } 825 826 831 public boolean getExportHeader(MediaTypeEnum exportType) 832 { 833 return getBooleanProperty(PROPERTY_EXPORT_PREFIX 834 + SEP 835 + exportType.getName() 836 + SEP 837 + EXPORTPROPERTY_BOOLEAN_EXPORTHEADER); 838 } 839 840 845 public String getExportLabel(MediaTypeEnum exportType) 846 { 847 return getProperty(PROPERTY_EXPORT_PREFIX + SEP + exportType.getName() + SEP + EXPORTPROPERTY_STRING_LABEL); 848 } 849 850 855 public String getExportFileName(MediaTypeEnum exportType) 856 { 857 return getProperty(PROPERTY_EXPORT_PREFIX + SEP + exportType.getName() + SEP + EXPORTPROPERTY_STRING_FILENAME); 858 } 859 860 864 public boolean getExportDecorated() 865 { 866 return getBooleanProperty(PROPERTY_BOOLEAN_EXPORTDECORATED); 867 } 868 869 873 public String getExportBanner() 874 { 875 return getProperty(PROPERTY_STRING_EXPORTBANNER); 876 } 877 878 882 public String getExportBannerSeparator() 883 { 884 return getProperty(PROPERTY_STRING_EXPORTBANNER_SEPARATOR); 885 } 886 887 891 public boolean getShowHeader() 892 { 893 return getBooleanProperty(PROPERTY_BOOLEAN_SHOWHEADER); 894 } 895 896 900 public String getEmptyListMessage() 901 { 902 return getProperty(PROPERTY_STRING_EMPTYLIST_MESSAGE); 903 } 904 905 909 public String getEmptyListRowMessage() 910 { 911 return getProperty(PROPERTY_STRING_EMPTYLISTROW_MESSAGE); 912 } 913 914 918 public boolean getEmptyListShowTable() 919 { 920 return getBooleanProperty(PROPERTY_BOOLEAN_EMPTYLIST_SHOWTABLE); 921 } 922 923 927 public boolean getExportFullList() 928 { 929 return "list".equals(getProperty(PROPERTY_STRING_EXPORTAMOUNT)); } 931 932 936 public boolean getSortFullList() 937 { 938 return "list".equals(getProperty(PROPERTY_STRING_SORTAMOUNT)); } 940 941 945 public boolean getAddPagingBannerTop() 946 { 947 String placement = getProperty(PROPERTY_STRING_BANNER_PLACEMENT); 948 return "top".equals(placement) || "both".equals(placement); } 950 951 955 public boolean getAddPagingBannerBottom() 956 { 957 String placement = getProperty(PROPERTY_STRING_BANNER_PLACEMENT); 958 return "bottom".equals(placement) || "both".equals(placement); } 960 961 967 public String getCssRow(int rowNumber) 968 { 969 return getProperty((rowNumber % 2 == 0) ? PROPERTY_CSS_TR_ODD : PROPERTY_CSS_TR_EVEN); 970 } 971 972 978 public String getCssOrder(boolean ascending) 979 { 980 return getProperty(ascending ? PROPERTY_CSS_TH_SORTED_ASCENDING : PROPERTY_CSS_TH_SORTED_DESCENDING); 981 } 982 983 987 public String getCssSorted() 988 { 989 return getProperty(PROPERTY_CSS_TH_SORTED); 990 } 991 992 996 public String getCssTable() 997 { 998 return getProperty(PROPERTY_CSS_TABLE); 999 } 1000 1001 1005 public String getCssSortable() 1006 { 1007 return getProperty(PROPERTY_CSS_TH_SORTABLE); 1008 } 1009 1010 1014 public String [] getExportTypes() 1015 { 1016 String list = getProperty(PROPERTY_EXPORTTYPES); 1017 if (list == null) 1018 { 1019 return new String [0]; 1020 } 1021 1022 return StringUtils.split(list); 1023 } 1024 1025 1030 public String getExportClass(String exportName) 1031 { 1032 return getProperty(PROPERTY_EXPORT_PREFIX + SEP + exportName + SEP + EXPORTPROPERTY_STRING_CLASS); 1033 } 1034 1035 1040 public RequestHelperFactory getRequestHelperFactoryInstance() throws FactoryInstantiationException 1041 { 1042 Object loadedObject = getClassPropertyInstance(PROPERTY_CLASS_REQUESTHELPERFACTORY); 1043 1044 if (loadedObject == null) 1046 { 1047 return new DefaultRequestHelperFactory(); 1048 } 1049 1050 try 1051 { 1052 return (RequestHelperFactory) loadedObject; 1053 } 1054 catch (ClassCastException e) 1055 { 1056 throw new FactoryInstantiationException(getClass(), PROPERTY_CLASS_REQUESTHELPERFACTORY, loadedObject 1057 .getClass() 1058 .getName(), e); 1059 } 1060 } 1061 1062 1067 public DecoratorFactory getDecoratorFactoryInstance() throws FactoryInstantiationException 1068 { 1069 Object loadedObject = getClassPropertyInstance(PROPERTY_CLASS_DECORATORFACTORY); 1070 1071 if (loadedObject == null) 1072 { 1073 return new DefaultDecoratorFactory(); 1074 } 1075 1076 try 1077 { 1078 return (DecoratorFactory) loadedObject; 1079 } 1080 catch (ClassCastException e) 1081 { 1082 throw new FactoryInstantiationException(getClass(), PROPERTY_CLASS_DECORATORFACTORY, loadedObject 1083 .getClass() 1084 .getName(), e); 1085 } 1086 } 1087 1088 public String getPaginationSortParam() 1089 { 1090 String result = getProperty(PROPERTY_STRING_PAGINATION_SORT_PARAM); 1091 if (result == null) 1092 { 1093 result = "sort"; 1094 } 1095 return result; 1096 } 1097 1098 public String getPaginationPageNumberParam() 1099 { 1100 String result = getProperty(PROPERTY_STRING_PAGINATION_PAGE_NUMBER_PARAM); 1101 if (result == null) 1102 { 1103 result = "page"; 1104 } 1105 return result; 1106 } 1107 1108 public String getPaginationSortDirectionParam() 1109 { 1110 String result = getProperty(PROPERTY_STRING_PAGINATION_SORT_DIRECTION_PARAM); 1111 if (result == null) 1112 { 1113 result = "dir"; 1114 } 1115 return result; 1116 } 1117 1118 public String getPaginationSearchIdParam() 1119 { 1120 String result = getProperty(PROPERTY_STRING_PAGINATION_SEARCH_ID_PARAM); 1121 if (result == null) 1122 { 1123 result = "searchId"; 1124 } 1125 return result; 1126 } 1127 1128 public String getPaginationAscValue() 1129 { 1130 String result = getProperty(PROPERTY_STRING_PAGINATION_ASC_VALUE); 1131 if (result == null) 1132 { 1133 result = "asc"; 1134 } 1135 return result; 1136 } 1137 1138 public String getPaginationDescValue() 1139 { 1140 String result = getProperty(PROPERTY_STRING_PAGINATION_DESC_VALUE); 1141 if (result == null) 1142 { 1143 result = "desc"; 1144 } 1145 return result; 1146 } 1147 1148 public boolean getPaginationSkipPageNumberInSort() 1149 { 1150 String s = getProperty(PROPERTY_BOOLEAN_PAGINATION_SKIP_PAGE_NUMBER_IN_SORT); 1151 if (s == null) 1152 { 1153 return true; 1154 } 1155 else 1156 { 1157 return getBooleanProperty(PROPERTY_BOOLEAN_PAGINATION_SKIP_PAGE_NUMBER_IN_SORT); 1158 } 1159 } 1160 1161 1163 1169 public I18nResourceProvider geResourceProvider() 1170 { 1171 String className = getProperty(PROPERTY_CLASS_LOCALEPROVIDER); 1172 1173 if (resourceProvider == null) 1174 { 1175 if (className != null) 1176 { 1177 try 1178 { 1179 Class classProperty = ReflectHelper.classForName(className); 1180 resourceProvider = (I18nResourceProvider) classProperty.newInstance(); 1181 1182 log.info(Messages.getString("TableProperties.classinitializedto", new Object []{ClassUtils.getShortClassName(I18nResourceProvider.class), className})); 1184 } 1185 catch (Throwable e) 1186 { 1187 log.warn(Messages.getString("TableProperties.errorloading", new Object []{ 1189 ClassUtils.getShortClassName(I18nResourceProvider.class), 1190 e.getClass().getName(), 1191 e.getMessage()})); 1192 } 1193 } 1194 else 1195 { 1196 log.info(Messages.getString("TableProperties.noconfigured", new Object []{ClassUtils.getShortClassName(I18nResourceProvider.class)})); 1198 } 1199 1200 if (resourceProvider == null) 1202 { 1203 resourceProvider = new I18nResourceProvider() 1205 { 1206 1207 public String getResource(String titleKey, String property, Tag tag, PageContext context) 1209 { 1210 return null; 1211 } 1212 }; 1213 } 1214 } 1215 1216 return resourceProvider; 1217 } 1218 1219 1224 private String getProperty(String key) 1225 { 1226 return this.properties.getProperty(key); 1227 } 1228 1229 1234 public void setProperty(String key, String value) 1235 { 1236 this.properties.setProperty(key, value); 1237 } 1238 1239 1244 private boolean getBooleanProperty(String key) 1245 { 1246 return Boolean.TRUE.toString().equals(getProperty(key)); 1247 } 1248 1249 1256 private Object getClassPropertyInstance(String key) throws FactoryInstantiationException 1257 { 1258 Object instance = objectCache.get(key); 1259 if (instance != null) 1260 { 1261 return instance; 1262 } 1263 1264 String className = getProperty(key); 1265 1266 if (className == null) 1268 { 1269 return null; 1270 } 1271 1272 try 1273 { 1274 Class classProperty = ReflectHelper.classForName(className); 1275 instance = classProperty.newInstance(); 1276 objectCache.put(key, instance); 1277 return instance; 1278 } 1279 catch (Exception e) 1280 { 1281 throw new FactoryInstantiationException(getClass(), key, className, e); 1282 } 1283 } 1284 1285 1291 private int getIntProperty(String key, int defaultValue) 1292 { 1293 try 1294 { 1295 return Integer.parseInt(getProperty(key)); 1296 } 1297 catch (NumberFormatException e) 1298 { 1299 log.warn(Messages.getString("TableProperties.invalidvalue", new Object []{key, getProperty(key), new Integer (defaultValue)})); 1302 } 1303 1304 return defaultValue; 1305 } 1306 1307 1312 public String getExportDecoratorName(MediaTypeEnum thatEnum) 1313 { 1314 return getProperty(PROPERTY_EXPORT_PREFIX + SEP + thatEnum + SEP + PROPERTY_EXPORT_DECORATOR_SUFFIX); 1315 } 1316} | Popular Tags |