📄 actionservlet.java.svn-base
字号:
+ config.getPrefix(), config); return config; } /** * <p>Parses one module config file.</p> * * @param digester Digester instance that does the parsing * @param path The path to the config file to parse. * @throws UnavailableException if file cannot be read or parsed * @since Struts 1.2 * @deprecated use parseModuleConfigFile(Digester digester, URL url) * instead */ protected void parseModuleConfigFile(Digester digester, String path) throws UnavailableException { try { List paths = splitAndResolvePaths(path); if (paths.size() > 0) { // Get first path as was the old behavior URL url = (URL) paths.get(0); parseModuleConfigFile(digester, url); } else { throw new UnavailableException("Cannot locate path " + path); } } catch (UnavailableException ex) { throw ex; } catch (ServletException ex) { handleConfigException(path, ex); } } /** * <p>Parses one module config file.</p> * * @param digester Digester instance that does the parsing * @param url The url to the config file to parse. * @throws UnavailableException if file cannot be read or parsed * @since Struts 1.3 */ protected void parseModuleConfigFile(Digester digester, URL url) throws UnavailableException { try { digester.parse(url); } catch (IOException e) { handleConfigException(url.toString(), e); } catch (SAXException e) { handleConfigException(url.toString(), e); } } /** * <p>Simplifies exception handling in the parseModuleConfigFile * method.<p> * * @param path The path to which the exception relates. * @param e The exception to be wrapped and thrown. * @throws UnavailableException as a wrapper around Exception */ private void handleConfigException(String path, Exception e) throws UnavailableException { String msg = internal.getMessage("configParse", path); log.error(msg, e); throw new UnavailableException(msg); } /** * <p>Handle errors related to creating an instance of the specified * class.</p> * * @param className The className that could not be instantiated. * @param e The exception that was caught. * @throws ServletException to communicate the error. */ private void handleCreationException(String className, Exception e) throws ServletException { String errorMessage = internal.getMessage("configExtends.creation", className); log.error(errorMessage, e); throw new UnavailableException(errorMessage); } /** * <p>General handling for exceptions caught while inheriting config * information.</p> * * @param configType The type of configuration object of configName. * @param configName The name of the config that could not be extended. * @param e The exception that was caught. * @throws ServletException to communicate the error. */ private void handleGeneralExtensionException(String configType, String configName, Exception e) throws ServletException { String errorMessage = internal.getMessage("configExtends", configType, configName); log.error(errorMessage, e); throw new UnavailableException(errorMessage); } /** * <p>Handle errors caused by required fields that were not * specified.</p> * * @param field The name of the required field that was not found. * @param configType The type of configuration object of configName. * @param configName The name of the config that's missing the required * value. * @throws ServletException to communicate the error. */ private void handleValueRequiredException(String field, String configType, String configName) throws ServletException { String errorMessage = internal.getMessage("configFieldRequired", field, configType, configName); log.error(errorMessage); throw new UnavailableException(errorMessage); } /** * <p>Initialize the plug ins for the specified module.</p> * * @param config ModuleConfig information for this module * @throws ServletException if initialization cannot be performed * @since Struts 1.1 */ protected void initModulePlugIns(ModuleConfig config) throws ServletException { if (log.isDebugEnabled()) { log.debug("Initializing module path '" + config.getPrefix() + "' plug ins"); } PlugInConfig[] plugInConfigs = config.findPlugInConfigs(); PlugIn[] plugIns = new PlugIn[plugInConfigs.length]; getServletContext().setAttribute(Globals.PLUG_INS_KEY + config.getPrefix(), plugIns); for (int i = 0; i < plugIns.length; i++) { try { plugIns[i] = (PlugIn) RequestUtils.applicationInstance(plugInConfigs[i] .getClassName()); BeanUtils.populate(plugIns[i], plugInConfigs[i].getProperties()); // Pass the current plugIn config object to the PlugIn. // The property is set only if the plugin declares it. // This plugin config object is needed by Tiles try { PropertyUtils.setProperty(plugIns[i], "currentPlugInConfigObject", plugInConfigs[i]); } catch (Exception e) { ; // FIXME Whenever we fail silently, we must document a valid // reason for doing so. Why should we fail silently if a // property can't be set on the plugin? /** * Between version 1.138-1.140 cedric made these changes. * The exceptions are caught to deal with containers * applying strict security. This was in response to bug * #15736 * * Recommend that we make the currentPlugInConfigObject part * of the PlugIn Interface if we can, Rob */ } plugIns[i].init(this, config); } catch (ServletException e) { throw e; } catch (Exception e) { String errMsg = internal.getMessage("plugIn.init", plugInConfigs[i].getClassName()); log(errMsg, e); throw new UnavailableException(errMsg); } } } /** * <p>Initialize the form beans for the specified module.</p> * * @param config ModuleConfig information for this module * @throws ServletException if initialization cannot be performed * @since Struts 1.3 */ protected void initModuleFormBeans(ModuleConfig config) throws ServletException { if (log.isDebugEnabled()) { log.debug("Initializing module path '" + config.getPrefix() + "' form beans"); } // Process form bean extensions. FormBeanConfig[] formBeans = config.findFormBeanConfigs(); for (int i = 0; i < formBeans.length; i++) { FormBeanConfig beanConfig = formBeans[i]; processFormBeanExtension(beanConfig, config); } for (int i = 0; i < formBeans.length; i++) { FormBeanConfig formBean = formBeans[i]; // Verify that required fields are all present for the form config if (formBean.getType() == null) { handleValueRequiredException("type", formBean.getName(), "form bean"); } // ... and the property configs FormPropertyConfig[] fpcs = formBean.findFormPropertyConfigs(); for (int j = 0; j < fpcs.length; j++) { FormPropertyConfig property = fpcs[j]; if (property.getType() == null) { handleValueRequiredException("type", property.getName(), "form property"); } } // Force creation and registration of DynaActionFormClass instances // for all dynamic form beans if (formBean.getDynamic()) { formBean.getDynaActionFormClass(); } } } /** * <p>Extend the form bean's configuration as necessary.</p> * * @param beanConfig the configuration to process. * @param moduleConfig the module configuration for this module. * @throws ServletException if initialization cannot be performed. */ protected void processFormBeanExtension(FormBeanConfig beanConfig, ModuleConfig moduleConfig) throws ServletException { try { if (!beanConfig.isExtensionProcessed()) { if (log.isDebugEnabled()) { log.debug("Processing extensions for '" + beanConfig.getName() + "'"); } beanConfig = processFormBeanConfigClass(beanConfig, moduleConfig); beanConfig.processExtends(moduleConfig); } } catch (ServletException e) { throw e; } catch (Exception e) { handleGeneralExtensionException("FormBeanConfig", beanConfig.getName(), e); } } /** * <p>Checks if the current beanConfig is using the correct class based on * the class of its ancestor form bean config.</p> * * @param beanConfig The form bean to check. * @param moduleConfig The config for the current module. * @return The form bean config using the correct class as determined by * the config's ancestor and its own overridden value. * @throws UnavailableException if an instance of the form bean config * class cannot be created. * @throws ServletException on class creation error */ protected FormBeanConfig processFormBeanConfigClass( FormBeanConfig beanConfig, ModuleConfig moduleConfig) throws ServletException { String ancestor = beanConfig.getExtends(); if (ancestor == null) { // Nothing to do, then return beanConfig; } // Make sure that this bean is of the right class FormBeanConfig baseConfig = moduleConfig.findFormBeanConfig(ancestor); if (baseConfig == null) { throw new UnavailableException("Unable to find " + "form bean '" + ancestor + "' to extend."); } // Was our bean's class overridden already? if (beanConfig.getClass().equals(FormBeanConfig.class)) { // Ensure that our bean is using the correct class if (!baseConfig.getClass().equals(beanConfig.getClass())) { // Replace the bean with an instance of the correct class FormBeanConfig newBeanConfig = null; String baseConfigClassName = baseConfig.getClass().getName(); try { newBeanConfig = (FormBeanConfig) RequestUtils.applicationInstance(baseConfigClassName); // copy the values BeanUtils.copyProperties(newBeanConfig, beanConfig); FormPropertyConfig[] fpc = beanConfig.findFormPropertyConfigs(); for (int i = 0; i < fpc.length; i++) { newBeanConfig.addFormPropertyConfig(fpc[i]); } } catch (Exception e) { handleCreationException(baseConfigClassName, e); } // replace beanConfig with newBeanConfig moduleConfig.removeFormBeanConfig(beanConfig); moduleConfig.addFormBeanConfig(newBeanConfig); beanConfig = newBeanConfig; } } return beanConfig; } /** * <p>Initialize the forwards for the specified module.</p> * * @param config ModuleConfig information for this module * @throws ServletException if initialization cannot be performed */ protected void initModuleForwards(ModuleConfig config) throws ServletException {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -