You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by ep...@apache.org on 2003/06/07 00:08:09 UTC

cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/util TurbineConfig.java

epugh       2003/06/06 15:08:09

  Modified:    src/java/org/apache/turbine/util TurbineConfig.java
  Added:       conf/test TurbineConfiguration.xml TurbineResources.xml
               src/test/org/apache/turbine TurbineConfigTest.java
                        ConfigurationTest.java
  Log:
  Changed TurbineConfig to take in a .xml file that is assumed to be a
  ConfigurationFactory xml file.  Added testcases and support files
  for testcases.
  
  Revision  Changes    Path
  1.1                  jakarta-turbine-2/conf/test/TurbineConfiguration.xml
  
  Index: TurbineConfiguration.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1" ?>
  
  <configuration>
    <dom4j className="org.apache.commons.configuration.DOM4JConfiguration" fileName="/conf/test/TurbineResources.xml"/>
    <properties className="org.apache.commons.configuration.PropertiesConfiguration" fileName="/conf/test/TemplateService.properties"/>
  </configuration>
  
    
    
  
  
  
  
  
  
  1.1                  jakarta-turbine-2/conf/test/TurbineResources.xml
  
  Index: TurbineResources.xml
  ===================================================================
  <XmlConfiguration>
  	<module>
  		<cache>true</cache>
  	</module>
  </XmlConfiguration>
  
  
  
  1.1                  jakarta-turbine-2/src/test/org/apache/turbine/TurbineConfigTest.java
  
  Index: TurbineConfigTest.java
  ===================================================================
  package org.apache.turbine;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  import javax.servlet.*;
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.apache.turbine.Turbine;
  import org.apache.turbine.util.TurbineConfig;
  
  /**
   * This testcase verifies that TurbineConfig can be used to startup Turbine in a non
   * servlet environment properly.
   *
   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
   *
   * @version $Id: TurbineConfigTest.java,v 1.1 2003/06/06 22:08:09 epugh Exp $
   */
  public class TurbineConfigTest
      extends TestCase
  {
      private static TurbineConfig tc = null;
  
      public TurbineConfigTest(String name)
      {
          super(name);
               
          
      }
  
      public static Test suite()
      {
          return new TestSuite(TurbineConfigTest.class);
      }
  
      public void testTurbineConfigWithPropertiesFile() throws Exception {
          String value = "/conf/test/TemplateService.properties";
          tc = new TurbineConfig(".", value);
          ServletContext context = tc.getServletContext();
          ServletConfig config = (ServletConfig)tc;
          String confFile= Turbine.findInitParameter(context, config, 
                  TurbineConfig.PROPERTIES_PATH_KEY, 
                  null);
          assertEquals(value,confFile);
          
      }
      
      public void testTurbineConfigWithconfigurationFile() throws Exception {
              String value = "/conf/test/TurbineConfiguration.xml";
              tc = new TurbineConfig(".", value);
              ServletContext context = tc.getServletContext();
              ServletConfig config = (ServletConfig)tc;
              String confFile= Turbine.findInitParameter(context, config, 
                      TurbineConfig.CONFIGURATION_PATH_KEY, 
                      null);
              assertEquals(value,confFile);
          
          }
  
      
  }
  
  
  
  1.1                  jakarta-turbine-2/src/test/org/apache/turbine/ConfigurationTest.java
  
  Index: ConfigurationTest.java
  ===================================================================
  package org.apache.turbine;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  import javax.servlet.*;
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.apache.turbine.Turbine;
  import org.apache.turbine.util.TurbineConfig;
  import org.apache.commons.configuration.Configuration;
  import org.apache.commons.configuration.ConfigurationFactory;
  import org.apache.commons.configuration.PropertiesConfiguration;
  
  /**
   * Tests that the ConfigurationFactory and regular old properties methods both work.
   * Verify the overriding of properties.
   * 
   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
   * 
   * @version $Id: ConfigurationTest.java,v 1.1 2003/06/06 22:08:09 epugh Exp $
   */
  public class ConfigurationTest
      extends TestCase
  {
      private static TurbineConfig tc = null;
  
      public ConfigurationTest(String name)
      {
          super(name);
       
          
          
      }
  
      public static Test suite()
      {
          return new TestSuite(ConfigurationTest.class);
      }
  
      
      
      public void testCreateTurbineWithConfigurationXML() throws Exception
         {
             tc = new TurbineConfig(".", "/conf/test/TurbineConfiguration.xml");
             tc.initialize();
           
             Configuration configuration = Turbine.getConfiguration();
             assertTrue("Make sure we have values", !configuration.isEmpty());
             
             // overridden value
             String key = "module.cache";
             assertEquals("Read a config value " + key + ", receieved:" + configuration.getString(key), "true", configuration.getString(key));
             
             // non overridden value
             key = "scheduledjob.cache.size";
             assertEquals("Read a config value " + key + ", receieved:" + configuration.getString(key), "10", configuration.getString(key));
  
  
         }
         
   
  }
  
  
  
  1.14      +18 -11    jakarta-turbine-2/src/java/org/apache/turbine/util/TurbineConfig.java
  
  Index: TurbineConfig.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/util/TurbineConfig.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- TurbineConfig.java	2 Jun 2003 10:24:46 -0000	1.13
  +++ TurbineConfig.java	6 Jun 2003 22:08:09 -0000	1.14
  @@ -109,14 +109,13 @@
    * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
    * @version $Id$
    */
  -public class TurbineConfig
  -        implements ServletConfig, ServletContext, Initializable, Disposable
  +public class TurbineConfig implements ServletConfig, ServletContext, Initializable, Disposable
   {
       /**
        * Servlet initialization parameter name for the path to
        * TurbineConfiguration.xml file used by Turbine
        */
  -    public static final String CONFIGURATION_PATH_KEY = "configuration";    
  +    public static final String CONFIGURATION_PATH_KEY = "configuration";
   
       /**
        * Servlet initialization parameter name for the path to
  @@ -128,8 +127,7 @@
        * Default value of TurbineResources.properties file path
        * (<code>/WEB-INF/conf/TurbineResources.properties</code>).
        */
  -    public static final String PROPERTIES_PATH_DEFAULT =
  -            "/WEB-INF/conf/TurbineResources.properties";
  +    public static final String PROPERTIES_PATH_DEFAULT = "/WEB-INF/conf/TurbineResources.properties";
   
       /** Filenames are looked up in this directory. */
       private File root;
  @@ -182,12 +180,22 @@
        * Turbine easiliy in the common setups.
        *
        * @param path The web application root (i.e. the path for file lookup).
  -     * @param properties the relative path to TurbineResources.properties file
  +     * @param properties the relative path to setup file.  Either 
  +     * TurbineResources.properties or TurbineConfiguration.xml.  If the file
  +     * ends in .xml, then we assume taht it is a ConfigurationFactory config
  +     * file.  Otherwise we assume it is a standard TurbineResources.propeties file.
        */
       public TurbineConfig(String path, String properties)
       {
           this(path, new HashMap(1));
  -        initParams.put(PROPERTIES_PATH_KEY, properties);
  +        if (properties.toLowerCase().endsWith(".xml"))
  +        {
  +            initParams.put(CONFIGURATION_PATH_KEY, properties);
  +        }
  +        else
  +        {
  +            initParams.put(PROPERTIES_PATH_KEY, properties);
  +        }
       }
   
       /**
  @@ -271,7 +279,7 @@
   
           if (f.exists())
           {
  -          result = f.getPath();
  +            result = f.getPath();
           }
           else
           {
  @@ -335,8 +343,7 @@
        * @return a URL pointing to the resource
        * @exception MalformedURLException
        */
  -    public URL getResource(String s)
  -            throws MalformedURLException
  +    public URL getResource(String s) throws MalformedURLException
       {
           return new URL("file://" + getRealPath(s));
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/util TurbineConfig.java

Posted by "Henning P. Schmiedehausen" <hp...@intermeta.de>.
epugh@apache.org writes:

Eric,

can you please stop reformatting lines without good reason? We agreed to
be somehow agnostic to line wrapping as long as they pass through checkstyle
without error. As far as I can see, all of these

public class Foo implement Bar, Baz
{
}

public class Foo 
       implement Bar, Baz
{
}

public class Foo 
       implement Bar, 
                 Baz
{
}

do. This one don't:

>  -public class TurbineConfig
>  -        implements ServletConfig, ServletContext, Initializable, Disposable
>  +public class TurbineConfig implements ServletConfig, ServletContext, Initializable, Disposable

We are running checkstyle with linewrap == 80. So these lines will now
show up. And we're adding unneccesary changes to the code which make
it hard to track in the annotation view, who changed what.

>  -        initParams.put(PROPERTIES_PATH_KEY, properties);
>  +        if (properties.toLowerCase().endsWith(".xml"))
>  +        {
>  +            initParams.put(CONFIGURATION_PATH_KEY, properties);
>  +        }
>  +        else
>  +        {
>  +            initParams.put(PROPERTIES_PATH_KEY, properties);
>  +        }
>       }

I actually _hate_ checks like these. They lead to unplasant
surprises. What if we get a third kind of configuration? Will we add
more checks? 

Please make a TurbineXmlConfig which is derived from TurbineConfig and
accepts an XML file. This shouldn't be too hard. If someone is using
the standalone Turbine, he should be able to use the right
configuration class.

	Regards
		Henning

-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH
hps@intermeta.de        +49 9131 50 654 0   http://www.intermeta.de/

Java, perl, Solaris, Linux, xSP Consulting, Web Services 
freelance consultant -- Jakarta Turbine Development  -- hero for hire

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org