1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.taglib.ui;
24  
25  import com.liferay.portal.NoSuchUserException;
26  import com.liferay.portal.kernel.servlet.PortalIncludeUtil;
27  import com.liferay.portal.kernel.util.Validator;
28  import com.liferay.portal.model.User;
29  import com.liferay.portal.service.UserLocalServiceUtil;
30  
31  import javax.servlet.http.HttpServletRequest;
32  import javax.servlet.jsp.JspException;
33  import javax.servlet.jsp.tagext.TagSupport;
34  
35  /**
36   * <a href="UserDisplayTag.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   *
40   */
41  public class UserDisplayTag extends TagSupport {
42  
43      public int doStartTag() throws JspException {
44          try {
45              HttpServletRequest request =
46                  (HttpServletRequest)pageContext.getRequest();
47  
48              request.setAttribute(
49                  "liferay-ui:user-display:user-id", String.valueOf(_userId));
50              request.setAttribute(
51                  "liferay-ui:user-display:user-name", _userName);
52  
53              User user = null;
54  
55              try {
56                  user = UserLocalServiceUtil.getUserById(_userId);
57  
58                  request.setAttribute("liferay-ui:user-display:user", user);
59  
60                  pageContext.setAttribute("userDisplay", user);
61              }
62              catch (NoSuchUserException usue) {
63                  request.removeAttribute("liferay-ui:user-display:user");
64  
65                  pageContext.removeAttribute("userDisplay");
66              }
67  
68              request.setAttribute("liferay-ui:user-display:url", _url);
69              request.setAttribute(
70                  "liferay-ui:user-display:displayStyle",
71                  String.valueOf(_displayStyle));
72  
73              PortalIncludeUtil.include(pageContext, getStartPage());
74  
75              if (user != null) {
76                  return EVAL_BODY_INCLUDE;
77              }
78              else {
79                  return SKIP_BODY;
80              }
81          }
82          catch (Exception e) {
83              throw new JspException(e);
84          }
85      }
86  
87      public int doEndTag() throws JspException {
88          try {
89              PortalIncludeUtil.include(pageContext, getEndPage());
90  
91              return EVAL_PAGE;
92          }
93          catch (Exception e) {
94              throw new JspException(e);
95          }
96      }
97  
98      public String getStartPage() {
99          if (Validator.isNull(_startPage)) {
100             return _START_PAGE;
101         }
102         else {
103             return _startPage;
104         }
105     }
106 
107     public void setStartPage(String startPage) {
108         _startPage = startPage;
109     }
110 
111     public String getEndPage() {
112         if (Validator.isNull(_endPage)) {
113             return _END_PAGE;
114         }
115         else {
116             return _endPage;
117         }
118     }
119 
120     public void setEndPage(String endPage) {
121         _endPage = endPage;
122     }
123 
124     public void setUserId(long userId) {
125         _userId = userId;
126     }
127 
128     public void setUserName(String userName) {
129         _userName = userName;
130     }
131 
132     public void setUrl(String url) {
133         _url = url;
134     }
135 
136     public void setDisplayStyle(int displayStyle) {
137         _displayStyle = displayStyle;
138     }
139 
140     private static final String _START_PAGE =
141         "/html/taglib/ui/user_display/start.jsp";
142 
143     private static final String _END_PAGE =
144         "/html/taglib/ui/user_display/end.jsp";
145 
146     private String _startPage;
147     private String _endPage;
148     private long _userId;
149     private String _userName;
150     private String _url;
151     private int _displayStyle = 1;
152 
153 }