All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.struts.plugins.ModuleConfigVerifier Maven / Gradle / Ivy

Go to download

Base project: http://central.maven.org/maven2/struts/struts/1.2.9/ This version of Struts doesn't throw java.io.NotSerializableException when the application server wants to persist sessions and makes renderFocusJavascript return valid xml

The newest version!
/*
 * $Id: ModuleConfigVerifier.java 54929 2004-10-16 16:38:42Z germuska $ 
 *
 * Copyright 1999-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package org.apache.struts.plugins;


import javax.servlet.ServletException;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ForwardConfig;
import org.apache.struts.config.MessageResourcesConfig;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.config.PlugInConfig;
import org.apache.struts.util.RequestUtils;


/**
 * 

Convenient implementation of {@link PlugIn} that performs as many * verification tests on the information stored in the {@link ModuleConfig} * for this module as is practical. Based on the setting of the * fatal property (which defaults to true), the * detection of any such errors will cause a ServletException * to be thrown from the init method, which will ultimately * cause the initialization of your Struts controller servlet to fail.

* *

Under all circumstances, errors that are detected will be logged via * calls to ServletContext.log.

* * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $ * @since Struts 1.1 */ public class ModuleConfigVerifier implements PlugIn { // ----------------------------------------------------- Instance Variables /** *

The {@link ModuleConfig} instance for our module.

*/ protected ModuleConfig config = null; /** *

The {@link ActionServlet} instance we are associated with.

*/ protected ActionServlet servlet = null; // ------------------------------------------------------------- Properties /** *

Should the existence of configuration errors be fatal.

*/ private boolean fatal = true; /** *

Return the "configuation errors are fatal" flag.

*/ public boolean isFatal() { return (this.fatal); } /** *

Set the "configuration errors are fatal" flag.

* * @param fatal The new flag value */ public void setFatal(boolean fatal) { this.fatal = fatal; } // --------------------------------------------------------- Public Methods /** *

Receive notification that our owning module is being * shut down.

*/ public void destroy() { ; // No action required } // See interface for Javadoc. public void init(ActionServlet servlet, ModuleConfig config) throws ServletException { this.servlet = servlet; this.config = config; boolean ok = true; log(servlet.getInternal().getMessage("configVerifying")); // Perform detailed validations of each portion of ModuleConfig // :TODO: Complete methods to verify Action, Controller, et al, configurations. /* if (!verifyActionConfigs()) { ok = false; } */ if (!verifyActionMappingClass()) { ok = false; } /* if (!verifyControllerConfig()) { ok = false; } if (!verifyDataSourceConfigs()) { ok = false; } if (!verifyExceptionConfigs()) { ok = false; } if (!verifyFormBeanConfigs()) { ok = false; } */ if (!verifyForwardConfigs()) { ok = false; } if (!verifyMessageResourcesConfigs()) { ok = false; } if (!verifyPlugInConfigs()) { ok = false; } // Throw an exception on a fatal error log(servlet.getInternal().getMessage("configCompleted")); if (!ok && isFatal()) { throw new ServletException (servlet.getInternal().getMessage("configFatal")); } } // ------------------------------------------------------ Protected Methods /** *

Log the specified message to our servlet context log, after a * header including the module prefix.

* * @param message The message to be logged */ protected void log(String message) { String output = "[" + config.getPrefix() + "]: " + message; servlet.log(output); } /** *

Return true if information returned by * config.getActionMappingClass is all valid; * otherwise, log error messages and return false.

*/ protected boolean verifyActionMappingClass() { String amcName = config.getActionMappingClass(); if (amcName == null) { log(servlet.getInternal().getMessage ("verifyActionMappingClass.missing")); return (false); } try { Class amcClass = RequestUtils.applicationClass(amcName); } catch (ClassNotFoundException e) { log(servlet.getInternal().getMessage ("verifyActionMappingClass.invalid", amcName)); return (false); } return (true); } /** *

Return true if information returned by * config.findForwardConfigs is all valid; * otherwise, log error messages and return false.

*/ protected boolean verifyForwardConfigs() { boolean ok = true; ForwardConfig fcs[] = config.findForwardConfigs(); for (int i = 0; i < fcs.length; i++) { String path = fcs[i].getPath(); if (path == null) { log(servlet.getInternal().getMessage ("verifyForwardConfigs.missing", fcs[i].getName())); ok = false; } else if (!path.startsWith("/")) { log(servlet.getInternal().getMessage ("verifyForwardConfigs.invalid", path, fcs[i].getName())); } } return (ok); } /** *

Return true if information returned by * config.findMessageResourcesConfigs is all valid; * otherwise, log error messages and return false.

*/ protected boolean verifyMessageResourcesConfigs() { boolean ok = true; MessageResourcesConfig mrcs[] = config.findMessageResourcesConfigs(); for (int i = 0; i < mrcs.length; i++) { String factory = mrcs[i].getFactory(); if (factory == null) { log(servlet.getInternal().getMessage ("verifyMessageResourcesConfigs.missing")); ok = false; } else { try { Class clazz = RequestUtils.applicationClass(factory); } catch (ClassNotFoundException e) { log(servlet.getInternal().getMessage ("verifyMessageResourcesConfigs.invalid", factory)); ok = false; } } String key = mrcs[i].getKey(); if (key == null) { log(servlet.getInternal().getMessage ("verifyMessageResourcesConfigs.key")); } } return (ok); } /** *

Return true if information returned by * config.findPluginConfigs is all valid; * otherwise, log error messages and return false.

*/ protected boolean verifyPlugInConfigs() { boolean ok = true; PlugInConfig pics[] = config.findPlugInConfigs(); for (int i = 0; i < pics.length; i++) { String className = pics[i].getClassName(); if (className == null) { log(servlet.getInternal().getMessage ("verifyPlugInConfigs.missing")); ok = false; } else { try { Class clazz = RequestUtils.applicationClass(className); } catch (ClassNotFoundException e) { log(servlet.getInternal().getMessage ("verifyPlugInConfigs.invalid", className)); ok = false; } } } return (ok); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy