* Parse attributes of otherwise unmapped elements in sparse mode.

(fixes bug 216)
* Do not rely on helma.objectmodel.db.Node.getPrototype() to return null
to find out whether a node has been initialized. Even if the prototype is not set, the
Node will return "hopobject" as prototype.
This commit is contained in:
hns 2003-02-03 13:22:26 +00:00
parent 2e239f797e
commit 2c1fdf3d0f

View file

@ -92,17 +92,16 @@ public class XmlConverter implements XmlConstants {
Object previousNode = null; Object previousNode = null;
if (DEBUG) if (DEBUG)
debug("reading " + element.getNodeName() ); debug("reading " + element.getNodeName() );
helmaNode.setName( element.getNodeName() );
String prototype = props.getProperty(element.getNodeName()+"._prototype"); String prototype = props.getProperty(element.getNodeName()+"._prototype");
if ( prototype == null && !sparse ) if ( prototype == null && !sparse )
prototype = "HopObject"; prototype = "HopObject";
// if we have a prototype (either explicit or implicit "hopobject"), // if we have a prototype (either explicit or implicit "hopobject"),
// set it on the Helma node and store it in the node cache. // set it on the Helma node and store it in the node cache.
if ( prototype != null ) { if ( prototype != null ) {
helmaNode.setName( element.getNodeName() );
helmaNode.setPrototype( prototype ); helmaNode.setPrototype( prototype );
previousNode = nodeCache.put (prototype, helmaNode); previousNode = nodeCache.put (prototype, helmaNode);
} }
// check attributes of the current element // check attributes of the current element
attributes(element, helmaNode, nodeCache); attributes(element, helmaNode, nodeCache);
// check child nodes of the current element // check child nodes of the current element
@ -123,7 +122,7 @@ public class XmlConverter implements XmlConstants {
private INode children( Element element, helma.objectmodel.INode helmaNode, Map nodeCache ) { private INode children( Element element, helma.objectmodel.INode helmaNode, Map nodeCache ) {
NodeList list = element.getChildNodes(); NodeList list = element.getChildNodes();
int len = list.getLength(); int len = list.getLength();
boolean nodeHasPrototype = helmaNode.getPrototype() != null; boolean nodeIsInitialized = !nodeCache.isEmpty();
StringBuffer textcontent = new StringBuffer(); StringBuffer textcontent = new StringBuffer();
String domKey, helmaKey; String domKey, helmaKey;
for ( int i=0; i<len; i++ ) { for ( int i=0; i<len; i++ ) {
@ -133,7 +132,7 @@ public class XmlConverter implements XmlConstants {
// if the current node hasn't been initialized yet, try if it can // if the current node hasn't been initialized yet, try if it can
// be initialized and converted from one of the child elements. // be initialized and converted from one of the child elements.
if (!nodeHasPrototype) { if (!nodeIsInitialized) {
if (childNode.getNodeType() == Node.ELEMENT_NODE) { if (childNode.getNodeType() == Node.ELEMENT_NODE) {
convert ((Element) childNode, helmaNode, nodeCache); convert ((Element) childNode, helmaNode, nodeCache);
if (helmaNode.getPrototype() != null) if (helmaNode.getPrototype() != null)
@ -172,8 +171,9 @@ public class XmlConverter implements XmlConstants {
String prototype = helmaKey.substring (0, dot); String prototype = helmaKey.substring (0, dot);
INode node = (INode) nodeCache.get (prototype); INode node = (INode) nodeCache.get (prototype);
helmaKey = helmaKey.substring (dot+1); helmaKey = helmaKey.substring (dot+1);
if (node != null && node.getString(helmaKey)==null) if (node != null && node.getString(helmaKey)==null) {
node.setString (helmaKey, XmlUtil.getTextContent (childNode)); node.setString (helmaKey, XmlUtil.getTextContent (childNode));
}
} else if ( helmaNode.getString(helmaKey)==null ) { } else if ( helmaNode.getString(helmaKey)==null ) {
helmaNode.setString( helmaKey, XmlUtil.getTextContent(childNode) ); helmaNode.setString( helmaKey, XmlUtil.getTextContent(childNode) );
if (DEBUG) if (DEBUG)
@ -230,7 +230,8 @@ public class XmlConverter implements XmlConstants {
if (helmaKey == null) { if (helmaKey == null) {
// we don't map this child element itself since we do // we don't map this child element itself since we do
// sparse parsing, but there may be something of interest // sparse parsing, but there may be something of interest
// in the child's child elements. // in the child's attributes and child elements.
attributes (childElement, helmaNode, nodeCache);
children (childElement, helmaNode, nodeCache); children (childElement, helmaNode, nodeCache);
continue; continue;
} }
@ -305,8 +306,9 @@ public class XmlConverter implements XmlConstants {
if (dot > -1) { if (dot > -1) {
String prototype = helmaKey.substring (0, dot); String prototype = helmaKey.substring (0, dot);
INode node = (INode) nodeCache.get (prototype); INode node = (INode) nodeCache.get (prototype);
if (node != null) if (node != null) {
node.setString (helmaKey.substring(dot+1), attr.getNodeValue()); node.setString (helmaKey.substring(dot+1), attr.getNodeValue());
}
} else if (helmaNode.getPrototype() != null) { } else if (helmaNode.getPrototype() != null) {
helmaNode.setString( helmaKey, attr.getNodeValue() ); helmaNode.setString( helmaKey, attr.getNodeValue() );
} }