You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lenya.apache.org by Frank Hamilton <ii...@hotmail.com> on 2009/01/08 13:55:51 UTC

How to get session Attribute

Hi,

I´m create an usecase that put  "myUser" object in to
org.apache.cocoon.environment.Session. This is for my own login task in
Lenya. This usecase create "myUser" object from my own BD (if the user exist
in BD), and put it in Session.

My question is: Can I get myUser.getName() from session in page2htmlHome.xsl
(for example)?. I need this to put the name of loger user in the header of
my publication.

Thanks, and excuse my poor English.
-- 
View this message in context: http://www.nabble.com/How-to-get-session-Attribute-tp21351269p21351269.html
Sent from the Lenya - Dev mailing list archive at Nabble.com.


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


Re: How to get session Attribute

Posted by Frank Hamilton <ii...@hotmail.com>.
Ok, this is my solution:

In cocoon.xconf use the JXPathMetaModule:

<input-modules>
     .
     .
     .
     <component-instance
class="org.apache.cocoon.components.modules.input.JXPathMetaModule"    
logger="core.modules.input" name="user-attr">
       <input-module name="session-attr"/>
      <!--usuario is the name of object in session-->
       <parameter>usuario</parameter>
    
</component-instance>
     . 
     .
     .
</input-modules>
  
 
Get the parameter in sitemap. I put the parameter in the sitemap.xmap of
lenya/src/modules/sitetree/
in the the bottom matcher :

<map:match pattern="*/*/*/*/*/**.xml">
        <map:generate src="cocoon:/navtree/{2}/{3}/{4}/{5}/{6}.xml"/>
        <map:transform
src="fallback://lenya/modules/sitetree/xslt/navigation/{1}.xsl">
          <map:parameter name="area" value="{3}"/>
          <map:parameter name="root" value="/{2}/{3}/"/>
          <map:parameter name="chosenlanguage" value="{5}"/>
          <map:parameter name="defaultlanguage" value="{4}"/>
          
          <!-- nombre is the name of attribute in the usuario object. -->         
        <map:parameter name='nombre' value='{user-attr:nombre}'/>
                 
          
        </map:transform>       
        <map:serialize type="xml"/>
      </map:match>
  
 Last, in the xsl file :

declare the parameter:

            <xsl:param name="nombre"/>

and print the value:

           <xsl:value-of select="$nombre"/>


Thanks very much.




Frank Hamilton wrote:
> 
> Hi,
> 
> I´m create an usecase that put  "myUser" object in to
> org.apache.cocoon.environment.Session. This is for my own login task in
> Lenya. This usecase create "myUser" object from my own BD (if the user
> exist in BD), and put it in Session.
> 
> My question is: Can I get myUser.getName() from session in
> page2htmlHome.xsl (for example)?. I need this to put the name of loger
> user in the header of my publication.
> 
> Thanks, and excuse my poor English.
> 

-- 
View this message in context: http://www.nabble.com/How-to-get-session-Attribute-tp21351269p21438943.html
Sent from the Lenya - Dev mailing list archive at Nabble.com.


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


Re: How to get session Attribute

Posted by Andreas Hartmann <an...@apache.org>.
Hi Frank,

Frank Hamilton schrieb:
> I think that I need get  'MyUser.getName()'  in a pipeline and then get it
> in a xsl file.

maybe you can combine the JXPath meta module and the session attribute 
module:

http://cocoon.apache.org/2.1/userdocs/concepts/modules-ref.html

There's an example in the section "JXPathMetaModule" on this page.

HTH,

-- Andreas


-- 
Andreas Hartmann, CTO
BeCompany GmbH
http://www.becompany.ch
Tel.: +41 (0) 43 818 57 01


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


Re: How to get session Attribute

Posted by Frank Hamilton <ii...@hotmail.com>.
Excuse I read bad the documentation. Thanks.


>The documentation states, "The ReadDOMSessionTransformer is a
>standalone component, you don't need to use it in combination with the
>WriteDOMSessionTransformer."  You could look at how
>WriteDOMSessionTransformer adds objects to the session and use the
>same method.


-- 
View this message in context: http://www.nabble.com/How-to-get-session-Attribute-tp21351269p21372053.html
Sent from the Lenya - Dev mailing list archive at Nabble.com.


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


Re: How to get session Attribute

Posted by Andreas Hartmann <an...@apache.org>.
solprovider@apache.org schrieb:

[…]

> Have you researched the SessionModule?
> http://cocoon.apache.org/2.1/userdocs/concepts/modules-ref.html#N102E9
> 
> Andreas suggests the JXPathMetaModule. Should be similar to the
> SessionModule but more generic.

IIUC the JXPathMetaModule and SessionModule would have to be combined 
for this task. The SessionModule accesses the session, and the 
JXPathMetaModule traverses the object model of the session attribute 
value (in this case it returns the result of the myUser.getName() method).

-- Andreas


-- 
Andreas Hartmann, CTO
BeCompany GmbH
http://www.becompany.ch
Tel.: +41 (0) 43 818 57 01


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


Re: How to get session Attribute

Posted by Andreas Hartmann <an...@apache.org>.
solprovider@apache.org schrieb:

[…]

 > Have you researched the SessionModule?
 > http://cocoon.apache.org/2.1/userdocs/concepts/modules-ref.html#N102E9
 >
 > Andreas suggests the JXPathMetaModule. Should be similar to the
 > SessionModule but more generic.

IIUC the JXPathMetaModule and SessionModule would have to be combined 
for this task. The SessionModule accesses the session, and the 
JXPathMetaModule traverses the object model of the session attribute 
value (in this case it returns the result of the myUser.getName() method).

-- Andreas


-- 
Andreas Hartmann, CTO
BeCompany GmbH
http://www.becompany.ch
Tel.: +41 (0) 43 818 57 01


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


Re: How to get session Attribute

Posted by Frank Hamilton <ii...@hotmail.com>.
Thanks very much.

I will try to get my target and inform in this forum.




solprovider-2 wrote:
> 
> On 1/9/09, Frank Hamilton <ii...@hotmail.com> wrote:
>>  Thanks solprovider,
>>  I used Lenya 2.0.3 version.
> Disclaimer: I have little experience with Lenya 2.
> 
>>  I think that Read DOM Session Transformer is not valid for resolve my
>>  problem because I set "MyUser" object in session in a .java class and
>> not
>>  from the WriteDomSession.
> 
> The documentation states, "The ReadDOMSessionTransformer is a
> standalone component, you don't need to use it in combination with the
> WriteDOMSessionTransformer."  You could look at how
> WriteDOMSessionTransformer adds objects to the session and use the
> same method.
> 
>>  I think that I need get  'MyUser.getName()'  in a pipeline and then get
>> it
>>  in a xsl file.
>>   For example, with the "chosenlanguage" parameter:
>>  "Sitemap.xmap "
>>  <map:transform
>>  src="fallback://lenya/modules/sitetree/xslt/navigation/sitetree2nav.xsl"
>>  label="navtree">
>>           <map:parameter name="chosenlanguage"
>>  value="{request-param:language}"/>
>>           <map:parameter name="defaultlanguage"
>>  value="{page-envelope:default-language}"/>
>>           <map:parameter name="extension" value="html"/>
>>  </map:transform>
>>  and then in "example.xsl" I can get "choselanguage" parameter:
>>  <td><input type="text" name="language" value="{$chosenlanguage}"
>>  size="5"/></td>
> 
> Does getName() return the standard Lenya id or name?  The
> AccessControlInputModule can return those values:
> http://solprovider.com/lenya/variablescommon#access-control
> 
>>   Any ideas are grateful.
> 
> Have you researched the SessionModule?
> http://cocoon.apache.org/2.1/userdocs/concepts/modules-ref.html#N102E9
> 
> Andreas suggests the JXPathMetaModule. Should be similar to the
> SessionModule but more generic.
> 
> Finally, an XSP is Java code to create XML and so can access any Java
> objects to create precisely the XML desired.  May not be future-proof
> as Cocoon may not support XSPs in releases after 2.1.  When I was very
> new to Lenya and Cocoon, I created an XSP to add the current visitor's
> id, name, email, groups, and roles as XML to add security checks in
> XSLTs.  (My current work is to integrate language translations and
> security so well that everybody can almost forget about them.)
> 
> solprovider
> 
>>  solprovider wrote:
>>  > You might try the "Read DOM Session Transformer":
>>  > http://cocoon.apache.org/2.1/userdocs/readdomsession-transformer.html
>>  >
>>  > I have not used this Transformer.  I created an XSP to generate user
>>  > information and aggregated for processing with XSL.  Better methods
>>  > are likely.
>>  >
>>  > Which version of Lenya is being used?  The answer is very likely to
>>  > affect possible solutions.
>>  >
>>  > solprovider
>>  >
>>  > On 1/8/09, Frank Hamilton <ii...@hotmail.com> wrote:
>>  >>  I´m create an usecase that put  "myUser" object in to
>>  >>  org.apache.cocoon.environment.Session. This is for my own login task
>> in
>>  >>  Lenya. This usecase create "myUser" object from my own BD (if the
>> user
>>  >> exist in BD), and put it in Session.
>>  >>
>>  >>  My question is: Can I get myUser.getName() from session in
>>  >> page2htmlHome.xsl
>>  >>  (for example)?. I need this to put the name of loger user in the
>> header
>>  >> of
>>  >>  my publication.
>>  >>
>>  >>  Thanks, and excuse my poor English.
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-get-session-Attribute-tp21351269p21372173.html
Sent from the Lenya - Dev mailing list archive at Nabble.com.


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


Re: How to get session Attribute

Posted by so...@apache.org.
On 1/9/09, Frank Hamilton <ii...@hotmail.com> wrote:
>  Thanks solprovider,
>  I used Lenya 2.0.3 version.
Disclaimer: I have little experience with Lenya 2.

>  I think that Read DOM Session Transformer is not valid for resolve my
>  problem because I set "MyUser" object in session in a .java class and not
>  from the WriteDomSession.

The documentation states, "The ReadDOMSessionTransformer is a
standalone component, you don't need to use it in combination with the
WriteDOMSessionTransformer."  You could look at how
WriteDOMSessionTransformer adds objects to the session and use the
same method.

>  I think that I need get  'MyUser.getName()'  in a pipeline and then get it
>  in a xsl file.
>   For example, with the "chosenlanguage" parameter:
>  "Sitemap.xmap "
>  <map:transform
>  src="fallback://lenya/modules/sitetree/xslt/navigation/sitetree2nav.xsl"
>  label="navtree">
>           <map:parameter name="chosenlanguage"
>  value="{request-param:language}"/>
>           <map:parameter name="defaultlanguage"
>  value="{page-envelope:default-language}"/>
>           <map:parameter name="extension" value="html"/>
>  </map:transform>
>  and then in "example.xsl" I can get "choselanguage" parameter:
>  <td><input type="text" name="language" value="{$chosenlanguage}"
>  size="5"/></td>

Does getName() return the standard Lenya id or name?  The
AccessControlInputModule can return those values:
http://solprovider.com/lenya/variablescommon#access-control

>   Any ideas are grateful.

Have you researched the SessionModule?
http://cocoon.apache.org/2.1/userdocs/concepts/modules-ref.html#N102E9

Andreas suggests the JXPathMetaModule. Should be similar to the
SessionModule but more generic.

Finally, an XSP is Java code to create XML and so can access any Java
objects to create precisely the XML desired.  May not be future-proof
as Cocoon may not support XSPs in releases after 2.1.  When I was very
new to Lenya and Cocoon, I created an XSP to add the current visitor's
id, name, email, groups, and roles as XML to add security checks in
XSLTs.  (My current work is to integrate language translations and
security so well that everybody can almost forget about them.)

solprovider

>  solprovider wrote:
>  > You might try the "Read DOM Session Transformer":
>  > http://cocoon.apache.org/2.1/userdocs/readdomsession-transformer.html
>  >
>  > I have not used this Transformer.  I created an XSP to generate user
>  > information and aggregated for processing with XSL.  Better methods
>  > are likely.
>  >
>  > Which version of Lenya is being used?  The answer is very likely to
>  > affect possible solutions.
>  >
>  > solprovider
>  >
>  > On 1/8/09, Frank Hamilton <ii...@hotmail.com> wrote:
>  >>  I´m create an usecase that put  "myUser" object in to
>  >>  org.apache.cocoon.environment.Session. This is for my own login task in
>  >>  Lenya. This usecase create "myUser" object from my own BD (if the user
>  >> exist in BD), and put it in Session.
>  >>
>  >>  My question is: Can I get myUser.getName() from session in
>  >> page2htmlHome.xsl
>  >>  (for example)?. I need this to put the name of loger user in the header
>  >> of
>  >>  my publication.
>  >>
>  >>  Thanks, and excuse my poor English.

Re: How to get session Attribute

Posted by Frank Hamilton <ii...@hotmail.com>.
Thanks solprovider,

I used Lenya 2.0.3 version.

I think that Read DOM Session Transformer is not valid for resolve my
problem because I set "MyUser" object in session in a .java class and not
from the WriteDomSession.

I think that I need get  'MyUser.getName()'  in a pipeline and then get it
in a xsl file.
 
 For example, with the "chosenlanguage" parameter:

"Sitemap.xmap "

<map:transform
src="fallback://lenya/modules/sitetree/xslt/navigation/sitetree2nav.xsl"
label="navtree">
          <map:parameter name="chosenlanguage"
value="{request-param:language}"/>
          <map:parameter name="defaultlanguage"
value="{page-envelope:default-language}"/>
          <map:parameter name="extension" value="html"/>
</map:transform>

and then in "example.xsl" I can get "choselanguage" parameter:

 .
 .
<td><input type="text" name="language" value="{$chosenlanguage}"
size="5"/></td>
 .
 .

 Any ideas are grateful.










solprovider-2 wrote:
> 
> You might try the "Read DOM Session Transformer":
> http://cocoon.apache.org/2.1/userdocs/readdomsession-transformer.html
> 
> I have not used this Transformer.  I created an XSP to generate user
> information and aggregated for processing with XSL.  Better methods
> are likely.
> 
> Which version of Lenya is being used?  The answer is very likely to
> affect possible solutions.
> 
> solprovider
> 
> On 1/8/09, Frank Hamilton <ii...@hotmail.com> wrote:
>>  I´m create an usecase that put  "myUser" object in to
>>  org.apache.cocoon.environment.Session. This is for my own login task in
>>  Lenya. This usecase create "myUser" object from my own BD (if the user
>> exist
>>  in BD), and put it in Session.
>>
>>  My question is: Can I get myUser.getName() from session in
>> page2htmlHome.xsl
>>  (for example)?. I need this to put the name of loger user in the header
>> of
>>  my publication.
>>
>>  Thanks, and excuse my poor English.
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-get-session-Attribute-tp21351269p21369609.html
Sent from the Lenya - Dev mailing list archive at Nabble.com.


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


Re: How to get session Attribute

Posted by so...@apache.org.
You might try the "Read DOM Session Transformer":
http://cocoon.apache.org/2.1/userdocs/readdomsession-transformer.html

I have not used this Transformer.  I created an XSP to generate user
information and aggregated for processing with XSL.  Better methods
are likely.

Which version of Lenya is being used?  The answer is very likely to
affect possible solutions.

solprovider

On 1/8/09, Frank Hamilton <ii...@hotmail.com> wrote:
>  I´m create an usecase that put  "myUser" object in to
>  org.apache.cocoon.environment.Session. This is for my own login task in
>  Lenya. This usecase create "myUser" object from my own BD (if the user exist
>  in BD), and put it in Session.
>
>  My question is: Can I get myUser.getName() from session in page2htmlHome.xsl
>  (for example)?. I need this to put the name of loger user in the header of
>  my publication.
>
>  Thanks, and excuse my poor English.