JEECMS v3.0.2版源码分析

时间:2021-10-05 09:20:08

转  http://denchy0918.blog.163.com/blog/static/11484634220110812554548/

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

 

首先对web.xml分析一下

这里面用的是springmvc的配置

 

<?xml version="1.0" encoding="UTF-8"?>

<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>JeeCms3</display-name>

    <context-param>

       <param-name>contextConfigLocation</param-name>

       <!---->

       <param-value>

           /WEB-INF/config/application-context.xml

           /WEB-INF/config/cache-context.xml

           /WEB-INF/config/captcha-context.xml

           /WEB-INF/config/jeecore-context.xml

           /WEB-INF/config/jeecms-context.xml

       </param-value>

    </context-param>

    <filter>

       <filter-name>processTime</filter-name>

       <filter-class>com.jeecms.common.web.ProcessTimeFilter</filter-class>

    </filter>

    <filter>

       <filter-name>encoding</filter-name>

       <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

       <init-param>

           <param-name>encoding</param-name>

           <param-value>UTF-8</param-value>

       </init-param>

    </filter>

    <filter>

       <filter-name>osivFilter</filter-name>

    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>

    </filter>

    <!--

    <filter>

       <filter-name>urlrewriteFilter</filter-name>

       <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>

           <init-param>

              <param-name>confReloadCheckInterval</param-name>

              <param-value>0</param-value>

           </init-param>

           <init-param>

              <param-name>logLevel</param-name>

              <param-value>sysout:DEBUG</param-value>

           </init-param>       

    </filter>

    -->

    <filter-mapping>

       <filter-name>processTime</filter-name>

       <url-pattern>*.do</url-pattern>

    </filter-mapping>

    <filter-mapping>

       <filter-name>encoding</filter-name>

       <url-pattern>*.do</url-pattern>

    </filter-mapping>

    <filter-mapping>

       <filter-name>osivFilter</filter-name>

       <url-pattern>*.do</url-pattern>

    </filter-mapping>

    <filter-mapping>

       <filter-name>processTime</filter-name>

       <url-pattern>*.jspx</url-pattern>

    </filter-mapping>

    <filter-mapping>

       <filter-name>encoding</filter-name>

       <url-pattern>*.jspx</url-pattern>

    </filter-mapping>

    <filter-mapping>

       <filter-name>osivFilter</filter-name>

       <url-pattern>*.jspx</url-pattern>

    </filter-mapping>

    <filter-mapping>

       <filter-name>processTime</filter-name>

       <url-pattern>*.jhtml</url-pattern>

    </filter-mapping>

    <filter-mapping>

       <filter-name>encoding</filter-name>

       <url-pattern>*.jhtml</url-pattern>

    </filter-mapping>

    <filter-mapping>

       <filter-name>osivFilter</filter-name>

       <url-pattern>*.jhtml</url-pattern>

    </filter-mapping>

    <filter-mapping>

       <filter-name>processTime</filter-name>

       <url-pattern>*.htm</url-pattern>

    </filter-mapping>

    <filter-mapping>

       <filter-name>encoding</filter-name>

       <url-pattern>*.htm</url-pattern>

    </filter-mapping>

    <filter-mapping>

       <filter-name>osivFilter</filter-name>

       <url-pattern>*.htm</url-pattern>

    </filter-mapping>

    <filter-mapping>

       <filter-name>processTime</filter-name>

       <url-pattern>*.jsp</url-pattern>

    </filter-mapping>

    <filter-mapping>

       <filter-name>encoding</filter-name>

       <url-pattern>*.jsp</url-pattern>

    </filter-mapping>

    <filter-mapping>

       <filter-name>osivFilter</filter-name>

       <url-pattern>*.jsp</url-pattern>

    </filter-mapping>

    <servlet>

       <servlet-name>JeeCmsAdmin</servlet-name>

       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

       <init-param>

           <param-name>contextConfigLocation</param-name>

           <param-value>/WEB-INF/config/jeecms-servlet-admin.xml</param-value>

       </init-param>

       <load-on-startup>1</load-on-startup>

    </servlet>

    <servlet>

       <servlet-name>JeeCmsFront</servlet-name>

       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

       <init-param>

           <param-name>contextConfigLocation</param-name>

           <param-value>/WEB-INF/config/jeecms-servlet-front.xml</param-value>

       </init-param>

       <load-on-startup>2</load-on-startup>

    </servlet>

    <servlet>

       <servlet-name>Jcaptcha</servlet-name>

       <servlet-class>com.jeecms.common.captcha.JcaptchaServlet</servlet-class>

    </servlet>

    <servlet-mapping>

       <servlet-name>Jcaptcha</servlet-name>

       <url-pattern>/captcha.svl</url-pattern>

    </servlet-mapping>

    <servlet>

       <servlet-name>DbFile</servlet-name>

       <servlet-class>com.jeecms.core.action.front.DbFileServlet</servlet-class>

    </servlet>

    <servlet-mapping>

       <servlet-name>JeeCmsAdmin</servlet-name>

       <url-pattern>/jeeadmin/jeecms/*</url-pattern>

    </servlet-mapping>

    <servlet-mapping>

       <servlet-name>JeeCmsFront</servlet-name>

       <url-pattern>*.jhtml</url-pattern>

    </servlet-mapping>

    <servlet-mapping>

       <servlet-name>JeeCmsFront</servlet-name>

       <url-pattern>*.jspx</url-pattern>

    </servlet-mapping>

    <servlet-mapping>

       <servlet-name>JeeCmsFront</servlet-name>

       <url-pattern>*.jsp</url-pattern>

    </servlet-mapping>

    <servlet-mapping>

       <servlet-name>JeeCmsFront</servlet-name>

       <url-pattern>*.htm</url-pattern>

    </servlet-mapping>

    <servlet-mapping>

       <servlet-name>DbFile</servlet-name>

       <url-pattern>/dbfile.svl</url-pattern>

    </servlet-mapping>

    <listener>

       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

    </listener>

    <listener>

        <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>

    </listener>

    <session-config>

       <session-timeout>20</session-timeout>

    </session-config>

    <!--

       <jsp-config>

           <taglib>

              <taglib-uri>http://displaytag.sf.net/el</taglib-uri>

              <taglib-location>/WEB-INF/tld/displaytag-el.tld</taglib-location>

           </taglib>

       </jsp-config>

       -->

    <welcome-file-list>

       <welcome-file>index.html</welcome-file>

       <welcome-file>index.jhtml</welcome-file>

    </welcome-file-list>

    <error-page>

       <error-code>403</error-code>

       <location>/WEB-INF/error/403.jsp</location>

    </error-page>

    <mime-mapping>

       <extension>rar</extension>

       <mime-type>application/zip</mime-type>

    </mime-mapping>

    <mime-mapping>

       <extension>doc</extension>

       <mime-type>application/zip</mime-type>

    </mime-mapping>

    <!--

       <error-page>

           <exception-type>java.lang.Throwable</exception-type>

           <location>/WEB-INF/error/uncaughtException.jsp</location>

       </error-page>

       <error-page>

           <error-code>500</error-code>

           <location>/WEB-INF/error/500.jsp</location>

       </error-page>

       <error-page>

           <error-code>404</error-code>

           <location>/WEB-INF/error/404.jsp</location>

       </error-page>

       -->

</web-app>

 

分析jeecms filter配置

几个公用的filter

<filter>

        <filter-name>processTime</filter-name>

        <filter-class>com.jeecms.common.web.ProcessTimeFilter</filter-class>

</filter>

 

 

可以记录处理时间的在外面统计加,感觉比原来在程序内部加的好.包括整个处理流程中的时间都会记录

processTime被配置在过滤器的最前端

下面是编码encoding过滤器

<filter>

        <filter-name>encoding</filter-name>

        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

        <init-param>

            <param-name>encoding</param-name>

            <param-value>UTF-8</param-value>

        </init-param>

</filter>

默认字符编码是utf-8

 

 

下面是编码osivFilter过滤器

    <filter>

        <filter-name>osivFilter</filter-name>

        <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>

    </filter>

一个Request的处理周期内,Session都是Open

 

 

对这几个filter

处理不同的扩展名的请求:*.do,*.jspx,*.jhtml,*.htm,*.jsp

processTime

à

?

encoding

à

?

osivFilter

 

后台处理过滤器

JeeCmsAdmin

/jeeadmin/jeecms/*

 

Jeecms路径前台采用的是二级路径,不属于后台的请求被前台的filter拦截

JeeCmsFront

*.do,*.jspx,*.jhtml,*.htm,*.jsp

 

验证码

Jcaptcha

/captcha.svl

 

DbFile

/dbfile.svl

com.jeecms.cms.action.front. DynamicPageAct中预处理这些请求如/news/index.jhtml

/**

             * <pre>

             

             * 映射所有路径到 这个方法如 /news/index.jhtml

                </pre>

*/

  @RequestMapping(value={"/**/*.*"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})

   public String dynamic(HttpServletRequest request, HttpServletResponse response, ModelMap model)

   {

     int pageNo = URLHelper.getPageNo(request);

     String[] params = URLHelper.getParams(request);

     URLHelper.PageInfo info = URLHelper.getPageInfo(request);

     String[] paths = URLHelper.getPaths(request);

     int len = paths.length;

     if (len == 1)

     {

       return channel(paths[0], pageNo, params, info, request, response,

         model);

     }if (len == 2) {

       if (paths[1].equals("index"))

       {

         return channel(paths[0], pageNo, params, info, request,

           response, model);

       }

       try

       {

         Integer id = Integer.valueOf(Integer.parseInt(paths[1]));

         return content(id, pageNo, params, info, request, response,

           model);

       } catch (NumberFormatException e) {

         log.debug("Content id must String: {}", paths[1]);

         return FrontUtils.pageNotFound(request, response, model);

       }

     }

 

     log.debug("Illegal path length: {}, paths: {}", Integer.valueOf(len), paths);

     return FrontUtils.pageNotFound(request, response, model);

   }

 

 

DynamicPageAct中将处理首页请求/””/index.jhtml”

@RequestMapping(value={"/"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})

   public String index(HttpServletRequest request, ModelMap model)

   {

     CmsSite site = CmsUtils.getSite(request);

     FrontUtils.frontData(request, model, site);

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

       "index""tpl.index");

   }

 

   @RequestMapping(value={"/index.jhtml"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})

   public String indexForWeblogic(HttpServletRequest request, ModelMap model)

   {

     return index(request, model);

   }

 

 

 

      

例如运行访问首页运行结果

/WEB-INF/t/cms/www/red

CmsSite.java

public String getSolutionPath()

{

     return "/WEB-INF/t/cms/" + getPath() + "/" + getTplSolution();

}

 

 

首页处理方法会返回到对应的视图:下面的首页地址

/WEB-INF/t/cms/www/red/index/首页.html

 

DynamicPageAct.java

 

   @RequestMapping(value={"/"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})

   public String index(HttpServletRequest request, ModelMap model)

   {

     CmsSite site = CmsUtils.getSite(request);

     FrontUtils.frontData(request, model, site);

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

       "index""tpl.index");

   }