cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bos...@t-online.de (Boscoe)
Subject Re: XML data via POST request
Date Fri, 23 Aug 2002 11:22:26 GMT
  Sorry, I'm a bit late.

>What do you need the action for ? 
>
I used the action to keep my XSP and logicsheets as clean of all 
 implementation details as possible. I just pass the request to an 
application class and there access the HttpServletRequest. But, always 
good to know there is more than one way to do it ;-) .

>The way I do it is "pure" xsp, an example
>below.  I do not quite know though how to make it reusable and put it into
>logicsheet so I do not have to make xsp:includes and so I could do:
>Document document = <myutils:get-request-body-as-DOM/>;
>
>Could someone help me ?
>
><?xml version="1.0" encoding="ISO-8859-1"?>
><xsp:page language="java"
>          xmlns:xsp="http://apache.org/xsp"
>          xmlns:esql="http://apache.org/cocoon/SQL/v2">
><xsp:structure>
>	<xsp:include>java.net.*</xsp:include>
>	<xsp:include>org.w3c.dom.*</xsp:include>
>	<xsp:include>org.apache.cocoon.xml.dom.DOMStreamer</xsp:include>
>	<xsp:include>org.apache.cocoon.xml.dom.DOMBuilder</xsp:include>
>	<xsp:include>org.apache.cocoon.components.parser.Parser</xsp:include>
>	<xsp:include>org.apache.cocoon.util.PostInputStream</xsp:include>
>	<xsp:include>org.apache.cocoon.environment.http.HttpEnvironment</xsp:include>
>	<xsp:include>javax.servlet.http.HttpServletRequest</xsp:include>
>	<xsp:include>org.apache.xpath.XPathAPI</xsp:include>
>	<xsp:include>javax.xml.transform.TransformerException</xsp:include>
></xsp:structure>
><xsp:logic>
>	Document document = null;
>	public Document GetInputStreamDocument() throws IOException {
>		// > Node node = XPathAPI.selectNode(parser.parse(request.getParameter("xmlparam"),
"kazoo");
>    	int contentLength = request.getContentLength();
>    	if ( contentLength >= 0 ) {
>	    	HttpServletRequest request =
>	    			(HttpServletRequest) objectModel.get( HttpEnvironment.HTTP_REQUEST_OBJECT );
>
>	    	PostInputStream anStream = new PostInputStream( request.getInputStream(), contentLength
);
>	    	InputSource contentSource = new InputSource( anStream );
>
>			Parser newParser = null;
>			DOMBuilder builder = null;
>			try {
>				newParser = (Parser) this.manager.lookup(Parser.ROLE);
>				document = newParser.newDocument();
>				builder = new DOMBuilder(newParser);
>				newParser.setContentHandler(builder);
>				newParser.setLexicalHandler(builder);
>				newParser.parse( contentSource );
>				
>			} catch (Exception e) {
>				// ignore - return null
>			} finally {
>				this.manager.release((Component) newParser);
>			}
>			return builder.getDocument();
>    	}
>    	return null;
>	}
></xsp:logic>
><content>
>	<xsp:logic>
>	document = GetInputStreamDocument();
>	try {
>		<id><xsp:expr>XPathAPI.selectSingleNode(document, "/Orders/OrderID").getFirstChild().getNodeValue()</xsp:expr></id>
>   	} catch ( TransformerException e ) {
>   	} catch ( DOMException e ) {
>   	}
>	</xsp:logic>
></content>
></xsp:page>
>
>  
>
You could, for example, put this whole bunch of code ( except 
<xsp:page></xsp:page> ) into one logicsheet, wrap it in a template and 
access it via

<?xml-logicsheet href="blabla"?>
...
<example:example-element/>
...

from within your XSP.

Regards

Boscoe



---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <cocoon-users-unsubscribe@xml.apache.org>
For additional commands, e-mail:   <cocoon-users-help@xml.apache.org>


Mime
View raw message