cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Neeme Praks" <ne...@one.lv>
Subject RE: recursive func in XSP?
Date Mon, 05 Jun 2000 09:24:08 GMT

> -----Original Message-----
> From: Giacomo Pati [mailto:Giacomo.Pati@pwr.ch]
> Sent: Monday, June 05, 2000 10:18 AM
> To: cocoon-dev@xml.apache.org
> Subject: Re: recursive func in XSP?
> 
> 
> Neeme Praks wrote:
> > 
> > Thanks for all your valuable suggestions! I'll try them out 
> and will let
> > you know if I managed to solve my problem.
> > 
> > Just one more concern: if I use DOM objects, I'm incompatible with
> > cocoon2, right?
> > Or is there something that I missed along the way...
> 
> You mean in an XSP page? If you use standard xsp tags this 
> should be not
> problem. If you use things like
> 
>  Element e = yourMethodCall();
>  xspCurrentNode.appendChild(document.importNode(e));

But how can I achieve this kind of recursiveness only by using standard
stuff?
To illustrate, I'll include my current code. It doesn't compile properly
yet, but should give you an idea what I want to achieve.

Neeme

Sorry for the tabs, I haven't figured out how to force XMLSpy to use
spaces instead of tabs...
----------- code, cut here -------------------
<?xml version="1.0"?>
<?cocoon-process type="xsp"?>
<xsp:page language="java"
xmlns:xsp="http://www.apache.org/1999/XSP/Core">
	<xsp:structure>
		<xsp:include>diweb.bo.*</xsp:include>
		<xsp:include>org.w3c.dom.*</xsp:include>
	</xsp:structure>
	<xsp:logic><![CDATA[
		private String normalize(String string)
		{
			if (string == null) return "";
			else return string;
		}

		private Node BuildTree( Document doc, FolderTree tree,
long SelectedID, long RemovedID ) throws Exception
		{
			if ( tree == null )
			{
				return null;
			}
			Folder folder = tree.getRoot();
			long ID = folder.getId();
			if (ID == RemovedID)
				return null;

			Node result = doc.createElement("folder");
			result.appendChild(
doc.createAttribute("folderID") ).setNodeValue( String.valueOf(ID) );
			if (ID == SelectedID)
				result.appendChild(
doc.createAttribute("IsSelected") ).setNodeValue("1");
			result.setNodeValue( folder.getName() );

			if (tree.getNodes() != null)
			{
				for (int i = 0; i <
tree.getNodes().length; i++)
				{
					result.appendChild ( BuildTree(
doc, tree.getNodes()[i], SelectedID, RemovedID ) );
				}
			}

			return result;
		}

		int UserID = 1;
	]]></xsp:logic>
	<page>
		<title>Test XSP Page</title>
		<xsp:logic>
			FolderTree tree =
FolderUtility.getTreeByUser(UserID, UserID);
			Node node = BuildTree( document, tree, 0, 0);
	
xspCurrentNode.appendChild(document.importNode(node, true));
		</xsp:logic>
	</page>
</xsp:page>
----------- code, cut here -------------------

Currently it gives me the following error:

org.apache.xerces.dom.DOMExceptionImpl: DOM001 Modification not allowed
	at
org.apache.xerces.dom.ElementImpl.setNodeValue(ElementImpl.java:141)
	at
_D_._Turbine._webapps._cocoon._samples._xsp._mypage.BuildTree(_mypage.ja
va, Compiled Code)
	at
_D_._Turbine._webapps._cocoon._samples._xsp._mypage.populateDocument(_my
page.java:117)
	at
org.apache.cocoon.processor.xsp.XSPPage.getDocument(XSPPage.java:96)
	at
org.apache.cocoon.processor.xsp.XSPProcessor.process(XSPProcessor.java,
Compiled Code)
	at org.apache.cocoon.Engine.handle(Engine.java, Compiled Code)
	at org.apache.cocoon.Cocoon.service(Cocoon.java:167)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
	at
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java,
Compiled Code)
	at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:523)
	at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(H
ttpConnectionHandler.java:146)
	at
org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java
:334)
	at java.lang.Thread.run(Thread.java:479)

Probably I'll manage to solve this myself, but maybe the mistake is
obvious to somebody else...

Mime
View raw message