Search in sources :

Example 1 with CPMetadata

use of org.olat.ims.cp.objects.CPMetadata in project OpenOLAT by OpenOLAT.

the class CPCore method removeElement.

/**
 * removes an element with identifier "identifier" from the manifest
 *
 * @param identifier the identifier if the element to remove
 * @param booleanFlag indicates whether to remove linked resources as well...!
 *          (needed for moving elements)
 */
public void removeElement(String identifier, boolean resourceFlag) {
    DefaultElement el = rootNode.getElementByIdentifier(identifier);
    if (el != null) {
        if (el instanceof CPItem) {
            // element is CPItem
            CPItem item = (CPItem) el;
            // first remove resources
            if (resourceFlag) {
                // Delete children (depth first search)
                removeChildElements(item, resourceFlag);
                // remove referenced resource
                CPResource res = (CPResource) rootNode.getElementByIdentifier(item.getIdentifierRef());
                if (res != null && referencesCount(res) == 1) {
                    res.removeFromManifest();
                }
            }
            // then remove item
            item.removeFromManifest();
        } else if (el instanceof CPOrganization) {
            // element is organization
            CPOrganization org = (CPOrganization) el;
            org.removeFromManifest(resourceFlag);
        } else if (el instanceof CPMetadata) {
            // element is <metadata>
            CPMetadata md = (CPMetadata) el;
            md.removeFromManifest();
        }
    } else {
        throw new OLATRuntimeException(CPOrganizations.class, "couldn't remove element with id \"" + identifier + "\"! Element not found in manifest ", new Exception());
    }
}
Also used : DefaultElement(org.dom4j.tree.DefaultElement) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) CPResource(org.olat.ims.cp.objects.CPResource) CPItem(org.olat.ims.cp.objects.CPItem) CPOrganization(org.olat.ims.cp.objects.CPOrganization) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) CPMetadata(org.olat.ims.cp.objects.CPMetadata)

Example 2 with CPMetadata

use of org.olat.ims.cp.objects.CPMetadata in project openolat by klemens.

the class CPCore method removeElement.

/**
 * removes an element with identifier "identifier" from the manifest
 *
 * @param identifier the identifier if the element to remove
 * @param booleanFlag indicates whether to remove linked resources as well...!
 *          (needed for moving elements)
 */
public void removeElement(String identifier, boolean resourceFlag) {
    DefaultElement el = rootNode.getElementByIdentifier(identifier);
    if (el != null) {
        if (el instanceof CPItem) {
            // element is CPItem
            CPItem item = (CPItem) el;
            // first remove resources
            if (resourceFlag) {
                // Delete children (depth first search)
                removeChildElements(item, resourceFlag);
                // remove referenced resource
                CPResource res = (CPResource) rootNode.getElementByIdentifier(item.getIdentifierRef());
                if (res != null && referencesCount(res) == 1) {
                    res.removeFromManifest();
                }
            }
            // then remove item
            item.removeFromManifest();
        } else if (el instanceof CPOrganization) {
            // element is organization
            CPOrganization org = (CPOrganization) el;
            org.removeFromManifest(resourceFlag);
        } else if (el instanceof CPMetadata) {
            // element is <metadata>
            CPMetadata md = (CPMetadata) el;
            md.removeFromManifest();
        }
    } else {
        throw new OLATRuntimeException(CPOrganizations.class, "couldn't remove element with id \"" + identifier + "\"! Element not found in manifest ", new Exception());
    }
}
Also used : DefaultElement(org.dom4j.tree.DefaultElement) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) CPResource(org.olat.ims.cp.objects.CPResource) CPItem(org.olat.ims.cp.objects.CPItem) CPOrganization(org.olat.ims.cp.objects.CPOrganization) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) CPMetadata(org.olat.ims.cp.objects.CPMetadata)

Aggregations

DefaultElement (org.dom4j.tree.DefaultElement)2 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)2 CPItem (org.olat.ims.cp.objects.CPItem)2 CPMetadata (org.olat.ims.cp.objects.CPMetadata)2 CPOrganization (org.olat.ims.cp.objects.CPOrganization)2 CPResource (org.olat.ims.cp.objects.CPResource)2