Search in sources :

Example 21 with CPItem

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

the class CPManagerTest method testLoad.

@Test
public void testLoad() {
    ContentPackage relodedCP = mgr.load(cp.getRootDir(), cp.getResourcable());
    assertNotNull(relodedCP);
    CPOrganization orga = relodedCP.getFirstOrganizationInManifest();
    assertNotNull(orga);
    CPItem item = orga.getFirstItem();
    assertEquals(PAGE_TITLE, item.getTitle());
}
Also used : ContentPackage(org.olat.ims.cp.ContentPackage) CPOrganization(org.olat.ims.cp.objects.CPOrganization) CPItem(org.olat.ims.cp.objects.CPItem) Test(org.junit.Test)

Example 22 with CPItem

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

the class CPManagerTest method testAddElementAfter.

public void testAddElementAfter() {
    CPItem newItem = new CPItem();
    mgr.addElementAfter(cp, newItem, ITEM_ID);
    assertTrue("The new item wasn't inserted at the second position.", newItem.getPosition() == 1);
}
Also used : CPItem(org.olat.ims.cp.objects.CPItem)

Example 23 with CPItem

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

the class CPCore method addElement.

// *** CP manipulation ***
/**
 * adds an element as a child to the element with id parentId if the element
 * with parentId is not found, it returns false
 *
 * if adding was successful, it returns true
 */
public boolean addElement(DefaultElement newElement, String parentId, int position) {
    DefaultElement parentElement = rootNode.getElementByIdentifier(parentId);
    if (parentElement == null) {
        throw new OLATRuntimeException(CPOrganizations.class, "Parent-element with identifier:\"" + parentId + "\" not found!", new Exception());
    }
    if (parentElement instanceof CPItem) {
        // parent is a <item>
        if (newElement instanceof CPItem) {
            // only CPItems can be added to CPItems
            CPItem item = (CPItem) parentElement;
            item.addItemAt((CPItem) newElement, position);
            return true;
        } else {
            throw new OLATRuntimeException(CPOrganizations.class, "you can only add <item>  elements to an <item>-element", new Exception());
        }
    } else if (parentElement instanceof CPOrganization) {
        // parent is a <organization>
        if (newElement instanceof CPItem) {
            // add a new item to organization element
            CPOrganization org = (CPOrganization) parentElement;
            org.addItemAt((CPItem) newElement, position);
            return true;
        } else {
            throw new OLATRuntimeException(CPOrganizations.class, "you can only add <item>  elements to an <organization>-element", new Exception());
        }
    } else if (parentElement instanceof CPResource) {
        // parent is a <resource>
        CPResource resource = (CPResource) parentElement;
        if (newElement instanceof CPFile) {
            resource.addFile((CPFile) newElement);
        } else if (newElement instanceof CPDependency) {
            resource.addDependency((CPDependency) newElement);
        } else {
            throw new OLATRuntimeException(CPOrganizations.class, "you can only add <dependency> or <file> elements to a Resource", new Exception());
        }
        return true;
    } else if (parentElement instanceof CPResources) {
        // parent is <resources> !!see the "s" at the end ;)
        if (newElement instanceof CPResource) {
            CPResources resources = (CPResources) parentElement;
            resources.addResource((CPResource) newElement);
            return true;
        } else {
            throw new OLATRuntimeException(CPOrganizations.class, "you can only add <resource>elements to the <resources> element", new Exception());
        }
    }
    return false;
}
Also used : CPOrganizations(org.olat.ims.cp.objects.CPOrganizations) CPFile(org.olat.ims.cp.objects.CPFile) DefaultElement(org.dom4j.tree.DefaultElement) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) CPResources(org.olat.ims.cp.objects.CPResources) CPResource(org.olat.ims.cp.objects.CPResource) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) CPItem(org.olat.ims.cp.objects.CPItem) CPOrganization(org.olat.ims.cp.objects.CPOrganization) CPDependency(org.olat.ims.cp.objects.CPDependency)

Example 24 with CPItem

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

the class CPCore method moveElement.

public void moveElement(String nodeID, String newParentID, int position) {
    DefaultElement elementToMove = rootNode.getElementByIdentifier(nodeID);
    if (elementToMove != null) {
        if (elementToMove instanceof CPItem) {
            removeElement(nodeID, false);
            addElement(elementToMove, newParentID, position);
        } else if (elementToMove instanceof CPOrganization) {
        // not yet supported
        } else {
            throw new OLATRuntimeException(CPOrganizations.class, "Only <item>-elements are moveable...!", new Exception());
        }
    }
}
Also used : CPOrganizations(org.olat.ims.cp.objects.CPOrganizations) DefaultElement(org.dom4j.tree.DefaultElement) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) CPItem(org.olat.ims.cp.objects.CPItem) CPOrganization(org.olat.ims.cp.objects.CPOrganization) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Example 25 with CPItem

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

the class CPCore method _findReferencesToRes.

/**
 * searches recursively for <item>-elements with identifierRef "id" in the
 * children-collection of the item "item"
 *
 * @param item
 * @param id
 * @return
 */
private CPItem _findReferencesToRes(CPItem item, String id) {
    if (item.getIdentifierRef().equals(id))
        return item;
    for (Iterator<CPItem> itO = item.getItems().iterator(); itO.hasNext(); ) {
        CPItem it = itO.next();
        CPItem found = _findReferencesToRes(it, id);
        if (found != null)
            return found;
    }
    return null;
}
Also used : CPItem(org.olat.ims.cp.objects.CPItem)

Aggregations

CPItem (org.olat.ims.cp.objects.CPItem)32 CPOrganization (org.olat.ims.cp.objects.CPOrganization)22 DefaultElement (org.dom4j.tree.DefaultElement)20 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)12 CPResource (org.olat.ims.cp.objects.CPResource)10 CPDependency (org.olat.ims.cp.objects.CPDependency)6 CPOrganizations (org.olat.ims.cp.objects.CPOrganizations)6 CPFile (org.olat.ims.cp.objects.CPFile)4 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 Vector (java.util.Vector)2 Logger (java.util.logging.Logger)2 Element (org.dom4j.Element)2 JSONException (org.json.JSONException)2 Test (org.junit.Test)2 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)2 TreeNode (org.olat.core.gui.components.tree.TreeNode)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 ContentPackage (org.olat.ims.cp.ContentPackage)2 CPMetadata (org.olat.ims.cp.objects.CPMetadata)2