use of org.mycore.wcms2.datamodel.MCRNavigationItemContainer in project mycore by MyCoRe-Org.
the class MCRWCMSNavigationManager method updateHref.
/**
* Runs recursive through the item tree and changes each href and hrefStartingPage attribute to the new href.
*
* @param item
* navigation item to change (and all its children)
* @param from
* which href to change
* @param to
* new value of href
* @return if something in the tree was changed
*/
public static boolean updateHref(MCRNavigationBaseItem item, String from, String to) {
boolean dirty = false;
if (item instanceof MCRNavigation) {
MCRNavigation navigation = (MCRNavigation) item;
if (navigation.getHrefStartingPage() != null && navigation.getHrefStartingPage().equals(from)) {
navigation.setHrefStartingPage(to);
dirty = true;
}
} else if (item instanceof MCRNavigationItem) {
MCRNavigationItem navItem = (MCRNavigationItem) item;
if (navItem.getHref().equals(from)) {
navItem.setHref(to);
dirty = true;
}
}
if (item instanceof MCRNavigationItemContainer) {
MCRNavigationItemContainer container = (MCRNavigationItemContainer) item;
for (MCRNavigationBaseItem child : container.getChildren()) {
if (updateHref(child, from, to)) {
dirty = true;
}
}
}
return dirty;
}
use of org.mycore.wcms2.datamodel.MCRNavigationItemContainer in project mycore by MyCoRe-Org.
the class MCRWCMSDefaultNavigationProvider method createItem.
private MCRNavigationBaseItem createItem(JsonObject hierarchyObject, JsonArray items) {
if (!hierarchyObject.has(JSON_WCMS_ID)) {
LOGGER.warn("While saving navigation.xml. Invalid object in hierarchy.");
return null;
}
MCRNavigationBaseItem item = getNavigationItem(hierarchyObject.get(JSON_WCMS_ID).getAsString(), items);
if (item == null) {
LOGGER.warn("While saving navigation.xml. Item with id {} is null!", hierarchyObject.get(JSON_WCMS_ID));
return null;
}
JsonElement children = hierarchyObject.get(JSON_CHILDREN);
if (children != null && children.isJsonArray() && item instanceof MCRNavigationItemContainer) {
MCRNavigationItemContainer itemAsContainer = (MCRNavigationItemContainer) item;
for (JsonElement child : children.getAsJsonArray()) {
if (child.isJsonObject()) {
MCRNavigationBaseItem childItem = createItem(child.getAsJsonObject(), items);
if (childItem != null) {
itemAsContainer.getChildren().add(childItem);
}
}
}
}
return item;
}
Aggregations