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