Search in sources :

Example 16 with CPOrganization

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

the class CPTreeDataModel method getPath.

/*
	@Override
	public List<AjaxTreeNode> getChildrenFor(String nodeId) {

		CPManagerImpl cpMgm = (CPManagerImpl) CPManager.getInstance();
		Vector<AjaxTreeNode> nodeList = new Vector<AjaxTreeNode>();

		nodeId = getIdentifierForNodeID(nodeId);
		DefaultElement el = cpMgm.getElementByIdentifier(cp, nodeId);
		if (el == null) {
			log.info("element not found (id " + nodeId + ")");
			return nodeList;
		}
		try {
			if (el.getName().equals(CPCore.ORGANIZATION)) {
				CPOrganization org = (CPOrganization) el;
				for (Iterator<CPItem> it = org.getItemIterator(); it.hasNext();) {
					CPItem item = it.next();
					addItem(nodeList, item);
				}
			} else if (el.getName().equals(CPCore.ITEM)) {
				CPItem pItem = (CPItem) el;
				for (Iterator<CPItem> it = pItem.getItemIterator(); it.hasNext();) {
					CPItem item = it.next();
					addItem(nodeList, item);
				}
			} else {
				// element is not item nor orga -> ergo wrong element
				log.info("unknown element while building treemodel for gui (id: " + nodeId + ")");
			}
		} catch (JSONException e) {
			log.error("error while building treemodel");
		}

		return nodeList;
	}

	private void addItem(Vector<AjaxTreeNode> nodeList, CPItem item) throws JSONException {
		String nId;
		nId = putIdentifierForNodeID(item.getIdentifier());
		AjaxTreeNode child = new AjaxTreeNode(nId, item.getTitle());
		if (item.getItems().size() == 0) {
			// Expand the leaf in order to get rid of the plus sign in front of it.
			child.put(AjaxTreeNode.CONF_EXPANDED, true);
		} 
		child.put(AjaxTreeNode.CONF_ICON_CSS_CLASS, "o_cp_item");
		nodeList.add(child);
	}*/
/**
 * Returns the path of the given item in the tree.
 * <p>
 * Example: /0/12/3
 * <p>
 * The empty string signifies the root node.
 *
 * @param identifier The identifier of the page
 * @return The path to the node in the tree
 */
public String getPath(String identifier) {
    StringBuffer path = new StringBuffer();
    DefaultElement elem = cp.getElementByIdentifier(identifier);
    if (elem instanceof CPOrganization) {
        // Special case. Somehow, the root path should be an empty string.
        path.append("");
    } else {
        addElementToPath(elem, path);
    }
    return path.toString();
}
Also used : DefaultElement(org.dom4j.tree.DefaultElement) CPOrganization(org.olat.ims.cp.objects.CPOrganization)

Example 17 with CPOrganization

use of org.olat.ims.cp.objects.CPOrganization 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 18 with CPOrganization

use of org.olat.ims.cp.objects.CPOrganization 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 19 with CPOrganization

use of org.olat.ims.cp.objects.CPOrganization 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)

Example 20 with CPOrganization

use of org.olat.ims.cp.objects.CPOrganization 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)

Aggregations

CPOrganization (org.olat.ims.cp.objects.CPOrganization)30 CPItem (org.olat.ims.cp.objects.CPItem)22 DefaultElement (org.dom4j.tree.DefaultElement)20 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)12 CPResource (org.olat.ims.cp.objects.CPResource)8 CPDependency (org.olat.ims.cp.objects.CPDependency)6 CPOrganizations (org.olat.ims.cp.objects.CPOrganizations)6 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)4 TreeNode (org.olat.core.gui.components.tree.TreeNode)4 CPFile (org.olat.ims.cp.objects.CPFile)4 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 Vector (java.util.Vector)2 Element (org.dom4j.Element)2 JSONException (org.json.JSONException)2 Test (org.junit.Test)2 DeliveryOptions (org.olat.core.gui.control.generic.iframe.DeliveryOptions)2 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2