* 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:
parent
2e239f797e
commit
2c1fdf3d0f
1 changed files with 11 additions and 9 deletions
|
@ -92,17 +92,16 @@ public class XmlConverter implements XmlConstants {
|
|||
Object previousNode = null;
|
||||
if (DEBUG)
|
||||
debug("reading " + element.getNodeName() );
|
||||
helmaNode.setName( element.getNodeName() );
|
||||
String prototype = props.getProperty(element.getNodeName()+"._prototype");
|
||||
if ( prototype == null && !sparse )
|
||||
prototype = "HopObject";
|
||||
// if we have a prototype (either explicit or implicit "hopobject"),
|
||||
// set it on the Helma node and store it in the node cache.
|
||||
if ( prototype != null ) {
|
||||
helmaNode.setName( element.getNodeName() );
|
||||
helmaNode.setPrototype( prototype );
|
||||
previousNode = nodeCache.put (prototype, helmaNode);
|
||||
}
|
||||
|
||||
// check attributes of the current element
|
||||
attributes(element, helmaNode, nodeCache);
|
||||
// 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 ) {
|
||||
NodeList list = element.getChildNodes();
|
||||
int len = list.getLength();
|
||||
boolean nodeHasPrototype = helmaNode.getPrototype() != null;
|
||||
boolean nodeIsInitialized = !nodeCache.isEmpty();
|
||||
StringBuffer textcontent = new StringBuffer();
|
||||
String domKey, helmaKey;
|
||||
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
|
||||
// be initialized and converted from one of the child elements.
|
||||
if (!nodeHasPrototype) {
|
||||
if (!nodeIsInitialized) {
|
||||
if (childNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||
convert ((Element) childNode, helmaNode, nodeCache);
|
||||
if (helmaNode.getPrototype() != null)
|
||||
|
@ -172,8 +171,9 @@ public class XmlConverter implements XmlConstants {
|
|||
String prototype = helmaKey.substring (0, dot);
|
||||
INode node = (INode) nodeCache.get (prototype);
|
||||
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));
|
||||
}
|
||||
} else if ( helmaNode.getString(helmaKey)==null ) {
|
||||
helmaNode.setString( helmaKey, XmlUtil.getTextContent(childNode) );
|
||||
if (DEBUG)
|
||||
|
@ -230,7 +230,8 @@ public class XmlConverter implements XmlConstants {
|
|||
if (helmaKey == null) {
|
||||
// we don't map this child element itself since we do
|
||||
// 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);
|
||||
continue;
|
||||
}
|
||||
|
@ -305,8 +306,9 @@ public class XmlConverter implements XmlConstants {
|
|||
if (dot > -1) {
|
||||
String prototype = helmaKey.substring (0, dot);
|
||||
INode node = (INode) nodeCache.get (prototype);
|
||||
if (node != null)
|
||||
if (node != null) {
|
||||
node.setString (helmaKey.substring(dot+1), attr.getNodeValue());
|
||||
}
|
||||
} else if (helmaNode.getPrototype() != null) {
|
||||
helmaNode.setString( helmaKey, attr.getNodeValue() );
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue