Search in sources :

Example 1 with Node

use of de.pdark.decentxml.Node in project sling by apache.

the class JcrNode method delete.

public void delete() {
    if (parent == null) {
        // then I dont know how to delete
        return;
    }
    parent.children.remove(this);
    if (resource != null) {
        IWorkspaceRunnable r = new IWorkspaceRunnable() {

            @Override
            public void run(IProgressMonitor monitor) throws CoreException {
                resource.delete(true, monitor);
                if (dirSibling != null) {
                    dirSibling.getResource().delete(true, monitor);
                }
            }
        };
        try {
            ResourcesPlugin.getWorkspace().run(r, null);
        } catch (CoreException e) {
            Activator.getDefault().getPluginLogger().error("Error renaming resource (" + resource + "): " + e, e);
        }
    }
    if (domElement != null) {
        Element parentNode = domElement.getParentElement();
        domElement.remove();
        if (parentNode != null) {
            List<Node> allChildNodes = parentNode.getNodes();
            boolean nonTextChild = false;
            for (Iterator<Node> it = allChildNodes.iterator(); it.hasNext(); ) {
                Node node = it.next();
                if (node.getType() != Type.TEXT) {
                    nonTextChild = true;
                }
            }
            if (!nonTextChild) {
                for (Iterator<Node> it = allChildNodes.iterator(); it.hasNext(); ) {
                    Node node = it.next();
                    it.remove();
                }
                if (!parentNode.hasNodes()) {
                    parentNode.setCompactEmpty(true);
                }
            }
        }
    }
    if (underlying != null) {
        underlying.save();
    }
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) Element(de.pdark.decentxml.Element) Node(de.pdark.decentxml.Node)

Aggregations

Element (de.pdark.decentxml.Element)1 Node (de.pdark.decentxml.Node)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1