Difference between revisions of "Documentation/DevGuide/UCB/Executing Content Commands"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Robot: Changing Category:Universal Content Broker)
m (Robot: Changing Category:Documentation/Developers Guide/Universal Content Broker)
Line 63: Line 63:
 
{{PDL1}}
 
{{PDL1}}
  
[[Category:Documentation/Developers Guide/Universal Content Broker]]
+
[[Category:Documentation/Developer's Guide/Universal Content Broker]]

Revision as of 10:59, 5 June 2008



Each UCB content is able to execute commands. When the content object is created, commands are executed using its com.sun.star.ucb.XCommandProcessor interface. The execute() method at this interface expects a com.sun.star.ucb.Command, which is a struct containing the command name, command arguments and a handle:

Members of struct com.sun.star.ucb.Command
Name string, contains the name of the command
Handle long, contains an implementation-specific handle for the command
Argument any, contains the argument of the command

Refer to Appendix C Universal Content Providers for a complete list of predefined commands, the description of the UNO service com.sun.star.ucb.Content and the UCP reference that comes with the SDK. For the latest information, visit ucb.openoffice.org.

Template:Documentation/Note

If executing a command cannot proceed because of an error condition, the following occurs. If the execute call was supplied with a com.sun.star.ucb.XCommandEnvironment that contains a com.sun.star.task.XInteractionHandler, this interaction handler is used to resolve the problem. If no interaction handler is supplied by passing null to the execute() method, or it cannot resolve the problem, an exception describing the error condition is thrown.

The following method executeCommand() executes a command at a UCB content:

  import com.sun.star.uno.UnoRuntime;
  import com.sun.star.ucb.*;
 
  Object executeCommand(XContent xContent, String aCommandName, Object aArgument)
      throws com.sun.star.ucb.CommandAbortedException, com.sun.star.uno.Exception {
 
      /////////////////////////////////////////////////////////////////////
      // Obtain command processor interface from given content.
      /////////////////////////////////////////////////////////////////////
 
      XCommandProcessor xCmdProcessor = (XCommandProcessor)UnoRuntime.queryInterface( 
          XCommandProcessor.class, xContent);
 
      /////////////////////////////////////////////////////////////////////
      // Assemble command to execute.
      /////////////////////////////////////////////////////////////////////
 
      Command aCommand = new Command();
      aCommand.Name = aCommandName;
      aCommand.Handle = -1; // not available
      aCommand.Argument = aArgument;
 
      // Note: throws CommandAbortedException and Exception since
      // we pass null for the XCommandEnvironment parameter
      return xCmdProcessor.execute(aCommand, 0, null);
  }

Template:Documentation/Note

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools