List of usage examples for com.liferay.portal.kernel.servlet BufferCacheServletResponse getString
public String getString() throws IOException
From source file:com.fb.filter.OpenGraphFilter.java
License:Open Source License
@Override protected void processFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws Exception { request.setAttribute(SKIP_FILTER, Boolean.TRUE); if (_log.isDebugEnabled()) { String completeURL = HttpUtil.getCompleteURL(request); _log.debug("Adding Open Graph Attributes " + completeURL); }/*from ww w. ja v a 2 s . c o m*/ BufferCacheServletResponse bufferCacheServletResponse = new BufferCacheServletResponse(response); processFilter(OpenGraphFilter.class, request, bufferCacheServletResponse, filterChain); String content = bufferCacheServletResponse.getString(); String contentType = response.getContentType(); if ((contentType != null) && contentType.startsWith(ContentTypes.TEXT_HTML)) { content = getContent(request, content); ServletResponseUtil.write(response, content); } else { ServletResponseUtil.write(response, bufferCacheServletResponse); } }
From source file:com.liferay.adaptive.media.blogs.web.internal.filter.BlogsPortletFilter.java
License:Open Source License
@Override public void doFilter(RenderRequest renderRequest, RenderResponse renderResponse, FilterChain filterChain) throws IOException, PortletException { filterChain.doFilter(renderRequest, renderResponse); String mvcRenderCommandName = ParamUtil.getString(renderRequest, "mvcRenderCommandName"); if (!mvcRenderCommandName.equals("/blogs/view_entry")) { return;/*from ww w .ja v a 2 s . c o m*/ } HttpServletResponse httpServletResponse = _portal.getHttpServletResponse(renderResponse); BufferCacheServletResponse bufferCacheServletResponse = (BufferCacheServletResponse) httpServletResponse; String content = bufferCacheServletResponse.getString(); String transformedContent = _contentTransformerHandler.transform(ContentTransformerContentTypes.HTML, content); ServletResponseUtil.write(httpServletResponse, transformedContent); }
From source file:com.liferay.content.targeting.analytics.hook.filter.YoutubeVideoHtmlFilter.java
License:Open Source License
@Override protected void processFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws Exception { request.setAttribute(SKIP_FILTER, Boolean.TRUE); if (_log.isDebugEnabled()) { String completeURL = HttpUtil.getCompleteURL(request); _log.debug("Processing Youtube URLs for " + completeURL); }/*from w w w .j a v a2 s . c o m*/ BufferCacheServletResponse bufferCacheServletResponse = new BufferCacheServletResponse(response); processFilter(YoutubeVideoHtmlFilter.class, request, bufferCacheServletResponse, filterChain); String content = bufferCacheServletResponse.getString(); String contentType = response.getContentType(); if ((contentType != null) && contentType.startsWith(ContentTypes.TEXT_HTML)) { content = getContent(request, content); ServletResponseUtil.write(response, content); } else { ServletResponseUtil.write(response, bufferCacheServletResponse); } }
From source file:com.liferay.portlet.webproxy.WebProxyBasicAuthPortlet.java
License:Open Source License
@Override public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { if (!_enabled) { printError(renderResponse);/*from w ww . ja v a2s . c o m*/ return; } PortletPreferences preferences = renderRequest.getPreferences(); String initUrl = preferences.getValue("initUrl", StringPool.BLANK); if (Validator.isNull(initUrl)) { PortletContext portletContext = getPortletContext(); PortletRequestDispatcher portletRequestDispatcher = portletContext .getRequestDispatcher("/html/portal/portlet_not_setup.jsp"); portletRequestDispatcher.include(renderRequest, renderResponse); } else { super.doView(renderRequest, renderResponse); /* RenderResponseImpl renderResponseImpl = (RenderResponseImpl)renderResponse; */ BufferCacheServletResponse bufferCacheServletResponse = (BufferCacheServletResponse) PortalUtil .getHttpServletResponse(renderResponse); //renderResponse.getHttpServletResponse(); String output = bufferCacheServletResponse.getString(); output = StringUtil.replace(output, "//pbhs/", renderRequest.getContextPath() + "/pbhs/"); output = StringUtil.replace(output, renderRequest.getContextPath() + "/pbhs/", "/delegate" + "/pbhs/"); bufferCacheServletResponse.setString(output); } }
From source file:com.liferay.rtl.servlet.filters.dynamiccss.DynamicCSSFilter.java
License:Open Source License
protected Object getDynamicContent(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws Exception { String requestURI = request.getRequestURI(); String requestPath = requestURI; String contextPath = request.getContextPath(); if (!contextPath.equals(StringPool.SLASH)) { requestPath = requestPath.substring(contextPath.length()); }/*from w w w .j a va 2 s . c o m*/ URL resourceURL = _servletContext.getResource(requestPath); if (resourceURL == null) { return null; } URLConnection urlConnection = resourceURL.openConnection(); String cacheCommonFileName = getCacheFileName(request); File cacheContentTypeFile = new File(_tempDir, cacheCommonFileName + "_E_CONTENT_TYPE"); File cacheDataFile = new File(_tempDir, cacheCommonFileName + "_E_DATA"); if (cacheDataFile.exists() && (cacheDataFile.lastModified() >= urlConnection.getLastModified())) { if (cacheContentTypeFile.exists()) { String contentType = FileUtil.read(cacheContentTypeFile); response.setContentType(contentType); } return cacheDataFile; } String dynamicContent = null; String content = null; try { if (requestPath.endsWith(_CSS_EXTENSION)) { if (_log.isInfoEnabled()) { _log.info("Parsing SASS on CSS " + requestPath); } content = StringUtil.read(urlConnection.getInputStream()); dynamicContent = DynamicCSSUtil.parseSass(_servletContext, request, requestPath, content); response.setContentType(ContentTypes.TEXT_CSS); FileUtil.write(cacheContentTypeFile, ContentTypes.TEXT_CSS); } else if (requestPath.endsWith(_JSP_EXTENSION)) { if (_log.isInfoEnabled()) { _log.info("Parsing SASS on JSP or servlet " + requestPath); } BufferCacheServletResponse bufferCacheServletResponse = new BufferCacheServletResponse(response); processFilter(DynamicCSSFilter.class, request, bufferCacheServletResponse, filterChain); bufferCacheServletResponse.finishResponse(); content = bufferCacheServletResponse.getString(); dynamicContent = DynamicCSSUtil.parseSass(_servletContext, request, requestPath, content); FileUtil.write(cacheContentTypeFile, bufferCacheServletResponse.getContentType()); } else { return null; } } catch (Exception e) { _log.error("Unable to parse SASS on CSS " + requestPath, e); if (_log.isDebugEnabled()) { _log.debug(content); } response.setHeader(HttpHeaders.CACHE_CONTROL, HttpHeaders.CACHE_CONTROL_NO_CACHE_VALUE); } if (dynamicContent != null) { FileUtil.write(cacheDataFile, dynamicContent); } else { dynamicContent = content; } return dynamicContent; }
From source file:com.liferay.web.proxy.web.internal.portlet.WebProxyPortlet.java
License:Open Source License
@Override public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { if (!_enabled) { printError(renderResponse);//from w w w . j av a2 s .co m return; } PortletPreferences portletPreferences = renderRequest.getPreferences(); String initUrl = portletPreferences.getValue("initUrl", StringPool.BLANK); if (Validator.isNull(initUrl)) { PortletContext portletContext = getPortletContext(); PortletRequestDispatcher portletRequestDispatcher = portletContext .getRequestDispatcher("/portlet_not_setup.jsp"); portletRequestDispatcher.include(renderRequest, renderResponse); } else { super.doView(renderRequest, renderResponse); RenderResponseImpl renderResponseImpl = (RenderResponseImpl) renderResponse; BufferCacheServletResponse bufferCacheServletResponse = (BufferCacheServletResponse) renderResponseImpl .getHttpServletResponse(); String output = bufferCacheServletResponse.getString(); output = StringUtil.replace(output, "//pbhs/", renderRequest.getContextPath() + "/pbhs/"); bufferCacheServletResponse.setString(output); } }