001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.taglib.ui;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.MethodInvoker;
020    import com.liferay.portal.kernel.util.MethodWrapper;
021    import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
022    import com.liferay.portal.kernel.util.StringPool;
023    
024    import javax.servlet.jsp.JspException;
025    import javax.servlet.jsp.PageContext;
026    import javax.servlet.jsp.tagext.TagSupport;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     * @author Jorge Ferrer
031     */
032    public class InputPermissionsParamsTag extends TagSupport {
033    
034            public static String doTag(
035                            String modelName, PageContext pageContext)
036                    throws Exception {
037    
038                    Object returnObj = null;
039    
040                    Thread currentThread = Thread.currentThread();
041    
042                    ClassLoader contextClassLoader = currentThread.getContextClassLoader();
043    
044                    try {
045                            currentThread.setContextClassLoader(
046                                    PortalClassLoaderUtil.getClassLoader());
047    
048                            MethodWrapper methodWrapper = new MethodWrapper(
049                                    _TAG_CLASS, _TAG_DO_END_METHOD,
050                                    new Object[] {modelName, pageContext}
051                            );
052    
053                            returnObj = MethodInvoker.invoke(methodWrapper);
054                    }
055                    catch (Exception e) {
056                            _log.error(e, e);
057                    }
058                    finally {
059                            currentThread.setContextClassLoader(contextClassLoader);
060                    }
061    
062                    if (returnObj != null) {
063                            return returnObj.toString();
064                    }
065                    else {
066                            return StringPool.BLANK;
067                    }
068            }
069    
070            public int doEndTag() throws JspException {
071                    try {
072                            doTag(_modelName, pageContext);
073    
074                            return EVAL_PAGE;
075                    }
076                    catch (Exception e) {
077                            throw new JspException(e);
078                    }
079            }
080    
081            public void setModelName(String modelName) {
082                    _modelName = modelName;
083            }
084    
085            private static final String _TAG_CLASS =
086                    "com.liferay.portal.servlet.taglib.ui.InputPermissionsParamsTagUtil";
087    
088            private static final String _TAG_DO_END_METHOD = "doEndTag";
089    
090            private static Log _log = LogFactoryUtil.getLog(
091                    InputPermissionsParamsTag.class);
092    
093            private String _modelName;
094    
095    }