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    import com.liferay.taglib.util.IncludeTag;
024    
025    import javax.servlet.jsp.JspException;
026    import javax.servlet.jsp.PageContext;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     * @author Wilson S. Man
031     */
032    public class InputPermissionsTag extends IncludeTag {
033    
034            public static String doTag(
035                            String formName, String modelName, PageContext pageContext)
036                    throws Exception {
037    
038                    return doTag(_PAGE, formName, modelName, pageContext);
039            }
040    
041            public static String doTag(
042                            String page, String formName, String modelName,
043                            PageContext pageContext)
044                    throws Exception {
045    
046                    Object returnObj = null;
047    
048                    Thread currentThread = Thread.currentThread();
049    
050                    ClassLoader contextClassLoader = currentThread.getContextClassLoader();
051    
052                    try {
053                            currentThread.setContextClassLoader(
054                                    PortalClassLoaderUtil.getClassLoader());
055    
056                            MethodWrapper methodWrapper = new MethodWrapper(
057                                    _TAG_CLASS, _TAG_DO_END_METHOD,
058                                    new Object[] {page, formName, modelName, pageContext});
059    
060                            returnObj = MethodInvoker.invoke(methodWrapper);
061                    }
062                    catch (Exception e) {
063                            _log.error(e, e);
064                    }
065                    finally {
066                            currentThread.setContextClassLoader(contextClassLoader);
067                    }
068    
069                    if (returnObj != null) {
070                            return returnObj.toString();
071                    }
072                    else {
073                            return StringPool.BLANK;
074                    }
075            }
076    
077            public int doEndTag() throws JspException {
078                    try {
079                            doTag(getPage(), _formName, _modelName, pageContext);
080    
081                            return EVAL_PAGE;
082                    }
083                    catch (Exception e) {
084                            throw new JspException(e);
085                    }
086            }
087    
088            public void setFormName(String formName) {
089                    _formName = formName;
090            }
091    
092            public void setModelName(String modelName) {
093                    _modelName = modelName;
094            }
095    
096            protected String getPage() {
097                    return _PAGE;
098            }
099    
100            private static final String _TAG_CLASS =
101                    "com.liferay.portal.servlet.taglib.ui.InputPermissionsTagUtil";
102    
103            private static final String _TAG_DO_END_METHOD = "doEndTag";
104    
105            private static final String _PAGE =
106                    "/html/taglib/ui/input_permissions/page.jsp";
107    
108            private static Log _log = LogFactoryUtil.getLog(InputPermissionsTag.class);
109    
110            private String _formName = "fm";
111            private String _modelName = null;
112    
113    }