In my opinion, the simple answer is that you should use the authentication
framework. The action you have written below should instead be a generator.
The data in the map you are creating should instead be inserted into the
data section of the XML document the authentication framework requires.
Look at some of the generator examples for that.  You can then access the
user's data using the session-context input module. Another alternative that
might work better if you need access to all this data in various pipelines
would be to create your data as a DOM object and store it into the session
in the generator. It could then be retrieved via a generator and aggregated
into pipelines as required. 

Other than reading Lajos' book and emailing him a couple of times, I don't
know him at all, but a few days ago he announced a class coming up in
Colorado.  Based on what I got out of his book I would highly recommend this
class to you, if at all possible.

Ralph

-----Original Message-----
From: beyaNet Consultancy
To: [EMAIL PROTECTED]
Sent: 1/18/2004 3:26 PM
Subject: Re: Actions, pipelines, javabeans...

ok chaps (Ralph and Morley), 
correct me if I am wrong here, 

1. Action amendment: 
                        if (rs.next()) 
                        { 
                                map.put("user_id", rs.getString(1)); 
                                map.put("first_name", rs.getString(2)); 
                                map.put("last_name", rs.getString(3)); 
                                map.put("address1", rs.getString(4)); 
                                map.put("address2", rs.getString(5)); 
                                map.put("address3", rs.getString(6)); 
                                map.put("postcode", rs.getString(7)); 
                                map.put("country", rs.getString(8)); 
                                map.put("email", rs.getString(9)); 
                                map.put("home_telephone",
rs.getString(10)); 
                                map.put("mobile_telephone",
rs.getString(11)); 
                                map.put("date_joined",
rs.getString(12)); 
                        }else 
                        { 
                                rs.close(); 
                        } 

at this particular juncture would the idea be to encapsulate the the
parameters as an xml stream i.e 

<user_id>value</user_id> etc etc 

and then assign this xml stream to a map.put("xmlSteam",xmlStream), how
would I do this? Or would it be to write the xml stream to an xml
document i.e userdetails.xml and then <map:part
src="context://beyarecords/content/userdatils.xml" />? If it is the
later, how would alter my action so that it still returns true or false
dependent on whether a map is returned to the sitemap based on whether
the user login details exist or not? 

for reference, my action in full, is as follows: 

package test; 

import org.apache.avalon.excalibur.datasource.DataSourceComponent; 


import org.apache.avalon.framework.component.ComponentException; 
import org.apache.avalon.framework.component.ComponentManager; 
import org.apache.avalon.framework.component.ComponentSelector; 


import org.apache.avalon.framework.parameters.Parameters; 
import org.apache.avalon.framework.thread.ThreadSafe; 
import org.apache.avalon.framework.component.Composable; 
import org.apache.avalon.framework.activity.Disposable; 
import org.apache.cocoon.Constants; 
import org.apache.cocoon.environment.ObjectModelHelper; 
import org.apache.cocoon.environment.Redirector; 
import org.apache.cocoon.environment.Request; 
import org.apache.cocoon.environment.SourceResolver; 
import org.apache.cocoon.acting.AbstractAction; 

import java.sql.Connection; 
import java.sql.ResultSet; 
import java.sql.Statement; 
import java.sql.SQLException; 

import java.util.Enumeration; 
import java.util.HashMap; 
import java.util.Map; 

public class GetUserDetail2 extends AbstractAction implements
ThreadSafe, Composable, Disposable 
{ 
         
        protected ComponentSelector dbselector; 
        protected ComponentManager manager; 
         
        public void compose(ComponentManager manager) throws
ComponentException 
        { 
                this.dbselector = (ComponentSelector) 
                        manager.lookup(DataSourceComponent.ROLE +
"Selector"); 
        } 
         
        protected final DataSourceComponent getDataSource(String pool)
throws ComponentException 
        { 
                return (DataSourceComponent)
this.dbselector.select(pool); 
        } 
         
        public Map act ( Redirector redirector, SourceResolver resolver,

                                         Map objectModel, String source,
Parameters param) throws Exception 
        { 
                Request request =
ObjectModelHelper.getRequest(objectModel); 
                Map map = new HashMap(); 
                DataSourceComponent dataSource =
getDataSource("postgresql"); 
                Connection conn = null; 
                 
                 
                try 
                { 
                        conn = dataSource.getConnection(); 
                        Statement stmt = conn.createStatement(); 
                        String userName = param.getParameter("user"); 
                        String userPassword =
param.getParameter("pass"); 
                        String cmd = "Select user_id, first_name,
last_name, address1, address2, address3, postcode, country, email, " + 
                                                 "home_telephone,
mobile_telephone, date_joined from usertbl where username = '" +
userName + "'" + 
                                                 "and userpassword = '"
+ userPassword + "'"; 
                        ResultSet rs = stmt.executeQuery(cmd); 
                         
                        if (rs.next()) 
                        { 
                                map.put("user_id", rs.getString(1)); 
                                map.put("first_name", rs.getString(2)); 
                                map.put("last_name", rs.getString(3)); 
                                map.put("address1", rs.getString(4)); 
                                map.put("address2", rs.getString(5)); 
                                map.put("address3", rs.getString(6)); 
                                map.put("postcode", rs.getString(7)); 
                                map.put("country", rs.getString(8)); 
                                map.put("email", rs.getString(9)); 
                                map.put("home_telephone",
rs.getString(10)); 
                                map.put("mobile_telephone",
rs.getString(11)); 
                                map.put("date_joined",
rs.getString(12)); 
                        }else 
                        { 
                                rs.close(); 
                        } 
                         
                        stmt.close(); 
                }catch (Exception e){ 
                        getLogger().error("Query failed: ", e); 
                }finally 
                { 
                        try 
                        { 
                                if (conn != null) conn.close(); 
                        }catch (SQLException sqe) 
                        { 
                                getLogger().warn("Error closing the
datasource", sqe); 
                        } 
                } 
                 
                return(map); 
        } 
         
        public void dispose() 
        { 
                this.manager.release(dbselector); 
        } 
} 

On 18 Jan 2004, at 23:02, beyaNet Consultancy wrote: 


>Ok Ralph and Morley, 
>so i have a sitemap that does the following (aggregation): 
>
>                               <map:match pattern="support/home"> 
>                                
>                                       <map:aggregate element="home"> 
>                                               <map:part
>src="cocoon:/support/beya-menu" /> 
>                                               <map:part
>src="cocoon:/support/contract-summary" /> 
>                                               <map:part
>src="context://beyarecords/content/adv-xyz-01.xml" /> 
>                                               <map:part
>src="context://beyarecords/content/site_title.xml" /> 
>                                       </map:aggregate> 
>                                        
>                                       <map:transform type="xslt"
>src="style/home-page.xsl"> 
>                                               <map:parameter
>name="user" value="{../1}" /> 
>                                               <map:parameter
>name="pass" value="{../1}" /> 
>                                       </map:transform> 
>                                        
>                                       <map:serialize type="html" /> 
>                               </map:match> 
>
>Now in terms of session persistence and passing parameters around
>(shopping cart), how would I aggregate the parameters from my action
>into my xsl document and avoid the pitfalls of the approach i was
>taking before? 
>
>Andrew 
>On 18 Jan 2004, at 22:47, beyaNet Consultancy wrote: 
>
>
>       Ralph and Morley, 
>       as I have stated in my earlier message the approach i am
>currently taking leaves much to be desired, hence the request about
>JavaBeans. As I am completely new to this cocoon arena, could you
>please show me an example of what you mean in terms of 'use aggregation
>and turn your parameters into XML that are aggregated into the document
>processed by your transform'? 
>
>       Andrew 
>
>
>
>       On 18 Jan 2004, at 19:35, Ralph Goers wrote: 
>
>
>               When I first started using Cocoon I too was coding
>things like you are. It 
>               soon became apparent that this was not a good approach
>because every time a 
>               new data element had to be added too many things needed
>to be modified.  In 
>               addition, I believe passing parameters from the sitemap
>impacts Cocoon's 
>               caching of your transforms. 
>
>               A better approach is to use aggregation and turn your
>parameters into XML 
>               that are aggregated into the document processed by your
>transform. Thus, you 
>               won't have to see the parameters in the sitemap at all.
>Furthermore, you can 
>               use Betwixt or Castor to automatically convert any Java
>Bean into XML.  We 
>               are doing exactly that to retrieve data from our
>business tier. 
>
>               Ralph 
>
>               -----Original Message----- 
>               From: beyaNet Consultancy 
>               To: [EMAIL PROTECTED] 
>               Sent: 1/18/2004 6:44 AM 
>               Subject: Actions, pipelines, javabeans... 
>
>               Hi, 
>               I have created an action which returns parameters to a
>pipeline based on 
>               a users login details. I want these details to persist
>for the du ration 
>               of a user session and wanted to know how to store the
>values passed into 
>               the pipeline into a JavaBean instead. At the moment I
>have the 
>               parameters coming into my action as so: 
>
>               1. pipeline 
>
>                                       <map:match
>pattern="user-details"> 
>                                               <map:act
>type="get-detail2"> 
>                                                   <map:parameter
>name="user" 
>               value="{request-param:user}" /> 
>                                                       <map:parameter
>name="pass" 
>               value="{request-param:pass}" /> 
>                                                       <map:generate
>type="file" 
>               src="content/main.xml" /> 
>                                                       <map:transform 
>               src="style/main.xsl"> 
>       
><map:transform 
>               src="style/main.xsl"> 
>       
><map:parameter 
>               name="first_name" value="{first_name}" /> 
>       
><map:parameter 
>               name="last_name" value="{last_name}" /> 
>       
><map:parameter 
>               name="address1" value="{address1}" /> 
>       
><map:parameter 
>               name="address2" value="{address2}" /> 
>       
><map:parameter 
>               name="address3" value="{address3}" /> 
>       
><map:parameter 
>               name="postcode" value="{postcode}" /> 
>       
><map:parameter 
>               name="country" value="{country}" /> 
>       
><map:parameter 
>               name="email" value="{email}" /> 
>       
><map:parameter 
>               name="home_telephone" value="{home_telephone}" /> 
>       
><map:parameter 
>               name="mobile_telephone" value="{mobile_telephone}" /> 
>       
><map:parameter 
>               name="date_joined" value="{data_joined}" /> 
>                                                       </map:transform>
>
>                                                       <map:serialize
>type="html" /> 
>                                               </map:act> 
>
>               and are passed into the pipeline from the Action as so: 
>
>               2. Action 
>                                               map.put("user_id",
>rs.getString(1)); 
>                                               map.put("first_name",
>rs.getString(2)); 
>                                               map.put("last_name",
>rs.getString(3)); 
>                                               map.put("address1",
>rs.getString(4)); 
>                                               map.put("address2",
>rs.getString(5)); 
>                                               map.put("address3",
>rs.getString(6)); 
>                                               map.put("postcode",
>rs.getString(7)); 
>                                               map.put("country",
>rs.getString(8)); 
>                                               map.put("email",
>rs.getString(9)); 
>       
>map.put("home_telephone", 
>               rs.getString(10)); 
>       
>map.put("mobile_telephone", 
>               rs.getString(11)); 
>                                               map.put("date_joined", 
>               rs.getString(12)); 
>
>               and then into my xsl page as so 
>
>               3. xsl 
>               <?xml version="1.0"?> 
>
>                       <xsl:stylesheet version="1.0" 
>               xmlns:xsl="http://www.w3.org/1999/XSL/Transform";> 
>                        
>                               <xsl:param name="user_id"/> 
>                               <xsl:param name="first_name"/> 
>                               <xsl:param name="last_name"/> 
>                               <xsl:param name="address1"/> 
>                               <xsl:param name="address2"/> 
>                               <xsl:param name="address3"/> 
>                               <xsl:param name="postcode"/> 
>                               <xsl:param name="country"/> 
>                               <xsl:param name="email"/> 
>                               <xsl:param name="home_telephone"/> 
>                               <xsl:param name="mobile_telephone"/> 
>                               <xsl:param name="date_joined"/> 
>
>               Could I call and update the javabean from the within the
>transform: 
>               <map:transform src="style/main.xsl"> 
>                       instatiate javabean 
>                    javabean.user_id = <map:transform
>src="style/main.xsl"> 
>               </map:transform> 
>
>               Or would it be better to do it from within the Action
>and then just call 
>               the call javabean from within the xsl page itself?
>ultimately I want to 
>               be able to call the javebean parameters into my xsl or
>xsp pages. What 
>               is the best way to go about doing this? Is there any
>example code out 
>               there I can have a look at? 
>
>
>               Andrew 
>
>       
>--------------------------------------------------------------------- 
>               To unsubscribe, e-mail:
>[EMAIL PROTECTED] 
>               For additional commands, e-mail:
>[EMAIL PROTECTED] 
>
>
>
>
>       
>--------------------------------------------------------------------- 
>       To unsubscribe, e-mail: [EMAIL PROTECTED] 
>       For additional commands, e-mail: [EMAIL PROTECTED] 
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to