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.security;
21  
22  import com.liferay.portal.kernel.util.MethodInvoker;
23  import com.liferay.portal.kernel.util.MethodWrapper;
24  import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
25  import com.liferay.portal.kernel.util.StringUtil;
26  
27  import java.util.HashSet;
28  import java.util.Set;
29  
30  import javax.servlet.jsp.JspException;
31  import javax.servlet.jsp.tagext.TagSupport;
32  
33  /**
34   * <a href="EncryptTag.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   *
38   */
39  public class EncryptTag extends TagSupport {
40  
41      public int doStartTag() throws JspException {
42          Thread currentThread = Thread.currentThread();
43  
44          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
45  
46          try {
47              currentThread.setContextClassLoader(
48                  PortalClassLoaderUtil.getClassLoader());
49  
50              MethodWrapper methodWrapper = new MethodWrapper(
51                  _TAG_CLASS, _TAG_DO_START_METHOD,
52                  new Object[] {
53                      _className, _style, _protocol, _unencryptedParamsSet, _url,
54                      _target, pageContext
55                  });
56  
57              MethodInvoker.invoke(methodWrapper);
58          }
59          catch (Exception e) {
60              throw new JspException(e);
61          }
62          finally {
63              currentThread.setContextClassLoader(contextClassLoader);
64          }
65  
66          return EVAL_BODY_INCLUDE;
67      }
68  
69      public int doEndTag() throws JspException {
70          Thread currentThread = Thread.currentThread();
71  
72          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
73  
74          try {
75              currentThread.setContextClassLoader(
76                  PortalClassLoaderUtil.getClassLoader());
77  
78              MethodWrapper methodWrapper = new MethodWrapper(
79                  _TAG_CLASS, _TAG_DO_END_METHOD, new Object[] {pageContext});
80  
81              MethodInvoker.invoke(methodWrapper);
82          }
83          catch (Exception e) {
84              throw new JspException(e);
85          }
86          finally {
87              currentThread.setContextClassLoader(contextClassLoader);
88          }
89  
90          return EVAL_PAGE;
91      }
92  
93      public void setClassName(String className) {
94          _className = className;
95      }
96  
97      public void setStyle(String style) {
98          _style = style;
99      }
100 
101     public void setProtocol(String protocol) {
102         _protocol = protocol;
103     }
104 
105     public void setUnencryptedParams(String unencryptedParams) {
106         _unencryptedParamsSet.clear();
107 
108         String[] unencryptedParamsArray = StringUtil.split(unencryptedParams);
109 
110         for (int i = 0; i < unencryptedParamsArray.length; i++) {
111             _unencryptedParamsSet.add(unencryptedParamsArray[i]);
112         }
113     }
114 
115     public void setUrl(String url) {
116         _url = url;
117     }
118 
119     public void setTarget(String target) {
120         _target = target;
121     }
122 
123     private static final String _TAG_CLASS =
124         "com.liferay.portal.servlet.taglib.security.EncryptTagUtil";
125 
126     private static final String _TAG_DO_START_METHOD = "doStartTag";
127 
128     private static final String _TAG_DO_END_METHOD = "doEndTag";
129 
130     private String _className;
131     private String _style;
132     private String _protocol;
133     private Set<String> _unencryptedParamsSet = new HashSet<String>();
134     private String _url;
135     private String _target;
136 
137 }