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());
}
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);
}
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;
}
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());
}
}
}
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;
}
Aggregations