📄 postformatter.java
字号:
/*
* Copyright 2004 JavaFree.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.javabb.component;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.javabb.bbcode.ProcessBBCode;
import org.javabb.infra.Utils;
import org.javabb.transaction.BadWordTransaction;
import org.javabb.transaction.SmileTransaction;
import org.javabb.vo.Post;
import org.springframework.web.util.HtmlUtils;
/**
* $Id: PostFormatter.java,v 1.7.4.3.4.3 2006/12/22 13:25:17 daltoncamargo Exp $
* @author Ronald Tetsuo Miura
*/
public class PostFormatter {
protected final Log log = LogFactory.getLog(this.getClass());
/** */
private BadWordTransaction _badWordTransaction;
/** */
private SmileTransaction _smileTransaction;
/**
* @param badWordTransaction
*/
public void setBadWordTransaction(BadWordTransaction badWordTransaction) {
this._badWordTransaction = badWordTransaction;
}
/**
* @param smileTransaction
*/
public void setSmileTransaction(SmileTransaction smileTransaction) {
_smileTransaction = smileTransaction;
}
/**
* @param post
* @return bbcode-formated text
*/
public String formatPost(Post post) {
ProcessBBCode bbcodeFormatter = new ProcessBBCode();
bbcodeFormatter.setAcceptHTML(post.getAcceptHTML());
bbcodeFormatter.setAcceptBBCode(post.getAcceptBBCode());
bbcodeFormatter.setAcceptHTML(false);
bbcodeFormatter.setAcceptBBCode(true);
String text = Utils.verifyURLs(post.getPostBody());
text = bbcodeFormatter.preparePostText(text);
text = _badWordTransaction.verifyBadWords(text);
text = _smileTransaction.replaceSmiles(text);
return text;
}
public String formatWithoutBBCode(Post post) {
String text = Utils.verifyURLs(post.getPostBody());
text = HtmlUtils.htmlEscape(text);
text = _badWordTransaction.verifyBadWords(text);
text = _smileTransaction.replaceSmiles(text);
return text;
}
public String formatTextToBBCode(String textToBBcode){
ProcessBBCode bbcodeFormatter = new ProcessBBCode();
bbcodeFormatter.setAcceptHTML(false);
bbcodeFormatter.setAcceptBBCode(true);
String text = Utils.verifyURLs(textToBBcode);
text = bbcodeFormatter.preparePostText(text);
text = _badWordTransaction.verifyBadWords(text);
text = _smileTransaction.replaceSmiles(text);
return text;
}
/**
* @param text
* @return bbcode-formated text
*/
public String formatEscaped(String text) {
ProcessBBCode bbcodeFormatter = new ProcessBBCode();
bbcodeFormatter.setAcceptHTML(false);
bbcodeFormatter.setAcceptBBCode(false);
text = bbcodeFormatter.preparePostText(text);
text = _badWordTransaction.verifyBadWords(text);
return text;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -