/** * Returns the content for a particular BlogPost, based on what content setting the user has specified (titles, excerpts or entire) * * @param post the BlogPost * @param contentType the content type to be returned * @return the content of the BlogPost */ private String getContent(BlogPost post, String contentType) { String excerpt; if (CONTENT_EXCERPTS.equals(contentType)) { excerpt = excerptHelper.getExcerpt(post); // If page does not have an excerpt macro declared than calculate one manually from the whole body if (StringUtils.isBlank(excerpt)) { excerpt = excerptHelper.getText(post.getBodyAsString()); // CONFDEV-3633 // the excerptHelper returns element contents. If the element contained a CDATA with further markup // (e.g. in the case of a code macro showing XML code) then the excerpt will appear to contain // markup. Encode it. if (excerpt.length() > EXCERPT_LENGTH) { excerpt = GeneralUtil.htmlEncode(TextUtils.trimToEndingChar(excerpt, EXCERPT_LENGTH)) + "…"; } else { excerpt = GeneralUtil.htmlEncode(excerpt); } return excerpt; } } else { excerpt = post.getBodyAsString(); } return excerpt; }
@Override public Map<String, ?> getBlogPost(String authenticationToken, String id) { Map<String, Object> postStructure = null; BlogPost post = getPageManager().getBlogPost(Long.parseLong(id)); if (null != post && permissionManager.hasPermission(AuthenticatedUserThreadLocal.getUser(), Permission.VIEW, post)) { postStructure = new Hashtable<String, Object>(); postStructure.put("id", post.getIdAsString()); postStructure.put("spaceKey", post.getSpaceKey()); postStructure.put("title", post.getTitle()); postStructure.put("version", post.getVersion()); postStructure.put("content", post.getBodyAsString()); if (StringUtils.isNotBlank(post.getCreatorName())) postStructure.put("creator", post.getCreatorName()); postStructure.put("created", post.getCreationDate()); } return postStructure; } }