Difference between revisions of "Documentation/DevGuide/UCB/Instantiating the UCB"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (1 revision(s))
 
(5 intermediate revisions by 3 users not shown)
Line 5: Line 5:
 
|NextPage=Documentation/DevGuide/UCB/Accessing a UCB Content
 
|NextPage=Documentation/DevGuide/UCB/Accessing a UCB Content
 
}}
 
}}
{{DISPLAYTITLE:Instantiating the UCB}}
+
{{Documentation/DevGuideLanguages|Documentation/DevGuide/UCB/{{SUBPAGENAME}}}}
 +
{{DISPLAYTITLE:Instantiating the UCB}}
 
<!--<idltopic>com.sun.star.ucb.UniversalContentBroker</idltopic>-->
 
<!--<idltopic>com.sun.star.ucb.UniversalContentBroker</idltopic>-->
 
The following steps have to be performed before a process can use the UCB:
 
The following steps have to be performed before a process can use the UCB:
Line 13: Line 14:
  
 
There are several predefined UCB configurations. Each configuration contains data that describes a set of UCPs. All UCPs contained in a configuration are registered at the UCB that is created using this configuration. A UCB configuration is identified by two keys that are strings. The standard configuration is "<code>Local</code>" and "<code>Office</code>", which generally allows access to all UCPs available in a local installation.
 
There are several predefined UCB configurations. Each configuration contains data that describes a set of UCPs. All UCPs contained in a configuration are registered at the UCB that is created using this configuration. A UCB configuration is identified by two keys that are strings. The standard configuration is "<code>Local</code>" and "<code>Office</code>", which generally allows access to all UCPs available in a local installation.
 
+
<syntaxhighlight lang="java">
 
   import com.sun.star.lang.XMultiServiceFactory;
 
   import com.sun.star.lang.XMultiServiceFactory;
 
   import com.sun.star.uno.Exception;
 
   import com.sun.star.uno.Exception;
Line 35: Line 36:
 
           String[] keys = new String[2];
 
           String[] keys = new String[2];
 
           keys[ 0 ] = "Local";
 
           keys[ 0 ] = "Local";
           keys[ 0 ] = "Office";
+
           keys[ 1 ] = "Office";
 
            
 
            
 
           xUCB = xServiceFactory.createInstanceWithArguments(
 
           xUCB = xServiceFactory.createInstanceWithArguments(
Line 48: Line 49:
 
       return true;
 
       return true;
 
   }
 
   }
 
+
</syntaxhighlight>
 
For information about other configurations, refer to [[Documentation/DevGuide/UCB/Configuration|Configuration]].
 
For information about other configurations, refer to [[Documentation/DevGuide/UCB/Configuration|Configuration]].
  
 
{{PDL1}}
 
{{PDL1}}
[[Category: Universal Content Broker]]
+
 
 +
[[Category:Documentation/Developer's Guide/Universal Content Broker]]

Latest revision as of 16:08, 21 December 2020



The following steps have to be performed before a process can use the UCB:

  • Create and set the UNO service manager.
  • Create an instance of the UNO service com.sun.star.ucb.UniversalContentBroker, passing the keys identifying a predefined UCB configuration to createInstanceWithArguments().

There are several predefined UCB configurations. Each configuration contains data that describes a set of UCPs. All UCPs contained in a configuration are registered at the UCB that is created using this configuration. A UCB configuration is identified by two keys that are strings. The standard configuration is "Local" and "Office", which generally allows access to all UCPs available in a local installation.

  import com.sun.star.lang.XMultiServiceFactory;
  import com.sun.star.uno.Exception;
  import com.sun.star.uno.XInterface;
 
  boolean initUCB() {
 
      /////////////////////////////////////////////////////////////////////
      // Obtain Process Service Manager.
      /////////////////////////////////////////////////////////////////////
 
      XMultiServiceFactory xServiceFactory = ...
 
      /////////////////////////////////////////////////////////////////////
      // Create UCB. This needs to be done only once per process.
      /////////////////////////////////////////////////////////////////////
 
      XInterface xUCB;
      try {
          // Supply configuration to use for this UCB instance...
          String[] keys = new String[2];
          keys[ 0 ] = "Local";
          keys[ 1 ] = "Office";
 
          xUCB = xServiceFactory.createInstanceWithArguments(
              "com.sun.star.ucb.UniversalContentBroker", keys );
      }
      catch (com.sun.star.uno.Exception e) {
      }
 
      if (xUCB == null)
          return false;
 
      return true;
  }

For information about other configurations, refer to Configuration.

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