@Override public ActionForward render( ActionMapping mapping, ActionForm form, PortletConfig portletConfig, RenderRequest renderRequest, RenderResponse renderResponse) throws Exception { try { ActionUtil.getEntry(renderRequest); if (PropsValues.BLOGS_PINGBACK_ENABLED) { BlogsEntry entry = (BlogsEntry) renderRequest.getAttribute(WebKeys.BLOGS_ENTRY); if ((entry != null) && entry.isAllowPingbacks()) { HttpServletResponse response = PortalUtil.getHttpServletResponse(renderResponse); response.addHeader( "X-Pingback", PortalUtil.getPortalURL(renderRequest) + "/xmlrpc/pingback"); } } } catch (Exception e) { if (e instanceof NoSuchEntryException || e instanceof PrincipalException) { SessionErrors.add(renderRequest, e.getClass().getName()); return mapping.findForward("portlet.blogs.error"); } else { throw e; } } return mapping.findForward(getForward(renderRequest, "portlet.blogs.edit_entry")); }
@Override public String render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException { try { ActionUtil.getEntry(renderRequest); if (PropsValues.BLOGS_PINGBACK_ENABLED) { BlogsEntry entry = (BlogsEntry) renderRequest.getAttribute(WebKeys.BLOGS_ENTRY); if ((entry != null) && entry.isAllowPingbacks()) { HttpServletResponse response = PortalUtil.getHttpServletResponse(renderResponse); response.addHeader( "X-Pingback", PortalUtil.getPortalURL(renderRequest) + "/xmlrpc/pingback"); } } } catch (Exception e) { if (e instanceof NoSuchEntryException || e instanceof PrincipalException) { SessionErrors.add(renderRequest, e.getClass()); return "/html/portlet/blogs/error.jsp"; } else { throw new PortletException(e); } } long assetCategoryId = ParamUtil.getLong(renderRequest, "categoryId"); String assetCategoryName = ParamUtil.getString(renderRequest, "tag"); if ((assetCategoryId > 0) || Validator.isNotNull(assetCategoryName)) { return "/html/portlet/blogs/view.jsp"; } return getPath(); }
@Override protected void doImportStagedModel(PortletDataContext portletDataContext, BlogsEntry entry) throws Exception { long userId = portletDataContext.getUserId(entry.getUserUuid()); Element entryElement = portletDataContext.getImportDataStagedModelElement(entry); String content = _blogsEntryExportImportContentProcessor.replaceImportContentReferences( portletDataContext, entry, entry.getContent()); entry.setContent(content); Calendar displayDateCal = CalendarFactoryUtil.getCalendar(); displayDateCal.setTime(entry.getDisplayDate()); int displayDateMonth = displayDateCal.get(Calendar.MONTH); int displayDateDay = displayDateCal.get(Calendar.DATE); int displayDateYear = displayDateCal.get(Calendar.YEAR); int displayDateHour = displayDateCal.get(Calendar.HOUR); int displayDateMinute = displayDateCal.get(Calendar.MINUTE); if (displayDateCal.get(Calendar.AM_PM) == Calendar.PM) { displayDateHour += 12; } boolean allowPingbacks = entry.isAllowPingbacks(); boolean allowTrackbacks = entry.isAllowTrackbacks(); String[] trackbacks = StringUtil.split(entry.getTrackbacks()); ServiceContext serviceContext = portletDataContext.createServiceContext(entry); BlogsEntry importedEntry = null; if (portletDataContext.isDataStrategyMirror()) { serviceContext.setAttribute("urlTitle", entry.getUrlTitle()); BlogsEntry existingEntry = fetchStagedModelByUuidAndGroupId(entry.getUuid(), portletDataContext.getScopeGroupId()); if (existingEntry == null) { serviceContext.setUuid(entry.getUuid()); importedEntry = _blogsEntryLocalService.addEntry( userId, entry.getTitle(), entry.getSubtitle(), entry.getDescription(), entry.getContent(), displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, allowPingbacks, allowTrackbacks, trackbacks, entry.getCoverImageCaption(), null, null, serviceContext); } else { importedEntry = _blogsEntryLocalService.updateEntry( userId, existingEntry.getEntryId(), entry.getTitle(), entry.getSubtitle(), entry.getDescription(), entry.getContent(), displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, allowPingbacks, allowTrackbacks, trackbacks, entry.getCoverImageCaption(), new ImageSelector(), new ImageSelector(), serviceContext); } } else { importedEntry = _blogsEntryLocalService.addEntry( userId, entry.getTitle(), entry.getSubtitle(), entry.getDescription(), entry.getContent(), displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, allowPingbacks, allowTrackbacks, trackbacks, entry.getCoverImageCaption(), null, null, serviceContext); } if ((entry.getCoverImageFileEntryId() == 0) && Validator.isNull(entry.getCoverImageURL()) && (entry.getSmallImageFileEntryId() == 0) && Validator.isNull(entry.getSmallImageURL()) && !entry.isSmallImage()) { portletDataContext.importClassedModel(entry, importedEntry); return; } // Cover image ImageSelector coverImageSelector = null; List<Element> attachmentElements = portletDataContext.getReferenceDataElements( entry, DLFileEntry.class, PortletDataContext.REFERENCE_TYPE_WEAK); if (Validator.isNotNull(entry.getCoverImageURL())) { coverImageSelector = new ImageSelector(entry.getCoverImageURL()); } else if (entry.getCoverImageFileEntryId() != 0) { coverImageSelector = _getImageSelector( portletDataContext, entry.getCoverImageFileEntryId(), attachmentElements); } if (coverImageSelector != null) { _blogsEntryLocalService.addCoverImage(importedEntry.getEntryId(), coverImageSelector); } // Small image ImageSelector smallImageSelector = null; if (entry.isSmallImage()) { String smallImagePath = entryElement.attributeValue("small-image-path"); if (Validator.isNotNull(entry.getSmallImageURL())) { smallImageSelector = new ImageSelector(entry.getSmallImageURL()); } else if (Validator.isNotNull(smallImagePath)) { String smallImageFileName = entry.getSmallImageId() + StringPool.PERIOD + entry.getSmallImageType(); InputStream inputStream = null; try { inputStream = portletDataContext.getZipEntryAsInputStream(smallImagePath); smallImageSelector = new ImageSelector( FileUtil.getBytes(inputStream), smallImageFileName, MimeTypesUtil.getContentType(smallImageFileName), null); } finally { StreamUtil.cleanUp(inputStream); } } else if (entry.getSmallImageFileEntryId() != 0) { smallImageSelector = _getImageSelector( portletDataContext, entry.getSmallImageFileEntryId(), attachmentElements); } } if (smallImageSelector != null) { _blogsEntryLocalService.addSmallImage(importedEntry.getEntryId(), smallImageSelector); } if ((coverImageSelector != null) || (smallImageSelector != null)) { importedEntry = _blogsEntryLocalService.getBlogsEntry(importedEntry.getEntryId()); } portletDataContext.importClassedModel(entry, importedEntry); }