Search in sources :

Example 16 with CPItem

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

the class CPTreeDataModel method addElementToPath.

/**
 * @param identifier
 * @param path
 * @param slash
 * @param elem
 */
private void addElementToPath(DefaultElement elem, StringBuffer path) {
    final String slash = "/";
    if (elem instanceof CPItem) {
        CPItem item = (CPItem) elem;
        path.insert(0, slash).insert(1, getNodeIDForIdentifier(item.getIdentifier()));
        DefaultElement parent = item.getParentElement();
        if (parent != null)
            addElementToPath(parent, path);
    } else if (elem instanceof CPOrganization) {
        CPOrganization item = (CPOrganization) elem;
        path.insert(0, slash).insert(1, getNodeIDForIdentifier(item.getIdentifier()));
    }
}
Also used : DefaultElement(org.dom4j.tree.DefaultElement) CPItem(org.olat.ims.cp.objects.CPItem) CPOrganization(org.olat.ims.cp.objects.CPOrganization)

Example 17 with CPItem

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

the class ContentPackage method addBlankPage.

String addBlankPage(String parentID, String title) {
    CPItem newPage = new CPItem();
    newPage.setTitle(title);
    cpcore.addElement(newPage, parentID, 0);
    return newPage.getIdentifier();
}
Also used : CPItem(org.olat.ims.cp.objects.CPItem)

Example 18 with CPItem

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

the class CPCore method copyElement.

/**
 * duplicates an element and inserts it after targetID
 *
 * @param sourceID
 * @param targetID
 */
public String copyElement(String sourceID, String targetID) {
    DefaultElement elementToCopy = rootNode.getElementByIdentifier(sourceID);
    if (elementToCopy == null) {
        throw new OLATRuntimeException(CPOrganizations.class, "element with identifier \"" + sourceID + "\" not found..!", new Exception());
    }
    if (elementToCopy instanceof CPItem) {
        CPItem newItem = (CPItem) elementToCopy.clone();
        cloneResourceOfItemAndSubitems(newItem);
        addElementAfter(newItem, targetID);
        return newItem.getIdentifier();
    } else {
        // not yet supported
        throw new OLATRuntimeException(CPOrganizations.class, "You can only copy <item>-elements...!", new Exception());
    }
}
Also used : DefaultElement(org.dom4j.tree.DefaultElement) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) CPItem(org.olat.ims.cp.objects.CPItem)

Example 19 with CPItem

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

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 20 with CPItem

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

the class CPCore method findReferencesToResource.

/**
 * Searches for <item>-elements or <dependency>-elements which references to
 * the resource with id "resourceIdentifier"
 *
 * if an element is found, search is aborted and the found element is returned
 *
 * @param resourceIdentifier
 * @return the found element or null
 */
public DefaultElement findReferencesToResource(String resourceIdentifier) {
    // search for <item identifierref="resourceIdentifier" >
    for (Iterator<CPOrganization> it = rootNode.getOrganizations().getOrganizationIterator(); it.hasNext(); ) {
        CPOrganization org = it.next();
        for (Iterator<CPItem> itO = org.getItems().iterator(); itO.hasNext(); ) {
            CPItem item = itO.next();
            CPItem found = _findReferencesToRes(item, resourceIdentifier);
            if (found != null)
                return found;
        }
    }
    // search for <dependency identifierref="resourceIdentifier" >
    for (Iterator<CPResource> itRes = rootNode.getResources().getResourceIterator(); itRes.hasNext(); ) {
        CPResource res = itRes.next();
        for (Iterator<CPDependency> itDep = res.getDependencyIterator(); itDep.hasNext(); ) {
            CPDependency dep = itDep.next();
            if (dep.getIdentifierRef().equals(resourceIdentifier))
                return dep;
        }
    }
    return null;
}
Also used : CPResource(org.olat.ims.cp.objects.CPResource) CPOrganization(org.olat.ims.cp.objects.CPOrganization) CPItem(org.olat.ims.cp.objects.CPItem) CPDependency(org.olat.ims.cp.objects.CPDependency)

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