环境: 在tomcat中,
第一次访问Roller,要进行一些配置:
在$CATALINA_HOME中的 common/classes 目录中,新建一下客户环境化的配置文件: roller-custom.properties,
其实只要放在classpath中的任何一个目录中即可。
installation.type=auto
database.configurationType=jdbc
database.jdbc.driverClass=com.mysql.jdbc.Driver
database.jdbc.connectionURL=jdbc:mysql://localhost:3306/rollerdb
database.jdbc.username=scott
database.jdbc.password=tiger
mail.configurationType=properties
mail.hostName=smtp-server.example.com
mail.username=scott
mail.password=tiger
最主要的是 installation.type=auto,表示我们第一次要创建数据库结构
其他的配置:以database开始的是数据库连接的配置
以mail开始的是mail provider的配置
根据实际环境配置好后,可以启动tomcat,访问roller了
由于第一次访问配置的是 installation.type=auto, 在访问的时候被Filter : BootstrapFilter截获,
url被转向到 /roller-ui/install/install.rol
在Roller中,struts的请求后最被修改成 rol 了
这个在 struts.properties 中定义的 (Roller有一个struts.properties, 还有一个 struts.xml, 2个混用,不过一般只和struts相关的配置,都配置在 properties文件中,和应用相关的配置在xml文件中)
struts.action.extension=rol
在struts中的配置为:
<!-- Weblogger install/bootstrap actions -->
<package name="weblogger-install" namespace="/roller-ui/install" extends="weblogger">
<action name="install"
class="org.apache.roller.weblogger.ui.struts2.core.Install">
<result name="database_error" type="tiles">.DatabaseError</result>
<result name="create_database" type="tiles">.CreateDatabase</result>
<result name="upgrade_database" type="tiles">.UpgradeDatabase</result>
<result name="bootstrap" type="tiles">.Bootstrap</result>
<result name="success" type="chain">home</result>
</action>
</package>
安装是通过 org.apache.roller.weblogger.ui.struts2.core.Install 来完成的。
install类继承 UIAction
UIAction 继承 ActionSupport : 这个就不用解释了,UIAction在ActionSupport基础上增加了对error和状态的控制;
实现 UIActionPreparable
UISecurityEnforced
UIActionPreparable:的解释:
/**
* A Roller specific version of the struts2 Preparable interface.
*
* We only have this because we don't want to use the struts2 Preparable IF due
* to the fact that it is meant to be called much earlier in the interceptor
* stack, namely before our custom interceptors have been processed. While
* that may make sense in some cases, typically we want to prepare things based
* on the user or weblog that we are working on, so it's often of more use for
* us to prepare *after* our custom interceptors have been processed.
*
* So, this duplicate of the struts2 Preparable interface is here so that we
* can leave the default struts2 prepare() logic in place for any actions we
* may define that want to use that, but also provide a prepare option that is
* executed at the very end of our interceptor stack, just before the action
* method is executed. This way our custom prepare method can make use of
* anything our custom interceptors provide.
只是在Action执行之前的最后一步执行的工作
*/
public interface UIActionPreparable {
public void myPrepare();
}
UISecurityEnforced: 是有关权限的,但是需要Action进行实现
/**
* Implemented by struts2 actions which want to enforce some level of security
* protection on their action.
*
* Available enforcements are ...
* - require a logged in user
* - reguire a valid weblog to work on
* - require a specific user role, such as "admin"
* - require a specific weblog permission
*
*/
--------------------
install根据在系统初始化的时候的不同状态,返回不同的页面:
都是通过WebloggerStartup来获取状态的;
如果状态是需要创建数据库的,到:
<result name="create_database" type="tiles">.CreateDatabase</result>
---------------------
在Roller,页面采用tiles,看一下安装页面的配置:.CreateDatabase
<definition name=".CreateDatabase" extends=".tiles-installpage" >
<put-attribute name="content" value="/WEB-INF/jsps/core/CreateDatabase.jsp" />
<put-attribute name="footer" value="/WEB-INF/jsps/tiles/empty.jsp" />
<put-attribute name="banner" value="/WEB-INF/jsps/tiles/bannerInstallation.jsp" />
</definition>
每个页面,一开始都是加载:<%@ include file="/WEB-INF/jsps/taglibs-struts2.jsp" %>
这个里面包含了Response编码定义、所有的标签引用定义:
<% response.setContentType("text/html; charset=UTF-8"); %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib uri="http://jakarta.apache.org/taglibs/string-1.0.1" prefix="str" %>
在安装的页面中,主要关心:
/WEB-INF/jsps/core/CreateDatabase.jsp
这个是实际操作的页面。
创建数据库,调用的是
<s:form action="install!create">
<s:submit key="installer.yesCreateTables" />
</s:form>
install的create方法,实际调用WebloggerStartup的createDatabase方法。
调用 DatabaseInstaller的createbase
创建的时候,根据数据库连接获取提供厂商的名字: con.getMetaData().getDatabaseProductName
根据厂商的名字,到各自目录中,获取 createdb.sql 文件--- 具体的在 /dbscripts/厂商/createdb.sql 文件中,创建数据库脚本,
至此,数据库创建完成。