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.portlet.LiferayPortletRequest;
18  import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
19  import com.liferay.portal.kernel.workflow.WorkflowHandler;
20  import com.liferay.portal.service.WorkflowInstanceLinkLocalServiceUtil;
21  import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil;
22  import com.liferay.portlet.asset.model.AssetRenderer;
23  import com.liferay.portlet.asset.model.AssetRendererFactory;
24  
25  import javax.portlet.PortletURL;
26  
27  /**
28   * <a href="BaseWorkflowHandler.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Bruno Farache
31   * @author Marcellus Tavares
32   */
33  public abstract class BaseWorkflowHandler implements WorkflowHandler {
34  
35      public String getTitle(long classPK) throws Exception {
36          AssetRenderer assetRenderer = getAssetRenderer(classPK);
37  
38          if (assetRenderer != null) {
39              return assetRenderer.getTitle();
40          }
41          else {
42              return null;
43          }
44      }
45  
46      public String getType() {
47          return TYPE_UNKNOWN;
48      }
49  
50      public PortletURL getURLEdit(
51              long classPK, LiferayPortletRequest liferayPortletRequest,
52              LiferayPortletResponse liferayPortletResponse)
53          throws Exception {
54  
55          AssetRenderer assetRenderer = getAssetRenderer(classPK);
56  
57          if (assetRenderer != null) {
58              return assetRenderer.getURLEdit(
59                  liferayPortletRequest, liferayPortletResponse);
60          }
61          else {
62              return null;
63          }
64      }
65  
66      public void startWorkflowInstance(
67              long companyId, long groupId, long userId, long classPK,
68              Object model)
69          throws Exception {
70  
71          WorkflowInstanceLinkLocalServiceUtil.startWorkflowInstance(
72              companyId, groupId, userId, getClassName(), classPK);
73      }
74  
75      protected AssetRenderer getAssetRenderer(long classPK) throws Exception {
76          AssetRendererFactory assetRendererFactory =
77              AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
78                  getClassName());
79  
80          if (assetRendererFactory != null) {
81              return assetRendererFactory.getAssetRenderer(classPK);
82          }
83          else {
84              return null;
85          }
86      }
87  
88  }