/**
* <p>Initialize this servlet. Most of the processing has been factored into
* support methods so that you can overrideparticular functionality at a
* fairly granular level.</p>
*
* @exception ServletException if we cannotconfigure ourselves correctly
*/
publicvoidinit() throwsServletException {
// Wraps the entire initialization in a try/catch tobetter handle
// unexpected exceptions and errors to provide better feedback
// to the developer
try {
initInternal();
initOther();
initServlet();
getServletContext().setAttribute(Globals.ACTION_SERVLET_KEY, this);
initModuleConfigFactory();
// Initialize modules as needed
ModuleConfig moduleConfig =initModuleConfig("", config);
initModuleMessageResources(moduleConfig);
initModuleDataSources(moduleConfig);
initModulePlugIns(moduleConfig);
moduleConfig.freeze();
Enumeration names =getServletConfig().getInitParameterNames();
while (names.hasMoreElements()) {
String name = (String)namesnextElement();
if (!name.startsWith("config/")) {
continue;
}
String prefix =name.substring(6);
moduleConfig = initModuleConfig
(prefix,getServletConfig().getInitParameter(name));
initModuleMessageResources(moduleConfig);
initModuleDataSources(moduleConfig);
initModulePlugIns(moduleConfig);
moduleConfig.freeze();
}
this.initModulePrefixes(this.getServletContext());
thisdestroyConfigDigester();
} catch (UnavailableException ex) {
throw ex;
} catch (Throwable t) {
// The follow error message is not retrieved from internal message
// resources as they may not have been able to have been
// initialized
logerror("Unable to initialize Struts ActionServlet due to an "
+ "unexpected exception or error thrown, so marking the "
+ "servlet as unavailable. Mostlikely, this is due to an "
+ "incorrect or missing library dependency.", t);
throw new UnavailableException(t.getMessage());
}
}
/**
* <p>Initialize our internal MessageResourcesbundle</p>
*
* @exception ServletException if we cannotinitialize these resources
*/
protectedvoidinitInternal() throwsServletException {
// :FIXME: Document UnavailableException
try {
internal = MessageResourcesgetMessageResources(internalName);
} catch (MissingResourceException e) {
log.error("Cannot load internal resources from '"+ internalName+ "'",
e);
throw new UnavailableException
("Cannot load internal resources from '"+ internalName+ "'");
}
}
/**
* Create and return an instance of <code>MessageResources</code> for the
* created by the default <code>MessageResourcesFactory</code>.
*
* @param config Configuration parameterfor this message bundle.
*/
publicsynchronizedstaticMessageResources getMessageResources(String config) {
if (defaultFactory == null) {
defaultFactory =MessageResourcesFactory.createFactory();
}
return defaultFactory.createResources(config);
}
/**
* Create and return a <code>MessageResourcesFactory</code> instance ofthe
* appropriate class, which can be used tocreate customized
* <code>MessageResources</code>instances If no such factory can be
* created, return <code>null</code> instead
*/
publicstaticMessageResourcesFactory createFactory(){
// Construct a new instance of the specified factory class
try {
if (clazz == null)
clazz = RequestUtils.applicationClass(factoryClass);
MessageResourcesFactory factory =
(MessageResourcesFactory) clazz.newInstance();
return (factory);
} catch (Throwable t) {
LOG.error("MessageResourcesFactory.createFactory",t);
return (null);
}
}
/**
* <p>Initialize other global characteristics ofthe controller servlet</p>
*
* @exception ServletException if we cannotinitialize these resources
*/
protectedvoidinitOther() throwsServletException {
String value = null;
value =getServletConfig().getInitParameter("config");
if (value != null) {
config = value;
}
// Backwards compatibility for form beans of Java wrapper classes
// Set to true for strict Struts 0 compatibility
value =getServletConfig().getInitParameter("convertNull");
if ("true".equalsIgnoreCase(value)
|| "yes".equalsIgnoreCase(value)
|| "on".equalsIgnoreCase(value)
|| "y".equalsIgnoreCase(value)
|| "1".equalsIgnoreCase(value)) {
convertNull = true;
}
if (convertNull) {
ConvertUtils.deregister();
ConvertUtils.register(new BigDecimalConverter(null), BigDecimal.class);
ConvertUtils.register(new BigIntegerConverter(null), BigInteger.class);
ConvertUtils.register(new BooleanConverter(null), Boolean.class);
ConvertUtils.register(new ByteConverter(null), Byte.class);
ConvertUtils.register(new CharacterConverter(null), Character.class);
ConvertUtils.register(new DoubleConverter(null), Double.class);
ConvertUtils.register(new FloatConverter(null), Float.class);
ConvertUtils.register(new IntegerConverter(null), Integer.class);
ConvertUtils.register(new LongConverter(null), Long.class);
ConvertUtils.register(new ShortConverter(null), Short.class);
}
}
/**
* <p>Initialize the servlet mapping under which our controller servlet
* is being accessed. This will be used in the <code>&html:form></code>
* tag to generate correct destination URLs for form submissions.</p>
*
* @throws ServletException if error happens while scanning web.xml
*/
protected void initServlet() throws ServletException {
// Remember our servlet name
this.servletName = getServletConfig().getServletName();
// Prepare a Digester to scan the web application deployment descriptor
Digester digester = new Digester();
digester.push(this);
digester.setNamespaceAware(true);
digester.setValidating(false);
// Register our local copy of the DTDs that we can find
for (int i = 0; i < registrations.length; i += 2) {
URL url = this.getClass().getResource(registrations[i+1]);
if (url != null) {
digester.register(registrations[i], url.toString());
}
}
// Configure the processing rules that we need
digester.addCallMethod("web-app/servlet-mapping",
"addServletMapping", 2);
digester.addCallParam("web-app/servlet-mapping/servlet-name", 0);
digester.addCallParam("web-app/servlet-mapping/url-pattern", 1);
// Process the web application deployment descriptor
if (log.isDebugEnabled()) {
log.debug("Scanning web.xml for controller servlet mapping");
}
InputStream input =
getServletContext().getResourceAsStream("/WEB-INF/web.xml");
if (input == null) {
log.error(internal.getMessage("configWebXml"));
throw new ServletException(internal.getMessage("configWebXml"));
}
try {
digester.parse(input);
} catch (IOException e) {
log.error(internal.getMessage("configWebXml"), e);
throw new ServletException(e);
} catch (SAXException e) {
log.error(internal.getMessage("configWebXml"), e);
throw new ServletException(e);
} finally {
try {
input.close();
} catch (IOException e) {
log.error(internal.getMessage("configWebXml"), e);
throw new ServletException(e);
}
}
// Record a servlet context attribute (if appropriate)
if (log.isDebugEnabled()) {
logdebug("Mapping for servlet '" + servletName + "' = '" +
servletMapping + "'");
}
if (servletMapping != null) {
getServletContext().setAttribute(Globals.SERVLET_KEY, servletMapping);
}
}
public void init() throws ServletException {
try {
//初始化资源类
initInternal();
//注册转换类
initOther();
//利用digester读取webxml文件并且将其放到servletContext中
initServlet();
getServletContext().setAttribute(Globals.ACTION_SERVLET_KEY, this);
initModuleConfigFactory();
ModuleConfig moduleConfig = initModuleConfig("", config);
initModuleMessageResources(moduleConfig);
initModuleDataSources(moduleConfig);
initModulePlugIns(moduleConfig);
moduleConfig.freeze();
Enumeration names = getServletConfig().getInitParameterNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
if (!name.startsWith("config/")) {
continue;
}
String prefix = name.substring(6);
moduleConfig = initModuleConfig
(prefix, getServletConfig()getInitParameter(name));
initModuleMessageResources(moduleConfig);
initModuleDataSources(moduleConfig);
initModulePlugIns(moduleConfig);
moduleConfig.freeze();
}
this.initModulePrefixes(this.getServletContext());
this.destroyConfigDigester();
} catch (UnavailableException ex) {
throw ex;
} catch (Throwable t) {
log.error("Unable to initialize Struts ActionServlet due to an "
+ "unexpected exception or error thrown, so marking the "
+ "servlet as unavailable Most likely, this is due to an "
+ "incorrect or missing library dependency", t);
throw new UnavailableException(t.getMessage());
}
}
public static final String ACTION_SERVLET_KEY= "org.apache.struts.action.ACTION_SERVLET";
protected voidinitModuleConfigFactory(){
String configFactory =getServletConfig().getInitParameter("configFactory");
if (configFactory != null) {
ModuleConfigFactory.setFactoryClass(configFactory);
}
}
public static void setFactoryClass(String factoryClass) {
ModuleConfigFactory.factoryClass = factoryClass;
ModuleConfigFactory.clazz = null;
}
protected static String factoryClass =
"org.apache.struts.config.impl.DefaultModuleConfigFactory";
}
protected ModuleConfig initModuleConfig(Stringprefix, String paths)
throws ServletException {
// :FIXME: Document UnavailableException? (Doesn't actually throw anything)
if (log.isDebugEnabled()) {
log.debug(
"Initializing module path '"
+ prefix
+ "' configuration from '"
+ paths
+ "'");
}
// Parse the configuration for this module
ModuleConfigFactory factoryObject= ModuleConfigFactory.createFactory();
ModuleConfig config =factoryObject.createModuleConfig(prefix);
// Configure the Digester instance we will use
Digester digester =initConfigDigester();
// Process each specified resource path
while (paths.length() > 0) {
digester.push(config);
String path = null;
int comma = paths.indexOf(',');
if (comma >= 0) {
path =paths.substring(0, comma).trim();
paths =paths.substring(comma + 1);
} else {
path = pathstrim();
paths = "";
}
if (pathlength() < 1){
break;
}
this.parseModuleConfigFile(digester,path);
}
getServletContext().setAttribute(
Globals.MODULE_KEY +config.getPrefix(),
config);
// Force creation and registration of DynaActionFormClass instances
// for all dynamic form beans we wil be using
FormBeanConfig fbs[] =config.findFormBeanConfigs();
for (int i = 0; i < fbs.length; i++) {
if (fbs[i].getDynamic()) {
fbs[i].getDynaActionFormClass();
}
}
return config;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有