You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by shai200 <sh...@gmail.com> on 2008/03/18 00:48:30 UTC
How to inject the result of an action into a generator
Is this even possible?
>From the first glance at the Cocoon Core 2.2 documentation
(http://cocoon.apache.org/2.2/core-modules/core/2.2/1270_1_1.html), it is
unclear whether a String result of an Action (or perhaps a value passed
through the Map and Action returns) can be used to inject as the XML content
generated by the generator, down the pipeline.
If this is possible, how would I go about it?
Shai
--
View this message in context: http://www.nabble.com/How-to-inject-the-result-of-an-action-into-a-generator-tp16108820p16108820.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: How to inject the result of an action into a generator
Posted by Joerg Heinicke <jo...@gmx.de>.
On 18.03.2008 01:50, shai200 wrote:
> I am wondering about another option: is it possible to generate a JSP and
> then from within the JSP call a to a bean to which I'll pass the request
> object? Or will the JSP not have access to the request?
Generate a JSP? Sounds horrible ;-) In general the JSP integration in
Cocoon is not the best - to put it mildly.
Can you describe what you actually want to do before getting into
implementation details.
Joerg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: How to inject the result of an action into a generator
Posted by shai200 <sh...@gmail.com>.
Thanks, awesome.
I am wondering about another option: is it possible to generate a JSP and
then from within the JSP call a to a bean to which I'll pass the request
object? Or will the JSP not have access to the request?
Joerg Heinicke wrote:
>
> On 17.03.2008 19:48, shai200 wrote:
>
>>>>From the first glance at the Cocoon Core 2.2 documentation
>> (http://cocoon.apache.org/2.2/core-modules/core/2.2/1270_1_1.html), it is
>> unclear whether a String result of an Action (or perhaps a value passed
>> through the Map and Action returns) can be used to inject as the XML
>> content
>> generated by the generator, down the pipeline.
>>
>> If this is possible, how would I go about it?
>
> Yes, it is:
>
> <map:act>
> <map:generate>
> <map:parameter name="param" value="{paramAction}"/>
> </map:generate>
> </map:act>
>
> 'paramAction' has to be an entry in the map returned by the action.
>
> Joerg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/How-to-inject-the-result-of-an-action-into-a-generator-tp16108820p16114451.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: How to inject the result of an action into a generator
Posted by Vadim Gritsenko <va...@reverycodes.com>.
On Mar 25, 2008, at 11:15 AM, shai200 wrote:
>
> But I want the generator to take the XML output of my action and use
> that as
> the text to pass down, and not read a file or a servlet.
>
> How do I do that?
Action should not be used to create whole XML content for the
generator. In this situation, you could use any of following approaches:
1. Action returns name of the source to use by generator:
<!-- Action which picks what source to use. Returns 'source'
parameter with URL -->
<map:act type="pick-a-source">
<map:generate src="{source}"/>
</map:act>
2. Instead of Action, implement a Generator and use it:
<!-- Call your 'xml-generation' generator which produces XML -->
<map:generate type="xml-generation"/>
3. Alternatively, implement a Source and use it:
<!-- Standard file generator accesses XML generated by your 'xml-
source' protocol -->
<map:generate src="xml-source:"/>
4. Check if any of existing input modules and/or sources provide the
needed functionality (probably by using XModuleSource, even though
previous 3 approaches are better)
Vadim
> Vadim Gritsenko wrote:
>>
>> On Mar 25, 2008, at 12:31 AM, shai200 wrote:
>>>
>>> This doesn't work for me for some reason. I get an error (see end of
>>> this
>>> message).
>>
>> <snip/>
>>
>>> And my sitemap entry is:
>>>
>>> <map:match pattern="xmlaction">
>>> <map:act type="xml-injection">
>>> <map:generate>
>>> <map:parameter name="param"
>>> value="{paramAction}"/>
>>> </map:generate>
>>
>> Generator must have src attribute pointing to source document it
>> should use. For example, following would work:
>>
>> <map:generate type="jx" src="pages/result.jx">
>> <map:parameter name="param" value="{paramAction}"/>
>> </map:generate>
>>
>>
>> Vadim
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: How to inject the result of an action into a generator
Posted by shai200 <sh...@gmail.com>.
But I want the generator to take the XML output of my action and use that as
the text to pass down, and not read a file or a servlet.
How do I do that?
Vadim Gritsenko wrote:
>
> On Mar 25, 2008, at 12:31 AM, shai200 wrote:
>>
>> This doesn't work for me for some reason. I get an error (see end of
>> this
>> message).
>
> <snip/>
>
>> And my sitemap entry is:
>>
>> <map:match pattern="xmlaction">
>> <map:act type="xml-injection">
>> <map:generate>
>> <map:parameter name="param"
>> value="{paramAction}"/>
>> </map:generate>
>
> Generator must have src attribute pointing to source document it
> should use. For example, following would work:
>
> <map:generate type="jx" src="pages/result.jx">
> <map:parameter name="param" value="{paramAction}"/>
> </map:generate>
>
>
> Vadim
>
>
>> </map:act>
>> <map:transform src="demo/welcome.xslt"/>
>> <map:serialize type="xhtml"/>
>> </map:match>
>>
>>
>> The error I get is as follows:
>
> <snip/>
>
>> Caused by: java.net.MalformedURLException: Invalid System ID
>> at
>> org
>> .apache
>> .cocoon
>> .components
>> .source.CocoonSourceResolver.resolveURI(CocoonSourceResolver.java:109)
>> at
>> org
>> .apache
>> .cocoon
>> .components
>> .source.CocoonSourceResolver.resolveURI(CocoonSourceResolver.java:182)
>> at
>> org.apache.cocoon.generation.FileGenerator.setup(FileGenerator.java:
>> 108)
>> at
>> org
>> .apache
>> .cocoon
>> .components
>> .pipeline
>> .AbstractProcessingPipeline
>> .setupPipeline(AbstractProcessingPipeline.java:341)
>> ... 58 more
>>
>>
>>
>> Joerg Heinicke wrote:
>>>
>>> On 17.03.2008 19:48, shai200 wrote:
>>>
>>>>> From the first glance at the Cocoon Core 2.2 documentation
>>>> (http://cocoon.apache.org/2.2/core-modules/core/
>>>> 2.2/1270_1_1.html), it is
>>>> unclear whether a String result of an Action (or perhaps a value
>>>> passed
>>>> through the Map and Action returns) can be used to inject as the XML
>>>> content
>>>> generated by the generator, down the pipeline.
>>>>
>>>> If this is possible, how would I go about it?
>>>
>>> Yes, it is:
>>>
>>> <map:act>
>>> <map:generate>
>>> <map:parameter name="param" value="{paramAction}"/>
>>> </map:generate>
>>> </map:act>
>>>
>>> 'paramAction' has to be an entry in the map returned by the action.
>>>
>>> Joerg
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/How-to-inject-the-result-of-an-action-into-a-generator-tp16108820p16275802.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: How to inject the result of an action into a generator
Posted by Vadim Gritsenko <va...@reverycodes.com>.
On Mar 25, 2008, at 12:31 AM, shai200 wrote:
>
> This doesn't work for me for some reason. I get an error (see end of
> this
> message).
<snip/>
> And my sitemap entry is:
>
> <map:match pattern="xmlaction">
> <map:act type="xml-injection">
> <map:generate>
> <map:parameter name="param"
> value="{paramAction}"/>
> </map:generate>
Generator must have src attribute pointing to source document it
should use. For example, following would work:
<map:generate type="jx" src="pages/result.jx">
<map:parameter name="param" value="{paramAction}"/>
</map:generate>
Vadim
> </map:act>
> <map:transform src="demo/welcome.xslt"/>
> <map:serialize type="xhtml"/>
> </map:match>
>
>
> The error I get is as follows:
<snip/>
> Caused by: java.net.MalformedURLException: Invalid System ID
> at
> org
> .apache
> .cocoon
> .components
> .source.CocoonSourceResolver.resolveURI(CocoonSourceResolver.java:109)
> at
> org
> .apache
> .cocoon
> .components
> .source.CocoonSourceResolver.resolveURI(CocoonSourceResolver.java:182)
> at
> org.apache.cocoon.generation.FileGenerator.setup(FileGenerator.java:
> 108)
> at
> org
> .apache
> .cocoon
> .components
> .pipeline
> .AbstractProcessingPipeline
> .setupPipeline(AbstractProcessingPipeline.java:341)
> ... 58 more
>
>
>
> Joerg Heinicke wrote:
>>
>> On 17.03.2008 19:48, shai200 wrote:
>>
>>>> From the first glance at the Cocoon Core 2.2 documentation
>>> (http://cocoon.apache.org/2.2/core-modules/core/
>>> 2.2/1270_1_1.html), it is
>>> unclear whether a String result of an Action (or perhaps a value
>>> passed
>>> through the Map and Action returns) can be used to inject as the XML
>>> content
>>> generated by the generator, down the pipeline.
>>>
>>> If this is possible, how would I go about it?
>>
>> Yes, it is:
>>
>> <map:act>
>> <map:generate>
>> <map:parameter name="param" value="{paramAction}"/>
>> </map:generate>
>> </map:act>
>>
>> 'paramAction' has to be an entry in the map returned by the action.
>>
>> Joerg
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: How to inject the result of an action into a generator
Posted by so...@apache.org.
On 3/25/08, shai200 <sh...@gmail.com> wrote:
> And my sitemap entry is:
> <map:match pattern="xmlaction">
> <map:act type="xml-injection">
> <map:generate>
> <map:parameter name="param" value="{paramAction}"/>
> </map:generate>
> </map:act>
> <map:transform src="demo/welcome.xslt"/>
> <map:serialize type="xhtml"/>
> </map:match>
This code would be illegal if the Action does not return true because
the pipeline would have no Generator. Move the code from the Action
into a custom Generator.
solprovider
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: How to inject the result of an action into a generator
Posted by Thorsten Scherler <th...@apache.org>.
On Tue, 2008-03-25 at 21:49 -0400, Joerg Heinicke wrote:
> On 25.03.2008 18:46, shai200 wrote:
>
> > This requirement is the primary function that I'll need from Cocoon,
> > otherwise it's not good for me and I'll have to find some other servlet
> > generating framework.
>
> It's not that Cocoon does not support this functionality in general.
> What we said so far only means you picked the wrong component types.
> Actions are for different purpose than data generation. Look at Vadim's
> post regarding the alternatives.
>
> > What I require is an "Action Generator" (rather than the existing
> > FileGenerator) that takes XHTML output that a POJO (i.e. and Action class)
> > returns and then moves it down the pipeline.
>
> From what I understand you are looking for a component converting
> Strings into XML without coping with the parsing - otherwise you could
> just implement a generator. But even parsing is totally easy, an
> implementation of your own generator could be:
>
> InputSource source = new InputSource(new StringReader("<xmlString>");
> SAXParser parser = null;
> try {
> parser = (SAXParser) manager.lookup(SAXParser.ROLE);
> parser.parse(source, xmlConsumer);
> } finally {
> manager.release(parser);
> }
>
> xmlConsumer is available in a generator.
Actually as I understand the thread so far we need to point out that the
"<xmlString>" needs to have all the characteristics a valid xml document
has. I mean you need a wellformed "<xmlString>" since the Parser will
produce SAX events.
salu2
--
Thorsten Scherler thorsten.at.apache.org
Open Source Java consulting, training and solutions
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: How to inject the result of an action into a generator
Posted by Joerg Heinicke <jo...@gmx.de>.
On 25.03.2008 18:46, shai200 wrote:
> This requirement is the primary function that I'll need from Cocoon,
> otherwise it's not good for me and I'll have to find some other servlet
> generating framework.
It's not that Cocoon does not support this functionality in general.
What we said so far only means you picked the wrong component types.
Actions are for different purpose than data generation. Look at Vadim's
post regarding the alternatives.
> What I require is an "Action Generator" (rather than the existing
> FileGenerator) that takes XHTML output that a POJO (i.e. and Action class)
> returns and then moves it down the pipeline.
From what I understand you are looking for a component converting
Strings into XML without coping with the parsing - otherwise you could
just implement a generator. But even parsing is totally easy, an
implementation of your own generator could be:
InputSource source = new InputSource(new StringReader("<xmlString>");
SAXParser parser = null;
try {
parser = (SAXParser) manager.lookup(SAXParser.ROLE);
parser.parse(source, xmlConsumer);
} finally {
manager.release(parser);
}
xmlConsumer is available in a generator.
Joerg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: How to inject the result of an action into a generator
Posted by Joerg Heinicke <jo...@gmx.de>.
On 26.03.2008 11:47, shai200 wrote:
> I figured out the 2.1 way from reading that 2.1 documentation, and it works
> for me (only that I implemented AbstractGenerator instead of
> ServiceableGenerator). However the 2.2 Spring way is not fully documented
> yet, so I don't know how to do this...
Spring is about injecting dependencies/lower level components into
higher level components. This also works with simple configuration
parameters like strings and ints. You can do the same with the Avalon
interfaces like Configurable or Serviceable. If you do not even use the
latter you might have no dependencies/configuration - and so you
probably neither need Spring.
Joerg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: How to inject the result of an action into a generator
Posted by shai200 <sh...@gmail.com>.
Hi Joerg,
I figured out the 2.1 way from reading that 2.1 documentation, and it works
for me (only that I implemented AbstractGenerator instead of
ServiceableGenerator). However the 2.2 Spring way is not fully documented
yet, so I don't know how to do this...
Shai
Joerg Heinicke wrote:
>
> On 25.03.2008 22:45, shai200 wrote:
>
>> Alright, so since you're already in the groove of answering my questions
>> (thanks btw), I would need my generator class to also have access to the
>> entire Request Map (preferably in the form Map<String,String[]> where the
>> String[] key is the set of values in case a value is declared twice, but
>> that's not so crucial) as well as the Session object / map... how would I
>> go
>> about that?
>
> Generators are SitemapModelComponents [1] and so have access to a map
> that we call object model in the setup(..) method. If you extend from an
> existing generator (ServiceableGenerator [2] is mostly a reasonable
> choice) you only have to override the setup(..) method and the
> generate(..) method. You can access request from the object model using
> the ObjectModelHelper [3]: ObjectModelHelper.getRequest(objectModel);
>
> Disclaimer: What I explained is pretty much the Cocoon 2.1 way. If you
> use 2.2 this will still work but there might be better ways to do that
> like component setup through Spring. But I guess this does not make
> setup(..) obsolete, only additional component configurations.
>
> Joerg
>
> [1]
> http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/sitemap/SitemapModelComponent.html
> [2]
> http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/generation/ServiceableGenerator.html
> [3]
> http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/environment/ObjectModelHelper.html
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/How-to-inject-the-result-of-an-action-into-a-generator-tp16108820p16304025.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: How to inject the result of an action into a generator
Posted by Joerg Heinicke <jo...@gmx.de>.
On 25.03.2008 22:45, shai200 wrote:
> Alright, so since you're already in the groove of answering my questions
> (thanks btw), I would need my generator class to also have access to the
> entire Request Map (preferably in the form Map<String,String[]> where the
> String[] key is the set of values in case a value is declared twice, but
> that's not so crucial) as well as the Session object / map... how would I go
> about that?
Generators are SitemapModelComponents [1] and so have access to a map
that we call object model in the setup(..) method. If you extend from an
existing generator (ServiceableGenerator [2] is mostly a reasonable
choice) you only have to override the setup(..) method and the
generate(..) method. You can access request from the object model using
the ObjectModelHelper [3]: ObjectModelHelper.getRequest(objectModel);
Disclaimer: What I explained is pretty much the Cocoon 2.1 way. If you
use 2.2 this will still work but there might be better ways to do that
like component setup through Spring. But I guess this does not make
setup(..) obsolete, only additional component configurations.
Joerg
[1]
http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/sitemap/SitemapModelComponent.html
[2]
http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/generation/ServiceableGenerator.html
[3]
http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/environment/ObjectModelHelper.html
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: How to inject the result of an action into a generator
Posted by shai200 <sh...@gmail.com>.
Alright, so since you're already in the groove of answering my questions
(thanks btw), I would need my generator class to also have access to the
entire Request Map (preferably in the form Map<String,String[]> where the
String[] key is the set of values in case a value is declared twice, but
that's not so crucial) as well as the Session object / map... how would I go
about that?
Shai
solprovider-2 wrote:
>
> On 3/25/08, shai200 <sh...@gmail.com> wrote:
>> This requirement is the primary function that I'll need from Cocoon,
>> otherwise it's not good for me and I'll have to find some other servlet
>> generating framework.
>>
>> I have a system where I have objects generating XHTML code based on some
>> input I give them (other XML descriptors, Database queries, etc.). I'm
>> looking for a way to take this HTML output and apply transformation on
>> it
>> for further styling. Cocoon pipelines would be perfect for that, but
>> unfortunately I am starting to understand that I'll still need to create
>> separate servlets that provide the HTML output and then inject it into
>> Cocoon, which is a stupid thing to do because I am looking for a way to
>> create my servlets in the first place.
>>
>> What I require is an "Action Generator" (rather than the existing
>> FileGenerator) that takes XHTML output that a POJO (i.e. and Action
>> class)
>> returns and then moves it down the pipeline.
>>
>> Perhaps someone can suggest another framework that can achieve this?
>
> You do not need Actions. You may never need Actions. Most uses of
> Actions are better handled by other components. Please forget you
> ever heard of Cocoon Actions.
>
> Did you know that the "src" parameter can use many protocols including
> "http:" and "ftp:"? If XHTML (or any XML) is being generated by a
> servlet, you can use:
> <map:generate src="http://example.com/myXHTMLservlet"/>
> You could also pass querystring parameters to your generate:
> <map:generate
> src="http://example.com/myXHTMLservlet?{request-param:xmlDescriptor}&{request-param:query}"/>
>
> But wait, Cocoon provides more for the same low price. Generators are
> Java so you do not need to create servlets. A custom Generator can
> use your POJOs! (You are already creating an Action so I assume you
> program Java.) This exactly meets your specifications for an
> "ActionGenerator".
> <map:generate type="myActionGenerator">
> <map:param name="xmlDescriptor" value="something"/>
> <map:param name="query" value="databaseQuery"/>
> </map:generate>
>
> The definition of a custom Generator is an XML source that is created
> with custom Java code and will be processed by other Cocoon components
> (at least a Serializer, but also as many Transformers as you wish!) A
> custom Generator will handle all the requirements you have mentioned
> without the headaches you have encountered while attempting to use the
> wrong component for the task.
>
> solprovider
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/How-to-inject-the-result-of-an-action-into-a-generator-tp16108820p16294417.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: How to inject the result of an action into a generator
Posted by so...@apache.org.
On 3/25/08, shai200 <sh...@gmail.com> wrote:
> This requirement is the primary function that I'll need from Cocoon,
> otherwise it's not good for me and I'll have to find some other servlet
> generating framework.
>
> I have a system where I have objects generating XHTML code based on some
> input I give them (other XML descriptors, Database queries, etc.). I'm
> looking for a way to take this HTML output and apply transformation on it
> for further styling. Cocoon pipelines would be perfect for that, but
> unfortunately I am starting to understand that I'll still need to create
> separate servlets that provide the HTML output and then inject it into
> Cocoon, which is a stupid thing to do because I am looking for a way to
> create my servlets in the first place.
>
> What I require is an "Action Generator" (rather than the existing
> FileGenerator) that takes XHTML output that a POJO (i.e. and Action class)
> returns and then moves it down the pipeline.
>
> Perhaps someone can suggest another framework that can achieve this?
You do not need Actions. You may never need Actions. Most uses of
Actions are better handled by other components. Please forget you
ever heard of Cocoon Actions.
Did you know that the "src" parameter can use many protocols including
"http:" and "ftp:"? If XHTML (or any XML) is being generated by a
servlet, you can use:
<map:generate src="http://example.com/myXHTMLservlet"/>
You could also pass querystring parameters to your generate:
<map:generate
src="http://example.com/myXHTMLservlet?{request-param:xmlDescriptor}&{request-param:query}"/>
But wait, Cocoon provides more for the same low price. Generators are
Java so you do not need to create servlets. A custom Generator can
use your POJOs! (You are already creating an Action so I assume you
program Java.) This exactly meets your specifications for an
"ActionGenerator".
<map:generate type="myActionGenerator">
<map:param name="xmlDescriptor" value="something"/>
<map:param name="query" value="databaseQuery"/>
</map:generate>
The definition of a custom Generator is an XML source that is created
with custom Java code and will be processed by other Cocoon components
(at least a Serializer, but also as many Transformers as you wish!) A
custom Generator will handle all the requirements you have mentioned
without the headaches you have encountered while attempting to use the
wrong component for the task.
solprovider
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: How to inject the result of an action into a generator
Posted by shai200 <sh...@gmail.com>.
Hello,
This requirement is the primary function that I'll need from Cocoon,
otherwise it's not good for me and I'll have to find some other servlet
generating framework.
I have a system where I have objects generating XHTML code based on some
input I give them (other XML descriptors, Database queries, etc.). I'm
looking for a way to take this HTML output and apply transformation on it
for further styling. Cocoon pipelines would be perfect for that, but
unfortunately I am starting to understand that I'll still need to create
separate servlets that provide the HTML output and then inject it into
Coccoon, which is a stupid thing to do because I am looking for a way to
create my servlets in the first place.
What I require is an "Action Generator" (rather than the existing
FileGenerator) that takes XHTML output that a POJO (i.e. and Action class)
returns and then moves it down the pipeline.
Perhaps someone can suggest another framework that can achieve this?
Joerg Heinicke wrote:
>
> On 25.03.2008 00:31, shai200 wrote:
>
>> This doesn't work for me for some reason. I get an error (see end of this
>> message).
>>
>> My code snippet is:
>>
>> public class XMLInjectAction extends AbstractAction {
>> public Map act (Redirector redirector, SourceResolver resolver, Map
>> objectModel, String source, Parameters params) {
>> Map sitemapParams = new HashMap();
>> String xml="<content><h1>Automatically Generated By Action:
>> Hello</h1></content>";
>> sitemapParams.put("paramAction", xml);
>> return sitemapParams;
>> }
>> }
>>
>>
>> And my sitemap entry is:
>>
>> <map:match pattern="xmlaction">
>> <map:act type="xml-injection">
>> <map:generate>
>> <map:parameter name="param" value="{paramAction}"/>
>> </map:generate>
>> </map:act>
>> <map:transform src="demo/welcome.xslt"/>
>> <map:serialize type="xhtml"/>
>> </map:match>
>
> Additionally to Vadim's comment, your approach of injecting XML from an
> action into a generator is "wrong". An action is for deciding sitemap
> paths, constructing pipelines, not for creating or working with the
> actual data. A solution to your problem might be flowscript but you
> better might explain what you actually try to do, your requirements.
>
> Joerg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/How-to-inject-the-result-of-an-action-into-a-generator-tp16108820p16290507.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: How to inject the result of an action into a generator
Posted by Joerg Heinicke <jo...@gmx.de>.
On 25.03.2008 00:31, shai200 wrote:
> This doesn't work for me for some reason. I get an error (see end of this
> message).
>
> My code snippet is:
>
> public class XMLInjectAction extends AbstractAction {
> public Map act (Redirector redirector, SourceResolver resolver, Map
> objectModel, String source, Parameters params) {
> Map sitemapParams = new HashMap();
> String xml="<content><h1>Automatically Generated By Action:
> Hello</h1></content>";
> sitemapParams.put("paramAction", xml);
> return sitemapParams;
> }
> }
>
>
> And my sitemap entry is:
>
> <map:match pattern="xmlaction">
> <map:act type="xml-injection">
> <map:generate>
> <map:parameter name="param" value="{paramAction}"/>
> </map:generate>
> </map:act>
> <map:transform src="demo/welcome.xslt"/>
> <map:serialize type="xhtml"/>
> </map:match>
Additionally to Vadim's comment, your approach of injecting XML from an
action into a generator is "wrong". An action is for deciding sitemap
paths, constructing pipelines, not for creating or working with the
actual data. A solution to your problem might be flowscript but you
better might explain what you actually try to do, your requirements.
Joerg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: How to inject the result of an action into a generator
Posted by shai200 <sh...@gmail.com>.
Hello,
This doesn't work for me for some reason. I get an error (see end of this
message).
My code snippet is:
public class XMLInjectAction extends AbstractAction {
public Map act (Redirector redirector, SourceResolver resolver, Map
objectModel, String source, Parameters params) {
Map sitemapParams = new HashMap();
String xml="<content><h1>Automatically Generated By Action:
Hello</h1></content>";
sitemapParams.put("paramAction", xml);
return sitemapParams;
}
}
And my sitemap entry is:
<map:match pattern="xmlaction">
<map:act type="xml-injection">
<map:generate>
<map:parameter name="param" value="{paramAction}"/>
</map:generate>
</map:act>
<map:transform src="demo/welcome.xslt"/>
<map:serialize type="xhtml"/>
</map:match>
The error I get is as follows:
2008-03-25 00:28:50,812 btpool0-1 ERROR cocoon - Internal Cocoon Problem
org.apache.cocoon.ProcessingException: Failed to process pipeline
at <map:serialize type="xhtml"> -
file:///c:/1/skunk-neuvoip/neuvoip/./src/main/resources/COB-INF/sitemap.xmap:47:33
at <map:transform> -
file:///c:/1/skunk-neuvoip/neuvoip/./src/main/resources/COB-INF/sitemap.xmap:46:44
at <map:generate> -
file:///c:/1/skunk-neuvoip/neuvoip/./src/main/resources/COB-INF/sitemap.xmap:42:20
at <map:match> -
file:///c:/1/skunk-neuvoip/neuvoip/./src/main/resources/COB-INF/sitemap.xmap:40:34
at
org.apache.cocoon.ProcessingException.throwLocated(ProcessingException.java:143)
at
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.handleException(AbstractProcessingPipeline.java:921)
at
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.setupPipeline(AbstractProcessingPipeline.java:370)
at
org.apache.cocoon.components.pipeline.impl.AbstractCachingProcessingPipeline.setupPipeline(AbstractCachingProcessingPipeline.java:727)
at
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.preparePipeline(AbstractProcessingPipeline.java:464)
at
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.process(AbstractProcessingPipeline.java:409)
at sun.reflect.GeneratedMethodAccessor55.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.apache.cocoon.core.container.spring.avalon.PoolableProxyHandler.invoke(PoolableProxyHandler.java:72)
at $Proxy8.process(Unknown Source)
at
org.apache.cocoon.components.treeprocessor.sitemap.SerializeNode.invoke(SerializeNode.java:144)
at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:55)
at
org.apache.cocoon.components.treeprocessor.sitemap.MatchNode.invoke(MatchNode.java:87)
at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:77)
at
org.apache.cocoon.components.treeprocessor.sitemap.PipelineNode.invoke(PipelineNode.java:151)
at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:77)
at
org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNode.invoke(PipelinesNode.java:93)
at
org.apache.cocoon.components.treeprocessor.ConcreteTreeProcessor.process(ConcreteTreeProcessor.java:240)
at
org.apache.cocoon.components.treeprocessor.ConcreteTreeProcessor.process(ConcreteTreeProcessor.java:171)
at
org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreeProcessor.java:251)
at
org.apache.cocoon.servlet.RequestProcessor.process(RequestProcessor.java:357)
at
org.apache.cocoon.servlet.RequestProcessor.service(RequestProcessor.java:171)
at
org.apache.cocoon.sitemap.SitemapServlet.service(SitemapServlet.java:64)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at
org.apache.cocoon.servletservice.ServletServiceContext$PathDispatcher.forward(ServletServiceContext.java:567)
at
org.apache.cocoon.servletservice.ServletServiceContext$PathDispatcher.forward(ServletServiceContext.java:544)
at
org.apache.cocoon.servletservice.spring.ServletFactoryBean$ServiceInterceptor.invoke(ServletFactoryBean.java:230)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy5.service(Unknown Source)
at
org.apache.cocoon.servletservice.DispatcherServlet.service(DispatcherServlet.java:102)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at
org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingServlet.service(ReloadingServlet.java:89)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093)
at
org.apache.cocoon.servlet.multipart.MultipartFilter.doFilter(MultipartFilter.java:119)
at
org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingServletFilter.doFilter(ReloadingServletFilter.java:50)
at
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at org.apache.cocoon.servlet.DebugFilter.doFilter(DebugFilter.java:169)
at
org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingServletFilter.doFilter(ReloadingServletFilter.java:50)
at
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at
org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingSpringFilter.doFilter(ReloadingSpringFilter.java:69)
at
org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingServletFilter.doFilter(ReloadingServletFilter.java:50)
at
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at
org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:211)
at
org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
at org.mortbay.jetty.Server.handle(Server.java:313)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
at
org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:830)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
at
org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)
Caused by: java.net.MalformedURLException: Invalid System ID
at
org.apache.cocoon.components.source.CocoonSourceResolver.resolveURI(CocoonSourceResolver.java:109)
at
org.apache.cocoon.components.source.CocoonSourceResolver.resolveURI(CocoonSourceResolver.java:182)
at
org.apache.cocoon.generation.FileGenerator.setup(FileGenerator.java:108)
at
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.setupPipeline(AbstractProcessingPipeline.java:341)
... 58 more
Joerg Heinicke wrote:
>
> On 17.03.2008 19:48, shai200 wrote:
>
>>>>From the first glance at the Cocoon Core 2.2 documentation
>> (http://cocoon.apache.org/2.2/core-modules/core/2.2/1270_1_1.html), it is
>> unclear whether a String result of an Action (or perhaps a value passed
>> through the Map and Action returns) can be used to inject as the XML
>> content
>> generated by the generator, down the pipeline.
>>
>> If this is possible, how would I go about it?
>
> Yes, it is:
>
> <map:act>
> <map:generate>
> <map:parameter name="param" value="{paramAction}"/>
> </map:generate>
> </map:act>
>
> 'paramAction' has to be an entry in the map returned by the action.
>
> Joerg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/How-to-inject-the-result-of-an-action-into-a-generator-tp16108820p16268117.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: How to inject the result of an action into a generator
Posted by Joerg Heinicke <jo...@gmx.de>.
On 17.03.2008 19:48, shai200 wrote:
>>>From the first glance at the Cocoon Core 2.2 documentation
> (http://cocoon.apache.org/2.2/core-modules/core/2.2/1270_1_1.html), it is
> unclear whether a String result of an Action (or perhaps a value passed
> through the Map and Action returns) can be used to inject as the XML content
> generated by the generator, down the pipeline.
>
> If this is possible, how would I go about it?
Yes, it is:
<map:act>
<map:generate>
<map:parameter name="param" value="{paramAction}"/>
</map:generate>
</map:act>
'paramAction' has to be an entry in the map returned by the action.
Joerg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org