You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by "Matt P." <ma...@area403.org> on 2005/07/11 08:59:03 UTC

feeling deprecated and modifiable

Hello,

I've been looking at a way to modify a user's configuration file, stored
somewhere on the filesystem as an xml file. I apply the classic pattern
found in many cocoon sources, and transmogrify it with my sauce.

[...]
try
{
	parser =
	cocoon.getComponent(Packages.org.apache.excalibur.xml.dom.DOMParser.ROLE);
	resolver =
	cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.ROLE);
	source
	= resolver.resolveURI("file:/tmp/" + username + "/configuration.xml");
	if ( source instanceof Packages.org.apache.excalibur.source.ModifiableSource)
	{
		java.lang.System.err.println("Modifiable source");
		var inputSource = new Packages.org.xml.sax.InputSource(source.getInputStream());
		var document = parser.parseDocument(inputSource);
		//var outputStream = source.getOutputStream();
		//var document = parser.parseDocument(outputStream);
		java.lang.System.err.println("configuration " + document.getElementsByTagName("cx:configuration").getLength());
		var configurationNode = document.getElementsByTagName("cx:configuration").item(0);
		var inputNode = document.createElement("cx:input");
		inputNode.setAttribute("id", inputId);
		var sqlNode = document.createElement("cx:sql-statement");
		sqlNode.appendChild(document.createTextNode(sqlStatement));
		inputNode.appendChild(sqlNode);
		configurationNode.appendChild(inputNode);
		source.refresh();
		//var outputStream = source.getOutputStream();
		//outputStream.flush();
		//outputStream.close();
	}
}

[...]

Now, the above works ok, except it doesn't save nothing (I thought the
refresh would...). I added the 3 lines at the end to get an output
stream from the source, but the effect is my configuration files
disappears mysteriously (at least to me).

I'd appreciate if someone could give me some insight into this.

Oh, and while at it, is there a preference between using the w3c dom
model, or the xerces one?

Cheers, 

Matt

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