Serialize node text with CDATA.

This commit is contained in:
Paulo Veiga 2012-01-21 16:37:13 -03:00
parent 99146de711
commit 7ec7c18524

View File

@ -65,7 +65,6 @@ mindplot.XMLMindmapSerializer_Pela = new Class({
if (topic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { if (topic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
parentTopic.setAttribute("central", true); parentTopic.setAttribute("central", true);
} else { } else {
var parent = topic.getParent();
var pos = topic.getPosition(); var pos = topic.getPosition();
parentTopic.setAttribute("position", pos.x + ',' + pos.y); parentTopic.setAttribute("position", pos.x + ',' + pos.y);
@ -77,7 +76,7 @@ mindplot.XMLMindmapSerializer_Pela = new Class({
var text = topic.getText(); var text = topic.getText();
if ($defined(text)) { if ($defined(text)) {
parentTopic.setAttribute('text', text); this._noteTextToXML(document, parentTopic, text);
} }
var shape = topic.getShapeType(); var shape = topic.getShapeType();
@ -179,6 +178,17 @@ mindplot.XMLMindmapSerializer_Pela = new Class({
return noteDom; return noteDom;
}, },
_noteTextToXML : function(document, elem, text) {
if (text.indexOf('\n') == -1) {
elem.setAttribute('text', text);
} else {
var textDom = document.createElement("text");
var cdata = document.createCDATASection(text);
textDom.appendChild(cdata);
elem.appendChild(textDom);
}
},
_relationshipToXML : function(document, relationship) { _relationshipToXML : function(document, relationship) {
var relationDom = document.createElement("relationship"); var relationDom = document.createElement("relationship");
relationDom.setAttribute("srcTopicId", relationship.getFromNode()); relationDom.setAttribute("srcTopicId", relationship.getFromNode());
@ -319,7 +329,7 @@ mindplot.XMLMindmapSerializer_Pela = new Class({
for (var i = 0; i < children.length; i++) { for (var i = 0; i < children.length; i++) {
var child = children[i]; var child = children[i];
if (child.nodeType == Node.ELEMENT_NODE) { if (child.nodeType == Node.ELEMENT_NODE) {
$assert(child.tagName == "topic" || child.tagName == "icon" || child.tagName == "link" || child.tagName == "note", 'Illegal node type:' + child.tagName); $assert(child.tagName == "topic" || child.tagName == "icon" || child.tagName == "link" || child.tagName == "note" || child.tagName == "text", 'Illegal node type:' + child.tagName);
if (child.tagName == "topic") { if (child.tagName == "topic") {
var childTopic = this._deserializeNode(child, mindmap); var childTopic = this._deserializeNode(child, mindmap);
childTopic.connectTo(topic); childTopic.connectTo(topic);
@ -332,7 +342,11 @@ mindplot.XMLMindmapSerializer_Pela = new Class({
} else if (child.tagName == "note") { } else if (child.tagName == "note") {
var note = this._deserializeNote(child, topic); var note = this._deserializeNote(child, topic);
topic.addNote(note); topic.addNote(note);
} else if (child.tagName == "text") {
var nodeText = this._deserializeNodeText(child);
topic.setText(nodeText);
} }
} }
} }
return topic; return topic;
@ -362,6 +376,19 @@ mindplot.XMLMindmapSerializer_Pela = new Class({
return topic.createNote(value); return topic.createNote(value);
}, },
_deserializeNodeText: function(domElem) {
var children = domElem.childNodes;
var value = null;
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (child.nodeType == Node.CDATA_SECTION_NODE) {
value = child.nodeValue;
}
}
return value;
},
_deserializeRelationship : function(domElement, mindmap) { _deserializeRelationship : function(domElement, mindmap) {
var srcId = domElement.getAttribute("srcTopicId"); var srcId = domElement.getAttribute("srcTopicId");
var destId = domElement.getAttribute("destTopicId"); var destId = domElement.getAttribute("destTopicId");