Unconfigured UCBs
From Apache OpenOffice Wiki
< Documentation | DevGuide
A UCB is called unconfigured if it has no content providers, thus it is not able to provide any contents. Each UCB implements the interface com.sun.star.ucb.XContentProviderManager. This interface offers the functionality to register UCPs at runtime.
To create an unconfigured UCB and configure it manually:
- Create an instance of the UNO service com.sun.star.ucb.UniversalContentBroker.
- Register the appropriate UCPs using the com.sun.star.ucb.XContentProviderManager interface of the UCB.
XContentProviderManager
contains the following methods:
com::sun::star::ucb::XContentProvider registerContentProvider( [in] com::sun::star::ucb::XContentProvider Provider, [in] string Scheme, [in] boolean ReplaceExisting) oneway void deregisterContentProvider( [in] com::sun::star::ucb::XContentProvider Provider, [in] string Scheme) sequence< com::sun::star::ucb::ContentProviderInfo > queryContentProviders() com::sun::star::ucb::XContentProvider queryContentProvider([in] string URL)
The XContentProvider
configures a UCB for content providers, obtains com.sun.star.ucb.ContentProviderInfo structs describing the available providers, and the provider that is currently registered for a specific URL schema. The following example uses registerContentProvider()
to configure an unconfigured UCB for a file content provider.
Unconfigured UCB:
import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.ucb.DuplicateProviderException; import com.sun.star.ucb.XContentProvider; import com.sun.star.ucb.XContentProviderManager; import com.sun.star.uno.Exception; import com.sun.star.uno.UnoRuntime; boolean initUCB() { ///////////////////////////////////////////////////////////////////// // Obtain Process Service Manager. ///////////////////////////////////////////////////////////////////// XMultiServiceFactory xServiceFactory = ... ///////////////////////////////////////////////////////////////////// // Create UCB. This needs to be done only once per process. ///////////////////////////////////////////////////////////////////// XContentProviderManager xUCB; try { xUCB = (XContentProviderManager)UnoRuntime.queryInterface( XContentProviderManager.class, xServiceFactory.createInstance( "com.sun.star.ucb.UniversalContentBroker")); } catch (com.sun.star.uno.Exception e) { } if (xUCB == null) return false; ///////////////////////////////////////////////////////////////////// // Instanciate UCPs and register at UCB. ///////////////////////////////////////////////////////////////////// XContentProvider xFileProvider; try { xFileProvider = (XContentProvider)UnoRuntime.queryInterface( XContentProvider.class, xServiceFactory.createInstance( "com.sun.star.ucb.FileContentProvider")); } catch (com.sun.star.uno.Exception e) { } if (xFileProvider == null) return false; try { // Parameters: provider, URL scheme, boolean flag replaceExisting xUCB.registerContentProvider(xFileProvider, "file", new Boolean(false)); } catch (DuplicateProviderException ex) { } // Create/register other UCPs... return true; }
Content on this page is licensed under the Public Documentation License (PDL). |