KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > javabb > component > PostFormatter


1 /*
2  * Copyright 2004 JavaFree.org
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 /**
29  * $Id: PostFormatter.java,v 1.7.4.3.4.2 2006/04/17 17:47:31 daltoncamargo Exp $
30  * @author Ronald Tetsuo Miura
31  */

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     /**
43      * @param badWordTransaction
44      */

45     public void setBadWordTransaction(BadWordTransaction badWordTransaction) {
46         this._badWordTransaction = badWordTransaction;
47     }
48
49     /**
50      * @param smileTransaction
51      */

52     public void setSmileTransaction(SmileTransaction smileTransaction) {
53         _smileTransaction = smileTransaction;
54     }
55
56     /**
57      * @param post
58      * @return bbcode-formated text
59      */

60     public String JavaDoc formatPost(Post post) {
61         ProcessBBCode bbcodeFormatter = new ProcessBBCode();
62         bbcodeFormatter.setAcceptHTML(post.getAcceptHTML());
63         bbcodeFormatter.setAcceptBBCode(post.getAcceptBBCode());
64
65         String JavaDoc 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 JavaDoc formatWithoutBBCode(Post post) {
75         String JavaDoc 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 JavaDoc formatTextToBBCode(String JavaDoc textToBBcode){
84         
85         ProcessBBCode bbcodeFormatter = new ProcessBBCode();
86         bbcodeFormatter.setAcceptHTML(false);
87         bbcodeFormatter.setAcceptBBCode(true);
88
89         String JavaDoc 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     /**
98      * @param text
99      * @return bbcode-formated text
100      */

101     public String JavaDoc formatEscaped(String JavaDoc 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