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