Changes between Version 3 and Version 4 of codekata/refactor


Ignore:
Timestamp:
11/06/2013 04:55:19 PM (12 years ago)
Author:
zhangyihui
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • codekata/refactor

    v3 v4  
    191191}}}[[BR]] 
    192192 
    193  
    194  
    195  
    196  
    197  
    198  
    199  
    200  
    201  
    202  
    203  
    204  
    205  
    206  
    207  
    208  
    209  
     193当然,少不了咱们组共同写出来的方法[[BR]] 
     194 
     195{{{ 
     196import java.text.MessageFormat; 
     197 
     198public class Functions{ 
     199        private static String  rootUrl = "http://bbs.pcauto.com.cn"; 
     200        private static String  appName = "pcauto"; 
     201    /** 
     202     * 
     203     * 将页面链接静态化(wap),目前只支持Forum,Topic,Post,User对象,其他的如果是字符串则返回原字符串 
     204     * <br/>修改些方法的规则的同时也要修改parserUrl方法 
     205     * tid等于{4018911,4027940, 4040395}销售配合,此帖子跳转到指定链接 
     206     * 
     207     * @param object 
     208     *  
     209     *  
     210     * @param type 1:web, 2:wap 
     211     * @return 
     212     */ 
     213    public static String htmlUrl(Object object, int type) { 
     214                boolean isIt = false;  
     215                if (isIt && type != SystemConstant.TYPE_WAP ) { 
     216                        return "";  
     217                } else { 
     218 
     219                switch (type) { 
     220                    case SystemConstant.TYPE_WEB: 
     221                        rootUrl = rootUrl; 
     222                        break; 
     223                    case SystemConstant.TYPE_WAP: 
     224                        rootUrl = rootUrl;  
     225                        break; 
     226                    default: 
     227                        break; 
     228                } 
     229 
     230                if ("".equals(rootUrl) || rootUrl == null) { 
     231                    return ""; 
     232                } 
     233 
     234                if (object instanceof Forum) { 
     235                    Forum forum = (Forum) object; 
     236                    if (!isEmpty(forum.getRedirectUrl()) && SystemConstant.TYPE_WEB == type) { 
     237                        return forum.getRedirectUrl(); 
     238                    } else { 
     239                        return rootUrl + "/forum-" + forum.getFid() + ".html"; 
     240                    } 
     241                } else if (object instanceof Topic) { 
     242                        //销售配合,此帖子跳转到指定链接 
     243                        if(SystemConstant.AUTO_APP_NAME.equals(appName) && ((Topic) object).getTid() == 4018911){ 
     244                                return "http://ad.doubleclick.net/clk;275446626;102403463;a?http://bbs.pcauto.com.cn/topic-4018911.html"; 
     245                        } 
     246                        if(SystemConstant.AUTO_APP_NAME.equals(appName) && ((Topic) object).getTid() == 4027940){ 
     247                                return "http://ad.doubleclick.net/clk;275446638;102403466;g?http://bbs.pcauto.com.cn/topic-4027940.html"; 
     248                        } 
     249                        if(SystemConstant.AUTO_APP_NAME.equals(appName) && ((Topic) object).getTid() == 4040395){ 
     250                                return "http://ad.doubleclick.net/clk;275446642;102403468;d?http://bbs.pcauto.com.cn/topic-4040395.html"; 
     251                        } 
     252                    return rootUrl + "/topic-" + ((Topic) object).getTid() + ".html"; 
     253                } else if (object instanceof Post) { 
     254                    return rootUrl + "/post-" + ((Post) object).getTid() + '_' + ((Post) object).getPid() + ".html"; 
     255                } else if (object instanceof String) { 
     256                    return (String) object; 
     257                } else if (object instanceof User) { 
     258                    return  "/" + ((User) object).getUid(); 
     259                } else if (object instanceof ftree.Forum) { 
     260                    ftree.Forum forum = (ftree.Forum) object; 
     261                    return rootUrl + "/forum-" + forum.getFid() + ".html"; 
     262                } else { 
     263                    return ""; 
     264                } 
     265                } 
     266    } 
     267     
     268    public static boolean isEmpty(String text){ 
     269         return (null == text || "".equals(text)); 
     270    } 
     271     
     272    
     273    /** 
     274     * 板块URL静态化  
     275     * @param forum 板块 
     276     * @param rootUrl 应用路径 
     277     * @param appName 
     278     * @return 
     279     */ 
     280    public static String htmlUrl(Forum forum) { 
     281        if (forum == null) { 
     282                return Tpl.NOT_FOUND_URL; 
     283        } 
     284//      if ("itbbs".equals(appName)) { 
     285//              return rootUrl + "/f" + forum.getFid() + ".html"; 
     286//      } else { 
     287//              return rootUrl + "/forum-" + forum.getFid() + ".html"; 
     288//      } 
     289         
     290        return MessageFormat.format(Tpl.FORUM_URL, String.valueOf(forum.getFid())); 
     291         
     292    } 
     293     
     294    /** 
     295     * 主题URL静态化  
     296     * @param topic  主题  
     297     * @param rootUrl 应用路径 
     298     * @param appName 
     299     * @return 
     300     */ 
     301    public static String htmlUrl(Topic topic) { 
     302        if (topic == null) { 
     303                return Tpl.NOT_FOUND_URL; 
     304        } 
     305//      if ("itbbs".equals(appName)) { 
     306//              return rootUrl + "/" + topic.getTid() + ".html"; 
     307//      } else { 
     308//              return rootUrl + "/topic-" + topic.getTid() + ".html"; 
     309//      } 
     310         
     311        return MessageFormat.format(Tpl.TOPIC_URL, String.valueOf(topic.getTid())); 
     312                         
     313                         
     314         
     315    } 
     316     
     317     
     318    /** 
     319     * 帖子URL静态化  
     320     * @param post 帖子  
     321     * @param rootUrl 应用路径 
     322     * @param appName 
     323     * @return 
     324     */ 
     325     
     326    public static String htmlUrl(Post post) { 
     327         
     328        if (post == null) { 
     329                return Tpl.NOT_FOUND_URL; 
     330        } 
     331        String pid = String.valueOf(post.getPid()); 
     332        String tid = String.valueOf(post.getTid()); 
     333        return MessageFormat.format(Tpl.POST_URL, new Object[]{tid, pid}); 
     334    } 
     335     
     336     
     337    /** 
     338     * 用户URL静态化  
     339     * @param post 帖子  
     340     * @param rootUrl 应用路径 
     341     * @param appName 
     342     * @return 
     343     */ 
     344    public static String htmlUrl(User user) { 
     345        if (user == null) { 
     346                return Tpl.NOT_FOUND_URL; 
     347        } 
     348        return MessageFormat.format(Tpl.USER_URL, String.valueOf(user.getUid())); 
     349    } 
     350     
     351    /** 
     352     * URL静态化  
     353     * @param str string  
     354     * @param rootUrl 应用路径 
     355     * @param appName 
     356     * @return 
     357     */ 
     358    public static String htmlUrl(String str) { 
     359        if (str == null) { 
     360                return Tpl.NOT_FOUND_URL; 
     361        } 
     362        return str; 
     363    } 
     364     
     365    /** 
     366     * wap版版块URL静态化  
     367     * @param forum 版块 
     368     * @param rootUrl 应用路径 
     369     * @param appName 
     370     * @return 
     371     */ 
     372    public static String htmlUrl4Wap(Forum forum) { 
     373         
     374        return ""; 
     375    } 
     376     
     377    /** 
     378     * wap版帖子URL静态化  
     379     * @param post 帖子  
     380     * @param rootUrl 应用路径 
     381     * @param appName 
     382     * @return 
     383     */ 
     384    public static String htmlUrl4Wap(Post post) { 
     385         
     386        return ""; 
     387    } 
     388     
     389    /** 
     390     * wap版主题URL静态化  
     391     * @param topic 主题 
     392     * @param rootUrl 应用路径 
     393     * @param appName 
     394     * @return 
     395     */ 
     396    public static String htmlUrl4Wap(Topic topic) { 
     397         
     398        return ""; 
     399    } 
     400     
     401    /** 
     402     * wap版字符串URL静态化  
     403     * @param str string 
     404     * @param rootUrl 应用路径 
     405     * @param appName 
     406     * @return 
     407     */ 
     408    public static String htmlUrl4Wap(String str) { 
     409         
     410        return ""; 
     411    } 
     412     
     413    /** 
     414     * wap版用户URL静态化  
     415     * @param user 用户  
     416     * @param rootUrl 应用路径 
     417     * @param appName 
     418     * @return 
     419     */ 
     420    public static String htmlUrl4Wap(User user) { 
     421         
     422        return ""; 
     423    } 
     424     
     425     
     426} 
     427}}}