1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class UserDisplayTag extends TagSupport {
41  
42      public int doStartTag() throws JspException {
43          try {
44              HttpServletRequest request =
45                  (HttpServletRequest)pageContext.getRequest();
46  
47              request.setAttribute(
48                  "liferay-ui:user-display:user-id", String.valueOf(_userId));
49              request.setAttribute(
50                  "liferay-ui:user-display:user-name", _userName);
51  
52              User user = null;
53  
54              try {
55                  user = UserLocalServiceUtil.getUserById(_userId);
56  
57                  if (user.isDefaultUser()) {
58                      user = null;
59                  }
60  
61                  request.setAttribute("liferay-ui:user-display:user", user);
62  
63                  pageContext.setAttribute("userDisplay", user);
64              }
65              catch (NoSuchUserException usue) {
66                  request.removeAttribute("liferay-ui:user-display:user");
67  
68                  pageContext.removeAttribute("userDisplay");
69              }
70  
71              request.setAttribute("liferay-ui:user-display:url", _url);
72              request.setAttribute(
73                  "liferay-ui:user-display:displayStyle",
74                  String.valueOf(_displayStyle));
75  
76              PortalIncludeUtil.include(pageContext, getStartPage());
77  
78              if (user != null) {
79                  return EVAL_BODY_INCLUDE;
80              }
81              else {
82                  return SKIP_BODY;
83              }
84          }
85          catch (Exception e) {
86              throw new JspException(e);
87          }
88      }
89  
90      public int doEndTag() throws JspException {
91          try {
92              PortalIncludeUtil.include(pageContext, getEndPage());
93  
94              return EVAL_PAGE;
95          }
96          catch (Exception e) {
97              throw new JspException(e);
98          }
99      }
100 
101     public String getStartPage() {
102         if (Validator.isNull(_startPage)) {
103             return _START_PAGE;
104         }
105         else {
106             return _startPage;
107         }
108     }
109 
110     public void setStartPage(String startPage) {
111         _startPage = startPage;
112     }
113 
114     public String getEndPage() {
115         if (Validator.isNull(_endPage)) {
116             return _END_PAGE;
117         }
118         else {
119             return _endPage;
120         }
121     }
122 
123     public void setEndPage(String endPage) {
124         _endPage = endPage;
125     }
126 
127     public void setUserId(long userId) {
128         _userId = userId;
129     }
130 
131     public void setUserName(String userName) {
132         _userName = userName;
133     }
134 
135     public void setUrl(String url) {
136         _url = url;
137     }
138 
139     public void setDisplayStyle(int displayStyle) {
140         _displayStyle = displayStyle;
141     }
142 
143     private static final String _START_PAGE =
144         "/html/taglib/ui/user_display/start.jsp";
145 
146     private static final String _END_PAGE =
147         "/html/taglib/ui/user_display/end.jsp";
148 
149     private String _startPage;
150     private String _endPage;
151     private long _userId;
152     private String _userName;
153     private String _url;
154     private int _displayStyle = 1;
155 
156 }