1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.workflow;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portal.kernel.log.Log;
20  import com.liferay.portal.kernel.log.LogFactoryUtil;
21  import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
22  import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
23  import com.liferay.portal.kernel.workflow.WorkflowHandler;
24  import com.liferay.portal.service.WorkflowInstanceLinkLocalServiceUtil;
25  import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil;
26  import com.liferay.portlet.asset.model.AssetRenderer;
27  import com.liferay.portlet.asset.model.AssetRendererFactory;
28  
29  import javax.portlet.PortletURL;
30  
31  /**
32   * <a href="BaseWorkflowHandler.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Bruno Farache
35   * @author Marcellus Tavares
36   */
37  public abstract class BaseWorkflowHandler implements WorkflowHandler {
38  
39      public String getTitle(long classPK) {
40          try {
41              AssetRenderer assetRenderer = getAssetRenderer(classPK);
42  
43              if (assetRenderer != null) {
44                  return assetRenderer.getTitle();
45              }
46          }
47          catch (Exception e) {
48              if (_log.isWarnEnabled()) {
49                  _log.warn(e, e);
50              }
51          }
52  
53          return null;
54      }
55  
56      public String getType() {
57          return TYPE_UNKNOWN;
58      }
59  
60      public PortletURL getURLEdit(
61          long classPK, LiferayPortletRequest liferayPortletRequest,
62          LiferayPortletResponse liferayPortletResponse) {
63  
64          try {
65              AssetRenderer assetRenderer = getAssetRenderer(classPK);
66  
67              if (assetRenderer != null) {
68                  return assetRenderer.getURLEdit(
69                      liferayPortletRequest, liferayPortletResponse);
70              }
71          }
72          catch (Exception e) {
73              if (_log.isWarnEnabled()) {
74                  _log.warn(e, e);
75              }
76          }
77  
78          return null;
79      }
80  
81      public void startWorkflowInstance(
82              long companyId, long groupId, long userId, long classPK,
83              Object model)
84          throws PortalException, SystemException {
85  
86          WorkflowInstanceLinkLocalServiceUtil.startWorkflowInstance(
87              companyId, groupId, userId, getClassName(), classPK);
88      }
89  
90      protected AssetRenderer getAssetRenderer(long classPK)
91          throws PortalException, SystemException {
92  
93          AssetRendererFactory assetRendererFactory =
94              AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
95                  getClassName());
96  
97          if (assetRendererFactory != null) {
98              return assetRendererFactory.getAssetRenderer(classPK);
99          }
100         else {
101             return null;
102         }
103     }
104 
105     private static Log _log = LogFactoryUtil.getLog(BaseWorkflowHandler.class);
106 
107 }