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.taglib.ui;
16  
17  import com.liferay.portal.security.auth.CompanyThreadLocal;
18  import com.liferay.portlet.expando.model.ExpandoBridge;
19  import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
20  import com.liferay.taglib.util.ParamAndPropertyAncestorTagImpl;
21  
22  import java.util.Collections;
23  import java.util.List;
24  
25  /**
26   * <a href="CustomAttributesAvailableTag.java.html"><b><i>View Source</i></b>
27   * </a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class CustomAttributesAvailableTag
32      extends ParamAndPropertyAncestorTagImpl {
33  
34      public int doStartTag() {
35          long companyId = _companyId;
36  
37          if (companyId == 0) {
38              companyId = CompanyThreadLocal.getCompanyId();
39          }
40  
41          ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(
42              companyId, _className);
43  
44          List<String> attributeNames = Collections.list(
45              expandoBridge.getAttributeNames());
46  
47          if (attributeNames.isEmpty()) {
48              return EVAL_PAGE;
49          }
50          else {
51              return EVAL_BODY_INCLUDE;
52          }
53      }
54  
55      public void setClassName(String className) {
56          _className = className;
57      }
58  
59      public void setCompanyId(long companyId) {
60          _companyId = companyId;
61      }
62  
63      private String _className;
64      private long _companyId;
65  
66  }