List of usage examples for com.liferay.portal.kernel.servlet ServletContextPool put
public static void put(String servletContextName, ServletContext servletContext)
From source file:blade.portlet.GreeterPortlet.java
License:Apache License
@Override public void init(PortletConfig portletConfig) throws PortletException { super.init(portletConfig); LiferayPortletConfig liferayPortletConfig = (LiferayPortletConfig) portletConfig; com.liferay.portal.model.Portlet portlet = liferayPortletConfig.getPortlet(); PortletApp portletApp = portlet.getPortletApp(); ServletContextPool.put(portletApp.getServletContextName(), portletApp.getServletContext()); }
From source file:com.liferay.blade.samples.portlet.controlpanel.ControlPanelPortlet.java
License:Apache License
@Override public void init(PortletConfig portletConfig) throws PortletException { super.init(portletConfig); LiferayPortletConfig liferayPortletConfig = (LiferayPortletConfig) portletConfig; com.liferay.portal.kernel.model.Portlet portlet = liferayPortletConfig.getPortlet(); PortletApp portletApp = portlet.getPortletApp(); ServletContextPool.put(portletApp.getServletContextName(), portletApp.getServletContext()); }
From source file:com.liferay.httpservice.internal.http.HttpSupport.java
License:Open Source License
public BundleServletContext getNonWABBundleServletContext(Bundle bundle) { String servletContextName = BundleServletContext.getServletContextName(bundle, true); ServletContext servletContext = ServletContextPool.get(servletContextName); if (servletContext == null) { BundleServletContext bundleServletContext = new BundleServletContext(bundle, servletContextName, _webExtenderServlet.getServletContext()); bundleServletContext.setServletContextName(servletContextName); ServletContextPool.put(servletContextName, bundleServletContext); servletContext = bundleServletContext; }// w ww .j a va 2 s .c om return (BundleServletContext) servletContext; }
From source file:com.liferay.httpservice.internal.WebBundleDeployer.java
License:Open Source License
public void doStart(Bundle bundle, String servletContextName) { if (bundle.getState() != Bundle.ACTIVE) { return;/*w ww .j a v a2s. c om*/ } EventUtil.sendEvent(bundle, EventUtil.DEPLOYING, null, false); ServletContext servletContext = ServletContextPool.get(servletContextName); if (servletContext != null) { EventUtil.sendEvent(bundle, EventUtil.FAILED, null, true); _collidedWABBundleIds.add(bundle.getBundleId()); return; } try { BundleServletContext bundleServletContext = new BundleServletContext(bundle, servletContextName, _webExtenderServlet.getServletContext()); bundleServletContext.open(); ServletContextPool.put(servletContextName, bundleServletContext); } catch (Exception e) { EventUtil.sendEvent(bundle, EventUtil.FAILED, e, false); } }
From source file:com.liferay.taglib.util.ThemeUtil.java
License:Open Source License
public static String includeFTL(ServletContext servletContext, HttpServletRequest request, PageContext pageContext, String path, Theme theme, boolean write) throws Exception { // The servlet context name will be null when the theme is deployed to // the root directory in Tomcat. See // com.liferay.portal.servlet.MainServlet and // com.liferay.portlet.PortletContextImpl for other cases where a null // servlet context name is also converted to an empty string. String servletContextName = GetterUtil.getString(theme.getServletContextName()); if (ServletContextPool.get(servletContextName) == null) { // This should only happen if the FreeMarker template is the first // page to be accessed in the system ServletContextPool.put(servletContextName, servletContext); }//ww w . j a v a 2 s . c om String portletId = getPortletId(request); String resourcePath = theme.getResourcePath(servletContext, portletId, path); if (Validator.isNotNull(portletId) && !FreeMarkerEngineUtil.resourceExists(resourcePath) && portletId.contains(PortletConstants.INSTANCE_SEPARATOR)) { String rootPortletId = PortletConstants.getRootPortletId(portletId); resourcePath = theme.getResourcePath(servletContext, rootPortletId, path); } if (Validator.isNotNull(portletId) && !FreeMarkerEngineUtil.resourceExists(resourcePath)) { resourcePath = theme.getResourcePath(servletContext, null, path); } if (!FreeMarkerEngineUtil.resourceExists(resourcePath)) { _log.error(resourcePath + " does not exist"); return null; } FreeMarkerContext freeMarkerContext = FreeMarkerEngineUtil.getWrappedStandardToolsContext(); // FreeMarker variables FreeMarkerVariablesUtil.insertVariables(freeMarkerContext, request); // Theme servlet context ServletContext themeServletContext = ServletContextPool.get(servletContextName); freeMarkerContext.put("themeServletContext", themeServletContext); // Tag libraries HttpServletResponse response = (HttpServletResponse) pageContext.getResponse(); Writer writer = null; if (write) { // Wrapping is needed because of a bug in FreeMarker writer = UnsyncPrintWriterPool.borrow(pageContext.getOut()); } else { writer = new UnsyncStringWriter(); } VelocityTaglib velocityTaglib = new VelocityTaglib(servletContext, request, new PipingServletResponse(response, writer), pageContext); request.setAttribute(WebKeys.VELOCITY_TAGLIB, velocityTaglib); freeMarkerContext.put("taglibLiferay", velocityTaglib); freeMarkerContext.put("theme", velocityTaglib); freeMarkerContext.put("writer", writer); // Portal JSP tag library factory TemplateHashModel portalTaglib = FreeMarkerTaglibFactoryUtil.createTaglibFactory(servletContext); freeMarkerContext.put("PortalJspTagLibs", portalTaglib); // Theme JSP tag library factory TemplateHashModel themeTaglib = FreeMarkerTaglibFactoryUtil.createTaglibFactory(themeServletContext); freeMarkerContext.put("ThemeJspTaglibs", themeTaglib); // FreeMarker JSP tag library support final Servlet servlet = (Servlet) pageContext.getPage(); GenericServlet genericServlet = null; if (servlet instanceof GenericServlet) { genericServlet = (GenericServlet) servlet; } else { genericServlet = new GenericServlet() { @Override public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException { servlet.service(servletRequest, servletResponse); } }; genericServlet.init(pageContext.getServletConfig()); } ServletContextHashModel servletContextHashModel = new ServletContextHashModel(genericServlet, ObjectWrapper.DEFAULT_WRAPPER); freeMarkerContext.put("Application", servletContextHashModel); HttpRequestHashModel httpRequestHashModel = new HttpRequestHashModel(request, response, ObjectWrapper.DEFAULT_WRAPPER); freeMarkerContext.put("Request", httpRequestHashModel); // Merge templates FreeMarkerEngineUtil.mergeTemplate(resourcePath, freeMarkerContext, writer); if (write) { return null; } else { return writer.toString(); } }
From source file:com.liferay.taglib.util.ThemeUtil.java
License:Open Source License
public static String includeVM(ServletContext servletContext, HttpServletRequest request, PageContext pageContext, String page, Theme theme, boolean write) throws Exception { // The servlet context name will be null when the theme is deployed to // the root directory in Tomcat. See // com.liferay.portal.servlet.MainServlet and // com.liferay.portlet.PortletContextImpl for other cases where a null // servlet context name is also converted to an empty string. String servletContextName = GetterUtil.getString(theme.getServletContextName()); if (ServletContextPool.get(servletContextName) == null) { // This should only happen if the Velocity template is the first // page to be accessed in the system ServletContextPool.put(servletContextName, servletContext); }//from www . j a v a 2s . c o m String portletId = getPortletId(request); String resourcePath = theme.getResourcePath(servletContext, portletId, page); boolean checkResourceExists = true; if (Validator.isNotNull(portletId)) { if (portletId.contains(PortletConstants.INSTANCE_SEPARATOR) && (checkResourceExists = !VelocityEngineUtil.resourceExists(resourcePath))) { String rootPortletId = PortletConstants.getRootPortletId(portletId); resourcePath = theme.getResourcePath(servletContext, rootPortletId, page); } if (checkResourceExists && (checkResourceExists = !VelocityEngineUtil.resourceExists(resourcePath))) { resourcePath = theme.getResourcePath(servletContext, null, page); } } if (checkResourceExists && !VelocityEngineUtil.resourceExists(resourcePath)) { _log.error(resourcePath + " does not exist"); return null; } VelocityContext velocityContext = VelocityEngineUtil.getWrappedStandardToolsContext(); // Velocity variables VelocityVariablesUtil.insertVariables(velocityContext, request); // Page context velocityContext.put("pageContext", pageContext); // Theme servlet context ServletContext themeServletContext = ServletContextPool.get(servletContextName); velocityContext.put("themeServletContext", themeServletContext); // Tag libraries HttpServletResponse response = (HttpServletResponse) pageContext.getResponse(); Writer writer = null; if (write) { writer = pageContext.getOut(); } else { writer = new UnsyncStringWriter(); } VelocityTaglib velocityTaglib = new VelocityTaglib(servletContext, request, new PipingServletResponse(response, writer), pageContext); request.setAttribute(WebKeys.VELOCITY_TAGLIB, velocityTaglib); velocityContext.put("taglibLiferay", velocityTaglib); velocityContext.put("theme", velocityTaglib); velocityContext.put("writer", writer); // Merge templates VelocityEngineUtil.mergeTemplate(resourcePath, velocityContext, writer); if (write) { return null; } else { return ((UnsyncStringWriter) writer).toString(); } }