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

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Robot: Changing Category:Documentation/Developers Guide/Universal Content Broker)
(One intermediate revision by one other user not shown)
Line 5: Line 5:
 
|NextPage=Documentation/DevGuide/UCB/Obtaining Content Properties
 
|NextPage=Documentation/DevGuide/UCB/Obtaining Content Properties
 
}}
 
}}
{{DISPLAYTITLE:Executing Content Commands}}
+
{{Documentation/DevGuideLanguages|Documentation/DevGuide/UCB/{{SUBPAGENAME}}}}
 +
{{DISPLAYTITLE:Executing Content Commands}}
 
<!--<idltopic>com.sun.star.ucb.XCommandProcessor;com.sun.star.ucb.Command</idltopic>-->
 
<!--<idltopic>com.sun.star.ucb.XCommandProcessor;com.sun.star.ucb.Command</idltopic>-->
 
Each UCB content is able to execute commands. When the content object is created, commands are executed using its <idl>com.sun.star.ucb.XCommandProcessor</idl> interface. The <idlm>com.sun.star.ucb.XCommandProcessor:execute</idlm>() method at this interface expects a <idl>com.sun.star.ucb.Command</idl>, which is a struct containing the command name, command arguments and a handle:
 
Each UCB content is able to execute commands. When the content object is created, commands are executed using its <idl>com.sun.star.ucb.XCommandProcessor</idl> interface. The <idlm>com.sun.star.ucb.XCommandProcessor:execute</idlm>() method at this interface expects a <idl>com.sun.star.ucb.Command</idl>, which is a struct containing the command name, command arguments and a handle:
Line 25: Line 26:
 
Refer to Appendix C [[Documentation/DevGuide/AppendixC/Universal Content Providers|Universal Content Providers]] for a complete list of predefined commands, the description of the UNO service <idl>com.sun.star.ucb.Content</idl> and the UCP reference that comes with the SDK. For the latest information, visit [http://ucb.openoffice.org ucb.openoffice.org].
 
Refer to Appendix C [[Documentation/DevGuide/AppendixC/Universal Content Providers|Universal Content Providers]] for a complete list of predefined commands, the description of the UNO service <idl>com.sun.star.ucb.Content</idl> and the UCP reference that comes with the SDK. For the latest information, visit [http://ucb.openoffice.org ucb.openoffice.org].
  
{{Documentation/Note|Whenever we refer to UCB commands, we put them in double quotes as in "<tt>getPropertyValues</tt>" to make a distinction between UCB commands and methods in general that are written <tt>getPropertyValues()</tt>.}}
+
{{Note|Whenever we refer to UCB commands, we put them in double quotes as in "<tt>getPropertyValues</tt>" to make a distinction between UCB commands and methods in general that are written <tt>getPropertyValues()</tt>.}}
  
 
If executing a command cannot proceed because of an error condition, the following occurs. If the execute call was supplied with a <idl>com.sun.star.ucb.XCommandEnvironment</idl> that contains a <idl>com.sun.star.task.XInteractionHandler</idl>, this interaction handler is used to resolve the problem. If no interaction handler is supplied by passing null to the <code>execute()</code> method, or it cannot resolve the problem, an exception describing the error condition is thrown.
 
If executing a command cannot proceed because of an error condition, the following occurs. If the execute call was supplied with a <idl>com.sun.star.ucb.XCommandEnvironment</idl> that contains a <idl>com.sun.star.task.XInteractionHandler</idl>, this interaction handler is used to resolve the problem. If no interaction handler is supplied by passing null to the <code>execute()</code> method, or it cannot resolve the problem, an exception describing the error condition is thrown.
Line 59: Line 60:
 
   }
 
   }
 
   </source>
 
   </source>
{{Documentation/Note|The method <tt>executeCommand()</tt> from the example above is used in the following examples whenever a command is to be executed at a UCB content.}}
+
{{Note|The method <tt>executeCommand()</tt> from the example above is used in the following examples whenever a command is to be executed at a UCB content.}}
  
 
{{PDL1}}
 
{{PDL1}}
  
 
[[Category:Documentation/Developer's Guide/Universal Content Broker]]
 
[[Category:Documentation/Developer's Guide/Universal Content Broker]]

Revision as of 14:58, 4 July 2018



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.

Documentation note.png Whenever we refer to UCB commands, we put them in double quotes as in "getPropertyValues" to make a distinction between UCB commands and methods in general that are written getPropertyValues().

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);
  }
Documentation note.png The method executeCommand() from the example above is used in the following examples whenever a command is to be executed at a UCB content.
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages