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.aui;
16  
17  import com.liferay.portal.kernel.servlet.PortalIncludeUtil;
18  import com.liferay.portal.kernel.util.ServerDetector;
19  import com.liferay.portal.kernel.util.Validator;
20  import com.liferay.taglib.util.IncludeTag;
21  
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  import javax.servlet.http.HttpServletRequest;
26  import javax.servlet.jsp.JspException;
27  import javax.servlet.jsp.tagext.DynamicAttributes;
28  
29  /**
30   * <a href="ATag.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Julio Camarero
33   * @author Jorge Ferrer
34   * @author Brian Wing Shun Chan
35   */
36  public class ATag extends IncludeTag implements DynamicAttributes {
37  
38      public int doEndTag() throws JspException {
39          try{
40              PortalIncludeUtil.include(pageContext, getEndPage());
41  
42              return EVAL_PAGE;
43          }
44          catch (Exception e) {
45              throw new JspException(e);
46          }
47          finally {
48              if (!ServerDetector.isResin()) {
49                  _cssClass = null;
50                  _dynamicAttributes.clear();
51                  _endPage = null;
52                  _href = null;
53                  _id = null;
54                  _label = null;
55                  _startPage = null;
56              }
57          }
58      }
59  
60      public int doStartTag() throws JspException {
61          try{
62              HttpServletRequest request =
63                  (HttpServletRequest)pageContext.getRequest();
64  
65              request.setAttribute("aui:a:cssClass", _cssClass);
66              request.setAttribute("aui:a:dynamicAttributes", _dynamicAttributes);
67              request.setAttribute("aui:a:href", _href);
68              request.setAttribute("aui:a:id", _id);
69              request.setAttribute("aui:a:label", _label);
70  
71              PortalIncludeUtil.include(pageContext, getStartPage());
72  
73              return EVAL_BODY_INCLUDE;
74          }
75          catch (Exception e) {
76              throw new JspException(e);
77          }
78      }
79  
80      public String getEndPage() {
81          if (Validator.isNull(_endPage)) {
82              return _END_PAGE;
83          }
84          else {
85              return _endPage;
86          }
87      }
88  
89      public String getStartPage() {
90          if (Validator.isNull(_startPage)) {
91              return _START_PAGE;
92          }
93          else {
94              return _startPage;
95          }
96      }
97  
98      public void setCssClass(String cssClass) {
99          _cssClass = cssClass;
100     }
101 
102     public void setDynamicAttribute(
103         String uri, String localName, Object value) {
104 
105         _dynamicAttributes.put(localName, value);
106     }
107 
108     public void setEndPage(String endPage) {
109         _endPage = endPage;
110     }
111 
112     public void setHref(String href) {
113         _href = href;
114     }
115 
116     public void setId(String id) {
117         _id = id;
118     }
119 
120     public void setLabel(String label) {
121         _label = label;
122     }
123 
124     public void setStartPage(String startPage) {
125         _startPage = startPage;
126     }
127 
128     private static final String _END_PAGE =
129         "/html/taglib/aui/a/end.jsp";
130 
131     private static final String _START_PAGE =
132         "/html/taglib/aui/a/start.jsp";
133 
134     private String _cssClass;
135     private Map<String, Object> _dynamicAttributes =
136         new HashMap<String, Object>();
137     private String _endPage;
138     private String _href;
139     private String _id;
140     private String _label;
141     private String _startPage;
142 
143 }