⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 actionservlet.java

📁 将strutsConn目录拷贝到tomcat服务器的webapps目录下
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    }

    protected ApplicationConfig getApplicationConfig(HttpServletRequest request)
    {
        return new ApplicationConfig((ModuleConfigImpl)getModuleConfig(request));
    }

    protected ModuleConfig getModuleConfig(HttpServletRequest request)
    {
        ModuleConfig config = (ModuleConfig)request.getAttribute("org.apache.struts.action.MODULE");
        if(config == null)
            config = (ModuleConfig)getServletContext().getAttribute("org.apache.struts.action.MODULE");
        return config;
    }

    protected synchronized RequestProcessor getRequestProcessor(ModuleConfig config)
        throws ServletException
    {
        String key = "org.apache.struts.action.REQUEST_PROCESSOR" + config.getPrefix();
        RequestProcessor processor = (RequestProcessor)getServletContext().getAttribute(key);
        if(processor == null)
        {
            try
            {
                processor = (RequestProcessor)RequestUtils.applicationInstance(config.getControllerConfig().getProcessorClass());
            }
            catch(Exception e)
            {
                throw new UnavailableException("Cannot initialize RequestProcessor of class " + config.getControllerConfig().getProcessorClass() + ": " + e);
            }
            processor.init(this, config);
            getServletContext().setAttribute(key, processor);
        }
        return processor;
    }

    protected ApplicationConfig initApplicationConfig(String prefix, String path)
        throws ServletException
    {
        return new ApplicationConfig((ModuleConfigImpl)initModuleConfig(prefix, path));
    }

    protected ModuleConfig initModuleConfig(String prefix, String paths)
        throws ServletException
    {
        if(log.isDebugEnabled())
            log.debug("Initializing module path '" + prefix + "' configuration from '" + paths + "'");
        ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();
        ModuleConfig config = factoryObject.createModuleConfig(prefix);
        String mapping = getServletConfig().getInitParameter("mapping");
        if(mapping != null)
            config.setActionMappingClass(mapping);
        Digester digester = initConfigDigester();
        String path;
        for(; paths.length() > 0; parseModuleConfigFile(prefix, paths, config, digester, path))
        {
            digester.push(config);
            path = null;
            int comma = paths.indexOf(44);
            if(comma >= 0)
            {
                path = paths.substring(0, comma).trim();
                paths = paths.substring(comma + 1);
            }
            else
            {
                path = paths.trim();
                paths = "";
            }
            if(path.length() < 1)
                break;
        }

        FormBeanConfig fbs[] = config.findFormBeanConfigs();
        for(int i = 0; i < fbs.length; i++)
            if(fbs[i].getDynamic())
                DynaActionFormClass.createDynaActionFormClass(fbs[i]);

        if(prefix.length() < 1)
        {
            defaultControllerConfig(config);
            defaultMessageResourcesConfig(config);
            defaultFormBeansConfig(config);
            defaultForwardsConfig(config);
            defaultMappingsConfig(config);
        }
        return config;
    }

    private void parseModuleConfigFile(String prefix, String paths, ModuleConfig config, Digester digester, String path)
        throws UnavailableException
    {
        InputStream input = null;
        URL url = getServletContext().getResource(path);
        InputSource is = new InputSource(url.toExternalForm());
        input = getServletContext().getResourceAsStream(path);
        is.setByteStream(input);
        digester.parse(is);
        getServletContext().setAttribute("org.apache.struts.action.MODULE" + prefix, config);
        MalformedURLException e;
        if(input != null)
            try
            {
                input.close();
            }
            // Misplaced declaration of exception variable
            catch(MalformedURLException e)
            {
                throw new UnavailableException(e.getMessage());
            }
        break MISSING_BLOCK_LABEL_271;
        e;
        handleConfigException(paths, e);
        IOException e;
        if(input != null)
            try
            {
                input.close();
            }
            // Misplaced declaration of exception variable
            catch(IOException e)
            {
                throw new UnavailableException(e.getMessage());
            }
        break MISSING_BLOCK_LABEL_271;
        e;
        handleConfigException(paths, e);
        SAXException e;
        if(input != null)
            try
            {
                input.close();
            }
            // Misplaced declaration of exception variable
            catch(SAXException e)
            {
                throw new UnavailableException(e.getMessage());
            }
        break MISSING_BLOCK_LABEL_271;
        e;
        handleConfigException(paths, e);
        if(input != null)
            try
            {
                input.close();
            }
            catch(IOException e)
            {
                throw new UnavailableException(e.getMessage());
            }
        break MISSING_BLOCK_LABEL_271;
        Exception exception;
        exception;
        if(input != null)
            try
            {
                input.close();
            }
            catch(IOException e)
            {
                throw new UnavailableException(e.getMessage());
            }
        throw exception;
    }

    private void handleConfigException(String paths, Exception e)
        throws UnavailableException
    {
        log.error(internal.getMessage("configParse", paths), e);
        throw new UnavailableException(internal.getMessage("configParse", paths));
    }

    protected void initApplicationDataSources(ModuleConfig config)
        throws ServletException
    {
        initModuleDataSources(config);
    }

    protected void initModuleDataSources(ModuleConfig config)
        throws ServletException
    {
        if(log.isDebugEnabled())
            log.debug("Initializing module path '" + config.getPrefix() + "' data sources");
        ServletContextWriter scw = new ServletContextWriter(getServletContext());
        DataSourceConfig dscs[] = config.findDataSourceConfigs();
        if(dscs == null)
            dscs = new DataSourceConfig[0];
        dataSources.setFast(false);
        for(int i = 0; i < dscs.length; i++)
        {
            if(log.isDebugEnabled())
                log.debug("Initializing module path '" + config.getPrefix() + "' data source '" + dscs[i].getKey() + "'");
            DataSource ds = null;
            try
            {
                ds = (DataSource)RequestUtils.applicationInstance(dscs[i].getType());
                BeanUtils.populate(ds, dscs[i].getProperties());
                if(ds instanceof GenericDataSource)
                    ((GenericDataSource)ds).open();
                ds.setLogWriter(scw);
            }
            catch(Exception e)
            {
                log.error(internal.getMessage("dataSource.init", dscs[i].getKey()), e);
                throw new UnavailableException(internal.getMessage("dataSource.init", dscs[i].getKey()));
            }
            getServletContext().setAttribute(dscs[i].getKey() + config.getPrefix(), ds);
            dataSources.put(dscs[i].getKey(), ds);
        }

        dataSources.setFast(true);
        if("".equals(config.getPrefix()))
            initDataSources();
    }

    protected void initApplicationPlugIns(ModuleConfig config)
        throws ServletException
    {
        initModulePlugIns(config);
    }

    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("org.apache.struts.action.PLUG_INS" + 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());
                try
                {
                    PropertyUtils.setProperty(plugIns[i], "currentPlugInConfigObject", plugInConfigs[i]);
                }
                catch(Exception e) { }
                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);
            }

    }

    protected void initApplicationMessageResources(ModuleConfig config)
        throws ServletException
    {
        initModuleMessageResources(config);
    }

    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)
            {
                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();
                MessageResources resources = factoryObject.createResources(mrcs[i].getParameter());
                resources.setReturnNull(mrcs[i].getNull());
                getServletContext().setAttribute(mrcs[i].getKey() + config.getPrefix(), resources);
            }

    }

    protected Digester initConfigDigester()
        throws ServletException
    {
        if(configDigester != null)
            return configDigester;
        boolean validating = true;
        String value = getServletConfig().getInitParameter("validating");
        if("false".equalsIgnoreCase(value) || "no".equalsIgnoreCase(value) || "n".equalsIgnoreCase(value) || "0".equalsIgnoreCase(value))
            validating = false;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -