`
yelifei94
  • 浏览: 30333 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
社区版块
存档分类
最新评论

二、Jforum核心类 Jforum

阅读更多
<!-- 核心servlet 处理全部请求 -->
    <servlet>
		<servlet-name>jforum</servlet-name>
		<servlet-class>net.jforum.JForum</servlet-class>
		
		<init-param>
			<param-name>development</param-name>
			<param-value>true</param-value>
		</init-param>
    </servlet>

	<!-- Installer -->
	<!-- 初始化servlet -->
    <servlet>
    	<servlet-name>install</servlet-name>
    	<servlet-class>net.jforum.InstallServlet</servlet-class>
    	
    	<init-param>
			<param-name>development</param-name>
			<param-value>true</param-value>
		</init-param>
    </servlet>

    <!-- Mapping -->
    <servlet-mapping>
    	<servlet-name>install</servlet-name>
    	<url-pattern>/install/install.page</url-pattern>
    </servlet-mapping>
 
	<servlet-mapping>
    	<servlet-name>jforum</servlet-name>
    	<url-pattern>*.page</url-pattern>
    </servlet-mapping>

 

 

package net.jforum;


/**
 *集成基类Servlet JForumBaseServlet
 *JForumBaseServlet 中也是负责对一起基本配置的加载
 *搭配环境
 */
public class JForum extends JForumBaseServlet {
	private static boolean isDatabaseUp;

	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		super.startApplication();

		isDatabaseUp = ForumStartup.startDatabase();
		try {
			Connection conn = DBConnection.getImplementation().getConnection();
			
			/**
			 * 所有的SystemGlobals.getValue都是获取配置文件中的信息,至于他是如何加载配置文件
			 */
			conn.setAutoCommit(!(SystemGlobals
					.getBoolValue("database.use.transactions")));

			MySQLVersionWorkarounder dw = new MySQLVersionWorkarounder();
			dw.handleWorkarounds(conn);

			JForumExecutionContext ex = JForumExecutionContext.get();
			ex.setConnection(conn);
			JForumExecutionContext.set(ex);

			ForumStartup.startForumRepository();
			// 字面意思理解,加载排行,表情,板块信息
			RankingRepository.loadRanks();
			SmiliesRepository.loadSmilies();
			BanlistRepository.loadBanlist();
		} catch (Throwable e) {
			throw new ForumStartupException("Error while starting jforum", e);
		} finally {
			JForumExecutionContext.finish();
		}
	}

	/**
	 * 这个方法是重点,他负调用其他的业务层,处理数据
	 */
	public void service(HttpServletRequest req, HttpServletResponse res)
			throws IOException, ServletException {
		Writer out = null;

		/**
		 * JForumContext保存了容器的一些基本信息 从他的属性可以看出来 
		 * contextPath : 容器路径 不知道怎么理解
		 * servletExtension : servlet的拓展
		 * request :servlet原始请求信息
		 * response : 
		 * isEncodingDisabled : boolean 
		 * isBot : boolean
		 */
		JForumContext forumContext = null;
		RequestContext request = null;
		ResponseContext response = null;
		
		/**
		 * 获取默认编码 在config/database下面 不同的数据库都有
		 */
		String encoding = SystemGlobals.getValue("encoding");
		try {
			JForumExecutionContext ex = JForumExecutionContext.get();

			req.getParameterNames();
			
			/**
			 * WebRequestContext 这个类也非常重要,
			 * 它负责对请求的一些参数处理
			 */
			request = new WebRequestContext(req);
			response = new WebResponseContext(res);

			checkDatabaseStatus();
            
			/**
			 * 创建 JForumContext对象 封装容器基本信息
			 */
			forumContext = new JForumContext(request.getContextPath(),
					SystemGlobals.getValue("servlet.extension"), request,
					response);

			ex.setForumContext(forumContext);

			JForumExecutionContext.set(ex);

			/**
			 * context是封装在jar包里面的容器模板
			 */
			SimpleHash context = JForumExecutionContext.getTemplateContext();

			ControllerUtils utils = new ControllerUtils();
			utils.refreshSession();

			/**
			 * 下面是系列的通用处理过程,把一些配置信息加载到容器当中
			 * ,对我们改装jforum功能作用不大
			 */
			context.put("logged", SessionFacade.isLogged());

			SecurityRepository.load(SessionFacade.getUserSession().getUserId());

			utils.prepareTemplateContext(context, forumContext);

			String module = request.getModule();

			String moduleClass = (module != null) ? ModulesRepository
					.getModuleClass(module) : null;

			if (moduleClass == null) {
				response.sendError(404);
			} else {
				boolean shouldBan = shouldBan(request.getRemoteAddr());

				if (!(shouldBan)) {
					context.put("moduleName", module);
					context.put("action", request.getAction());
				} else {
					moduleClass = ModulesRepository.getModuleClass("forums");
					context.put("moduleName", "forums");
					((WebRequestContext) request).changeAction("banned");
				}

				if ((shouldBan)
						&& (SystemGlobals
								.getBoolValue("banlist.send.403forbidden"))) {
					response.sendError(403);
				} else {
					context.put("language", I18n.getUserLanguage());
					context.put("session", SessionFacade.getUserSession());
					context.put("request", req);
					context.put("response", response);

					out = processCommand(out, request, response, encoding,
							context, moduleClass);
				}
			}
		} catch (Exception e) {
			handleException(out, response, encoding, e, request);
		} finally {
			handleFinally(out, forumContext, response);
		}
	}
}

 

 

   如果需要 跟踪数据的话 毫无疑问是从这个类开始,以及编码 等其他信息均可在这里得到。

0
1
分享到:
评论

相关推荐

    Jforum二次开发成果

    Jforum二次开发成果 Jforum 二次开发 eclipse 给予JForum 2.1.8开发的一个小论坛。 增加了很多功能。(子论坛、主页、热门帖子、推荐帖子等)

    jforum二次开发 详解 BBS开源安装

    jforum二次开发 详解 BBS开源安装

    JForum论坛数据库表结构.rar

    1、附件关系表JFORUM_ATTACH 2 2、附件详细信息表JFORUM_ATTACH_DESC 2 3、附件配置限定关系表JFORUM_ATTACH_QUOTA 2 4、封锁表JFORUM_BANLIST 2 5、标识表JFORUM_BANNER 3 6、书签表JFORUM_BOOKMARKS 3 7、...

    jforum功能说明

    可以说JForum是论坛二次开发的绝佳选择。 JForum采用的是自己的MVC框架,因此在初次接触的时候可能会有些不习惯,但在熟悉后,该框架还是很容易使用的。在这里只是对JForum的框架进行简单的介绍以利于利用JForum...

    JForum3 jforum java 开源论坛 论坛

    JForum3 jforum java 开源论坛 论坛

    jforum3.0所需要的jar包

    jforum3.0所需要的jar包

    Jforum数据库

    JForum - Java论坛系统 数据库表结构,如:附件关系表JFORUM_ATTACH,附件详细信息表JFORUM_ATTACH_DESC,用户分组表JFORUM_GROUPS等表结构说明,如帖子表JFORUM_POSTS说明: 名称 字段名 字段类型 字段说明 帖子...

    Jforum论坛数据库架构

    Jforum论坛数据库架构Jforum论坛数据库架构

    jforum漏洞利用源代码

    jforum漏洞利用源代码

    JForum 2.1.9 源码包.zip

    JForum 是采用Java开发的功能强大且稳定...JForum 采用 FreeMarker 作为页面模板引擎,支持包括中文在内的二十几种语言。 JForum 最大的优点是采用 BSD 开源协议,你可以最大限度的进行任何修改和扩展,包括商业用途。

    jforum开源的论坛文档

    jforum开源的论坛文档jforum开源的论坛文档jforum开源的论坛文档

    JForum3 完整项目

    jforum 完整源代码,从svn上 导出 没有任何修改

    JForum_SSO_-_JForum单点登陆原理与配置

    对于我们已有的WEB应用中的用户,若该用户已经登陆,并通过 联结迁移到JForum页面时,JForum要能够识别该用户已经登陆(不需要二次登陆)才不会让用户感到别扭(对用户来说,就好像使用的是同一个系统似的)。...

    JForum数据库ER图

    JForum 开源论坛系统的 数据库ER图,很详细。

    JForum2.6.2.rar

    1、包含jforum2.6.2的war包、源码包 2、war包可直接放在tomcat的webapps目录下 3、2.6.2版本里面自带汉化功能,在http://localhost:8080/jforum/install.jsp安装时,注意选择中文

    JForum v2.1.9 源码版

    JForum 是采用Java开发的功能强大且稳定的...JForum 采用 FreeMarker 作为页面模板引擎,支持包括中文在内的二十几种语言。JForum 最大的优点是采用 BSD 开源协议,你可以最大限度的进行任何修改和扩展,包括商业用途。

    jforum说明文档 源码解析 单点登录 jforum缓存

    jforum的开发文档,以及源码解析 数据库 重要配置文件和包,缓存 权限控制 单点登录

    jforum安装部署指南

    jforum安装部署指南:修改对应的数据库文件JFORUM\WEB-INF\config\database下面。例如:mysql.properties修改其中的数据库信息

    jforum论坛整合说明

    本文档是自己在做jforum二次开发过程中遇到的一些问题的总结。如果你做jforum整合,相信会给你帮助。

    jforum论坛图片资源

    用于配置中文jforum,里面包含各种语言的图片文件,将其中的zh_CN目录复制到jforum安装目录下的templates\default\images。就可以显示中文图片

Global site tag (gtag.js) - Google Analytics