anil pisze:
> Hi Grzegorz -
>
> Thanks for your help regarding talking to a pipeline in another block. I've
> got a supplementary question which I hope you can help with.
>
> How do I pass a string of XML to the pipeline to have it transformed?
>
> Basically I receive a string of XML in flowscript (this XML is read from the
> input stream, sent by an xforms engine) and I'd like to pass this string to
> the pipeline to perform some XSLT transformation, and have the result of the
> transformation passed back to me within flowscript.
>
> To achieve this previously I had done:
>
>
> var output = pipelineUtil.processToDOM("transformForExist", viewData);
>
>
> with viewData being the data - this is then read by:
>
> <map:generate src="module:flow-attr:stringOutput" />
>
> So now I am using the source resolver my flowscript is as follows:
>
> var map = new java.util.HashMap();
> map.put("stringOutput", submission);
>
> var source =
> sourceResolver.resolveURI("servlet:rmm-search:/transformForSolr", null,
> map);
> var sourceOutput = SourceUtil.toDOM(source);
This wrong because the map you pass is not used to build parameters attached to
the URI. Javadocs of
SourceResolver#resolveURI() say:
parameters - - Additional parameters for the URI. The parameters are specific
to the used scheme.
Since it's schema specific it implys it's not universal way to pass parameters
that will be taken
the same way as they could be passed using literal ?param=value syntax.
Actually, servlet: source
implementation (along with most implementations of other sources) completely
ignores parameters object.
> But I can't find a way to read the parameter within the transformForSolr
> pipeline. I tried using the request generator to read the parameters, but
> this didn't seem to work.
>
> Sorry, I'm just a bit confused - am I doing the right thing?
The whole approach must be different, you have basically two choices:
1. Make a Servlet *Service* request
2. Attach you string as a parameter to your URI using ?param=value syntax.
Method
appendParameters()[1] would be helpful.
Since second method is rather ineffective and clumsy (because parameters in URI
should be used for
short values) I won't elaborate on this method.
Let's take a closer look of Servlet *Service* request. I have put word service
in bold quite
intentionally in order to point out that it's not plain servlet request that
you make using
SourceResolver which is, in fact, plain GET request. Servlet Service request is
also implemented as
standard HTTP request but with POST method and special meaning attached to the
POSTed data. See [2]
for more information about it (it's link to docs of SSF just being created now).
The only missing detail is how to enforce Source object obtained from
ServletResolver to make a
service request and how to pass the data? Let's take a look at API docs of
ServletSource[3]. As you
see it implements PostableSource[4] interface. That's the key, you need to
getOutputStream from
source and write your XML data to it. Then you can use SourceUtil.toDOM(source)
method as before.
You may wonder how you are going to parse XML coming as POST data to your
another block. Answer is
simple, use standard ("file") generator and service-consumer: source. Your
pipeline should look like:
<map:generate src="service-consumer:"/>
[...]
<map:serialize type="xml"/>
And you are done.
I think that for such operations should some helper/util class be created.
Moreover, this should be
moved to documentation as FAQ entry. Anil, since I helped quite a lot it would
be nice if you could
take care of adding summary of this discussion to our documentation.
Instructions how to do that are
here[5].
[1]
http://excalibur.apache.org/apidocs/org/apache/excalibur/source/SourceUtil.html#appendParameters(java.lang.String,%20org.apache.excalibur.source.SourceParameters)
[2] http://cocoon.zones.apache.org/daisy/cdocs-servlet-service-impl/g1/1412.html
[3]
http://cocoon.apache.org/subprojects/servlet-service/1.0/servlet-service-components/1.0/apidocs/org/apache/cocoon/servletservice/components/ServletSource.html
[4]
http://cocoon.apache.org/subprojects/servlet-service/1.0/servlet-service-components/1.0/apidocs/org/apache/cocoon/servletservice/postable/PostableSource.html
[5] http://cocoon.apache.org/1273_1_1.html
--
Grzegorz Kossakowski
Committer and PMC Member of Apache Cocoon
http://reflectingonthevicissitudes.wordpress.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]