Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2011 eXo Platform SAS.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.exoplatform.services.jcr.ext.distribution.impl;
 
 
 import java.util.List;
 import java.util.Map;
 
 import javax.jcr.Node;
This data distribution will distribute the data in a understandable way for a human being. The expected data id is for example a login of a user. It will generate a hierarchy of sub-nodes with n levels of depth for example with n = 4:
  • Usename: john.smith (size >= 4) it will generate a path of type "j___/jo___/joh___/john.smith"
  • Usename: bob (size < 4) it will generate a path of type "b___/bo___/bob"

Author(s):
Nicolas Filotto
Version:
$Id$
 
 {

   
The level of depth used by the algorithm
 
    private int depth = 4;

   
The suffix used by the algorithm to indicate that they are sub nodes inside
 
    private String suffix = "___";

   
 
    @Override
    protected List<StringgetAncestors(String dataId)
    {
       List<Stringresult = new ArrayList<String>();
       int length = dataId.length();
       for (int i = 0; i <  - 1 && i < length - 1; i++)
       {
          StringBuilder buffer = new StringBuilder();
          buffer.append(dataId, 0, i + 1);
          buffer.append();
          result.add(buffer.toString());
       }
       result.add(dataId);
       return result;
    }

   
 
    @Override
    protected boolean useParametersOnLeafOnly()
    {
       return true;
    }

   
 
    public void migrate(Node rootNodethrows RepositoryException
    {
       migrate(rootNodenullnullnull);
    }

   
 
    public void migrate(Node rootNodeString nodeTypeList<StringmixinTypesMap<StringString[]> permissions)
      throws RepositoryException
   {
      NodeIterator iter = ((NodeImpl)rootNode).getNodesLazily();
      while (iter.hasNext())
      {
         Node userNode = iter.nextNode();
         if (!alreadyMigrated(userNode))
         {
            Node ancestorNode = rootNode;
            Iterator<Stringancestors = getAncestors(userNode.getName()).iterator();
            while (ancestors.hasNext())
            {
               String ancestorName = ancestors.next();
               if (ancestors.hasNext())
               {
                  try
                  {
                     ancestorNode = ancestorNode.getNode(ancestorName);
                     continue;
                  }
                  catch (PathNotFoundException e)
                  {
                     ancestorNode =
                        createNode(ancestorNodeancestorNamenodeTypemixinTypespermissionsfalsefalse);
                  }
               }
               else
               {
                  rootNode.getSession().move(userNode.getPath(), ancestorNode.getPath() + "/" + ancestorName);
               }
            }
            rootNode.getSession().save();
         }
      }
   }
   private boolean alreadyMigrated(Node userNodethrows RepositoryException
   {
      String nodeName = userNode.getName();
      return nodeName.length() == 1 || nodeName.endsWith();
   }
New to GrepCode? Check out our FAQ X