<%@ page import="com.atlassian.jira.portal.PortletConfiguration,
                 webwork.action.CoreActionContext,
                 com.atlassian.util.profiling.UtilTimerStack,
                 com.atlassian.jira.web.portlet.bean.PortletRenderer,
                 com.atlassian.jira.ComponentManager"%>
<%@ page import="com.atlassian.jira.config.properties.LookAndFeelBean"%>
<%@ page import="com.atlassian.plugin.webresource.WebResourceManager"%>
<%@ page import="com.atlassian.jira.ManagerFactory"%>
<%@ taglib uri="webwork" prefix="webwork" %>

<%
    WebResourceManager webResourceManagerRunPortlet = ComponentManager.getInstance().getWebResourceManager();
%>

<style type="text/css" media="screen">@import "<%= request.getContextPath() %>/styles/combined.css";</style>
<style type="text/css" media="screen">@import "<%= webResourceManagerRunPortlet.getStaticResourcePrefix(String.valueOf(LookAndFeelBean.getInstance(ManagerFactory.getApplicationProperties()).getVersion())) %>/styles/global.css";</style>

<webwork:property value="portletConfiguration">

<%
          final PortletConfiguration portletConfiguration = (PortletConfiguration)CoreActionContext.getValueStack().findValue((String)null);
          final PortletRenderer portletRenderer = new PortletRenderer();
%>
    <%  String viewHtml = portletRenderer.renderPortlet(request, response, portletConfiguration, false);
        if (viewHtml != null) //velocity portlet
        {
            out.print(viewHtml);
        }
        else // jsp portlet
        {
            String template = portletConfiguration.getPortlet().getTemplateLocation();
            UtilTimerStack.push("Running portlet: " + template);
            try { %>
                <jsp:include page="<%=template%>" />
         <% } catch (Throwable t) {
                System.err.println("Exception rendering portlet "+template);
                t.printStackTrace();
         %>
                <span class="errLabel">Error rendering <%= template %>: <%= t.getMessage() %>. <br>
                           Removing and recreating this portlet may solve the problem.<br>
                           If not please ask your <a href="Administrators.jspa">JIRA adminstrator</a> to send a <a href="admin/jira/JiraSupportRequest!default.jspa">support request</a></span>
         <% }
                finally {
                    UtilTimerStack.pop("Running portlet: " + template);
                }
            }
         %>
</webwork:property>