📄 urlutils.java
字号:
/*
* Created on 2007-2-13
* Last modified on 2007-6-5
* Powered by YeQiangWei.com
*/
package com.yeqiangwei.club.view.util;
import javax.servlet.http.HttpServletRequest;
import com.yeqiangwei.club.service.ServiceLocator;
import com.yeqiangwei.club.service.ServiceWrapper;
import com.yeqiangwei.club.service.forum.ForumService;
import com.yeqiangwei.club.service.model.ForumModel;
import com.yeqiangwei.club.service.util.BasicInfoService;
import com.yeqiangwei.club.view.model.ForumView;
import com.yeqiangwei.club.view.model.ReplyView;
import com.yeqiangwei.club.view.model.TopicView;
import com.yeqiangwei.util.ParamUtils;
import com.yeqiangwei.util.Validator;
public class UrlUtils {
public static final int FORUM = 1;
public static final int TOPIC = 2;
public static final int REPLY = 3;
public static final int USER = 0;
/*
public static String getUrl(int type, int id, int idd, HttpServletRequest request){
return UrlUtils.getUrl(type,id,String.valueOf(idd),request);
}
*/
public static String getUrl(int type, TopicView view, HttpServletRequest request){
return getUrl(type, view.getTopicId(), view.getForumId(), request);
}
public static String getUrl(int type, ReplyView view, HttpServletRequest request){
return getUrl(type, view.getReplyId(), view.getForumId(), request);
}
public static String getTopicUrl(HttpServletRequest request){
return getUrl(UrlUtils.TOPIC, ParamUtils.getIntParameter(request,"topicId")
, ParamUtils.getIntParameter(request,"forumId")
, request);
}
public static String getUrl(int type, int id, int idd, HttpServletRequest request){
String url = "/";
StringBuffer sb = new StringBuffer();
Integer forumId;
switch(type){
case USER:
sb.append("/club/");
if(getBasicInfoService().findOnly().getUrlRewrite()){
sb.append("u");
sb.append(id);
sb.append(".html");
}else{
sb.append("/club/user.jsp?userId=");
sb.append(id);
}
break;
case FORUM:
ForumModel forumModel = UrlUtils.getForumService().findById(id);
if(forumModel.getCategory()==4){
sb.append(forumModel.getLinkUrl());
}
else if(getBasicInfoService().findOnly().getUrlRewrite()){
sb.append("/club/f");
sb.append(id);
sb.append("fp");
sb.append(ParamUtils.getStringParameter(request,"fpage","1"));
sb.append(".html");
}else{
sb.append("/club/forum.jsp?forumId=");
sb.append(id);
sb.append("&fpage=");
sb.append(ParamUtils.getStringParameter(request,"fpage","1"));
}
break;
case TOPIC:
forumId = idd;
if(!Validator.isEmpty(request)&&Validator.isEmpty(forumId)){
forumId = ParamUtils.getIntAuto(request,"forumId");
}
if(getBasicInfoService().findOnly().getUrlRewrite()){
sb.append("/club/f");
sb.append(forumId);
sb.append("fp");
sb.append(ParamUtils.getStringParameter(request,"fpage","1"));
sb.append("t");
sb.append(id);
sb.append("p");
if(ParamUtils.getStringParameter(request,"act","").equals("addreply")&&ParamUtils.getIntParameter(request,"replyId",0)==0){
sb.append(ParamUtils.getStringParameter(request,"lpage","1"));
}else{
sb.append(ParamUtils.getStringParameter(request,"page","1"));
}
sb.append(".html");
}else{
sb.append("/club/thread.jsp?forumId=");
sb.append(forumId);
sb.append("&fpage=");
sb.append(ParamUtils.getStringParameter(request,"fpage","1"));
sb.append("&topicId=");
sb.append(id);
sb.append("&page=");
if(ParamUtils.getStringParameter(request,"act","").equals("addreply")&&ParamUtils.getIntParameter(request,"replyId",0)==0){
sb.append(ParamUtils.getStringParameter(request,"lpage","1"));
}else{
sb.append(ParamUtils.getStringParameter(request,"page","1"));
}
}
break;
case REPLY:
forumId = idd;
if(!Validator.isEmpty(request)&&Validator.isEmpty(forumId)){
forumId = ParamUtils.getIntAuto(request,"forumId");
}
if(getBasicInfoService().findOnly().getUrlRewrite()){
sb.append("/club/f");
sb.append(forumId);
sb.append("fp");
sb.append(ParamUtils.getStringParameter(request,"fpage","1"));
sb.append("r");
sb.append(id);
sb.append(".html");
}else{
sb.append("/club/thread.jsp?forumId=");
sb.append(forumId);
sb.append("&fpage=");
sb.append(ParamUtils.getStringParameter(request,"fpage","1"));
sb.append("&replyId=");
sb.append(id);
}
break;
case 4:
break;
}
if(sb!=null){
url = sb.toString();
}
return url;
}
public static String forumUrl(ForumView forum, String value, String url, String rel, String property,HttpServletRequest request){
if(forum==null){
return "";
}
StringBuffer sb = new StringBuffer();
if(forum.getType()==1){
sb.append("<a href=\"");
if(!Validator.isEmpty(url)){
sb.append(url);
}
sb.append(UrlUtils.getUrl(UrlUtils.FORUM,forum.getForumId(),0,request));
sb.append("\"");
if(!Validator.isEmpty(rel)){
sb.append(" target=\"");
sb.append(rel);
sb.append("\"");
}
if(!Validator.isEmpty(property)){
sb.append(property);
}
sb.append(">");
if(Validator.isEmpty(value)){
sb.append(forum.getForumName());
}else{
sb.append(value);
}
sb.append("</a>");
}else{
sb.append(forum.getForumName());
}
return sb.toString();
}
public static String getCss(){
/*
StringBuffer sb = new StringBuffer();
sb.append("<link type=\"text/css\" href=\"/club/css.do");
//sb.append(getBasicInfoService().findOnly().getCssPath()+"YeQiangWeiStyle.css");
sb.append("\" rel=\"stylesheet\" />");
sb.toString();
*/
return "<link type=\"text/css\" href=\"/club/css.do\" rel=\"stylesheet\" />";
}
public static BasicInfoService getBasicInfoService() {
return ServiceWrapper.<BasicInfoService>getSingletonInstance(ServiceLocator.BASICINFO);
}
public static ForumService getForumService() {
return ServiceWrapper.<ForumService>getSingletonInstance(ServiceLocator.FORUM);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -