001
014
015 package com.liferay.portal.velocity;
016
017 import com.liferay.portal.bean.BeanLocatorImpl;
018 import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
019 import com.liferay.portal.kernel.bean.PortletBeanLocatorUtil;
020 import com.liferay.portal.kernel.log.Log;
021 import com.liferay.portal.kernel.log.LogFactoryUtil;
022
023
026 public class UtilLocator {
027
028 public static UtilLocator getInstance() {
029 return _instance;
030 }
031
032 private UtilLocator() {
033 }
034
035 public Object findUtil(String utilName) {
036 Object bean = null;
037
038 try {
039 bean = PortalBeanLocatorUtil.locate(_getUtilName(utilName));
040 }
041 catch (Exception e) {
042 _log.error(e, e);
043 }
044
045 return bean;
046 }
047
048 public Object findUtil(
049 String servletContextName, String utilName) {
050
051 Object bean = null;
052
053 try {
054 bean = PortletBeanLocatorUtil.locate(
055 servletContextName, _getUtilName(utilName));
056 }
057 catch (Exception e) {
058 _log.error(e, e);
059 }
060
061 return bean;
062 }
063
064 private String _getUtilName(String utilName) {
065 if (!utilName.endsWith(BeanLocatorImpl.VELOCITY_SUFFIX)) {
066 utilName += BeanLocatorImpl.VELOCITY_SUFFIX;
067 }
068
069 return utilName;
070 }
071
072 private static Log _log = LogFactoryUtil.getLog(UtilLocator.class);
073
074 private static UtilLocator _instance = new UtilLocator();
075
076 }