Author: husted Date: Fri Feb 10 11:42:56 2006 New Revision: 376813 URL: http://svn.apache.org/viewcvs?rev=376813&view=rev Log: Checkstyle Roundup * Extra package reformatted with latest Jalopy settings. Stylistic changes only.
Modified: struts/extras/trunk/src/java/org/apache/struts/plugins/DigestingPlugIn.java struts/extras/trunk/src/java/org/apache/struts/plugins/ModuleConfigVerifier.java Modified: struts/extras/trunk/src/java/org/apache/struts/plugins/DigestingPlugIn.java URL: http://svn.apache.org/viewcvs/struts/extras/trunk/src/java/org/apache/struts/plugins/DigestingPlugIn.java?rev=376813&r1=376812&r2=376813&view=diff ============================================================================== --- struts/extras/trunk/src/java/org/apache/struts/plugins/DigestingPlugIn.java (original) +++ struts/extras/trunk/src/java/org/apache/struts/plugins/DigestingPlugIn.java Fri Feb 10 11:42:56 2006 @@ -15,16 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.struts.plugins; -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.net.URLConnection; - -import javax.servlet.ServletException; - import org.apache.commons.digester.Digester; import org.apache.commons.digester.RuleSet; import org.apache.commons.digester.xmlrules.DigesterLoader; @@ -36,45 +28,39 @@ import org.apache.struts.util.RequestUtils; import org.xml.sax.SAXException; +import javax.servlet.ServletException; + +import java.io.File; +import java.io.IOException; + +import java.net.URL; +import java.net.URLConnection; + /** - * <p>An implementation of <code>PlugIn</code> which - * can be configured to instantiate a graph of objects - * using the Commons Digester and place the root object - * of that graph into the Application context.</p> + * <p>An implementation of <code>PlugIn</code> which can be configured to + * instantiate a graph of objects using the Commons Digester and place the + * root object of that graph into the Application context.</p> * * @version $Rev$ * @see org.apache.struts.action.PlugIn * @since Struts 1.2 */ public class DigestingPlugIn implements PlugIn { - /** * Commons Logging instance. */ private static Log log = LogFactory.getLog(DigestingPlugIn.class); - protected static final String SOURCE_CLASSPATH = "classpath"; - protected static final String SOURCE_FILE = "file"; - protected static final String SOURCE_SERVLET = "servlet"; - protected String configPath = null; - protected String configSource = SOURCE_SERVLET; - protected String digesterPath = null; - protected String digesterSource = SOURCE_SERVLET; - protected String key = null; - protected ModuleConfig moduleConfig = null; - protected String rulesets = null; - protected ActionServlet servlet = null; - protected boolean push = false; /** @@ -94,20 +80,18 @@ /** * <p>Initialize a <code>Digester</code> and use it to parse a - * configuration file, resulting in a root object which will be placed into - * the ServletContext.</p> - * - * @param servlet ActionServlet that is managing all the - * modules in this web application - * @param config ModuleConfig for the module with which - * this plug-in is associated + * configuration file, resulting in a root object which will be placed + * into the ServletContext.</p> * - * @throws ServletException if this <code>PlugIn</code> cannot - * be successfully initialized + * @param servlet ActionServlet that is managing all the modules in this + * web application + * @param config ModuleConfig for the module with which this plug-in is + * associated + * @throws ServletException if this <code>PlugIn</code> cannot be + * successfully initialized */ public void init(ActionServlet servlet, ModuleConfig config) throws ServletException { - this.servlet = servlet; this.moduleConfig = config; @@ -121,26 +105,27 @@ } try { - log.debug("XML data file: [path: " - + this.configPath - + ", source: " - + this.configSource + "]"); - - URL configURL = this.getConfigURL(this.configPath, this.configSource); - if (configURL == null) throw new ServletException("Unable to locate XML data file at [path: " - + this.configPath - + ", source: " - + this.configSource + "]"); + log.debug("XML data file: [path: " + this.configPath + ", source: " + + this.configSource + "]"); + + URL configURL = + this.getConfigURL(this.configPath, this.configSource); + + if (configURL == null) { + throw new ServletException( + "Unable to locate XML data file at [path: " + + this.configPath + ", source: " + this.configSource + "]"); + } + URLConnection conn = configURL.openConnection(); + conn.setUseCaches(false); conn.connect(); obj = digester.parse(conn.getInputStream()); - } catch (IOException e) { // TODO Internationalize msg log.error("Exception processing config", e); throw new ServletException(e); - } catch (SAXException e) { // TODO Internationalize msg log.error("Exception processing config", e); @@ -153,29 +138,26 @@ /** * Initialize the <code>Digester</code> which will be used to process the * main configuration. + * * @return a Digester, ready to use. * @throws ServletException */ - protected Digester initializeDigester() throws ServletException { + protected Digester initializeDigester() + throws ServletException { Digester digester = null; - if (this.digesterPath != null && this.digesterSource != null) { - + if ((this.digesterPath != null) && (this.digesterSource != null)) { try { log.debug("Initialize digester from XML [path: " - + this.digesterPath - + "; source: " - + this.digesterSource + "]"); + + this.digesterPath + "; source: " + this.digesterSource + + "]"); digester = this.digesterFromXml(this.digesterPath, this.digesterSource); - } catch (IOException e) { // TODO Internationalize msg log.error("Exception instantiating digester from XML ", e); throw new ServletException(e); - } - } else { log.debug("No XML rules for digester; call newDigesterInstance()"); digester = this.newDigesterInstance(); @@ -187,9 +169,10 @@ } /** - * <p>Instantiate a <code>Digester</code>.</p> - * <p>Subclasses may wish to override this to provide a subclass of Digester, - * or to configure the Digester using object methods.</p> + * <p>Instantiate a <code>Digester</code>.</p> <p>Subclasses may wish to + * override this to provide a subclass of Digester, or to configure the + * Digester using object methods.</p> + * * @return a basic instance of <code>org.apache.commons.digester.Digester</code> */ protected Digester newDigesterInstance() { @@ -199,8 +182,11 @@ /** * <p>Instantiate a Digester from an XML input stream using the Commons * <code>DigesterLoader</code>.</p> - * @param path the path to the digester rules XML to be found using <code>source</code> - * @param source a string indicating the lookup method to be used with <code>path</code> + * + * @param path the path to the digester rules XML to be found using + * <code>source</code> + * @param source a string indicating the lookup method to be used with + * <code>path</code> * @return a configured Digester * @throws FileNotFoundException * @throws MalformedURLException @@ -208,12 +194,13 @@ */ protected Digester digesterFromXml(String path, String source) throws IOException { - URL configURL = this.getConfigURL(path, source); - if (configURL == null) - { - throw new NullPointerException("No resource '" + path + "' found in '" + source + "'"); + + if (configURL == null) { + throw new NullPointerException("No resource '" + path + + "' found in '" + source + "'"); } + return DigesterLoader.createDigester(configURL); } @@ -221,19 +208,23 @@ * Instantiate any <code>RuleSet</code> classes defined in the * <code>rulesets</code> property and use them to add rules to our * <code>Digester</code>. + * * @param digester the Digester instance to add RuleSet objects to. * @throws ServletException */ - protected void applyRuleSets(Digester digester) throws ServletException { - - if (this.rulesets == null || this.rulesets.trim().length() == 0) { + protected void applyRuleSets(Digester digester) + throws ServletException { + if ((this.rulesets == null) || (this.rulesets.trim().length() == 0)) { return; } rulesets = rulesets.trim(); + String ruleSet = null; + while (rulesets.length() > 0) { int comma = rulesets.indexOf(","); + if (comma < 0) { ruleSet = rulesets.trim(); rulesets = ""; @@ -244,7 +235,8 @@ if (log.isDebugEnabled()) { // TODO Internationalize msg - log.debug("Configuring custom Digester Ruleset of type " + ruleSet); + log.debug("Configuring custom Digester Ruleset of type " + + ruleSet); } try { @@ -252,7 +244,6 @@ (RuleSet) RequestUtils.applicationInstance(ruleSet); digester.addRuleSet(instance); - } catch (Exception e) { // TODO Internationalize msg log.error("Exception configuring custom Digester RuleSet", e); @@ -262,21 +253,31 @@ } /** - * <p>Look up a resource path using one of a set of known path resolution mechanisms - * and return a URL to the resource.</p> - * @param path a String which is meaningful to one of the known resolution mechanisms. + * <p>Look up a resource path using one of a set of known path resolution + * mechanisms and return a URL to the resource.</p> + * + * @param path a String which is meaningful to one of the known + * resolution mechanisms. * @param source one of the known path resolution mechanisms: - * <ul> - * <li>file - the path is a fully-qualified filesystem path.</li> - * <li>servlet - the path is a servlet-context relative path.</li> - * <li>classpath - the path is a classpath-relative path.</li> - * </ul> + * + * <ul> + * + * <li>file - the path is a fully-qualified filesystem + * path.</li> + * + * <li>servlet - the path is a servlet-context relative + * path.</li> + * + * <li>classpath - the path is a classpath-relative + * path.</li> + * + * </ul> * @return a URL pointing to the given path in the given mechanism. - * @throws FileNotFoundException - * @throws MalformedURLException + * @throws java.io.FileNotFoundException + * @throws java.net.MalformedURLException */ - protected URL getConfigURL(String path, String source) throws IOException { - + protected URL getConfigURL(String path, String source) + throws IOException { if (SOURCE_CLASSPATH.equals(source)) { return this.getClassPathURL(path); } @@ -290,44 +291,52 @@ } // TODO Internationalize msg - throw new IllegalArgumentException( - "ConfigSource " + source + " is not recognized"); + throw new IllegalArgumentException("ConfigSource " + source + + " is not recognized"); } /** * Given a string, return a URL to a classpath resource of that name. + * * @param path a Classpath-relative string identifying a resource. - * @return a URL identifying the resource on the classpath. - * TODO Do we need to be smarter about ClassLoaders? + * @return a URL identifying the resource on the classpath. TODO Do we + * need to be smarter about ClassLoaders? */ protected URL getClassPathURL(String path) { return getClass().getClassLoader().getResource(path); } /** - * Given a string, return a URL to a Servlet Context resource of that name. + * Given a string, return a URL to a Servlet Context resource of that + * name. + * * @param path a Classpath-relative string identifying a resource. * @return a URL identifying the resource in the Servlet Context * @throws MalformedURLException */ - protected URL getServletContextURL(String path) throws IOException { + protected URL getServletContextURL(String path) + throws IOException { return this.servlet.getServletContext().getResource(path); } /** * Given a string, return a URL to a Filesystem resource of that name. + * * @param path a path to a file. * @return a URL identifying the resource in the in the file system. * @throws MalformedURLException * @throws FileNotFoundException */ - protected URL getFileURL(String path) throws IOException { + protected URL getFileURL(String path) + throws IOException { File file = new File(path); + return file.toURL(); } /** - * @param configPath the path to configuration information for this PlugIn. + * @param configPath the path to configuration information for this + * PlugIn. * @see #configSource */ public void setConfigPath(String configPath) { @@ -344,20 +353,11 @@ /** * Set the source of the config file. Should be one of the following: - * <ul> - * <li> - * "classpath" - indicates that the configPath will be resolved by the - * ClassLoader. - * </li> - * <li> - * "file" - indicates that the configPath is a fully-qualified - * filesystem path. - * </li> - * <li> - * "servlet" - indicates that the configPath will be found by the - * ServletContext. - * </li> - * </ul> + * <ul> <li> "classpath" - indicates that the configPath will be resolved + * by the ClassLoader. </li> <li> "file" - indicates that the configPath + * is a fully-qualified filesystem path. </li> <li> "servlet" - indicates + * that the configPath will be found by the ServletContext. </li> </ul> + * * @param configSource the source (lookup method) for the config file. * @see #configPath */ @@ -367,7 +367,7 @@ /** * @return the string describing which access method should be used to - * resolve configPath. + * resolve configPath. * @see #configPath */ public String getConfigSource() { @@ -377,25 +377,28 @@ /** * This method is called after the Digester runs to store the generated * object somewhere. This implementation places the given object into the - * ServletContext under the attribute name as defined in <code>key</code>. + * ServletContext under the attribute name as defined in + * <code>key</code>. + * * @param obj The object to save. */ protected void storeGeneratedObject(Object obj) { - log.debug("Put [" + obj + "] into application context [key:" + this.key + "]"); + log.debug("Put [" + obj + "] into application context [key:" + this.key + + "]"); this.servlet.getServletContext().setAttribute(this.getKey(), obj); } /** * @param key The ServletContext attribute name to store the generated - * object under. + * object under. */ public void setKey(String key) { this.key = key; } /** - * @return The ServletContext attribute name the generated object is stored - * under. + * @return The ServletContext attribute name the generated object is + * stored under. */ public String getKey() { return key; @@ -419,6 +422,7 @@ /** * <p>The path to a Digester XML configuration file, relative to the * <code>digesterSource</code> property. (Optional)</p> + * * @see #digesterSource * @see #getConfigURL(String, String) */ @@ -437,8 +441,8 @@ /** * <p>The lookup mechanism to be used to resolve <code>digesterPath</code> - * (optional). - * </p> + * (optional). </p> + * * @param digesterSource * @see #getConfigURL(String, String) */ @@ -448,7 +452,7 @@ /** * @return the configured lookup mechanism for resolving - * <code>digesterPath</code>. + * <code>digesterPath</code>. * @see #getConfigURL(String, String) */ public String getDigesterSource() { @@ -456,10 +460,10 @@ } /** - * <p>If set to <code>true</code>, this PlugIn will be pushed onto - * the Digester stack before the digester <code>parse</code> method is - * called.</p> - * <p>Defaults to <code>false</code></p> + * <p>If set to <code>true</code>, this PlugIn will be pushed onto the + * Digester stack before the digester <code>parse</code> method is + * called.</p> <p>Defaults to <code>false</code></p> + * * @param push */ public void setPush(boolean push) { @@ -468,11 +472,10 @@ /** * @return Whether or not this <code>PlugIn</code> instance will be pushed - * onto the <code>Digester</code> stack before <code>digester.parse()</code> - * is called. + * onto the <code>Digester</code> stack before + * <code>digester.parse()</code> is called. */ public boolean getPush() { return this.push; } - } Modified: struts/extras/trunk/src/java/org/apache/struts/plugins/ModuleConfigVerifier.java URL: http://svn.apache.org/viewcvs/struts/extras/trunk/src/java/org/apache/struts/plugins/ModuleConfigVerifier.java?rev=376813&r1=376812&r2=376813&view=diff ============================================================================== --- struts/extras/trunk/src/java/org/apache/struts/plugins/ModuleConfigVerifier.java (original) +++ struts/extras/trunk/src/java/org/apache/struts/plugins/ModuleConfigVerifier.java Fri Feb 10 11:42:56 2006 @@ -15,12 +15,8 @@ * 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; @@ -29,97 +25,82 @@ import org.apache.struts.config.PlugInConfig; import org.apache.struts.util.RequestUtils; +import javax.servlet.ServletException; /** * <p>Convenient implementation of [EMAIL PROTECTED] PlugIn} that performs as many * verification tests on the information stored in the [EMAIL PROTECTED] ModuleConfig} * for this module as is practical. Based on the setting of the * <code>fatal</code> property (which defaults to <code>true</code>), the - * detection of any such errors will cause a <code>ServletException</code> - * to be thrown from the <code>init</code> method, which will ultimately - * cause the initialization of your Struts controller servlet to fail.</p> + * detection of any such errors will cause a <code>ServletException</code> to + * be thrown from the <code>init</code> method, which will ultimately cause + * the initialization of your Struts controller servlet to fail.</p> * * <p>Under all circumstances, errors that are detected will be logged via * calls to <code>ServletContext.log</code>.</p> * - * @version $Rev$ $Date$ + * @version $Rev$ $Date: 2005-11-14 15:09:02 -0500 (Mon, 14 Nov 2005) + * $ * @since Struts 1.1 */ - public class ModuleConfigVerifier implements PlugIn { - - // ----------------------------------------------------- Instance Variables - /** * <p>The [EMAIL PROTECTED] ModuleConfig} instance for our module.</p> */ protected ModuleConfig config = null; - /** * <p>The [EMAIL PROTECTED] ActionServlet} instance we are associated with.</p> */ protected ActionServlet servlet = null; - // ------------------------------------------------------------- Properties - /** * <p>Should the existence of configuration errors be fatal.</p> */ private boolean fatal = true; - /** * <p>Return the "configuation errors are fatal" flag.</p> */ public boolean isFatal() { - return (this.fatal); - } - /** * <p>Set the "configuration errors are fatal" flag.</p> * * @param fatal The new flag value */ public void setFatal(boolean fatal) { - this.fatal = fatal; - } - // --------------------------------------------------------- Public Methods - /** - * <p>Receive notification that our owning module is being - * shut down.</p> + * <p>Receive notification that our owning module is being shut down.</p> */ public void destroy() { - ; // No action required - } - - // See interface for Javadoc. + // 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; @@ -128,6 +109,7 @@ if (!verifyActionMappingClass()) { ok = false; } + /* if (!verifyControllerConfig()) { ok = false; @@ -142,158 +124,149 @@ 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")); + throw new ServletException(servlet.getInternal().getMessage("configFatal")); } - - } - - // ------------------------------------------------------ Protected Methods - /** - * <p>Log the specified message to our servlet context log, after a - * header including the module prefix.</p> + * <p>Log the specified message to our servlet context log, after a header + * including the module prefix.</p> * * @param message The message to be logged */ protected void log(String message) { - String output = "[" + config.getPrefix() + "]: " + message; - servlet.log(output); + servlet.log(output); } - /** * <p>Return <code>true</code> if information returned by - * <code>config.getActionMappingClass</code> is all valid; - * otherwise, log error messages and return <code>false</code>.</p> + * <code>config.getActionMappingClass</code> is all valid; otherwise, log + * error messages and return <code>false</code>.</p> */ protected boolean verifyActionMappingClass() { - String amcName = config.getActionMappingClass(); + if (amcName == null) { - log(servlet.getInternal().getMessage - ("verifyActionMappingClass.missing")); + log(servlet.getInternal().getMessage("verifyActionMappingClass.missing")); + return (false); } + try { Class amcClass = RequestUtils.applicationClass(amcName); } catch (ClassNotFoundException e) { - log(servlet.getInternal().getMessage - ("verifyActionMappingClass.invalid", amcName)); + log(servlet.getInternal().getMessage("verifyActionMappingClass.invalid", + amcName)); + return (false); } - return (true); + return (true); } - /** * <p>Return <code>true</code> if information returned by - * <code>config.findForwardConfigs</code> is all valid; - * otherwise, log error messages and return <code>false</code>.</p> + * <code>config.findForwardConfigs</code> is all valid; otherwise, log + * error messages and return <code>false</code>.</p> */ protected boolean verifyForwardConfigs() { - boolean ok = true; - ForwardConfig fcs[] = config.findForwardConfigs(); + 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())); + 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())); + log(servlet.getInternal().getMessage("verifyForwardConfigs.invalid", + path, fcs[i].getName())); } } - return (ok); + return (ok); } - /** * <p>Return <code>true</code> if information returned by * <code>config.findMessageResourcesConfigs</code> is all valid; * otherwise, log error messages and return <code>false</code>.</p> */ protected boolean verifyMessageResourcesConfigs() { - boolean ok = true; - MessageResourcesConfig mrcs[] = config.findMessageResourcesConfigs(); + 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")); + 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)); + log(servlet.getInternal().getMessage("verifyMessageResourcesConfigs.invalid", + factory)); ok = false; } } + String key = mrcs[i].getKey(); + if (key == null) { - log(servlet.getInternal().getMessage - ("verifyMessageResourcesConfigs.key")); + log(servlet.getInternal().getMessage("verifyMessageResourcesConfigs.key")); } } - return (ok); + return (ok); } - /** * <p>Return <code>true</code> if information returned by - * <code>config.findPluginConfigs</code> is all valid; - * otherwise, log error messages and return <code>false</code>.</p> + * <code>config.findPluginConfigs</code> is all valid; otherwise, log + * error messages and return <code>false</code>.</p> */ protected boolean verifyPlugInConfigs() { - boolean ok = true; - PlugInConfig pics[] = config.findPlugInConfigs(); + 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")); + 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)); + log(servlet.getInternal().getMessage("verifyPlugInConfigs.invalid", + className)); ok = false; } } } - return (ok); + return (ok); } - - } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]