/wolfengine-core/src/main/java/com/sfeir/wolfengine/server/servlet/renderer/impl/StoryHtmlRenderer.java
Java | 661 lines | 519 code | 64 blank | 78 comment | 118 complexity | 1fbcf2bbc3ade1772c5e4643f4354fd0 MD5 | raw file
Possible License(s): CC0-1.0
- package com.sfeir.wolfengine.server.servlet.renderer.impl;
-
- import java.io.IOException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import java.util.ListIterator;
- import java.util.Random;
-
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
-
- import com.google.appengine.api.datastore.Key;
- import com.google.appengine.api.datastore.KeyFactory;
- import com.google.appengine.api.users.User;
- import com.google.appengine.api.users.UserServiceFactory;
- import com.google.inject.Guice;
- import com.google.inject.Inject;
- import com.google.inject.Injector;
- import com.google.inject.name.Named;
- import com.sfeir.wolfengine.client.model.entity.SearchResult;
- import com.sfeir.wolfengine.server.entity.Story;
- import com.sfeir.wolfengine.server.entity.datamanagement.Category;
- import com.sfeir.wolfengine.server.entity.datamanagement.Comment;
- import com.sfeir.wolfengine.server.entity.datamanagement.HitsLink;
- import com.sfeir.wolfengine.server.entity.datamanagement.HitsTag;
- import com.sfeir.wolfengine.server.guice.WolfEngineModule;
- import com.sfeir.wolfengine.server.servlet.model.StoryModel;
-
- /**
- * This class implements the HTML rendering of BlogPost objects.
- *
- * @author Sfeir
- */
- public class StoryHtmlRenderer extends HtmlRenderer<StoryModel> {
- public static class PostMessages extends Messages {
- @Inject
- @Named("message.allTags")
- public String allTags;
- @Inject
- @Named("message.categories")
- public String categories;
- @Inject
- @Named("message.comments")
- public String comments;
- @Inject
- @Named("message.email")
- public String email;
- @Inject
- @Named("message.feedRss")
- public String feedRss;
- @Inject
- @Named("message.feedRssInfo")
- public String feedRssInfo;
- @Inject
- @Named("message.htmlAndEmailMessageInfo")
- public String htmlAndEmailMessageInfo;
- @Inject
- @Named("message.links")
- public String links;
- @Inject
- @Named("message.listLinks")
- public String listLinks;
- @Inject
- @Named("message.logoImage")
- public String logoImage;
- @Inject
- @Named("message.logoUrl")
- public String logoUrl;
- @Inject
- @Named("message.next")
- public String next;
- @Inject
- @Named("message.noComment")
- public String noComment;
- @Inject
- @Named("message.noContent")
- public String noContent;
- @Inject
- @Named("message.oneComment")
- public String oneComment;
- @Inject
- @Named("message.prev")
- public String prev;
- @Inject
- @Named("message.propulsed")
- public String propulsed;
- @Inject
- @Named("message.pseudo")
- public String pseudo;
- @Inject
- @Named("message.syndication")
- public String syndication;
- @Inject
- @Named("message.tags")
- public String tags;
- @Inject
- @Named("message.unknownDate")
- public String unknownDate;
- @Inject
- @Named("message.website")
- public String website;
- @Inject
- @Named("message.send")
- public String send;
- @Inject
- @Named("message.addComment")
- public String addComment;
- @Inject
- @Named("message.starredstories")
- public String starredstories;
- }
-
- private static Log log = LogFactory.getLog(StoryHtmlRenderer.class);
-
- // Date formatter used to created dates like : Lundi 10 d?cembre 2006
- private SimpleDateFormat sdf = new SimpleDateFormat("EEEEEE dd MMMM yyyy");
-
- // Date formatter used to created dates like : Lundi 10 d?cembre 2006 12:56
- private SimpleDateFormat sdfWithHour = new SimpleDateFormat("EEEEEE dd MMMM yyyy hh:mm");
-
- // StringBuilder used to store HtmlContent to display
- private StringBuilder stringBuilder;
-
- protected void buildCategories(List<Category> categories) {
- stringBuilder.append("<div class=\"categories\"><h2>");
- stringBuilder.append(getMessage().categories);
- stringBuilder.append("</h2><ul>");
- for (Category category : categories) {
- stringBuilder.append("<li><a href=\"");
- stringBuilder.append(getMessage().CATEGORY_URL.replace("{NAME}", category.getUrl()));
- stringBuilder.append("\">");
- stringBuilder.append(category.getName());
- stringBuilder.append("</a></li>");
- }
- stringBuilder.append("</ul></div>");
- }
-
- protected void buildStarredStories(SearchResult<Story> searchResult) {
- stringBuilder.append("<div class=\"starredstories\"><h2>");
- stringBuilder.append(getMessage().starredstories);
- stringBuilder.append("</h2><ul>");
- for (Story story : searchResult.getItems()) {
- stringBuilder.append("<li><a href=\"");
- stringBuilder.append(getMessage().POST_URL + story.getUrl());
- stringBuilder.append("\">");
- stringBuilder.append(story.getTitle());
- stringBuilder.append("</a></li>");
- }
- stringBuilder.append("</ul></div>");
- }
-
- private void buildFooter(StoryModel model) {
- stringBuilder.append("</div></div><div id=\"sidebar\"><div id=\"blognav\"><div class=\"text\"><a href=\"");
- stringBuilder.append(getMessage().logoUrl);
- stringBuilder.append("\"><img src=\"");
- stringBuilder.append(getMessage().logoImage);
- stringBuilder.append("\" /></a></div><div id=\"topnav\"><ul></ul></div>");
-
- buildTags(model.getTags());
-
- buildCategories(model.getCategories());
-
- buildStarredStories(model.getStarredSories());
-
- stringBuilder.append("</div><div id=\"blogextra\"><div class=\"syndicate\"><h2>");
- stringBuilder.append(getMessage().syndication);
- stringBuilder.append("</h2><ul><li><a type=\"application/rss+xml\" href=\"");
- stringBuilder.append(getMessage().FEED_URL);
- stringBuilder.append("\" title=\"");
- stringBuilder.append(getMessage().feedRssInfo);
- stringBuilder.append("\" class=\"feed\">");
- stringBuilder.append(getMessage().feedRss);
- stringBuilder.append("</a></li>");
- stringBuilder.append("</ul></div><div class=\"links\"><h2>");
- stringBuilder.append(getMessage().links);
- stringBuilder.append("</h2>");
- stringBuilder.append(getMessage().listLinks);
- stringBuilder.append("</div></div></div></div><div id=\"footer\"><p>");
- stringBuilder.append(getMessage().propulsed);
- stringBuilder.append("</p></div></div></body></html>");
- }
-
- private void buildHeader() {
-
- String result = "<html><head><title>"
- + this.title
- + "</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /><style type=\"text/css\" media=\"print\">@import url(/ressource/css/print.css);</style><style type=\"text/css\">@import url(/ressource/css/custom_style.css);</style><link rel=\"alternate\" type=\"application/xml\" title=\"rss 2.0\" href=\"" + getMessage().FEED_URL + "\" /></head><body class=\"dc-home\"><div id=\"page\"><div id=\"top\"><h1><span><a href=\"" + getMessage().HOST_INDEX
- + "\">" + this.title + "</a></span></h1></div><p id=\"prelude\"><a href=\"#main\">"
- + getMessage().gotoContent + "</a> | <a href=\"#blognav\">" + getMessage().gotoMenu + "</a> | <a href=\"#search\">" + getMessage().gotoSearch
- + "</a></p><div id=\"wrapper\"><div id=\"main\"><div id=\"content\">";
- stringBuilder.insert(0, result); // To add the title
-
- }
-
- /**
- * Build a representation of the most used tags
- *
- * @param result
- * @param tags
- * @return Tags HTML representation
- */
- protected void buildTags(List<HitsTag> tags) {
- // Default max value
- long max = 100;
- if (tags != null && !tags.isEmpty() && tags.get(0).getHits() != null)
- max = tags.get(0).getHits();
-
- stringBuilder.append("<div class=\"content-inner\"><div class=\"tags\"><h2>");
- stringBuilder.append(getMessage().tags);
- stringBuilder.append("</h2><ul>");
- if (null == tags) {
- stringBuilder.append("<li>No tags</li>");
- } else {
- Long tagOccurency;
- Integer compteur = 0;
- ListIterator<HitsTag> iterator = tags.listIterator();
- while (iterator.hasNext() && compteur < 20) {
- HitsTag tag = iterator.next();
- compteur++;
- if (tag.getHits() != null)
- tagOccurency = ((tag.getHits().intValue() * 100) / max);
- else
- tagOccurency = 0l;
- stringBuilder.append("<li><a href=\"");
- stringBuilder.append(getMessage().TAG_URL.replace("{NAME}", tag.getName()));
- stringBuilder.append("\" class=\"tag");
- stringBuilder.append(getTagRate(tagOccurency));
- stringBuilder.append("\">");
- stringBuilder.append(tag.getName());
- stringBuilder.append("</a> </li>");
- }
- }
- stringBuilder.append("</ul><p><strong><a href=\"");
- stringBuilder.append(getMessage().TAGS_URL);
- stringBuilder.append("\">");
- stringBuilder.append(getMessage().allTags);
- stringBuilder.append("</a></strong></p></div></div>");
- }
-
- @Override
- protected PostMessages createMessages() {
- return new PostMessages();
- }
-
- /**
- * Return the content to display according to the view's context (list,
- * specific item, ...) Content is added to a global and shared StringBuilder
- * and returned at the end The StringBuilder's content is trashed at each
- * call
- */
- @Override
- protected String getHtmlRepresentation(StoryModel model) throws Exception {
- log.info("<StoryHtmlRenderer.getHtmlRepresentation>" + System.currentTimeMillis());
-
- // main content
- stringBuilder = new StringBuilder();
- // Display a list
- if (model.isMultiplePostMode()) {
-
- // Add the content of the posts list to the string Builder
- writeListOfPosts(model.getStories(), model);
- log.info("<StoryHtmlRenderer.getHtmlRepresentation.1>" + System.currentTimeMillis());
-
- // Add the pager to the String Builder according to the number of
- // posts
- writePagination(model);
- log.info("<StoryHtmlRenderer.getHtmlRepresentation.2>" + System.currentTimeMillis());
-
- }// Display a specific post
- else if (model.getViewMode().equals(StoryModel.PostViewModeEnum.DETAILED_MODE)) {
- // Get the post and add its html representation to the StringBuilder
- Story blogPostToDisplay = model.getStories().get(0);
- this.title += " - " + blogPostToDisplay.getTitle();
- log.info("<StoryHtmlRenderer.getHtmlRepresentation.3>" + System.currentTimeMillis());
-
- writeDetailedPost(blogPostToDisplay, model, false, true);
- log.info("<StoryHtmlRenderer.getHtmlRepresentation.4>" + System.currentTimeMillis());
-
- } else if (model.getViewMode().equals(StoryModel.PostViewModeEnum.TAGS)) {
- writeTagsCloud(model);
- } else
- throw new IllegalArgumentException("Bad view mode : " + model.getViewMode());
-
- // footer
- log.info("<StoryHtmlRenderer.getHtmlRepresentation.5>" + System.currentTimeMillis());
-
- buildFooter(model);
- buildHeader(); // To add the title after
- String result = stringBuilder.toString();
- log.info("</StoryHtmlRenderer.getHtmlRepresentation>" + System.currentTimeMillis());
-
- return result;
- }
-
- protected PostMessages getMessage() {
- if (messages == null) {
- messages = createMessages();
- Injector injector = Guice.createInjector(new WolfEngineModule(this));
- injector.injectMembers(messages);
- }
- return (PostMessages) messages;
- }
-
- /**
- * Method that return the size that the tag shoud be displayed with
- *
- * @param tagOccurency
- * @return font size value
- */
- private String getTagRate(Long tagOccurency) {
- String occurencyString = tagOccurency.toString().charAt(0) + "";
- if (tagOccurency < 10 && tagOccurency > 0)
- return "10";
- for (int i = 0; i < tagOccurency.toString().length() - 1; i++)
- occurencyString += 0;
- return occurencyString;
- }
-
- private String replaceLinks(String text) {
- text = text.replace("<", "<").replace(">", ">");
- return text.replaceAll("(http://\\S*)", "<a href=\"$1\" rel=\"nofollow\">$1</a>").replaceAll("\\n", "<br/>").replaceAll("(\\S*)@(\\S*)",
- "<a href=\"#\" onclick=\"window.location=[\'$2\',\'@\',\'$1\',\'://\',\'to\', \'mail\'].reverse().join(\'\'); return false;\" rel=\"nofollow\">$1[@]$2</a>");
- }
-
-
- /**
- * Add the form to post comments to a post into the StringBuffer
- *
- * @param story
- */
- private void writeCommentsForm(Story story, StoryModel model) {
- Boolean areCommentsAllowed = true;
- if (model != null && model.getSetupInfo() != null) {
- areCommentsAllowed = model.areCommentsAllowed(story, model.getSetupInfo().getCommentsAllowedTime());
- } else {
- areCommentsAllowed = model.areCommentsAllowed(story, null);
- }
- if (areCommentsAllowed) {
- User user = UserServiceFactory.getUserService().getCurrentUser();
- Comment currComment = model.getCurrComment();
- if (model.getCommentError() != null) {
- stringBuilder.append("<p class=\"error\">" + model.getCommentError() + "</p>");
- }
- stringBuilder.append("<form action=\"" + getMessage().COMMENT_URL.replace("{POST_URL}", story.getUrl()) + "\" method=\"post\" id=\"comment-form\">");
- stringBuilder.append("<h3>");
- stringBuilder.append(getMessage().addComment);
- stringBuilder.append("</h3>");
- stringBuilder.append("<fieldset>");
- stringBuilder.append("<p class=\"field\"><label for=\"c_name\">");
- stringBuilder.append(getMessage().pseudo);
- stringBuilder.append(" :</label>");
- stringBuilder.append("<input name=\"c_name\" id=\"c_name\" type=\"text\" size=\"30\" maxlength=\"255\" value=\"");
- if (currComment != null && currComment.getAlias() != null) {
- stringBuilder.append(currComment.getAlias());
- } else if (user != null) {
- stringBuilder.append(user.getNickname());
- }
- stringBuilder.append("\"/>");
- stringBuilder.append("</p>");
- stringBuilder.append("<p class=\"field\"><label for=\"c_mail\">");
- stringBuilder.append(getMessage().email);
- stringBuilder.append(" :</label>");
- stringBuilder.append("<input name=\"c_mail\" id=\"c_mail\" type=\"text\" size=\"30\" maxlength=\"255\" value=\"");
- if (currComment != null && currComment.getEmail() != null) {
- stringBuilder.append(currComment.getEmail());
- } else if (user != null) {
- stringBuilder.append(user.getEmail());
- }
- stringBuilder.append("\" />");
- stringBuilder.append("</p>");
- stringBuilder.append("<p class=\"field\"><label for=\"c_site\">");
- stringBuilder.append(getMessage().website);
- stringBuilder.append(" :</label>");
- stringBuilder.append("<input name=\"c_site\" id=\"c_site\" type=\"text\" size=\"30\" maxlength=\"255\" value=\"");
- if ((currComment != null && currComment.getWebSite() != null))
- stringBuilder.append(currComment.getWebSite());
- stringBuilder.append("\" />");
- stringBuilder.append("</p>");
- stringBuilder.append("<p style=\"display:none\"><input name=\"f_mail\" type=\"text\" size=\"30\" maxlength=\"255\" value=\"\" />");
- stringBuilder.append("</p>");
- stringBuilder.append("<p class=\"field\"><label for=\"c_content\">");
- stringBuilder.append(getMessage().comments);
- stringBuilder.append(" :</label>");
- stringBuilder.append("<textarea name=\"c_content\" id=\"c_content\" cols=\"25\" rows=\"7\">");
- if (currComment != null && currComment.getContent() != null)
- stringBuilder.append(currComment.getContent());
- stringBuilder.append("</textarea>");
- stringBuilder.append("</p>");
- stringBuilder.append("<p class=\"form-help\">");
- stringBuilder.append(getMessage().htmlAndEmailMessageInfo);
- stringBuilder.append("</p></fieldset><fieldset>");
- stringBuilder.append("<p class=\"buttons\"><input type=\"submit\" class=\"preview\" name=\"preview\" value=\"");
- stringBuilder.append(getMessage().send);
- stringBuilder.append("\" />");
- stringBuilder.append("</p></fieldset></form>");
- }
- }
-
- /**
- * Write the content of a specific post
- *
- * @param story
- * @param headerView
- * @param first
- * TODO: -Refactor into some methods -Make it more readable
- */
- private void writeDetailedPost(Story story, StoryModel model, boolean headerView, boolean first) {
-
- log.info("<StoryHtmlRenderer.writeDetailedPost>" + System.currentTimeMillis());
-
- String cssClass;
- String dateAsString;
- String dateAsStringWithHour;
- if (first)
- cssClass = "post odd first";
- else
- cssClass = "post odd ";
-
- if (story.getPublishDate() != null) {
- dateAsString = sdf.format(story.getPublishDate());
- dateAsStringWithHour = sdfWithHour.format(story.getPublishDate());
- } else if (story.getCreationDate() != null) {
- dateAsString = sdf.format(story.getCreationDate());
- dateAsStringWithHour = sdfWithHour.format(story.getCreationDate());
- } else {
- dateAsString = getMessage().unknownDate;
- dateAsStringWithHour = getMessage().unknownDate;
- }
-
- log.info("<StoryHtmlRenderer.writeDetailedPost.1>" + System.currentTimeMillis());
-
- stringBuilder.append("<div class=\"").append(cssClass);
- stringBuilder.append("\" lang=\"fr\" xml:lang=\"fr\">");
- stringBuilder.append("<p class=\"day-date\">").append(dateAsString).append("</p>");
- stringBuilder.append("<h2 id=\"p312296\" class=\"post-title\">");
- stringBuilder.append("<a href=\"").append(getMessage().POST_URL).append(story.getUrl());
- stringBuilder.append("\">").append(story.getTitle()).append("</a>" + "</h2>");
- stringBuilder.append("<p class=\"post-info\">");
-
- log.info("<StoryHtmlRenderer.writeDetailedPost.2>" + System.currentTimeMillis());
-
- String author = null;
- if (story.getAuthors() != null)
- author = model.getAuthor(story.getAuthors().get(0));
-
- log.info("<StoryHtmlRenderer.writeDetailedPost.3>" + System.currentTimeMillis());
-
- if (author != null && !author.isEmpty())
- stringBuilder.append("Par " + author);
- stringBuilder.append(" le " + dateAsStringWithHour);
-
- log.info("<StoryHtmlRenderer.writeDetailedPost.4>" + System.currentTimeMillis());
-
- if (story.getCategory() != null) {
- Category category = model.getCategory(story.getCategory());
- if (category != null) {
- stringBuilder.append(" - <a href=\"" + getMessage().CATEGORY_URL.replace("{NAME}", category.getUrl()) + "\">");
- stringBuilder.append(category.getName() + "</a>");
- }
- }
- log.info("<StoryHtmlRenderer.writeDetailedPost.5>" + System.currentTimeMillis());
-
- stringBuilder.append("</p>" + "<ul class=\"post-tags\">");
- if (story.getTags() != null) {
- for (Key tag : story.getTags()) {
- String tagname = model.getTag(tag);
- if (tagname != null) {
- stringBuilder.append("<li><a href=\"" + getMessage().TAG_URL.replace("{NAME}", tagname) + "\">" + tagname + "</a></li>");
- }
- }
- }
- log.info("<StoryHtmlRenderer.writeDetailedPost.7>" + System.currentTimeMillis());
-
- stringBuilder.append("</ul>");
- stringBuilder.append("<div class=\"post-content\">");
-
- String content = "";
- if (story.getDescription() != null)
- content = story.getDescription();
- if (!headerView || content == null || "".equals(content.trim()))
- content += story.getContent();
-
- if (content != null)
- stringBuilder.append(content);
- else
- stringBuilder.append(getMessage().noContent);
-
- log.info("<StoryHtmlRenderer.writeDetailedPost.8>" + System.currentTimeMillis());
-
- // Affichage des liens
- if (story.getLinks() != null) {
- for (HitsLink link : story.getLinks()) {
- stringBuilder.append("<p><a title=\"");
- stringBuilder.append(link.getUrl().getValue());
- stringBuilder.append("\" href=\"");
- stringBuilder.append(getMessage().LINK_URL.replace("{KEY}", KeyFactory.keyToString(link.getKey())));
- stringBuilder.append("\">").append(link.getLabel()).append(" (").append(link.getHits().intValue()).append(" hits)</a><p>");
- }
- }
-
- log.info("<StoryHtmlRenderer.writeDetailedPost.9>" + System.currentTimeMillis());
-
- stringBuilder.append("<p class=\"post-info-co\">");
- if (headerView) {// On affiche le nombre de commentaires
- if (story.getComments() != null && !story.getComments().isEmpty()) {
- if (story.getComments().size() == 1) {
- stringBuilder.append("<a href=\"");
- stringBuilder.append(getMessage().POST_URL + story.getUrl());
- stringBuilder.append("#comments\" class=\"comment_count\">");
- stringBuilder.append(getMessage().oneComment);
- stringBuilder.append("</a>");
- } else {
- stringBuilder.append("<a href=\"");
- stringBuilder.append(getMessage().POST_URL + story.getUrl());
- stringBuilder.append("#comments\" class=\"comment_count\">");
- stringBuilder.append(story.getComments().size());
- stringBuilder.append(getMessage().comments);
- stringBuilder.append("</a>");
- }
- } else {
- stringBuilder.append("<a href=\"");
- stringBuilder.append(getMessage().POST_URL + story.getUrl());
- stringBuilder.append("#comments\" class=\"comment_count\">");
- stringBuilder.append(getMessage().next);
- stringBuilder.append("</a>");
- }
- stringBuilder.append("</p></div>");
- stringBuilder.append("</div>");
- } else {
- stringBuilder.append("</p></div>");
- stringBuilder.append("</div>");
- // On affiche la liste des commentaires
- if (story.getComments() != null && !story.getComments().isEmpty()) {
- writePostComments(story.getComments());
- }
-
- // On affiche le formulaire permettant de poster un commentaire
- writeCommentsForm(story, model);
- }
- log.info("</StoryHtmlRenderer.writeDetailedPost>" + System.currentTimeMillis());
- }
-
- /**
- * Write the content of a list of posts
- *
- * @param liste
- * post list
- * @throws IOException
- */
- private void writeListOfPosts(List<Story> liste, StoryModel model) throws IOException {
- for (Story blogPost : liste) {
- writeDetailedPost(blogPost, model, true, false);
- }
- }
-
- /**
- * Write the pagination panel
- *
- * @param model
- * post model
- */
- private void writePagination(StoryModel model) {
- // Ecriture de la pagination
- stringBuilder.append("<p class=\"pagination\">");
- if (!model.isOnLastPage()) {
- stringBuilder.append("<a href=\"").append(request.getRequestURI()).append("?p=");
- stringBuilder.append(model.getActualPage() + 1);
- stringBuilder.append("\" class=\"prev\">« ");
- stringBuilder.append(getMessage().prev);
- stringBuilder.append("</a> - ");
- }
- stringBuilder.append("page ").append(model.getActualPage() + 1).append(" de ");
- stringBuilder.append(model.getNbPages());
- if (!model.isOnFirstPage()) {
- stringBuilder.append(" - <a href=\"").append(request.getRequestURI()).append("?p=");
- stringBuilder.append(model.getActualPage() - 1);
- stringBuilder.append("\" class=\"next\">");
- stringBuilder.append(getMessage().next);
- stringBuilder.append(" »</a>");
- }
- stringBuilder.append("</p>");
- }
-
- /**
- * Adds the comments list to the StringBuffer content
- *
- * @param comments
- */
- private void writePostComments(List<Comment> comments) {
- stringBuilder.append("<div id=\"comments\">");
- stringBuilder.append("<h3>");
- stringBuilder.append(getMessage().comments);
- stringBuilder.append("</h3><dl>");
- Integer commentNumber = 1;
- for (Comment comment : comments) {
- stringBuilder.append("<dt id=\"" + comment.getKey().getId() + "\" class=\" odd first\">");
- stringBuilder.append("<a href=\"#" + comment.getKey().getId() + "\" class=\"comment-number\">" + commentNumber + ".</a>");
- if (comment.getDate() != null)
- stringBuilder.append(sdfWithHour.format(comment.getDate()));
- stringBuilder.append(" par ");
- String href = comment.getWebSite();
- if (href != null && !href.isEmpty()) {
- if (!href.startsWith("http://"))
- href = "http://" + href;
- stringBuilder.append("<a href=\"" + href + "\" rel=\"nofollow\">" + comment.getAlias() + "</a>");
- } else {
- stringBuilder.append(comment.getAlias());
- }
- stringBuilder.append("</dt><dd class=\" odd first\">");
- stringBuilder.append(replaceLinks(comment.getContent()));
- stringBuilder.append("</dd>");
- commentNumber++;
- }
- stringBuilder.append("</dl></div>");
- }
-
- /**
- * Write a Tag Cloud according to the tags in the model
- *
- * @param model
- */
- private void writeTagsCloud(StoryModel model) {
- List<HitsTag> tags = (List<HitsTag>) ((ArrayList<HitsTag>) model.getTags()).clone();
- assert tags != null;
-
- /*
- * if(tags.size() > 5) tags = tags.subList(0, 5);
- */
- long max = 100;
- if (tags != null && !tags.isEmpty() && tags.get(0).getHits() != null)
- max = tags.get(0).getHits();
-
- Collections.shuffle(tags, new Random());
- stringBuilder.append("<div id=\"content-info\">");
- stringBuilder.append("<h2>");
- stringBuilder.append(getMessage().tags);
- stringBuilder.append("</h2>");
- stringBuilder.append("</div>");
- stringBuilder.append("<div class=\"content-inner\"><ul class=\"tags\">");
-
- Long tagOccurency = 0l;
- for (HitsTag tag : tags) {
- if (tag.getHits() != null)
- tagOccurency = ((tag.getHits().intValue() * 100) / max);
- else
- tagOccurency = 0l;
- stringBuilder.append("<li><a href=\"");
- stringBuilder.append(getMessage().TAG_URL);
- stringBuilder.append("/");
- stringBuilder.append(tag.getName());
- stringBuilder.append("\" class=\"tag");
- stringBuilder.append(getTagRate(tagOccurency)).append("\"> ");
- stringBuilder.append(tag.getName());
- stringBuilder.append("</a> </li>");
- }
- stringBuilder.append("</ul>");
- stringBuilder.append("</div>");
- }
- }