* @return the new dom position based on the insert. May return null if
* insert fails.
*/
public static IDOMPosition insertBody(IDOMPosition position, QName body,
String defaultPrefix) {
IBodyInfo bodyInfo = getBodyInfo((IDOMNode) position.getContainerNode());
Node node = position.getContainerNode();
final Node originalContainer = node;
final Node nextSibling = position.getNextSiblingNode();
// create the body element first.
Document ownerDoc;
if (node instanceof Document) {
ownerDoc = (Document) node;
} else {
ownerDoc = node.getOwnerDocument();
}
if (ownerDoc == null) {
return null; // should not happen
}
final String prefix = JSPUtil.getOrCreatePrefix(((IDOMNode) node).getModel(),
body.getNamespaceURI(), defaultPrefix);
final Element ele = ownerDoc.createElement((prefix == null ? "" //$NON-NLS-1$
: (prefix + ":")) //$NON-NLS-1$
+ body.getLocalPart());
// need to find out the insertion point
while (node instanceof IDOMNode) {
if (bodyInfo.isBodyContainer((IDOMNode) node)) {
// ok, node is a body container.
// we could create the new node as child of node and move all
// node's none header children
// as children of the new node.