コード例 #1
0
 @Managed
 @ManagedDescription("Delete node specified by path in existing navigation")
 @Impact(ImpactType.READ)
 public void deleteNode(
     @ManagedDescription("Type of target navigation") @ManagedName("navType") String navType,
     @ManagedDescription("Owner of target navigation") @ManagedName("navOwner") String navOwner,
     @ManagedDescription("Path from root to target node") @ManagedName("pathFromRoot")
         String pathFromRoot) {
   try {
     startTransaction();
     NavigationContext ctx = navService.loadNavigation(new SiteKey(navType, navOwner));
     if (ctx == null) {
       LOG.error("Navigation type= " + navType + " , owner= " + navOwner + " does not exist");
     } else {
       String[] path = pathFromRoot.split("/");
       NavNode rootNode =
           navService
               .loadNode(new NavNodeModel(), ctx, GenericScope.branchShape(path), null)
               .getNode();
       NavNode targetNode = rootNode.getDescendant(path);
       if (targetNode != null && targetNode != rootNode) {
         targetNode.remove();
       }
     }
   } finally {
     endTransaction();
   }
 }
コード例 #2
0
 /**
  * @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);
     }
   }
 }