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;
 
 
Created by The eXo Platform SAS Author : Vitaly Guly.

Version:
$Id: $
 
 public class MoveCommand
 {

   
Cache control object.
 
    private static CacheControl cacheControl = new CacheControl();

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

   
Provides URI information needed for 'location' header in 'CREATED' response
 
    private final UriBuilder uriBuilder;
   
   
To trace if an item on destination path existed.
 
    private final boolean itemExisted;
 
    // Fix problem with moving under Windows Explorer.
    static
    {
       .setNoCache(true);
    }

   
Empty constructor
 
    public MoveCommand()
    {
       this. = null;
       this. = false;
    }

   
Here we pass URI builder and info about pre-existence of item on the move destination path If an item existed, we must respond with NO_CONTENT (204) HTTP status. If an item did not exist, we must respond with CREATED (201) HTTP status More info can be found here.

Parameters:
uriBuilder - provide data used in 'location' header
itemExisted - indicates if an item existed on copy destination
 
    public MoveCommand(UriBuilder uriBuilderboolean itemExisted)
    {
       this. = uriBuilder;
       this. = itemExisted;
    }

   
Webdav Move method implementation.

Parameters:
session current session.
srcPath source resource path
destPath destination resource path
Returns:
the instance of javax.ws.rs.core.Response
   public Response move(Session sessionString srcPathString destPath)
   {
      try
      {
         session.move(srcPathdestPath);
         session.save();
         // If the source resource was successfully moved
         // to a pre-existing destination resource.
         if ()
         {
            return Response.status(.).cacheControl().build();
         }
         // If the source resource was successfully moved,
         // and a new resource was created at the destination.
         else
         {
            if ( != null)
            {
               return Response.created(.path(session.getWorkspace().getName()).path(destPath).build())
                  .cacheControl().build();
            }
            // to save compatibility if uriBuilder is not provided
            return Response.status(.).cacheControl().build();
         }
      }
      catch (LockException exc)
      {
         return Response.status(.).entity(exc.getMessage()).build();
      }
      catch (PathNotFoundException exc)
      {
         return Response.status(.).entity(exc.getMessage()).build();
      }
      catch (RepositoryException exc)
      {
         .error(exc.getMessage(), exc);
         return Response.serverError().entity(exc.getMessage()).build();
      }
   }

   
Webdav Move method implementation.

Parameters:
sourceSession source session
destSession destination session
srcPath source resource path
destPath destination resource path
Returns:
the instance of javax.ws.rs.core.Response
   public Response move(Session sourceSessionSession destSessionString srcPathString destPath)
   {
      try
      {
         destSession.getWorkspace().copy(sourceSession.getWorkspace().getName(), srcPathdestPath);
         sourceSession.getItem(srcPath).remove();
         sourceSession.save();
         // If the source resource was successfully moved
         // to a pre-existing destination resource.
         if ()
         {
            return Response.status(.).cacheControl().build();
         }
         // If the source resource was successfully moved,
         // and a new resource was created at the destination.
         else
         {
            if ( != null)
            {
               return Response.created(.path(destSession.getWorkspace().getName()).path(destPath).build())
                  .cacheControl().build();
            }
            // to save compatibility if uriBuilder is not provided
            return Response.status(.).cacheControl().build();
         }
      }
      catch (LockException exc)
      {
         return Response.status(.).entity(exc.getMessage()).build();
      }
      catch (PathNotFoundException exc)
      {
         return Response.status(.).entity(exc.getMessage()).build();
      }
      catch (RepositoryException exc)
      {
         .error(exc.getMessage(), exc);
         return Response.serverError().entity(exc.getMessage()).build();
      }
   }
New to GrepCode? Check out our FAQ X