- use JNDI instead of SharedPoolDataSourceFactory (with jetty)
- add archetype generate goals in README.txt
- fix injection bug in SecureScreen.java, cft. README.txt

git-svn-id: https://svn.apache.org/repos/asf/turbine/maven/archetypes/trunk/turbine-webapp-4.0@1768538 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 2b03aaa..618a3f6 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -25,6 +25,9 @@
 
   <body>
    <release version="1.0.1" date="in Subversion">
+      <action dev="gk" type="update">
+       JNDI Jetty Update
+      </action>
        <action dev="gk" type="update">
        Fulcrum Torque Security added manager, om classes
       </action>
diff --git a/src/main/resources/META-INF/maven/archetype-metadata.xml b/src/main/resources/META-INF/maven/archetype-metadata.xml
index cff504c..b6481b5 100644
--- a/src/main/resources/META-INF/maven/archetype-metadata.xml
+++ b/src/main/resources/META-INF/maven/archetype-metadata.xml
@@ -37,7 +37,7 @@
       <defaultValue>auto</defaultValue>
     </requiredProperty>
     <requiredProperty key="turbine_database_jndipath">
-      <defaultValue>java:comp/env/jdbc/Turbine</defaultValue>
+      <defaultValue>jdbc/turbine</defaultValue>
     </requiredProperty>
     <requiredProperty key="turbine_database_driver">
       <defaultValue>com.mysql.jdbc.Driver</defaultValue>
diff --git a/src/main/resources/archetype-resources/docs/README.txt b/src/main/resources/archetype-resources/docs/README.txt
index 3cec655..7db3cb6 100644
--- a/src/main/resources/archetype-resources/docs/README.txt
+++ b/src/main/resources/archetype-resources/docs/README.txt
@@ -27,6 +27,7 @@
   (because of some minor bugs in Fulcrum Security 1.1.0, which should be fixed in v 1.1.1/Turbine 4.0)
   - LogoutAction is included (fixed getUserFromSession)
   - om stub classes are included (until configurable in schema with Torque version 2.1)
+  - (in SecureScreen) TurbineConfiguration returns a Commons configuration object, even if field is not assignable (will be fixed in Turbine 4.0, you can then assign e.g. to String instead)
   
 
 Quick Guide to using the new Turbine 4.0-M2 maven archetype 
@@ -51,10 +52,12 @@
     -Dturbine_database_adapter=mysql \
     -Dturbine_database_user=db_username \
     -Dturbine_database_password=db_password \
-    -Dturbine_database_name=helloWorld
+    -Dturbine_database_name=helloWorld \
+    -Dgoals=generate-sources,sql:execute
 
 
-Note that the database URL will be appended with your database name
+Note that the database URL (turbine_database_url=jdbc:mysql://localhost:3306/) 
+will be appended with your database name
 in the final pom.xml, so you do not need to specify that in 
 the configuration.
 
@@ -67,6 +70,9 @@
 
 cd helloWorld
 
+You can skip the next two mvn commands, if you have already set the goals 
+when invoking archetype:generate.
+
 mvn generate-sources  ## This will generate the OM layer and SQL 
 					  ## code for creating the corresponding
 					  ## database tables
@@ -75,8 +81,9 @@
 					  ## the application schema defined 
 					  ## in src/main/torque-schema
 
-You should now insert the sample data file provided as Torque 4.0 
-has disabled the datasql task.
+You should now check the database tables and if some data is missing
+insert the sample data file provided 
+as Torque 4.0 has disabled the datasql task.
 
 mvn jetty:run         ## Now you can launch your new Turbine application
 
diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml
index b57835b..582d96f 100644
--- a/src/main/resources/archetype-resources/pom.xml
+++ b/src/main/resources/archetype-resources/pom.xml
@@ -99,7 +99,7 @@
             </configuration>
           </execution>
           <execution>
-            <id>torque-sql-${turbine_database_adapter}</id>
+            <id>torque-sql-mysql</id><!-- ${turbine_database_adapter} -->
             <phase>generate-sources</phase>
             <goals>
               <goal>generate</goal>
@@ -108,11 +108,11 @@
               <packaging>classpath</packaging>
               <configPackage>org.apache.torque.templates.sql</configPackage>
               <sourceDir>#var("basedir")/src/main/torque-schema</sourceDir>
-              <defaultOutputDir>#var("project.build.directory")/generated-sql/torque/${turbine_database_adapter}</defaultOutputDir>
+              <defaultOutputDir>#var("project.build.directory")/generated-sql/torque/mysql</defaultOutputDir>
               <defaultOutputDirUsage>none</defaultOutputDirUsage>
               <loglevel>error</loglevel>
               <options>
-                <torque.database>${turbine_database_adapter}</torque.database>
+                <torque.database>mysql</torque.database>
               </options>
             </configuration>
           </execution>
diff --git a/src/main/resources/archetype-resources/src/main/java/modules/screens/SecureScreen.java b/src/main/resources/archetype-resources/src/main/java/modules/screens/SecureScreen.java
index 9d0a454..2e2a59f 100644
--- a/src/main/resources/archetype-resources/src/main/java/modules/screens/SecureScreen.java
+++ b/src/main/resources/archetype-resources/src/main/java/modules/screens/SecureScreen.java
@@ -28,6 +28,7 @@
 import org.apache.turbine.pipeline.PipelineData;
 import org.apache.turbine.services.security.SecurityService;
 import org.apache.velocity.context.Context;
+import org.apache.commons.configuration.Configuration;
 
 /**
  * This class provides a sample implementation for creating a secured screen
@@ -37,11 +38,11 @@
 	@TurbineService
 	protected SecurityService securityService;
 	
-    @TurbineConfiguration( TurbineConstants.TEMPLATE_LOGIN )
-    private String templateLogin;
+  @TurbineConfiguration( TurbineConstants.TEMPLATE_LOGIN )
+  private Configuration templateLogin;
 
-    @TurbineConfiguration( TurbineConstants.TEMPLATE_HOMEPAGE )
-    private String templateHomepage;
+  @TurbineConfiguration( TurbineConstants.TEMPLATE_HOMEPAGE )
+  private Configuration templateHomepage;
 
 	@Override
 	protected boolean isAuthorized(PipelineData data) throws Exception 
@@ -56,7 +57,8 @@
 
 		if (acl == null) 
 		{
-			getRunData(data).setScreenTemplate(templateLogin);
+      // commons configuration getProperty: prefix removed, the key for the value .. is an empty string, the result an object
+			getRunData(data).setScreenTemplate( (String) templateLogin.getProperty("") );
 			isAuthorized = false;
 		} 
 		else if (acl.hasRole("turbineadmin")) 
@@ -65,7 +67,7 @@
 		}
 		else 
 		{
-			getRunData(data).setScreenTemplate(templateHomepage);
+			getRunData(data).setScreenTemplate( (String) templateHomepage.getProperty("") );
 			getRunData(data).setMessage("You do not have access to this part of the site.");
 			isAuthorized = false;
 		}
diff --git a/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/conf/Torque.properties b/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/conf/Torque.properties
index feebf6a..023ef76 100644
--- a/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/conf/Torque.properties
+++ b/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/conf/Torque.properties
@@ -41,9 +41,9 @@
 # For JNDI configuration please see: https://db.apache.org/torque/torque-4.0/documentation/orm-reference/initialisation-configuration.html
 # 
 #
-#torque.dsfactory.${turbine_database_name}.factory=org.apache.torque.dsfactory.JndiDataSourceFactory
-#torque.dsfactory.${turbine_database_name}.jndi.path=${turbine_database_jndipath}
-#torque.dsfactory.${turbine_database_name}.jndi.ttl=300000
+torque.dsfactory.${turbine_database_name}.factory=org.apache.torque.dsfactory.JndiDataSourceFactory
+torque.dsfactory.${turbine_database_name}.jndi.path=java:comp/env/${turbine_database_jndipath}
+torque.dsfactory.${turbine_database_name}.jndi.ttl=300000
 
 # -------------------------------------------------------------------
 #
@@ -52,8 +52,9 @@
 # -------------------------------------------------------------------
 #torque.database.default=${turbine_database_name}
 torque.database.${turbine_database_name}.adapter=${turbine_database_adapter}
-torque.database.${turbine_database_name}.user=${turbine_database_user}
-torque.database.${turbine_database_name}.password=${turbine_database_password}
+
+#torque.database.${turbine_database_name}.user=${turbine_database_user}
+#torque.database.${turbine_database_name}.password=${turbine_database_password}
 #
 #torque.defaults.pool.maxActive =       	30
 #torque.defaults.pool.testOnBorrow =    	true
@@ -64,11 +65,11 @@
 #torque.defaults.connection.user =      	${turbine_database_user}
 #torque.defaults.connection.password =  	${turbine_database_password}
 #
-torque.dsfactory.${turbine_database_name}.connection.driver =    	${turbine_database_driver}
-torque.dsfactory.${turbine_database_name}.connection.url =       	${turbine_database_url}${turbine_database_name}
-torque.dsfactory.${turbine_database_name}.connection.user =      	${turbine_database_user}
-torque.dsfactory.${turbine_database_name}.connection.password =  	${turbine_database_password}
-torque.dsfactory.${turbine_database_name}.factory=org.apache.torque.dsfactory.SharedPoolDataSourceFactory
+#torque.dsfactory.${turbine_database_name}.connection.driver =    	${turbine_database_driver}
+#torque.dsfactory.${turbine_database_name}.connection.url =       	${turbine_database_url}${turbine_database_name}
+#torque.dsfactory.${turbine_database_name}.connection.user =      	${turbine_database_user}
+#torque.dsfactory.${turbine_database_name}.connection.password =  	${turbine_database_password}
+#torque.dsfactory.${turbine_database_name}.factory=org.apache.torque.dsfactory.SharedPoolDataSourceFactory
 # -------------------------------------------------------------------
 
 # Determines if the quantity column of the IDBroker's id_table should
diff --git a/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/jetty-env.xml b/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/jetty-env.xml
new file mode 100644
index 0000000..64f7b2c
--- /dev/null
+++ b/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/jetty-env.xml
@@ -0,0 +1,15 @@
+<Configure class="org.eclipse.jetty.webapp.WebAppContext">
+  <New id="Turbine" class="org.eclipse.jetty.plus.jndi.Resource">
+    <Arg></Arg> <!-- reference to WebAppContext requires jetty 9.x only  -->
+    <Arg>${turbine_database_jndipath}</Arg>
+    <Arg>
+        <New class="org.apache.commons.dbcp.BasicDataSource">
+           <Set name="driverClassName">${turbine_database_driver}</Set>
+            <Set name="url">${turbine_database_url}${turbine_database_name}</Set>
+            <Set name="username">${turbine_database_user}</Set>
+            <Set name="password">${turbine_database_password}</Set>
+            <Set name="validationQuery">SELECT 1</Set>
+        </New>
+    </Arg>
+  </New>
+</Configure>
\ No newline at end of file
diff --git a/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml b/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
index 4f55623..7241e9d 100644
--- a/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
+++ b/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
@@ -71,6 +71,18 @@
   <welcome-file-list>

     <welcome-file>app</welcome-file>

   </welcome-file-list>

+  

+  

+ <!-- ======================================================================== -->

+<!--                                                                          -->

+<!-- JNDI Ressource                                                           -->

+<!-- ======================================================================== -->

+  

+   <resource-ref>

+    <res-ref-name>${turbine_database_jndipath}</res-ref-name>

+    <res-type>javax.sql.DataSource</res-type>

+    <res-auth>Container</res-auth>

+  </resource-ref>

 

 <!-- ======================================================================== -->

 <!--                                                                          -->

diff --git a/src/test/resources/projects/first/archetype.properties b/src/test/resources/projects/first/archetype.properties
index 9c5f810..0a96356 100644
--- a/src/test/resources/projects/first/archetype.properties
+++ b/src/test/resources/projects/first/archetype.properties
@@ -6,7 +6,7 @@
 turbine_intake_file=intake.xml
 turbine_database_name=turbine
 turbine_database_adapter=auto
-turbine_database_jndipath=java:comp/env/jdbc/Turbine
+turbine_database_jndipath=jdbc/turbine
 turbine_database_driver=com.mysql.jdbc.Driver
 turbine_database_url=jdbc:mysql://localhost:3306/
 turbine_database_user=db_user