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