📄 topictag.java
字号:
/*
* Created on 2007-3-29
* Last modified on 2007-9-28
* Powered by YeQiangWei.com
*/
package com.yeqiangwei.club.view.tag;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;
import org.apache.log4j.Logger;
import com.yeqiangwei.club.service.security.UserPower;
import com.yeqiangwei.club.controller.form.TopicPostForm;
import com.yeqiangwei.club.view.model.ManageLogView;
import com.yeqiangwei.club.view.model.TopicView;
import com.yeqiangwei.club.view.model.ReplyView;
import com.yeqiangwei.club.view.util.EnCoder;
import com.yeqiangwei.club.view.util.ViewCoder;
import com.yeqiangwei.club.view.util.UrlUtils;
import com.yeqiangwei.html.OutPrint;
import com.yeqiangwei.util.ParamUtils;
import com.yeqiangwei.util.StringHelper;
import com.yeqiangwei.util.Validator;
public class TopicTag extends TagSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
private static final Logger logger = Logger.getLogger(TopicTag.class);
private HttpServletRequest request;
private TopicView topic;
private ReplyView reply;
private Object object;
private String type;
private String topicStr;
//private String contentStr;
private boolean escapeUBB = false;
private UserPower userPower;
public void setObject(Object object) {
this.object = object;
}
public void setEscapeUBB(boolean escapeUBB) {
this.escapeUBB = escapeUBB;
}
public void setTopicStr(String topicStr) {
this.topicStr = topicStr;
}
public void setType(String type) {
this.type = type;
}
public void setReply(ReplyView reply) {
this.reply = reply;
}
public void setRequest(HttpServletRequest request) {
this.request = request;
}
public void setTopic(TopicView topic) {
this.topic = topic;
}
public void initialize(){
if(!Validator.isEmpty(object)){
if(object instanceof TopicView){
topic = (TopicView) object;
object = null;
}
else if(object instanceof ReplyView){
reply = (ReplyView) object;
object = null;
}
}
}
private String quoteUtil(int storey, String userName, String title, String content, int len){
if(Validator.isEmpty(content)&&Validator.isEmpty(title)){
return "";
}
if(Validator.isEmpty(content)){
content = title;
}
StringBuffer sb = new StringBuffer();
if(storey!=-1){
//String quote = StringHelper.ubbPattern(content,"\\[quote=(.*?)\\](.*?)\\[/quote\\]","[quote=$1]$2[/quote]","");
content = StringHelper.ubbPattern(content,"\\[quote=(.*?)\\](.*?)\\[/quote\\]","","");
content = StringHelper.substring(content,0,200,"");
int s = content.lastIndexOf("[");
int e = content.lastIndexOf("]");
if(s>e){
content = StringHelper.substring(content,0,s,"");
}
if(len>200){
content += "...";
}
sb.append("[quote=");
sb.append(userName);
if(storey==0){
sb.append(ViewCoder.getStorey(storey));
sb.append("说]");
}
else if(storey<4){
sb.append("坐在");
sb.append(ViewCoder.getStorey(storey));
sb.append("上说:]");
}
else{
sb.append("站在");
sb.append(ViewCoder.getStorey(storey));
sb.append("说:]");
}
//sb.append(quote);
sb.append(content);
sb.append("[/quote]<br/>");
}else{
sb.append(content);
}
return sb.toString();
}
public int doEndTag() throws JspTagException{
StringBuffer sb = new StringBuffer();
if(type.equals("title")){
if(topicStr==null){topicStr="";}
else{
topicStr = StringHelper.htmlEncoder(topicStr);
}
sb.append(topicStr);
}
else if(type.equals("content")){
this.initialize();
String content = "";
if(!Validator.isEmpty(topic)){
content = ViewCoder.getContent(request, topic, escapeUBB);
content = content.replaceAll("alt=\"\"", "alt=\""+topic.getTitle()+"\"");
}
else if(!Validator.isEmpty(reply)){
content = ViewCoder.getContent(request, reply, escapeUBB);
content = content.replaceAll("alt=\"\"", "alt=\""+reply.getTitle()+"\"");
}
sb.append(content);
}
else if(type.equals("editcontent")){
this.initialize();
int storey = ParamUtils.getIntParameter(request,"storey",-1);
String act = ParamUtils.getStringParameter(request,"act",null);
String content = "";
TopicPostForm form = (TopicPostForm) request.getAttribute("TopicPostForm");
if(request.getMethod().equals("POST")&&!Validator.isEmpty(form)){
if(!escapeUBB){
content = StringHelper.htmlEncoder(form.getContent());
content = EnCoder.simpleTag(content);
}else{
content = StringHelper.htmlEncoder(form.getContent());
content = EnCoder.advancedTag(content);
}
}
else if(!Validator.isEmpty(act)&&act.equals("addreply")&&storey==-1){
}
else{
if(!Validator.isEmpty(topic)){
if(storey==-1){
content = ViewCoder.getContent(request, topic, escapeUBB);
}else{ //如果是引用
content = topic.getContent();
content = (this.quoteUtil(storey, topic.getUserName(), topic.getTitle(),content, topic.getContentLength()));
}
}
else if(!Validator.isEmpty(reply)){
if(storey==-1){
content = ViewCoder.getContent(request, reply, escapeUBB);
}else{ //如果是引用
content = reply.getContent();
content = (this.quoteUtil(storey, reply.getUserName(), reply.getTitle(),content, reply.getContentLength()));
}
}
}
sb.append(content);
content = null;
}
else if(type.equals("penName")){
this.initialize();
if(!Validator.isEmpty(topic)&&!Validator.isEmpty(topic.getUser())){
sb.append("<div class=\"\">");
sb.append(topic.getUser().getPenName());
sb.append("</div>");
}
else if(!Validator.isEmpty(reply)&&!Validator.isEmpty(reply.getUser())){
sb.append("<div class=\"\">");
sb.append(reply.getUser().getPenName());
sb.append("</div>");
}
}
else if(type.equals("signatures")){
this.initialize();
if(!Validator.isEmpty(topic)
&& !Validator.isEmpty(topic.getUser())
&& topic.getListSignatures()>0
&& !Validator.isEmpty(topic.getUser().getSignatures())
)
{
sb.append("<div class=\"sig\">");
sb.append(ViewCoder.signaturesFilter(topic.getUser().getSignatures()));
sb.append("</div>");
}
else if(!Validator.isEmpty(reply)
&&!Validator.isEmpty(reply.getUser())
&&reply.getListSignatures()>0
&&!Validator.isEmpty(reply.getUser().getSignatures())
)
{
sb.append("<div class=\"sig\">");
sb.append(ViewCoder.signaturesFilter(reply.getUser().getSignatures()));
sb.append("</div>");
}
}
else if(type.equals("copyright")){
this.initialize();
if(!Validator.isEmpty(topic)&&(topic.getCopyright()>0))
{
sb.append(ViewCoder.copyright(topic.getCopyright()));
}
else if(!Validator.isEmpty(reply)&&(reply.getCopyright()>0))
{
sb.append(ViewCoder.copyright(reply.getCopyright()));
}
}
else if(type.equals("userIp")){
this.initialize();
if(this.getUserPower().canAccess(request,UserPower.BROWSEPOWER,9)){
if(!Validator.isEmpty(topic)){
sb.append("IP:");
sb.append(topic.getUserIp());
}
else if(!Validator.isEmpty(reply)){
sb.append("IP:");
sb.append(reply.getUserIp());
}
}
}
else if(type.equals("manageLog")){
List<ManageLogView> list = null;
this.initialize();
if(!Validator.isEmpty(topic)){
list = topic.getManageLogList();
}else if(!Validator.isEmpty(reply)){
list = reply.getManageLogList();
}
if(!Validator.isEmpty(list)){
sb.append("<div class=\"log\">");
for(int i=0; i<list.size(); i++){
ManageLogView v = list.get(i);
sb.append("<fieldset>");
sb.append("<legend>");
sb.append(v.getMemo());
sb.append("</legend>");
sb.append("<div>");
sb.append("信誉:");
sb.append(v.getCredit());
sb.append(" ");
sb.append("积分:");
sb.append(v.getScore());
sb.append(" ");
sb.append("金币:");
sb.append(v.getMoney());
sb.append("</div>");
sb.append("<div>");
sb.append(StringHelper.htmlEncoder(v.getContent()));
sb.append("</div>");
sb.append("<div>");
if(v.getListByUserName()){
sb.append("by ");
sb.append("<a href=\"");
sb.append(UrlUtils.getUrl(UrlUtils.USER,v.getByUserId(),0,request));
sb.append("\" target=\"_blank\">");
sb.append(v.getByUserName());
sb.append("</a>");
sb.append(" on ");
}
sb.append(OutPrint.isDateHtml(v.getCreateDateTime()));
sb.append("</div>");
sb.append("</fieldset>");
}
sb.append("</div>");
}
}
outWrite(sb);
sb.delete(0, sb.length());
object = null;
topic = null;
reply = null;
return EVAL_PAGE;
}
public UserPower getUserPower() {
if(Validator.isEmpty(userPower)){
userPower = new UserPower();
}
return userPower;
}
public void outWrite(String s){
try {
pageContext.getOut().write(s);
} catch (IOException e) {
logger.error(e.toString());
}
}
public void outWrite(StringBuffer s){
try {
pageContext.getOut().write(s.toString());
} catch (IOException e) {
logger.error(e.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -