Java Code Examples for org.jdom.Parent#removeContent()

The following examples show how to use org.jdom.Parent#removeContent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SequencerModel.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * Method to determine if the navigation file has changed since it was last imported. If so then we need to check for old <items> and remove them from the document
 * 
 * @param items
 */
protected void removeOldNodes(final String[] items) {
    final Vector v = new Vector();
    final List itemList = getDocument().getRootElement().getChildren(ITEM_NODE);
    if (itemList != null && !itemList.isEmpty()) {
        final Iterator itemListElement = itemList.iterator();
        while (itemListElement.hasNext()) {
            final Element anItem = (Element) itemListElement.next();
            if (!doesItemExist(anItem.getAttributeValue(ITEM_IDENTIFIER), items)) {
                // mark this node - (can't delete at the same time as looping
                // otherwise get concurrent access errors)
                v.add(anItem);
            }
        }
        final Iterator itemsToRemove = v.iterator();
        while (itemsToRemove.hasNext()) {
            final Element anItemToDelete = (Element) itemsToRemove.next();
            final Parent parent = anItemToDelete.getParent();
            if (parent != null) {
                log.warn("item no longer exists so remove " + anItemToDelete.getAttributeValue(ITEM_IDENTIFIER), null);
                parent.removeContent(anItemToDelete);
            }
        }
    }
    v.clear();
}
 
Example 2
Source File: SequencerModel.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * Method to determine if the navigation file has changed since it was last imported. If so then we need to check for old <items> and remove them from the document
 * 
 * @param items
 */
protected void removeOldNodes(final String[] items) {
    final Vector v = new Vector();
    final List itemList = getDocument().getRootElement().getChildren(ITEM_NODE);
    if (itemList != null && !itemList.isEmpty()) {
        final Iterator itemListElement = itemList.iterator();
        while (itemListElement.hasNext()) {
            final Element anItem = (Element) itemListElement.next();
            if (!doesItemExist(anItem.getAttributeValue(ITEM_IDENTIFIER), items)) {
                // mark this node - (can't delete at the same time as looping
                // otherwise get concurrent access errors)
                v.add(anItem);
            }
        }
        final Iterator itemsToRemove = v.iterator();
        while (itemsToRemove.hasNext()) {
            final Element anItemToDelete = (Element) itemsToRemove.next();
            final Parent parent = anItemToDelete.getParent();
            if (parent != null) {
                log.warn("item no longer exists so remove " + anItemToDelete.getAttributeValue(ITEM_IDENTIFIER), null);
                parent.removeContent(anItemToDelete);
            }
        }
    }
    v.clear();
}