📄 actionservlet.java.svn-base
字号:
protected void processActionConfigExtension(ActionConfig actionConfig, ModuleConfig moduleConfig) throws ServletException { try { if (!actionConfig.isExtensionProcessed()) { if (log.isDebugEnabled()) { log.debug("Processing extensions for '" + actionConfig.getPath() + "'"); } actionConfig = processActionConfigClass(actionConfig, moduleConfig); actionConfig.processExtends(moduleConfig); } // Process forwards extensions. ForwardConfig[] forwards = actionConfig.findForwardConfigs(); for (int i = 0; i < forwards.length; i++) { ForwardConfig forward = forwards[i]; processForwardExtension(forward, moduleConfig, actionConfig); } // Process exception extensions. ExceptionConfig[] exceptions = actionConfig.findExceptionConfigs(); for (int i = 0; i < exceptions.length; i++) { ExceptionConfig exception = exceptions[i]; processExceptionExtension(exception, moduleConfig, actionConfig); } } catch (ServletException e) { throw e; } catch (Exception e) { handleGeneralExtensionException("Action", actionConfig.getPath(), e); } } /** * <p>Checks if the current actionConfig is using the correct class based * on the class of its ancestor ActionConfig.</p> * * @param actionConfig The action config to check. * @param moduleConfig The config for the current module. * @return The config object using the correct class as determined by the * config's ancestor and its own overridden value. * @throws ServletException if an instance of the action config class * cannot be created. */ protected ActionConfig processActionConfigClass(ActionConfig actionConfig, ModuleConfig moduleConfig) throws ServletException { String ancestor = actionConfig.getExtends(); if (ancestor == null) { // Nothing to do, then return actionConfig; } // Make sure that this config is of the right class ActionConfig baseConfig = moduleConfig.findActionConfig(ancestor); if (baseConfig == null) { throw new UnavailableException("Unable to find " + "action config for '" + ancestor + "' to extend."); } // Was our actionConfig's class overridden already? if (actionConfig.getClass().equals(ActionMapping.class)) { // Ensure that our config is using the correct class if (!baseConfig.getClass().equals(actionConfig.getClass())) { // Replace the config with an instance of the correct class ActionConfig newActionConfig = null; String baseConfigClassName = baseConfig.getClass().getName(); try { newActionConfig = (ActionConfig) RequestUtils.applicationInstance(baseConfigClassName); // copy the values BeanUtils.copyProperties(newActionConfig, actionConfig); // copy the forward and exception configs, too ForwardConfig[] forwards = actionConfig.findForwardConfigs(); for (int i = 0; i < forwards.length; i++) { newActionConfig.addForwardConfig(forwards[i]); } ExceptionConfig[] exceptions = actionConfig.findExceptionConfigs(); for (int i = 0; i < exceptions.length; i++) { newActionConfig.addExceptionConfig(exceptions[i]); } } catch (Exception e) { handleCreationException(baseConfigClassName, e); } // replace actionConfig with newActionConfig moduleConfig.removeActionConfig(actionConfig); moduleConfig.addActionConfig(newActionConfig); actionConfig = newActionConfig; } } return actionConfig; } /** * <p>Initialize the application <code>MessageResources</code> 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 initModuleMessageResources(ModuleConfig config) throws ServletException { MessageResourcesConfig[] mrcs = config.findMessageResourcesConfigs(); for (int i = 0; i < mrcs.length; i++) { if ((mrcs[i].getFactory() == null) || (mrcs[i].getParameter() == null)) { continue; } if (log.isDebugEnabled()) { log.debug("Initializing module path '" + config.getPrefix() + "' message resources from '" + mrcs[i].getParameter() + "'"); } String factory = mrcs[i].getFactory(); MessageResourcesFactory.setFactoryClass(factory); MessageResourcesFactory factoryObject = MessageResourcesFactory.createFactory(); factoryObject.setConfig(mrcs[i]); MessageResources resources = factoryObject.createResources(mrcs[i].getParameter()); resources.setReturnNull(mrcs[i].getNull()); resources.setEscape(mrcs[i].isEscape()); getServletContext().setAttribute(mrcs[i].getKey() + config.getPrefix(), resources); } } /** * <p>Create (if needed) and return a new <code>Digester</code> instance * that has been initialized to process Struts module configuration files * and configure a corresponding <code>ModuleConfig</code> object (which * must be pushed on to the evaluation stack before parsing begins).</p> * * @return A new configured <code>Digester</code> instance. * @throws ServletException if a Digester cannot be configured * @since Struts 1.1 */ protected Digester initConfigDigester() throws ServletException { // :FIXME: Where can ServletException be thrown? // Do we have an existing instance? if (configDigester != null) { return (configDigester); } // Create a new Digester instance with standard capabilities configDigester = new Digester(); configDigester.setNamespaceAware(true); configDigester.setValidating(this.isValidating()); configDigester.setUseContextClassLoader(true); configDigester.addRuleSet(new ConfigRuleSet()); for (int i = 0; i < registrations.length; i += 2) { URL url = this.getClass().getResource(registrations[i + 1]); if (url != null) { configDigester.register(registrations[i], url.toString()); } } this.addRuleSets(); // Return the completely configured Digester instance return (configDigester); } /** * <p>Add any custom RuleSet instances to configDigester that have been * specified in the <code>rulesets</code> init parameter.</p> * * @throws ServletException if an error occurs */ private void addRuleSets() throws ServletException { String rulesets = getServletConfig().getInitParameter("rulesets"); if (rulesets == null) { rulesets = ""; } rulesets = rulesets.trim(); String ruleset; while (rulesets.length() > 0) { int comma = rulesets.indexOf(","); if (comma < 0) { ruleset = rulesets.trim(); rulesets = ""; } else { ruleset = rulesets.substring(0, comma).trim(); rulesets = rulesets.substring(comma + 1).trim(); } if (log.isDebugEnabled()) { log.debug("Configuring custom Digester Ruleset of type " + ruleset); } try { RuleSet instance = (RuleSet) RequestUtils.applicationInstance(ruleset); this.configDigester.addRuleSet(instance); } catch (Exception e) { log.error("Exception configuring custom Digester RuleSet", e); throw new ServletException(e); } } } /** * <p>Check the status of the <code>validating</code> initialization * parameter.</p> * * @return true if the module Digester should validate. */ private boolean isValidating() { boolean validating = true; String value = getServletConfig().getInitParameter("validating"); if ("false".equalsIgnoreCase(value) || "no".equalsIgnoreCase(value) || "n".equalsIgnoreCase(value) || "0".equalsIgnoreCase(value)) { validating = false; } return validating; } /** * <p>Initialize our internal MessageResources bundle.</p> * * @throws ServletException if we cannot initialize these resources * @throws UnavailableException if we cannot load resources */ protected void initInternal() throws ServletException { try { internal = MessageResources.getMessageResources(internalName); } catch (MissingResourceException e) { log.error("Cannot load internal resources from '" + internalName + "'", e); throw new UnavailableException( "Cannot load internal resources from '" + internalName + "'"); } } /** * <p>Parse the configuration documents specified by the * <code>chainConfig</code> init-param to configure the default {@link * org.apache.commons.chain.Catalog} that is registered in the {@link * CatalogFactory} instance for this application.</p> * * @throws ServletException if an error occurs. */ protected void initChain() throws ServletException { // Parse the configuration file specified by path or resource try { String value; value = getServletConfig().getInitParameter("chainConfig"); if (value != null) { chainConfig = value; } ConfigParser parser = new ConfigParser(); List urls = splitAndResolvePaths(chainConfig); URL resource; for (Iterator i = urls.iterator(); i.hasNext();) { resource = (URL) i.next(); log.info("Loading chain catalog from " + resource); parser.parse(resource); } } catch (Exception e) { log.error("Exception loading resources", e); throw new ServletException(e); } } /** * <p>Initialize other global characteristics of the controller * servlet.</p> * * @throws ServletException if we cannot initialize these resources */ protected void initOther() throws ServletException { String value; value = getServletConfig().getInitParameter("config"); if (value != null) { config = value; } // Backwards compatibility for form beans of Java wrapper classes // Set to true for strict Struts 1.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.regist
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -