JEECMS v3.0.1 beta版源码分析2

JEECMS v3.0.1 beta版发布,采用的是采用hibernate3+spring mvc+spring2+freemarker主流技术架构.


再对前台配置文件进行分析jeecms-servlet-front.xml

加载的资源文件
    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">

       <property name="cacheSeconds" value="0"/>

       <property name="basenames">

           <list>
              <value>/WEB-INF/languages/jeecms_front/messages</value>
              <value>/WEB-INF/languages/fck/messages</value>
           </list>
       </property>
    </bean>




/WEB-INF/languages/jeecms_front/messages

/WEB-INF/languages/fck/messages

因为前台和后台是分离的两个独立的
Springmvc messageSource中只加载front前台的资源文件
messages_cn.properties

#专题模板
tpl.topicIndex=专题导航页
tpl.topicChannel=专题栏目页
tpl.topicDefault=专题默认页


#专用模板
tpl.tagIndex=标签导航页
tpl.tagDetail=标签详情页
tpl.searchInput=搜索输入页
tpl.searchResult=搜索结果页
tpl.commentPage=评论页
tpl.rss=RSS


模板页面都是中文名称,如
/WEB-INF/t/cms/www/red/index/首页.html

#客户端包含模板
tpl.index=首页
在程序中使用tpl.index最后对应模板中的”首页.html”的”首页”

如FrontUtils.getTplPath(request, site.getSolutionPath(),

"index", "tpl.index");

public static String getTplPath(HttpServletRequest request, String solution, String dir, String name)
   {
     return solution + "/" + dir + "/" +
       MessageResolver.getMessage(request, name, new Object[0]) + ".html";
  }

public static String getTplPath(HttpServletRequest request, String solution, String dir, String name)
   {
     return solution + "/" + dir + "/" +
       MessageResolver.getMessage(request, name, new Object[0]) + ".html";
  }




使用multipartResolver视图解析器
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>






配置拦截器
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">

       <property name="interceptors">

           <list>
              <ref bean="frontContextInterceptor"/>

              <ref bean="frontLocaleInterceptor"/>

           </list>
       </property>
    </bean>




FrontContextInterceptor.java
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
     throws ServletException
   {
     CmsSite site = null;
     List<CmsSite> list = this.cmsSiteMng.getListFromCache();
     int size = list.size();
     if (size == 0)
       throw new RuntimeException("no site record in database!");
     if (size == 1) {
       site = (CmsSite)list.get(0);
     } else {
       String server = request.getServerName();

       for (CmsSite s : list)
       {
         if (s.getDomain().equals(server)) {
           site = s;
           break;
         }

         String alias = s.getDomainAlias();
         if (!StringUtils.isBlank(alias)) {
           for (String a : StringUtils.split(alias, ',')) {
             if (a.equals(server)) {
               site = s;
               break;
             }
           }
         }

         String redirect = s.getDomainRedirect();
         if (!StringUtils.isBlank(redirect)) {
           for (String r : StringUtils.split(redirect, ',')) {
             if (!r.equals(server)) continue;
             try {
               response.sendRedirect(s.getUrl());
             } catch (IOException e) {
               throw new RuntimeException(e);
             }
             return false;
           }
         }
       }

       if (site == null) {
         throw new SiteNotFoundException(server);
       }
     }

     CmsUtils.setSite(request, site);

     CmsUser user = null;
     Integer userId = this.authMng.retrieveUserIdFromSession(this.session, request);
     if (userId != null) {
       user = this.cmsUserMng.findById(userId);
     }

     if (user != null) {
       CmsUtils.setUser(request, user);
     }
     return true;
   }


你可能感兴趣的:(spring,Web,freemarker,cms,mvc)