Difference between revisions of "Documentation/DevGuide/UCB/Copying, Moving and Linking"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (1 revision(s))
Line 13: Line 13:
 
Copying, moving and creating links to a resource are shown in the following example:  
 
Copying, moving and creating links to a resource are shown in the following example:  
 
<!--[SOURCE:UCB/ResourceManager.java]-->
 
<!--[SOURCE:UCB/ResourceManager.java]-->
 
+
  <source lang="java">
 
   import com.sun.star.ucb.*;
 
   import com.sun.star.ucb.*;
 
   import com.sun.star.uno.UnoRuntime;
 
   import com.sun.star.uno.UnoRuntime;
Line 59: Line 59:
 
       }
 
       }
 
   }
 
   }
 
+
  </source>
 
{{PDL1}}
 
{{PDL1}}
 
[[Category: Universal Content Broker]]
 
[[Category: Universal Content Broker]]

Revision as of 21:52, 14 March 2008



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.

Template:Documentation/Note

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