@Override protected byte[] getRSS(HttpServletRequest request) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); Layout layout = themeDisplay.getLayout(); long plid = ParamUtil.getLong(request, "p_l_id"); if (plid == LayoutConstants.DEFAULT_PLID) { plid = themeDisplay.getPlid(); } long companyId = ParamUtil.getLong(request, "companyId"); long groupId = ParamUtil.getLong(request, "groupId"); long organizationId = ParamUtil.getLong(request, "organizationId"); int status = WorkflowConstants.STATUS_APPROVED; int max = ParamUtil.getInteger(request, "max", SearchContainer.DEFAULT_DELTA); String type = ParamUtil.getString(request, "type", RSSUtil.FORMAT_DEFAULT); double version = ParamUtil.getDouble(request, "version", RSSUtil.VERSION_DEFAULT); String displayStyle = ParamUtil.getString(request, "displayStyle", RSSUtil.DISPLAY_STYLE_DEFAULT); String feedURL = themeDisplay.getPortalURL() + themeDisplay.getPathMain() + "/blogs/find_entry?"; String entryURL = feedURL; String rss = StringPool.BLANK; if (companyId > 0) { feedURL = StringPool.BLANK; rss = _blogsEntryService.getCompanyEntriesRSS( companyId, new Date(), status, max, type, version, displayStyle, feedURL, entryURL, themeDisplay); } else if (groupId > 0) { feedURL += "p_l_id=" + plid; entryURL = feedURL; rss = _blogsEntryService.getGroupEntriesRSS( groupId, new Date(), status, max, type, version, displayStyle, feedURL, entryURL, themeDisplay); } else if (organizationId > 0) { feedURL = StringPool.BLANK; rss = _blogsEntryService.getOrganizationEntriesRSS( organizationId, new Date(), status, max, type, version, displayStyle, feedURL, entryURL, themeDisplay); } else if (layout != null) { groupId = themeDisplay.getScopeGroupId(); feedURL = themeDisplay.getPathMain() + "/blogs/rss"; entryURL = feedURL; rss = _blogsEntryService.getGroupEntriesRSS( groupId, new Date(), status, max, type, version, displayStyle, feedURL, entryURL, themeDisplay); } return rss.getBytes(StringPool.UTF8); }
@Override public void sendRequest( ThemeDisplay themeDisplay, ActionRequest actionRequest, ActionResponse actionResponse) throws PortalException { HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest); request = PortalUtil.getOriginalServletRequest(request); HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse); HttpSession session = request.getSession(); LiferayPortletResponse liferayPortletResponse = PortalUtil.getLiferayPortletResponse(actionResponse); String openId = ParamUtil.getString(actionRequest, "openId"); PortletURL portletURL = liferayPortletResponse.createActionURL(); portletURL.setParameter(ActionRequest.ACTION_NAME, "/login/openid"); portletURL.setParameter("saveLastPath", Boolean.FALSE.toString()); portletURL.setParameter("mvcRenderCommandName", "/login/openid"); portletURL.setParameter(Constants.CMD, Constants.READ); try { List<DiscoveryInformation> discoveryInformationList = _consumerManager.discover(openId); DiscoveryInformation discoveryInformation = _consumerManager.associate(discoveryInformationList); session.setAttribute(OpenIdWebKeys.OPEN_ID_DISCO, discoveryInformation); AuthRequest authRequest = _consumerManager.authenticate( discoveryInformation, portletURL.toString(), themeDisplay.getPortalURL()); if (_userLocalService.fetchUserByOpenId(themeDisplay.getCompanyId(), openId) != null) { response.sendRedirect(authRequest.getDestinationUrl(true)); return; } String screenName = getScreenName(openId); User user = _userLocalService.fetchUserByScreenName(themeDisplay.getCompanyId(), screenName); if (user != null) { _userLocalService.updateOpenId(user.getUserId(), openId); response.sendRedirect(authRequest.getDestinationUrl(true)); return; } FetchRequest fetchRequest = FetchRequest.createFetchRequest(); OpenIdProvider openIdProvider = _openIdProviderRegistry.getOpenIdProvider(discoveryInformation.getOPEndpoint()); Map<String, String> openIdAXTypes = openIdProvider.getAxTypes(); for (String openIdAXType : openIdAXTypes.keySet()) { fetchRequest.addAttribute(openIdAXType, openIdAXTypes.get(openIdAXType), true); } authRequest.addExtension(fetchRequest); SRegRequest sRegRequest = SRegRequest.createFetchRequest(); sRegRequest.addAttribute(_OPEN_ID_SREG_ATTR_EMAIL, true); sRegRequest.addAttribute(_OPEN_ID_SREG_ATTR_FULLNAME, true); authRequest.addExtension(sRegRequest); response.sendRedirect(authRequest.getDestinationUrl(true)); } catch (ConsumerException ce) { throw new OpenIdServiceException.ConsumerException(ce.getMessage(), ce); } catch (DiscoveryException de) { throw new OpenIdServiceException.DiscoveryException(de.getMessage(), de); } catch (MessageException me) { throw new OpenIdServiceException.MessageException(me.getMessage(), me); } catch (IOException ioe) { throw new SystemException("Unable to communicate with OpenId provider", ioe); } }
public void sendFile( String targetExtension, PortletRequest portletRequest, PortletResponse portletResponse) throws IOException { if (Validator.isNull(targetExtension)) { return; } long groupId = ParamUtil.getLong(portletRequest, "groupId"); String articleId = ParamUtil.getString(portletRequest, "articleId"); String languageId = LanguageUtil.getLanguageId(portletRequest); PortletRequestModel portletRequestModel = new PortletRequestModel(portletRequest, portletResponse); ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); HttpServletRequest request = PortalUtil.getHttpServletRequest(portletRequest); HttpServletResponse response = PortalUtil.getHttpServletResponse(portletResponse); JournalArticleDisplay articleDisplay = _journalContent.getDisplay( groupId, articleId, null, "export", languageId, 1, portletRequestModel, themeDisplay); int pages = articleDisplay.getNumberOfPages(); StringBundler sb = new StringBundler(pages + 12); sb.append("<html>"); sb.append("<head>"); sb.append("<meta content=\""); sb.append(ContentTypes.TEXT_HTML_UTF8); sb.append("\" http-equiv=\"content-type\" />"); sb.append("<base href=\""); sb.append(themeDisplay.getPortalURL()); sb.append("\" />"); sb.append("</head>"); sb.append("<body>"); sb.append(articleDisplay.getContent()); for (int i = 2; i <= pages; i++) { articleDisplay = _journalContent.getDisplay(groupId, articleId, "export", languageId, i, themeDisplay); sb.append(articleDisplay.getContent()); } sb.append("</body>"); sb.append("</html>"); InputStream is = new UnsyncByteArrayInputStream(sb.toString().getBytes(StringPool.UTF8)); String title = articleDisplay.getTitle(); String sourceExtension = "html"; String fileName = title.concat(StringPool.PERIOD).concat(sourceExtension); String contentType = ContentTypes.TEXT_HTML; String id = DLUtil.getTempFileId( articleDisplay.getId(), String.valueOf(articleDisplay.getVersion()), languageId); File convertedFile = DocumentConversionUtil.convert(id, is, sourceExtension, targetExtension); if (convertedFile != null) { targetExtension = StringUtil.toLowerCase(targetExtension); fileName = title.concat(StringPool.PERIOD).concat(targetExtension); contentType = MimeTypesUtil.getContentType(fileName); is = new FileInputStream(convertedFile); } ServletResponseUtil.sendFile(request, response, fileName, is, contentType); }