1
22
23 package com.liferay.portal.velocity;
24
25 import com.liferay.portal.bean.BeanLocatorImpl;
26 import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
27 import com.liferay.portal.kernel.bean.PortletBeanLocatorUtil;
28 import com.liferay.portal.kernel.log.Log;
29 import com.liferay.portal.kernel.log.LogFactoryUtil;
30
31
36 public class UtilLocator {
37
38 public static UtilLocator getInstance() {
39 return _instance;
40 }
41
42 private UtilLocator() {
43 }
44
45 public Object findUtil(String utilName) {
46 Object bean = null;
47
48 try {
49 bean = PortalBeanLocatorUtil.locate(_getUtilName(utilName));
50 }
51 catch (Exception e) {
52 _log.error(e, e);
53 }
54
55 return bean;
56 }
57
58 public Object findUtil(
59 String servletContextName, String utilName) {
60
61 Object bean = null;
62
63 try {
64 bean = PortletBeanLocatorUtil.locate(
65 servletContextName, _getUtilName(utilName));
66 }
67 catch (Exception e) {
68 _log.error(e, e);
69 }
70
71 return bean;
72 }
73
74 private String _getUtilName(String utilName) {
75 if (!utilName.endsWith(BeanLocatorImpl.VELOCITY_SUFFIX)) {
76 utilName += BeanLocatorImpl.VELOCITY_SUFFIX;
77 }
78
79 return utilName;
80 }
81
82 private static Log _log = LogFactoryUtil.getLog(UtilLocator.class);
83
84 private static UtilLocator _instance = new UtilLocator();
85
86 }