You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@forrest.apache.org by Thorsten Scherler <th...@apache.org> on 2005/08/27 22:17:59 UTC

[locationmap] How to activate actions in the locationmap

On Fri, 2005-08-26 at 08:41 -0400, Tim Williams wrote:

> > Can a selector in the lm provide a map? Can I use:
> > <traversal>
> >    <location src="{calculatedValue}"/>
> > </traversal>
> >
> > If the <traversal> selector returns null then the child will be ignored,
> > otherwise it will use the {calculatedValue} that have been placed in the
> > returning map of the selector. Is that possible?
> 
> I missed this reply.  If I understand the question, the answer is kind
> of.  All null-returning locations would be ignored except the last one
> which would, not surprisingly, actually return null, meaning your
> example above would also return null.  If this is done in the context
> of a parent selector, then maybe it would get ignored -- I'd have to
> check.
> 
> I'll admit that I didn't fully cook the [new traversal selector] idea
> in my head before my fingers started typing it;)  I think this one
> deserves more study and should be filed as a JIRA issue.
> 

I just looked into 
package org.apache.cocoon.selection;
public interface Selector extends Component {

    String ROLE = Selector.class.getName();
    /**
     * Selectors test pattern against some objects in a <code>Map</code>
     * model and signals success with the returned boolean value
     * @param expression  The expression to test.
     * @param objectModel The <code>Map</code> containing object of the
     *                    calling environment which may be used
     *                    to select values to test the expression.
     * @param parameters  The sitemap parameters, as specified by
&lt;parameter/&gt; tags.
     * @return boolean    Signals successfull test.
     */
    boolean select (String expression, Map objectModel, Parameters
parameters);
}

What I had in mind is not possible with a selector. That leads us to the
question whether it is possible to use actions in lm. The answer was not
out of the box how I found out. ;-) 

I wrote a new action RecursiveDirectoryTraversalAction.java that only
contains the recursive part of the fallbackResolverAction. I tested it
on the sitemap and that worked just fine.

Now I extend my project lm like this:
...
<components>
...
 <actions default="RecursiveDirectoryTraversalAction">
  <action name="RecursiveDirectoryTraversalAction"
src="org.apache.forrest.plugin.internal.view.acting.RecursiveDirectoryTraversalAction"/>
 </actions> 
...
</components>
<locator>
  <match pattern="views/**">
    <act type="RecursiveDirectoryTraversalAction">
      <parameter value="{1}" name="request"/>
      <parameter value="{project:theme}" name="projectFallback"/>
      <parameter value="{project:theme-ext}" name="projectExtension"/>
      <parameter value="{project:content.xdocs}" name="projectDir"/>
      <location src="{uri}" />
    </act>
    <location
src="{defaults:view-themes}/{defaults:theme}{defaults:theme-ext}" 
      />
  </match>
</locator>
...

I needed do change some classes to allow actions in the lm to be
matched:
?      java/org/apache/forrest/locationmap/lm/ActNode.java
M      java/org/apache/forrest/locationmap/lm/MatchNode.java
M      java/org/apache/forrest/locationmap/lm/SelectNode.java
M      java/org/apache/forrest/locationmap/lm/LocationMap.java
M      java/org/apache/forrest/locationmap/lm/LocatorNode.java

The step where I need some help with in ActNode.java is how do I get:
public String locate(Map objectModel, InvokeContext context) throws
Exception {
  Parameters parameters = resolveParameters(context,objectModel);
  Map substitutions = m_action.act(redirector, resolver, objectModel,
source, parameters);
...
}
working.

Where can I get the redirector, resolver and the source that I need to
parse to the action? Any tips welcome.

TIA

salu2
-- 
thorsten

"Together we stand, divided we fall!" 
Hey you (Pink Floyd)


Re: [locationmap] How to activate actions in the locationmap

Posted by Thorsten Scherler <th...@apache.org>.
On Sat, 2005-08-27 at 22:53 +0200, Thorsten Scherler wrote:
> > I needed do change some classes to allow actions in the lm to be
> > matched:
> > ?      java/org/apache/forrest/locationmap/lm/ActNode.java
> > M      java/org/apache/forrest/locationmap/lm/MatchNode.java
> > M      java/org/apache/forrest/locationmap/lm/SelectNode.java
> > M      java/org/apache/forrest/locationmap/lm/LocationMap.java
> > M      java/org/apache/forrest/locationmap/lm/LocatorNode.java
> > 
> > The step where I need some help with in ActNode.java is how do I get:
> > public String locate(Map objectModel, InvokeContext context) throws
> > Exception {
> >   Parameters parameters = resolveParameters(context,objectModel);
> >   Map substitutions = m_action.act(redirector, resolver, objectModel,
> > source, parameters);
> > ...
> > }
> > working.
> 
> BTW should I check that in regardless it is <act/> is not working?
> Everything else seems to work fine?
> 

Parameters parameters = resolveParameters(context,objectModel);
Redirector redirector = context.getRedirector();
String source = "";

Still need to test. 

salu2
-- 
thorsten

"Together we stand, divided we fall!" 
Hey you (Pink Floyd)


Re: [locationmap] How to activate actions in the locationmap

Posted by Thorsten Scherler <th...@apache.org>.
> I needed do change some classes to allow actions in the lm to be
> matched:
> ?      java/org/apache/forrest/locationmap/lm/ActNode.java
> M      java/org/apache/forrest/locationmap/lm/MatchNode.java
> M      java/org/apache/forrest/locationmap/lm/SelectNode.java
> M      java/org/apache/forrest/locationmap/lm/LocationMap.java
> M      java/org/apache/forrest/locationmap/lm/LocatorNode.java
> 
> The step where I need some help with in ActNode.java is how do I get:
> public String locate(Map objectModel, InvokeContext context) throws
> Exception {
>   Parameters parameters = resolveParameters(context,objectModel);
>   Map substitutions = m_action.act(redirector, resolver, objectModel,
> source, parameters);
> ...
> }
> working.

BTW should I check that in regardless it is <act/> is not working?
Everything else seems to work fine?

salu2
-- 
thorsten

"Together we stand, divided we fall!" 
Hey you (Pink Floyd)


Re: [locationmap] How to activate actions in the locationmap

Posted by Thorsten Scherler <th...@apache.org>.
On Sun, 2005-08-28 at 18:53 +0100, Ross Gardler wrote:
> Thorsten Scherler wrote:
> > --closed--
> > 
> > I activated actions in the locationmap successfully. :) I will commit
> > asap.
> 
> Cool stuff, great to see we (well, you at the moment) are actioning 
> Davids request for us to broaden our perspective from our "pet" 
> projects. I'm still playing with views, but you will see more commits 
> from me soon since I am using it in production now.
> 
> Ross

I am looking forward to see your code. ;-)

BTW there is a bug in the ActNode. It is not reading <act type="..."
src="notReaded"/> the @src attribute. I found out in trying to use the
sourcetype action in the lm.

salu2
-- 
thorsten

"Together we stand, divided we fall!" 
Hey you (Pink Floyd)


Re: [locationmap] How to activate actions in the locationmap

Posted by Ross Gardler <rg...@apache.org>.
Thorsten Scherler wrote:
> --closed--
> 
> I activated actions in the locationmap successfully. :) I will commit
> asap.

Cool stuff, great to see we (well, you at the moment) are actioning 
Davids request for us to broaden our perspective from our "pet" 
projects. I'm still playing with views, but you will see more commits 
from me soon since I am using it in production now.

Ross

Re: [locationmap] How to activate actions in the locationmap

Posted by Thorsten Scherler <th...@apache.org>.
--closed--

I activated actions in the locationmap successfully. :) I will commit
asap.

On Sat, 2005-08-27 at 22:17 +0200, Thorsten Scherler wrote:
> On Fri, 2005-08-26 at 08:41 -0400, Tim Williams wrote:
> 
> > > Can a selector in the lm provide a map? Can I use:
> > > <traversal>
> > >    <location src="{calculatedValue}"/>
> > > </traversal>
> > >
> > > If the <traversal> selector returns null then the child will be ignored,
> > > otherwise it will use the {calculatedValue} that have been placed in the
> > > returning map of the selector. Is that possible?
> > 
> > I missed this reply.  If I understand the question, the answer is kind
> > of.  All null-returning locations would be ignored except the last one
> > which would, not surprisingly, actually return null, meaning your
> > example above would also return null.  If this is done in the context
> > of a parent selector, then maybe it would get ignored -- I'd have to
> > check.
> > 
> > I'll admit that I didn't fully cook the [new traversal selector] idea
> > in my head before my fingers started typing it;)  I think this one
> > deserves more study and should be filed as a JIRA issue.
> > 
> 
> I just looked into 
> package org.apache.cocoon.selection;
> public interface Selector extends Component {
> 
>     String ROLE = Selector.class.getName();
>     /**
>      * Selectors test pattern against some objects in a <code>Map</code>
>      * model and signals success with the returned boolean value
>      * @param expression  The expression to test.
>      * @param objectModel The <code>Map</code> containing object of the
>      *                    calling environment which may be used
>      *                    to select values to test the expression.
>      * @param parameters  The sitemap parameters, as specified by
> &lt;parameter/&gt; tags.
>      * @return boolean    Signals successfull test.
>      */
>     boolean select (String expression, Map objectModel, Parameters
> parameters);
> }
> 
> What I had in mind is not possible with a selector. That leads us to the
> question whether it is possible to use actions in lm. The answer was not
> out of the box how I found out. ;-) 
> 
> I wrote a new action RecursiveDirectoryTraversalAction.java that only
> contains the recursive part of the fallbackResolverAction. I tested it
> on the sitemap and that worked just fine.
> 
> Now I extend my project lm like this:
> ...
> <components>
> ...
>  <actions default="RecursiveDirectoryTraversalAction">
>   <action name="RecursiveDirectoryTraversalAction"
> src="org.apache.forrest.plugin.internal.view.acting.RecursiveDirectoryTraversalAction"/>
>  </actions> 
> ...
> </components>
> <locator>
>   <match pattern="views/**">
>     <act type="RecursiveDirectoryTraversalAction">
>       <parameter value="{1}" name="request"/>
>       <parameter value="{project:theme}" name="projectFallback"/>
>       <parameter value="{project:theme-ext}" name="projectExtension"/>
>       <parameter value="{project:content.xdocs}" name="projectDir"/>
>       <location src="{uri}" />
>     </act>
>     <location
> src="{defaults:view-themes}/{defaults:theme}{defaults:theme-ext}" 
>       />
>   </match>
> </locator>
> ...
> 
> I needed do change some classes to allow actions in the lm to be
> matched:
> ?      java/org/apache/forrest/locationmap/lm/ActNode.java
> M      java/org/apache/forrest/locationmap/lm/MatchNode.java
> M      java/org/apache/forrest/locationmap/lm/SelectNode.java
> M      java/org/apache/forrest/locationmap/lm/LocationMap.java
> M      java/org/apache/forrest/locationmap/lm/LocatorNode.java
> 
> The step where I need some help with in ActNode.java is how do I get:
> public String locate(Map objectModel, InvokeContext context) throws
> Exception {
>   Parameters parameters = resolveParameters(context,objectModel);
>   Map substitutions = m_action.act(redirector, resolver, objectModel,
> source, parameters);
> ...
> }
> working.
> 
> Where can I get the redirector, resolver and the source that I need to
> parse to the action? Any tips welcome.
> 
> TIA
> 
> salu2
-- 
thorsten

"Together we stand, divided we fall!" 
Hey you (Pink Floyd)