public void addNodes( String navType, String navOwner, String nodePrefix, int startIndex, int endIndex) { if (startIndex < endIndex) { SiteKey key = new SiteKey(navType, navOwner); NavigationContext navCtx = navService.loadNavigation(key); if (navCtx == null) { LOG.error("Navigation type= " + navType + " , owner= " + navOwner + " does not exist"); } else { NavNode rootNode = navService.loadNode(new NavNodeModel(), navCtx, Scope.CHILDREN, null).getNode(); int index = rootNode.getSize(); for (int i = startIndex; i < endIndex; i++) { String nodeName = nodePrefix + "_" + i; if (rootNode.getChild(nodeName) != null) { LOG.debug( "Navigation node named " + nodeName + " already exist, will not add it anymore"); } else { rootNode.addChild(index, nodeName); index++; } } navService.saveNode(rootNode.context, null); } } }
/** * @param navType * @param navOwner * @param absolutePath path from root to targeted node * @param nodePrefix * @param startIndex * @param endIndex */ public void addNodes( String navType, String navOwner, String absolutePath, String nodePrefix, int startIndex, int endIndex) { SiteKey key = new SiteKey(navType, navOwner); NavigationContext navCtx = navService.loadNavigation(key); if (navCtx == null) { LOG.error("Navigation type= " + navType + " , owner= " + navOwner + " does not exist"); } else { String[] path = absolutePath.split("/"); NavNode rootNode = navService .loadNode(new NavNodeModel(), navCtx, GenericScope.branchShape(path), null) .getNode(); NavNode targetNode = rootNode.getDescendant(path); if (targetNode == null) { LOG.error( "Could not find node specified by path " + absolutePath + " under navigation type= " + navType + " , owner= " + navOwner); } else { int index = targetNode.getSize(); for (int i = startIndex; i < endIndex; i++) { String nodeName = nodePrefix + "_" + i; if (targetNode.getChild(nodeName) == null) { targetNode.addChild(index, nodeName); index++; } } navService.saveNode(targetNode.context, null); } } }