getWebSocket().send(MessageBuilder.status().code(422).message("Cannot add node without parentId").build(), true);
return;
}
// check if content node with given ID exists
final DOMNode contentNode = getDOMNode(parentId);
if (contentNode == null) {
getWebSocket().send(MessageBuilder.status().code(404).message("Parent node not found").build(), true);
return;
}
final Document document = getPage(pageId);
if (document != null) {
final String tagName = (String) nodeData.get("tagName");
nodeData.remove("tagName");
final DOMNode parentNode = (DOMNode) contentNode.getParentNode();
try {
DOMNode elementNode = null;
if (tagName != null && !tagName.isEmpty()) {
elementNode = (DOMNode) document.createElement(tagName);
}
// append new node to parent parent node
if (elementNode != null) {
parentNode.appendChild(elementNode);
}
// append new node to parent parent node
if (elementNode != null) {
// append content node to new node
elementNode.appendChild(contentNode);
}
} catch (DOMException dex) {