1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.taglib.ui;
16  
17  import com.liferay.portal.NoSuchUserException;
18  import com.liferay.portal.kernel.servlet.PortalIncludeUtil;
19  import com.liferay.portal.kernel.util.Validator;
20  import com.liferay.portal.model.User;
21  import com.liferay.portal.service.UserLocalServiceUtil;
22  
23  import javax.servlet.http.HttpServletRequest;
24  import javax.servlet.jsp.JspException;
25  import javax.servlet.jsp.tagext.TagSupport;
26  
27  /**
28   * <a href="UserDisplayTag.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   */
32  public class UserDisplayTag extends TagSupport {
33  
34      public int doStartTag() throws JspException {
35          try {
36              HttpServletRequest request =
37                  (HttpServletRequest)pageContext.getRequest();
38  
39              request.setAttribute(
40                  "liferay-ui:user-display:user-id", String.valueOf(_userId));
41              request.setAttribute(
42                  "liferay-ui:user-display:user-name", _userName);
43  
44              User user = null;
45  
46              try {
47                  user = UserLocalServiceUtil.getUserById(_userId);
48  
49                  if (user.isDefaultUser()) {
50                      user = null;
51                  }
52  
53                  request.setAttribute("liferay-ui:user-display:user", user);
54  
55                  pageContext.setAttribute("userDisplay", user);
56              }
57              catch (NoSuchUserException usue) {
58                  request.removeAttribute("liferay-ui:user-display:user");
59  
60                  pageContext.removeAttribute("userDisplay");
61              }
62  
63              request.setAttribute("liferay-ui:user-display:url", _url);
64              request.setAttribute(
65                  "liferay-ui:user-display:displayStyle",
66                  String.valueOf(_displayStyle));
67  
68              PortalIncludeUtil.include(pageContext, getStartPage());
69  
70              if (user != null) {
71                  return EVAL_BODY_INCLUDE;
72              }
73              else {
74                  return SKIP_BODY;
75              }
76          }
77          catch (Exception e) {
78              throw new JspException(e);
79          }
80      }
81  
82      public int doEndTag() throws JspException {
83          try {
84              PortalIncludeUtil.include(pageContext, getEndPage());
85  
86              return EVAL_PAGE;
87          }
88          catch (Exception e) {
89              throw new JspException(e);
90          }
91      }
92  
93      public String getStartPage() {
94          if (Validator.isNull(_startPage)) {
95              return _START_PAGE;
96          }
97          else {
98              return _startPage;
99          }
100     }
101 
102     public void setStartPage(String startPage) {
103         _startPage = startPage;
104     }
105 
106     public String getEndPage() {
107         if (Validator.isNull(_endPage)) {
108             return _END_PAGE;
109         }
110         else {
111             return _endPage;
112         }
113     }
114 
115     public void setEndPage(String endPage) {
116         _endPage = endPage;
117     }
118 
119     public void setUserId(long userId) {
120         _userId = userId;
121     }
122 
123     public void setUserName(String userName) {
124         _userName = userName;
125     }
126 
127     public void setUrl(String url) {
128         _url = url;
129     }
130 
131     public void setDisplayStyle(int displayStyle) {
132         _displayStyle = displayStyle;
133     }
134 
135     private static final String _START_PAGE =
136         "/html/taglib/ui/user_display/start.jsp";
137 
138     private static final String _END_PAGE =
139         "/html/taglib/ui/user_display/end.jsp";
140 
141     private String _startPage;
142     private String _endPage;
143     private long _userId;
144     private String _userName;
145     private String _url;
146     private int _displayStyle = 1;
147 
148 }