Search in sources :

Example 1 with MCRNavigationGroup

use of org.mycore.wcms2.datamodel.MCRNavigationGroup in project mycore by MyCoRe-Org.

the class MCRWCMSDefaultNavigationProvider method add.

private JsonObject add(MCRNavigationBaseItem item, JsonArray hierarchy, JsonArray items) {
    int id = items.size();
    JsonObject jsonItem = gson.toJsonTree(item).getAsJsonObject();
    jsonItem.addProperty(JSON_WCMS_ID, id);
    jsonItem.remove(JSON_CHILDREN);
    WCMSType type = null;
    String href = null;
    if (item instanceof MCRNavigation) {
        type = WCMSType.root;
        href = ((MCRNavigation) item).getHrefStartingPage();
    } else if (item instanceof MCRNavigationMenuItem) {
        type = WCMSType.menu;
        href = ((MCRNavigationMenuItem) item).getDir();
    } else if (item instanceof MCRNavigationItem) {
        type = WCMSType.item;
        href = ((MCRNavigationItem) item).getHref();
    } else if (item instanceof MCRNavigationInsertItem) {
        type = WCMSType.insert;
    } else if (item instanceof MCRNavigationGroup) {
        type = WCMSType.group;
    } else {
        LOGGER.warn("Unable to set type for item {}", id);
    }
    jsonItem.addProperty(JSON_WCMS_TYPE, type.name());
    if (href != null) {
        jsonItem.add("access", getAccess(href));
    }
    items.add(jsonItem);
    // create hierarchy for root
    JsonObject hierarchyObject = new JsonObject();
    hierarchyObject.addProperty(JSON_WCMS_ID, id);
    hierarchy.add(hierarchyObject);
    return hierarchyObject;
}
Also used : MCRNavigation(org.mycore.wcms2.datamodel.MCRNavigation) MCRNavigationItem(org.mycore.wcms2.datamodel.MCRNavigationItem) MCRNavigationMenuItem(org.mycore.wcms2.datamodel.MCRNavigationMenuItem) JsonObject(com.google.gson.JsonObject) MCRNavigationInsertItem(org.mycore.wcms2.datamodel.MCRNavigationInsertItem) MCRNavigationGroup(org.mycore.wcms2.datamodel.MCRNavigationGroup)

Aggregations

JsonObject (com.google.gson.JsonObject)1 MCRNavigation (org.mycore.wcms2.datamodel.MCRNavigation)1 MCRNavigationGroup (org.mycore.wcms2.datamodel.MCRNavigationGroup)1 MCRNavigationInsertItem (org.mycore.wcms2.datamodel.MCRNavigationInsertItem)1 MCRNavigationItem (org.mycore.wcms2.datamodel.MCRNavigationItem)1 MCRNavigationMenuItem (org.mycore.wcms2.datamodel.MCRNavigationMenuItem)1