Search in sources :

Example 26 with CPOrganization

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

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 27 with CPOrganization

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

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 28 with CPOrganization

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

the class CPTreeDataModel method getChildrenFor.

public List<TreeNode> getChildrenFor(String nodeId) {
    List<TreeNode> nodeList = new ArrayList<TreeNode>();
    nodeId = getIdentifierForNodeID(nodeId);
    DefaultElement el = cp.getElementByIdentifier(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;
}
Also used : DefaultElement(org.dom4j.tree.DefaultElement) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) JSONException(org.json.JSONException) CPOrganization(org.olat.ims.cp.objects.CPOrganization) CPItem(org.olat.ims.cp.objects.CPItem)

Example 29 with CPOrganization

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

Example 30 with CPOrganization

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

the class ContentPackage method updatePage.

protected void updatePage(CPPage page) {
    DefaultElement ele = cpcore.getElementByIdentifier(page.getIdentifier());
    if (ele instanceof CPItem) {
        CPItem item = (CPItem) ele;
        item.setTitle(page.getTitle());
        item.setMetadata(page.getMetadata());
        String itemIdentifierRef = item.getIdentifierRef();
        if (itemIdentifierRef == null || itemIdentifierRef.equals("")) {
            // This item has no linked resource yet. Add one if there is a page file
            // attached.
            VFSLeaf pageFile = page.getPageFile();
            if (pageFile != null) {
                CPResource res = new CPResource();
                CPFile file = new CPFile(pageFile);
                res.addFile(file);
                // TODO:GW Set type according to file
                res.setType("text/html");
                res.setHref(file.getHref());
                item.setIdentifierRef(res.getIdentifier());
                cpcore.getRootNode().getResources().addResource(res);
            }
        } else {
        // this item has already a linked resource
        // this is not supported, we don't change linked resources...
        }
    } else if (ele instanceof CPOrganization) {
        CPOrganization organization = (CPOrganization) ele;
        organization.setTitle(page.getTitle());
    } else {
        // ERROR: this shouldn't be
        throw new OLATRuntimeException("Error while updating manifest with new Page-Data. Invalid identifier " + page.getIdentifier(), null);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) CPFile(org.olat.ims.cp.objects.CPFile) 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)

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