1 16 17 package org.javabb.component; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 import org.javabb.bbcode.ProcessBBCode; 22 import org.javabb.infra.Utils; 23 import org.javabb.transaction.BadWordTransaction; 24 import org.javabb.transaction.SmileTransaction; 25 import org.javabb.vo.Post; 26 import org.springframework.web.util.HtmlUtils; 27 28 32 public class PostFormatter { 33 34 protected final Log log = LogFactory.getLog(this.getClass()); 35 36 37 private BadWordTransaction _badWordTransaction; 38 39 40 private SmileTransaction _smileTransaction; 41 42 45 public void setBadWordTransaction(BadWordTransaction badWordTransaction) { 46 this._badWordTransaction = badWordTransaction; 47 } 48 49 52 public void setSmileTransaction(SmileTransaction smileTransaction) { 53 _smileTransaction = smileTransaction; 54 } 55 56 60 public String formatPost(Post post) { 61 ProcessBBCode bbcodeFormatter = new ProcessBBCode(); 62 bbcodeFormatter.setAcceptHTML(post.getAcceptHTML()); 63 bbcodeFormatter.setAcceptBBCode(post.getAcceptBBCode()); 64 65 String text = Utils.verifyURLs(post.getPostBody()); 66 text = bbcodeFormatter.preparePostText(text); 67 text = _badWordTransaction.verifyBadWords(text); 68 text = _smileTransaction.replaceSmiles(text); 69 70 return text; 71 } 72 73 74 public String formatWithoutBBCode(Post post) { 75 String text = Utils.verifyURLs(post.getPostBody()); 76 text = HtmlUtils.htmlEscape(text); 77 text = _badWordTransaction.verifyBadWords(text); 78 text = _smileTransaction.replaceSmiles(text); 79 return text; 80 } 81 82 83 public String formatTextToBBCode(String textToBBcode){ 84 85 ProcessBBCode bbcodeFormatter = new ProcessBBCode(); 86 bbcodeFormatter.setAcceptHTML(false); 87 bbcodeFormatter.setAcceptBBCode(true); 88 89 String text = Utils.verifyURLs(textToBBcode); 90 text = bbcodeFormatter.preparePostText(text); 91 text = _badWordTransaction.verifyBadWords(text); 92 text = _smileTransaction.replaceSmiles(text); 93 return text; 94 95 } 96 97 101 public String formatEscaped(String text) { 102 ProcessBBCode bbcodeFormatter = new ProcessBBCode(); 103 bbcodeFormatter.setAcceptHTML(false); 104 bbcodeFormatter.setAcceptBBCode(false); 105 text = bbcodeFormatter.preparePostText(text); 106 text = _badWordTransaction.verifyBadWords(text); 107 return text; 108 } 109 } 110 | Popular Tags |