I am however a bit uncomfortable with the current implementation and I wanted to see if it's just me not having the correct approach.
A source property (both in webdav sense and in the SourceProperty implementation) is made of three part: a local name (String), a namespace (String) and a value (DOM Element). It's worth noticing that the property value is actually the *holder element* plus it's value (that is a text node - in case of a string value - or other Elements), so that effectively you get, in case of webdav,
<getcontenttype xmlns="DAV:">text/xml</getcontenttype>
a property name of "getcontenttype, a namespace of "DAV:" and a value of (xml-ized)
<getcontenttype xmlns="DAV:">text/xml</getcontenttype>. User space tools will then give you a value of "text/xml", but this is a different issue.
All this said, I fail to understand why this transformer is somehow reinveinting XML by using this syntax:
<source:prop name="author" namespace="meta">me</source:prop>
which forces, besides, to use a very risky solution to rebuild the property:
String pre = "<"+name+" xmlns="+quote+namespace+quote+">"; String post = "</"+name+">"; String xml = pre+value+post; StringReader reader = new StringReader(xml); Document doc = parser.parseDocument(new InputSource(reader)); SourceProperty property = new SourceProperty(doc.getDocumentElement()); ((InspectableSource)source).setSourceProperty(property);
One of my biggest no-no is not to use string manipulation to build XML: this algo would fail in case the element has any XML reserver characters or is an XML property value with nested elements.
What about using good 'ole XML instead? I'm considering something like:
<source:props> <myns:author xmlns:myns="meta">me</myns:author> </source:props>
This would allow using standard Transformer tools (startRecording() instead than startTextRecording()) to set the properties later. It would be much safer and a good bit more XMLish (and WebDAVish too). Also, this modification could be inserted directly into the SourceWritingTransformer without requiring a new transformer just to set properties.
How does it sound? Am I overlooking something?
-- Gianugo Rabellino Pro-netics s.r.l. - http://www.pro-netics.com Orixo, the XML business alliance - http://www.orixo.com (Now blogging at: http://blogs.cocoondev.org/gianugo/)