Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2009 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.webdav.command;
 
 
 import java.net.URI;
 import java.util.List;
 
 import javax.jcr.Node;
Created by The eXo Platform SAS. Author : Vitaly Guly

Version:
$Id: $
 
 public class OrderPatchCommand
 {

   
logger.
 
    private static Log log = ExoLogger.getLogger("exo.jcr.component.webdav.OrderPatchCommand");

   
Constructor.
 
    public OrderPatchCommand()
    {
    }

   
Webdav OrderPatch method implementation.

Parameters:
session current session
path resource path
body responce body
baseURI base uri
Returns:
the instance of javax.ws.rs.core.Response
 
    public Response orderPatch(Session sessionString pathHierarchicalProperty bodyString baseURI)
    {
       try
       {
          Node node = (Node)session.getItem(path);
 
          List<OrderMembermembers = getMembers(body);
 
          WebDavNamespaceContext nsContext = new WebDavNamespaceContext(session);
          URI uri = new URI(TextUtil.escape(baseURI + node.getPath(), '%'true));
 
          if (doOrder(nodemembers))
          {
             return Response.ok().build();
          }
 
          OrderPatchResponseEntity orderPatchEntity = new OrderPatchResponseEntity(nsContexturinodemembers);
          return Response.status(.).entity(orderPatchEntity).build();
       }
       catch (PathNotFoundException exc)
       {
          return Response.status(.).entity(exc.getMessage()).build();
       }
       catch (LockException exc)
       {
          return Response.status(.).entity(exc.getMessage()).build();
      }
      catch (Exception exc)
      {
         .error(exc.getMessage(), exc);
         return Response.serverError().entity(exc.getMessage()).build();
      }
   }

   
Get oder members.

Parameters:
body request body.
Returns:
list of members
   {
      ArrayList<OrderMembermembers = new ArrayList<OrderMember>();
      List<HierarchicalPropertychilds = body.getChildren();
      for (int i = 0; i < childs.size(); i++)
      {
         OrderMember member = new OrderMember(childs.get(i));
         members.add(member);
      }
      return members;
   }

   
Order members.

Parameters:
parentNode parent node
members members
Returns:
true if can order
   protected boolean doOrder(Node parentNodeList<OrderMembermembers)
   {
      boolean success = true;
      for (int i = 0; i < members.size(); i++)
      {
         OrderMember member = members.get(i);
         int status = .;
         try
         {
            parentNode.getSession().refresh(false);
            String positionedNodeName = null;
            if (!parentNode.hasNode(member.getSegment()))
            {
               throw new PathNotFoundException();
            }
            if (!new QName("DAV:""last").equals(member.getPosition()))
            {
               NodeIterator nodeIter = parentNode.getNodes();
               boolean finded = false;
               while (nodeIter.hasNext())
               {
                  Node curNode = nodeIter.nextNode();
                  if (new QName("DAV:""first").equals(member.getPosition()))
                  {
                     positionedNodeName = curNode.getName();
                     finded = true;
                     break;
                  }
                  if (new QName("DAV:""before").equals(member.getPosition())
                     && curNode.getName().equals(member.getPositionSegment()))
                  {
                     positionedNodeName = curNode.getName();
                     finded = true;
                     break;
                  }
                  if (new QName("DAV:""after").equals(member.getPosition())
                     && curNode.getName().equals(member.getPositionSegment()))
                  {
                     if (nodeIter.hasNext())
                     {
                        positionedNodeName = nodeIter.nextNode().getName();
                     }
                     finded = true;
                     break;
                  }
               }
               if (!finded)
               {
                  throw new AccessDeniedException();
               }
            }
            parentNode.getSession().refresh(false);
            parentNode.orderBefore(member.getSegment(), positionedNodeName);
            parentNode.getSession().save();
         }
         catch (LockException exc)
         {
            status = .;
         }
         catch (PathNotFoundException exc)
         {
            status = .;
         }
         catch (AccessDeniedException exc)
         {
            status = .;
         }
         catch (RepositoryException exc)
         {
            .error(exc.getMessage(), exc);
            status = .;
         }
         member.setStatus(status);
         if (status != .)
         {
            success = false;
         }
      }
      return success;
   }
New to GrepCode? Check out our FAQ X