Copying, Moving and Linking

From Apache OpenOffice Wiki
Jump to: navigation, search



Copying, moving and creating links to a resource works differently from the other operations available for UCB Contents. There are three UCB Contents involved in these operations, the source object, target folder, and target object. There may even be two content Providers, for example, when moving a file located on an FTP server to the local file system of a workstation. Each implementation of the com.sun.star.ucb.UniversalContentBroker service supports the com.sun.star.ucb.XCommandProcessor interface. This command processor implements the command "globalTransfer" that can be used to copy and move UCB Contents, and create links to UCB Contents. The command takes an argument of type com.sun.star.ucb.GlobalTransferCommandArgument. To copy, move or create a link to a resource, execute the "globalTransfer" command at the UCB.

Documentation note.png The reasons for the different handling are mainly technical. We did not want to force every single implementation of the transfer command of a UCB content to accept nearly all types of contents. Instead, we wanted to have one single implementation that would be able to handle all types of contents.

Copying, moving and creating links to a resource are shown in the following example:

  import com.sun.star.ucb.*;
  import com.sun.star.uno.UnoRuntime;
  import com.sun.star.uno.XInterface;
  
  {
      String aSourceURL = ... // URL of the source object
      String aTargetFolderURL = ... // URL of the target folder
      
      /////////////////////////////////////////////////////////////////////
      // Obtain access to UCB...
      /////////////////////////////////////////////////////////////////////
      XInterface xUCB = ...
      
      // Obtain XCommandProcessor interface from UCB...
      XCommandProcessor xProcessor = (XCommandProcessor)UnoRuntime.queryInterface(
          XCommandProcessor.class, xUCB);
      
      if (xProcessor == null)
          ... error ...
      /////////////////////////////////////////////////////////////////////
      // Copy a resource to another location...
      /////////////////////////////////////////////////////////////////////
      try {
          GlobalTransferCommandArgument aArg = new GlobalTransferCommandArgument();
          aArg.TransferCommandOperation = TransferCommandOperation_COPY;
          aArg.SourceURL = aSourceURL;
          aArg.TargetURL = aTargetFolderURL;
          
          // object keeps it current name
          aArg.NewTitle = "";
          
          // fail,if object with same name exists in target folder
          aArg.NameClash = NameClash.ERROR;
          
          // Let UCB execute the command "globalTransfer",
          // using helper method executeCommand (see [CHAPTER:UCB.Using.Commands])
          executeCommand(xProcessor, "globalTransfer", aArg);
      }
      catch (com.sun.star.ucb.CommandAbortedException e) {
          ... error ...
      }
      catch (com.sun.star.uno.Exception e) {
          ... error ...
      }
  }
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages