| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> |
| <HTML> |
| <head> |
| <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=iso-8859-1"> |
| <TITLE>How To Use The Universal Content Broker API</TITLE> |
| <META NAME="GENERATOR" CONTENT="StarOffice/5.2 (Win32)"> |
| <META NAME="CREATED" CONTENT="20010110;19410735"> |
| <META NAME="CHANGEDBY" CONTENT="Kai Sommerfeld"> |
| <META NAME="CHANGED" CONTENT="20010511;15364025"> |
| <STYLE> |
| <!-- |
| A:link { color: #444488 } |
| A:visited { color: #444488 } |
| --> |
| </STYLE> |
| </head> |
| <body LINK="#444488" VLINK="#444488"> |
| <TABLE WIDTH=100% BORDER=0 CELLPADDING=4 CELLSPACING=0 STYLE="page-break-before: always"> |
| <COL WIDTH=75> |
| <TR> |
| <TD BGCOLOR="#666699"> |
| <H1 ALIGN=CENTER STYLE="margin-top: 0cm; text-decoration: none"><A HREF="http://www.openoffice.org/"><IMG SRC="../images/open_office_org_logo.gif" NAME="Graphic1" ALT="OpenOffice.org" ALIGN=RIGHT WIDTH=126 HEIGHT=53 BORDER=0></A><FONT COLOR="#ffffff"><FONT SIZE=6>How |
| To Use The Universal Content Broker API</FONT></FONT></H1> |
| </TD> |
| </TR> |
| </TABLE> |
| <HR SIZE=3 NOSHADE> |
| <TABLE WIDTH=100% BORDER=0 CELLPADDING=4 CELLSPACING=0 STYLE="page-break-before: always"> |
| <COL WIDTH=256*> |
| <TR> |
| <TD WIDTH=100% BGCOLOR="#666699"> |
| <H3 ALIGN=LEFT STYLE="margin-top: 0cm; text-decoration: none"><FONT COLOR="#ffffff"><FONT SIZE=4>Contents</FONT></FONT></H3> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100%> |
| <P STYLE="margin-bottom: 0.1cm"><A HREF="#Abstract">Abstract</A><BR><A HREF="#AccessUCB">Getting |
| access to the UCB</A><BR><A HREF="#CreateContent">Creating a UCB |
| Content for a given URL</A><BR><A HREF="#RunCommand">Executing a |
| command at a UCB Content</A><BR><A HREF="#QueryCommands">Querying |
| the commands supported by a UCB Content</A><BR><A HREF="#QueryProperties">Querying |
| the properties supported by a UCB Content</A><BR><A HREF="#GetPropertyValues">Obtaining |
| property values from a UCB Content</A><BR><A HREF="#SetPropertyValues">Setting |
| property values of a UCB Content</A><BR><A HREF="#AccessChildren">Accessing |
| the children of a UCB Folder Content</A><BR><A HREF="#GetDataStream">Accessing |
| (loading) the content data stream of a UCB Document |
| Content</A><BR><A HREF="#SetDataStream">Setting (storing) the |
| content data stream of a UCB Document Content</A><BR><A HREF="#CreateResource">Creating |
| a new resource</A><BR><A HREF="#DeleteResource">Deleting a |
| resource</A><BR><A HREF="#TransferResource">Copying, Moving and |
| Creating links to a resource</A></P> |
| <P><BR> |
| </P> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100% BGCOLOR="#666699"> |
| <H3 ALIGN=LEFT STYLE="margin-top: 0cm; text-decoration: none"><A NAME="Abstract"></A> |
| <FONT COLOR="#ffffff"><FONT SIZE=4>Abstract</FONT></FONT></H3> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100%> |
| <P STYLE="margin-bottom: 0.1cm">This document describes how |
| software developers can access the functionality of the Universal |
| Content Broker (UCB). There are code snippets in several sections |
| that demonstrate the usage of the UCB API, as well as the usage of |
| the <A HREF="http://www.openoffice.org/source/browse/ucb/ucbhelper/">UCBHELPER</A> |
| library. That library was designed especially to simplify UCB |
| usage.</P> |
| <P STYLE="margin-bottom: 0.1cm">An example for an application that |
| uses the native UCB API can be found at |
| <A HREF="http://www.openoffice.org/source/browse/ucb/ucb/workben/ucb/">http://www.openoffice.org/source/browse/ucb/ucb/workben/ucb/</A>. |
| An application that uses the UCBHELPER library can be found at |
| <A HREF="http://www.openoffice.org/source/browse/ucb/ucbhelper/workben/ucbexplorer/">http://www.openoffice.org/source/browse/ucb/ucbhelper/workben/ucbexplorer/</A>. |
| A complete description of the UCB's UNO interfaces and UNO |
| services can be found in the <A HREF="http://api.openoffice.org/common/ref/com/sun/star/ucb/index.html">UCB |
| API Reference</A>.</P> |
| <P ALIGN=LEFT><BR> |
| </P> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100% BGCOLOR="#666699"> |
| <H3 ALIGN=LEFT STYLE="margin-top: 0cm; text-decoration: none"><A NAME="AccessUCB"></A> |
| <FONT COLOR="#ffffff"><FONT SIZE=4>Getting access to the UCB</FONT></FONT></H3> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100%> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm">Before a process can |
| use the UCB, it needs to do the following steps once:</P> |
| <UL> |
| <LI><P STYLE="margin-bottom: 0.1cm">Create and set the UNO |
| Service Manager.</P> |
| <LI><P STYLE="margin-bottom: 0.1cm">Create an instance of the UNO |
| service "com.sun.star.ucb.UniversalContentBroker", |
| passing the keys identifying a predefined UCB configuration.</P> |
| </UL> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><B>Note:</B> There are |
| several predefined UCB configurations. Each configuration contains |
| data that describe a set of UCPs. All UCPs contained in a |
| configuration will be registered at the UCB that shall be created |
| using this configuration. A UCB configuration is identified by two |
| keys, which are strings. The standard configuration is "Local" |
| and "Office", which generally allows access to all UCPs.</P> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 1 (C++)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| bool initUCB() |
| { |
| ///////////////////////////////////////////////////////////////////// |
| // Create Process Service Manager. This needs to be done only once |
| // per process! Afterwards it is accessible via |
| // comphelper::getProcessServiceFactory(). |
| ///////////////////////////////////////////////////////////////////// |
| |
| uno::Reference< lang::XMultiServiceFactory > xServiceFactory; |
| try |
| { |
| xServiceFactory = cppu::createRegistryServiceFactory( |
| comphelper::getPathToSystemRegistry(), |
| rtl::OUString(), |
| true ); |
| } |
| catch ( uno::Exception const & ) {} |
| |
| if ( !xServiceFactory.is() ) |
| return false; |
| |
| comphelper::setProcessServiceFactory( xServiceFactory ); |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Create UCB. This needs to be done only once per process! |
| ///////////////////////////////////////////////////////////////////// |
| |
| // Supply configuration to use for this UCB instance... |
| uno::Sequence< uno::Any > aArgs( 2 ); |
| aArgs[ 0 ] <<= rtl::OUString::createFromAscii( "Local" ); |
| aArgs[ 1 ] <<= rtl::OUString::createFromAscii( "Office" ); |
| |
| uno::Reference< uno::XInterface > xUCB; |
| try |
| { |
| xUCB = xServiceFactory->createInstanceWithArguments( |
| rtl::OUString::createFromAscii( |
| "com.sun.star.ucb.UniversalContentBroker" ), |
| aArgs ); |
| } |
| catch ( uno::Exception const & ) {} |
| |
| if ( !xUCB.is() ) |
| return false; |
| |
| return true; |
| }</PRE> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 2 (C++, using UCBHELPER library)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| bool initUCB() |
| { |
| ///////////////////////////////////////////////////////////////////// |
| // Create Process Service Manager. This needs to be done only once |
| // per process! Afterwards it is accessible via |
| // comphelper::getProcessServiceFactory(). |
| ///////////////////////////////////////////////////////////////////// |
| |
| uno::Reference< lang::XMultiServiceFactory > xServiceFactory; |
| try |
| { |
| xServiceFactory = cppu::createRegistryServiceFactory( |
| comphelper::getPathToSystemRegistry(), |
| rtl::OUString(), |
| true ); |
| } |
| catch ( uno::Exception const & ) {} |
| |
| if ( !xServiceFactory.is() ) |
| return false; |
| |
| comphelper::setProcessServiceFactory( xServiceFactory ); |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Create UCB. This needs to be done only once per process! |
| ///////////////////////////////////////////////////////////////////// |
| |
| // Supply configuration to use for this UCB instance... |
| uno::Sequence< uno::Any > aArgs( 2 ); |
| aArgs[ 0 ] <<= rtl::OUString::createFromAscii( |
| UCB_CONFIGURATION_KEY1_LOCAL ); |
| aArgs[ 1 ] <<= rtl::OUString::createFromAscii( |
| UCB_CONFIGURATION_KEY2_OFFICE ); |
| |
| return ::ucb::ContentBroker::initialize( xServiceFactory, aArgs ); |
| }</PRE><P> |
| <BR> |
| </P> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100% BGCOLOR="#666699"> |
| <H3 ALIGN=LEFT STYLE="margin-top: 0cm; text-decoration: none"><A NAME="CreateContent"></A> |
| <FONT COLOR="#ffffff"><FONT SIZE=4>Creating a UCB Content for a |
| given URL</FONT></FONT></H3> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100%> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm">Each UCB Content can be |
| identified using a URL. To create a content object for a given |
| URL:</P> |
| <UL> |
| <LI><P STYLE="margin-bottom: 0.1cm">Obtain access to the UCB.</P> |
| <LI><P STYLE="margin-bottom: 0.1cm">Let the UCB create a content |
| identifier object for the requested URL |
| (createContentIdentifier).</P> |
| <LI><P STYLE="margin-bottom: 0.1cm">Let the UCB create a content |
| object for the just created content identifier object |
| (queryContent).</P> |
| <LI><P STYLE="margin-bottom: 0.1cm">The UCB dispatches the |
| queryContent-call to the appropriate UCP. The UCP will be |
| selected according to the URL contained in the identifier object.</P> |
| <LI><P STYLE="margin-bottom: 0.1cm">The UCP creates the content |
| implementation object.</P> |
| <LI><P STYLE="margin-bottom: 0.1cm">The UCB returns the content |
| object returned from the UCP to the original queryContent-caller.</P> |
| </UL> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 1 (C++)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| { |
| ///////////////////////////////////////////////////////////////////// |
| // Obtain access to UCB... |
| ///////////////////////////////////////////////////////////////////// |
| |
| uno::Reference< uno::XInterface > xUCB = ... |
| |
| // Obtain required UCB interfaces... |
| uno::Reference< ucb::XContentIdentifierFactory > xIdFactory( |
| xUCB, uno::UNO_QUERY ); |
| if ( !xIdFactory.is() ) |
| ... error ... |
| |
| uno::Reference< ucb::XContentProvider > xProvider( |
| xUCB, uno::UNO_QUERY ); |
| if ( !xProvider.is() ) |
| ... error ... |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Obtain content object from UCB... |
| ///////////////////////////////////////////////////////////////////// |
| |
| // Create identifier object. |
| uno::Reference< ucb::XContentIdentifier > xId |
| = xIdFactory->createContentIdentifier( rURL ); |
| |
| if ( !xId.is() ) |
| ... error ... |
| |
| uno::Reference< ucb::XContent > xContent |
| = xProvider->queryContent( xId ); |
| |
| if ( !xContent.is() ) |
| ... error ... |
| }</PRE> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 2 (C++, using UCBHELPER library)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| { |
| rtl::OUString aURL = ... |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Create an empty content object. ucb::Content::create(...) |
| // will associate that content with the requested URL... |
| ///////////////////////////////////////////////////////////////////// |
| |
| ::ucb::Content aContent; |
| bool bSuccess = ::ucb::Content::create( |
| aURL, uno::Reference< ucb::XCommandEnvironment >(), aContent ); |
| if ( bSuccess ) |
| { |
| // content is ready for usage now... |
| } |
| }</PRE><P> |
| <BR> |
| </P> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100% BGCOLOR="#666699"> |
| <H3 ALIGN=LEFT STYLE="margin-top: 0cm; text-decoration: none"><A NAME="RunCommand"></A> |
| <FONT COLOR="#ffffff"><FONT SIZE=4>Executing a command at a UCB |
| Content</FONT></FONT></H3> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100%> |
| <P STYLE="margin-bottom: 0.1cm">Each UCB Content is able to |
| execute commands. Once you have created a content object, you can |
| execute commands at it using its <A HREF="http://api.openoffice.org/common/ref/com/sun/star/ucb/XCommandProcessor.html">XCommandProcessor</A> |
| interface. For a complete list of predefined commands, refer to |
| the description of the UNO service <A HREF="http://api.openoffice.org/common/ref/com/sun/star/ucb/Content.html">Content</A>.</P> |
| <P STYLE="margin-bottom: 0.1cm">If executing a command cannot |
| proceed because of some error condition, the following happens: If |
| the execute-call was supplied with an <A HREF="http://api.openoffice.org/common/ref/com/sun/star/ucb/XCommandEnvironment.html">XCommandEnvironment</A> |
| that contains an <A HREF="http://api.openoffice.org/common/ref/com/sun/star/task/XInteractionHandler.html">XInteractionHandler</A>, |
| this interaction handler is used to resolve the problem. If no |
| interaction handler is supplied (or if it cannot resolve the |
| problem), an exception describing the error condition is thrown.</P> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 1 (C++)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| uno::Any executeCommand( const uno::Reference< ucb::XContent > & xContent, |
| const rtl::OUString & rCommandName, |
| const uno::Any & rArgument ) |
| throw ( ucb::CommandAbortedException, uno::Exception ) |
| { |
| ///////////////////////////////////////////////////////////////////// |
| // Obtain command processor interface from given content. |
| ///////////////////////////////////////////////////////////////////// |
| |
| ucb::XCommandProcessor xCmdProcessor( xContent, uno::UNO_QUERY ); |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Assemble command to execute. |
| ///////////////////////////////////////////////////////////////////// |
| |
| ucb::Command aCommand; |
| aCommand.Name = rCommandName; |
| aCommand.Handle = -1; // not available |
| aCommand.Argument = rArgument; |
| |
| // Note: throws ucb::CommandAbortedException, uno::Exception |
| return xCmdProcessor->execute( |
| aCommand, 0, uno::Reference< ucb::XCommandEnvironment >() ); |
| }</PRE> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 2 (C++, using UCBHELPER library)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| uno::Any executeCommand( const ::ucb::Content & rContent, |
| const rtl::OUString & rCommandName, |
| const uno::Any & rArgument ) |
| throw ( ucb::CommandAbortedException, uno::Exception ) |
| { |
| // Note: throws ucb::CommandAbortedException, uno::Exception |
| return rContent.executeCommand( rCommandName, rCommandArgument ); |
| }</PRE><P> |
| <BR> |
| </P> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100% BGCOLOR="#666699"> |
| <H3 ALIGN=LEFT STYLE="margin-top: 0cm; text-decoration: none"><A NAME="QueryCommands"></A> |
| <FONT COLOR="#ffffff"><FONT SIZE=4>Querying the commands supported |
| by a UCB Content</FONT></FONT></H3> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100%> |
| <P STYLE="margin-bottom: 0.1cm">Each UCB Content supports the |
| command <B>getCommandInfo</B>. This command takes a <B>void |
| argument</B> and returns an implementation of the interface |
| <A HREF="http://api.openoffice.org/common/ref/com/sun/star/ucb/XCommandInfo.html">XCommandInfo</A> |
| that can be used to obtain information on the supported commands. |
| </P> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 1 (C++)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| uno::Reference< ucb::XCommandInfo > getCommandInfo( |
| const uno::Reference< ucb::XContent > & xContent ) |
| { |
| // Execute command "getCommandInfo". |
| |
| uno::Reference< ucb::XCommandInfo > xInfo; |
| try |
| { |
| executeCommand( xContent, |
| rtl::OUString::createFromAscii( |
| "getCommandInfo" ), |
| uno::Any() ) >>= xInfo; |
| { |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| |
| return xInfo; |
| }</PRE> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 2 (C++, using UCBHELPER library)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| uno::Reference< ucb::XCommandInfo > getCommandInfo( |
| const ::ucb::Content & rContent ) |
| { |
| uno::Reference< ucb::XCommandInfo > xInfo; |
| try |
| { |
| // UCBHELPER Content has a special method for this command. |
| xInfo = rContent.getCommands(); |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| |
| return xInfo; |
| }</PRE><P> |
| <BR> |
| </P> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100% BGCOLOR="#666699"> |
| <H3 ALIGN=LEFT STYLE="margin-top: 0cm; text-decoration: none"><A NAME="QueryProperties"></A> |
| <FONT COLOR="#ffffff"><FONT SIZE=4>Querying the properties |
| supported by a UCB Content</FONT></FONT></H3> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100%> |
| <P STYLE="margin-bottom: 0.1cm">Each UCB Content supports the |
| command <B>getPropertySetInfo</B>. This command takes a <B>void |
| argument</B> and returns an implementation of the interface |
| <A HREF="http://api.openoffice.org/common/ref/com/sun/star/beans/XPropertySetInfo.html">XPropertySetInfo</A> |
| that can be used to obtain information on the supported |
| properties. |
| </P> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 1 (C++)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| uno::Reference< beans::XPropertySetInfo > getPropertySetInfo( |
| const uno::Reference< ucb::XContent > & xContent ) |
| { |
| uno::Reference< beans::XPropertySetInfo > xInfo; |
| try |
| { |
| // Execute command "getPropertySetInfo". |
| executeCommand( xContent, |
| rtl::OUString::createFromAscii( |
| "getPropertySetInfo" ), |
| uno::Any() ) >>= xInfo; |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| |
| return xInfo; |
| }</PRE> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 2 (C++, using UCBHELPER library)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| uno::Reference< beans::XPropertySetInfo > getPropertySetInfo( |
| const ::ucb::Content & rContent ) |
| { |
| uno::Reference< beans::XPropertySetInfo > xInfo; |
| try |
| { |
| // UCBHELPER Content has a special method for this command. |
| xInfo = rContent.getProperties(); |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| |
| return xInfo; |
| }</PRE><P> |
| <BR> |
| </P> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100% BGCOLOR="#666699"> |
| <H3 ALIGN=LEFT STYLE="margin-top: 0cm; text-decoration: none"><A NAME="GetPropertyValues"></A> |
| <FONT COLOR="#ffffff"><FONT SIZE=4>Obtaining property values from |
| a UCB Content</FONT></FONT></H3> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100%> |
| <P STYLE="margin-bottom: 0.1cm">A UCB Content maintains a set of |
| properties. It supports the command <B>getPropertyValues</B>, |
| which can be used to obtain one or more property values from a |
| content. This command takes an argument of type sequence< |
| <A HREF="http://api.openoffice.org/common/ref/com/sun/star/beans/Property.html">Property</A> |
| > and returns an implementation of the interface <A HREF="http://api.openoffice.org/common/ref/com/sun/star/sdbc/XRow.html">XRow</A>, |
| which is very similar to a row of a JDBC resultset. To obtain |
| property values from a UCB Content:</P> |
| <UL> |
| <LI><P STYLE="margin-bottom: 0.1cm">Define a sequence of |
| properties for which you want to obtain the values.</P> |
| <LI><P STYLE="margin-bottom: 0.1cm">Let the UCB Content execute |
| the command getPropertyValues.</P> |
| <LI><P STYLE="margin-bottom: 0.1cm">Obtain the property values |
| from the returned row object.</P> |
| </UL> |
| <P STYLE="margin-bottom: 0.1cm">Note that there are additional |
| methods available at the Content class of the UCBHELPER library |
| that can be used to obtain a single property value as uno::Any or |
| to obtain multiple values as a sequence of uno::Any.</P> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 1 (C++)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| { |
| uno::Reference< ucb::XContent > xContent = ... |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Obtain value of the string property Title and the boolean property |
| // IsFolder from xContent... |
| ///////////////////////////////////////////////////////////////////// |
| |
| // Define property sequence. |
| |
| uno::Sequence< beans::Property > aProps( 2 ); |
| aProps[ 0 ].Name = rtl::OUString::createFromAscii( "Title" ); |
| aProps[ 0 ].Handle = -1; // n/a |
| aProps[ 1 ].Name = rtl::OUString::createFromAscii( "IsFolder" ); |
| aProps[ 1 ].Handle = -1; // n/a |
| |
| uno::Reference< sdbc::XRow > xValues; |
| try |
| { |
| // Execute command "getPropertyValues". |
| executeCommand( xContent, |
| rtl::OUString::createFromAscii( |
| "getPropertyValues" ), |
| makeAny( aProps ) ) >>= xValues; |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| |
| if ( !xValues.is() ) |
| ... error ... |
| |
| // Extract values from row object. Note that that the |
| // first column is 1, not 0. |
| |
| // Title: Obtain value of column 1 as string. |
| rtl::OUString aTitle = xValues->getString( 1 ) ); |
| if ( aTitle.Len() == 0 && xValues->wasNull() ) |
| ... error ... |
| |
| // IsFolder: Obtain value of column 2 as boolean. |
| sal_Bool bFolder = xValues->getBoolean( 2 ); |
| if ( !bFolder && xValues->wasNull() ) |
| ... error ... |
| }</PRE> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 2a (C++, using UCBHELPER library)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| { |
| ::ucb::Content aContent = ... |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Obtain value of the string property Title and the boolean property |
| // IsFolder from xContent... |
| ///////////////////////////////////////////////////////////////////// |
| |
| // Define property sequence. |
| |
| uno::Sequence< rtl::OUString > aProps( 2 ); |
| aProps[ 0 ] = rtl::OUString::createFromAscii( "Title" ); |
| aProps[ 1 ] = rtl::OUString::createFromAscii( "IsFolder" ); |
| |
| uno::Reference< sdbc::XRow > xValues; |
| |
| try |
| { |
| // Obtain property values. |
| xValues = aContent.getPropertyValuesInterface( aProps ); |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| |
| // Extract values from row object. Note that that the |
| // first column is 1, not 0. |
| |
| // Title: Obtain value of column 1 as string. |
| rtl::OUString aTitle = xValues->getString( 1 ) ); |
| if ( aTitle.getLength() == 0 && xValues->wasNull() ) |
| ... error ... |
| |
| // IsFolder: Obtain value of column 2 as boolean. |
| sal_Bool bFolder = xValues->getBoolean( 2 ); |
| if ( !bFolder && xValues->wasNull() ) |
| ... error ... |
| }</PRE> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 2b (C++, using UCBHELPER library)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| { |
| ::ucb::Content aContent = ... |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Obtain value of the string property Title and the boolean property |
| // IsFolder from xContent... |
| ///////////////////////////////////////////////////////////////////// |
| |
| // Define property sequence. |
| |
| uno::Sequence< rtl::OUString > aProps( 2 ); |
| aProps[ 0 ] = rtl::OUString::createFromAscii( "Title" ); |
| aProps[ 1 ] = rtl::OUString::createFromAscii( "IsFolder" ); |
| |
| uno::Sequence< uno::Any > aValues; |
| |
| try |
| { |
| // Obtain property values. |
| aValues = aContent.getPropertyValues( aProps ); |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| |
| // Extract values from sequence. |
| |
| // Title: |
| rtl::OUString aTitle; |
| if ( !( aValues[ 0 ] >>= aTitle ) ) |
| ... error ... |
| |
| // IsFolder: |
| sal_Bool bFolder; |
| if ( !( aValues[ 1 ] >>= bFolder ) ) |
| ... error ... |
| }</PRE><P> |
| <BR> |
| </P> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100% BGCOLOR="#666699"> |
| <H3 ALIGN=LEFT STYLE="margin-top: 0cm; text-decoration: none"><A NAME="SetPropertyValues"></A> |
| <FONT COLOR="#ffffff"><FONT SIZE=4>Setting property values of a |
| UCB Content</FONT></FONT></H3> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100%> |
| <P STYLE="margin-bottom: 0.1cm">A UCB Content maintains a set of |
| properties. It supports the command <B>setPropertyValues</B>, |
| which can be used to set one or more property values of a content. |
| This command takes an argument of type sequence< <A HREF="http://api.openoffice.org/common/ref/com/sun/star/beans/PropertyValue.html">PropertyValue</A> |
| > and returns <B>void</B>. To set property values of a UCB |
| Content:</P> |
| <UL> |
| <LI><P STYLE="margin-bottom: 0.1cm">Define a sequence of property |
| values you want to set.</P> |
| <LI><P STYLE="margin-bottom: 0.1cm">Let the UCB Content execute |
| the command setPropertyValues.</P> |
| </UL> |
| <P STYLE="margin-bottom: 0.1cm">Note that the command will not be |
| aborted if one or more of the property values cannot be set |
| (because the requested property is not supported by the content or |
| because it is read-only). Currently there is no other way to check |
| whether a property value was set successfully than to obain the |
| property value after a set-operation. This may change in the near |
| future, when status information could be returned by the command |
| setPropertyValues.</P> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 1 (C++)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| { |
| uno::Reference< ucb::XContent > xContent = ... |
| rtl::OUString aNewTitle |
| = rtl::OUString::createFromAscii( "NewTitle" ); |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Set value of the string property Title... |
| ///////////////////////////////////////////////////////////////////// |
| |
| // Define property value sequence. |
| |
| uno::Sequence< beans::PropertyValue > aProps( 1 ); |
| aProps[ 0 ].Name = rtl::OUString::createFromAscii( "Title" ); |
| aProps[ 0 ].Handle = -1; // n/a |
| aProps[ 0 ].Value <<= aNewTitle; |
| |
| try |
| { |
| // Execute command "setPropertyValues". |
| executeCommand( xContent, |
| rtl::OUString::createFromAscii( |
| "setPropertyValues" ), |
| makeAny( aProps ); |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| }</PRE> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 2a (C++, using UCBHELPER library)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| { |
| ::ucb::Content aContent = ... |
| rtl::OUString aNewTitle |
| = rtl::OUString::createFromAscii( "NewTitle" ); |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Set value of the string property Title... |
| ///////////////////////////////////////////////////////////////////// |
| |
| // Define property name sequence. |
| uno::Sequence< rtl::OUString > aProps( 1 ); |
| aProps[ 0 ] = rtl::OUString::createFromAscii( "Title" ); |
| |
| // Define property value sequence. |
| uno::Sequence< uno::Any > aValues; |
| aValues[ 0 ] <<= aNewTitle; |
| |
| try |
| { |
| // Set property values. |
| aContent.setPropertyValues( aProps, aValues ); |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| }</PRE> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 2b (C++, using UCBHELPER library)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| { |
| ::ucb::Content aContent = ... |
| rtl::OUString aNewTitle |
| = rtl::OUString::createFromAscii( "NewTitle" ); |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Set value of the string property Title... |
| ///////////////////////////////////////////////////////////////////// |
| |
| try |
| { |
| // Set property value. |
| aContent.setPropertyValue( |
| rtl::OUString::createFromAscii( "Title" ), |
| makeAny( aNewTitle ) ); |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| }</PRE><P> |
| <BR> |
| </P> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100% BGCOLOR="#666699"> |
| <H3 ALIGN=LEFT STYLE="margin-top: 0cm; text-decoration: none"><A NAME="AccessChildren"></A> |
| <FONT COLOR="#ffffff"><FONT SIZE=4>Accessing the children of a UCB |
| Folder Content</FONT></FONT></H3> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100%> |
| <P STYLE="margin-bottom: 0.1cm">A UCB Content that is a folder |
| (which means that the value of the required property <B>IsFolder</B> |
| is true) should support the command <B>open</B>. This command |
| takes an argument of type <A HREF="http://api.openoffice.org/common/ref/com/sun/star/ucb/OpenCommandArgument2.html">OpenCommandArgument2</A>. |
| The value returned is an implementation of the service |
| <A HREF="http://api.openoffice.org/common/ref/com/sun/star/ucb/ContentResultSet.html">ContentResultSet</A>. |
| This resultset can be understood as a table, where each row |
| contains a child content of the folder content. You may travel |
| through the rows by using the resultset's interface <A HREF="http://api.openoffice.org/common/ref/com/sun/star/sdbc/XResultSet.html">XResultSet</A>. |
| The children may be accessed by traveling to the appropriate row |
| and using the interface <A HREF="http://api.openoffice.org/common/ref/com/sun/star/ucb/XContentAccess.html">XContentAccess</A>, |
| which is also implemented by the resultset. You may supply a |
| sequence< <A HREF="http://api.openoffice.org/common/ref/com/sun/star/beans/Property.html">Property</A> |
| > as part of the argument of the open command. In this case, |
| the resultset will contain an additional column for each property |
| value that was requested. You may access the property values by |
| traveling to the appropriate row and calling methods of the |
| interface <A HREF="http://api.openoffice.org/common/ref/com/sun/star/sdbc/XRow.html">XRow</A>. |
| There may also other parameters be passed to the open command. |
| Refer to the documentation of <A HREF="http://api.openoffice.org/common/ref/com/sun/star/ucb/OpenCommandArgument2.html">OpenCommandArgument2</A> |
| for more information.</P> |
| <P STYLE="margin-bottom: 0.1cm">To access the children of a UCB |
| Content:</P> |
| <UL> |
| <LI><P STYLE="margin-bottom: 0.1cm">Fill the OpenCommandArgument2 |
| structure according to your needs.</P> |
| <LI><P STYLE="margin-bottom: 0.1cm">Let the UCB Content execute |
| the command open.</P> |
| <LI><P STYLE="margin-bottom: 0.1cm">Access the children and the |
| requested property values using the returned resultset.</P> |
| </UL> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 1 (C++)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| { |
| uno::Reference< ucb::XContent > xContent = ... |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Open a folder content, request property values for the string |
| // property Title and the boolean property IsFolder... |
| ///////////////////////////////////////////////////////////////////// |
| |
| // Fill argument structure... |
| |
| ucb::OpenCommandArgument2 aArg; |
| |
| aArg.Mode = ucb::OpenMode::ALL; // FOLDER, DOCUMENTS -> simple filter |
| aArg.Priority = 32768; // Ignored by most implementations |
| |
| // Fill info for the properties wanted. |
| uno::Sequence< beans::Property > aProps( 2 ); |
| aProps[ 0 ].Name = rtl::OUString::createFromAscii( "Title" ); |
| aProps[ 0 ].Handle = -1; // n/a |
| aProps[ 1 ].Name = rtl::OUString::createFromAscii( "IsFolder" ); |
| aProps[ 1 ].Handle = -1; // n/a |
| |
| aArg.Properties = aProps; |
| |
| uno::Reference< ucb::XDynamicResultSet > xSet; |
| try |
| { |
| // Execute command "open". |
| executeCommand( xContent, |
| rtl::OUString::createFromAscii( "open" ), |
| makeAny( aArg ) >>= xSet; |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| |
| if ( !xSet.is() ) |
| ... error ... |
| |
| uno::Reference< sdbc::XResultSet > xResultSet( |
| xSet->getStaticResultSet() ); |
| |
| if ( !xResultSet.is() ) |
| ... error ... |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Iterate over children, access children and property values... |
| ///////////////////////////////////////////////////////////////////// |
| |
| try |
| { |
| // Move to begin. |
| if ( xResultSet->first() ) |
| { |
| uno::Reference< ucb::XContentAccess > xContentAccess( |
| xResultSet, uno::UNO_QUERY ); |
| uno::Reference< sdbc::XRow > xRow( |
| xResultSet, uno::UNO_QUERY ); |
| |
| do |
| { |
| // Obtain URL of child. |
| rtl::OUString aId |
| = xContentAccess->queryContentIdentifierString(); |
| |
| // ucb::XContent xChild |
| // = xContentAccess->queryContent(); |
| |
| // First column: Title ( column numbers are 1-based! ) |
| rtl::OUString aTitle = xRow->getString( 1 ); |
| if ( aTitle.getLength() == 0 && xRow->wasNull() ) |
| ... error ... |
| |
| // Second column: IsFolder |
| sal_Bool bFolder = xRow->getBoolean( 2 ); |
| if ( !bFolder && xRow->wasNull() ) |
| ... error ... |
| } |
| while ( xResultSet->next() ) // next child |
| } |
| } |
| catch ( ucb::ResultSetException const & ) |
| { |
| ... error ... |
| } |
| }</PRE> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 2 (C++, using UCBHELPER library)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| { |
| ::ucb::Content aContent = ... |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Open a folder content, request property values for the string |
| // property Title and the boolean property IsFolder... |
| ///////////////////////////////////////////////////////////////////// |
| |
| // Define property name sequence. |
| uno::Sequence< OUString > aProps( 2 ); |
| aProps[ 0 ] = rtl::OUString::createFromAscii( "Title" ); |
| aProps[ 1 ] = rtl::OUString::createFromAscii( "IsFolder" ); |
| |
| uno::Reference< sdbc::XResultSet > xResultSet; |
| try |
| { |
| xResultSet = aContent.createCursor( |
| aProps, ::ucb::INCLUDE_FOLDERS_AND_DOCUMENTS ); |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| |
| if ( !xResultSet.is() ) |
| ... error ... |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Iterate over children, access children and property values... |
| ///////////////////////////////////////////////////////////////////// |
| |
| try |
| { |
| // Move to begin. |
| if ( xResultSet->first() ) |
| { |
| uno::Reference< ucb::XContentAccess > xContentAccess( |
| xResultSet, uno::UNO_QUERY ); |
| uno::Reference< sdbc::XRow > xRow( |
| xResultSet, uno::UNO_QUERY ); |
| |
| do |
| { |
| // Obtain URL of child. |
| rtl::OUString aId |
| = xContentAccess->queryContentIdentifierString(); |
| |
| // ucb::XContent xChild |
| // = xContentAccess->queryContent(); |
| |
| // First column: Title ( column numbers are 1-based! ) |
| rtl::OUString aTitle = xRow->getString( 1 ); |
| if ( aTitle.getLength() == 0 && xRow->wasNull() ) |
| ... error ... |
| |
| // Second column: IsFolder |
| sal_Bool bFolder = xRow->getBoolean( 2 ); |
| if ( !bFolder && xRow->wasNull() ) |
| ... error ... |
| } |
| while ( xResultSet->next() ) // next child |
| } |
| } |
| catch ( ucb::ResultSetException const & ) |
| { |
| ... error ... |
| } |
| }</PRE><P> |
| <BR> |
| </P> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100% BGCOLOR="#666699"> |
| <H3 ALIGN=LEFT STYLE="margin-top: 0cm; text-decoration: none"><A NAME="GetDataStream"></A> |
| <FONT COLOR="#ffffff"><FONT SIZE=4>Accessing (loading) the content |
| data stream of a UCB Document Content</FONT></FONT></H3> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100%> |
| <P STYLE="margin-bottom: 0.1cm">A UCB Content that is a document |
| (which means that the value of the required property <B>IsDocument</B> |
| is true) should support the command <B>open</B>. The command takes |
| an argument of type <A HREF="http://api.openoffice.org/common/ref/com/sun/star/ucb/OpenCommandArgument2.html">OpenCommandArgument2</A>. |
| Note that this command (with the same argument type) is also used |
| to access the children of a folder. Whether you get access to the |
| children or the data stream (or even both, for contents that |
| support both) is controlled by the argument's <I>Mode</I> member, |
| as can be seen in the examples. If you are only interested in the |
| data stream, you can ignore the command's return value (which will |
| presumably be a null resultset, anyway).</P> |
| <P STYLE="margin-bottom: 0.1cm">The caller needs to supply the |
| implementation of a data sink with the arguments in order to get |
| access to the document's data stream. Generally there are two |
| different types of data sinks: <A HREF="http://api.openoffice.org/common/ref/com/sun/star/io/XActiveDataSink.html">XActiveDataSink</A> |
| and <A HREF="http://api.openoffice.org/common/ref/com/sun/star/io/XOutputStream.html">XOutputStream</A>.</P> |
| <P STYLE="margin-bottom: 0.1cm"><B>XActiveDataSink:</B> If this |
| type of data sink is supplied, the caller of the command is |
| active. The implementation of the command will supply an |
| implementation of the interface <A HREF="http://api.openoffice.org/common/ref/com/sun/star/io/XInputStream.html">XInputStream</A> |
| to the given XActiveDataSink (setInputStream) and return. Once the |
| execute-call has returned, the caller can access the input stream |
| (getInputStream) and read the data using that stream (readBytes, |
| readSomeBytes).</P> |
| <P STYLE="margin-bottom: 0.1cm"><B>XOutputStream:</B> If this type |
| of data sink is supplied, the caller of the command is passive. |
| The implementation of the command will write all data to the |
| output stream (writeBytes) and close it (closeOutput) after all |
| data were successfully written. Only then will the open command |
| return.</P> |
| <P STYLE="margin-bottom: 0.1cm">Which type to use highly depends |
| on the logic of the client application. If the application can be |
| designed so that it passively processes the data supplied by an |
| XOutputStream, using an XOutputStream as sink is advantageous, |
| because many content providers can implement this case efficiently |
| without buffering any data. If, on the other hand, the application |
| is designed so that it actively reads the data, you should use an |
| XActiveDataSink; any necessary buffering will then take place in |
| the implementation of the open command.</P> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 1 (C++)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| ///////////////////////////////////////////////////////////////////////// |
| // XActiveDataSink interface implementation. |
| ///////////////////////////////////////////////////////////////////////// |
| |
| class MyActiveDataSink : public cppu::OWeakObject, |
| public io::XActiveDataSink |
| { |
| uno::Reference< io::XInputStream > m_xStream; |
| |
| public: |
| // XInterface methods |
| ... queryInterface ... acquire ... release ... |
| |
| // XActiveDataSink methods. |
| virtual void SAL_CALL |
| setInputStream( const uno::Reference< io::XInputStream >& aStream ) |
| throw( uno::RuntimeException ) |
| { m_xStream = aStream; } |
| |
| virtual uno::Reference< io::XInputStream > SAL_CALL |
| getInputStream() |
| throw( uno::RuntimeException ) |
| { return m_xStream; } |
| }; |
| |
| { |
| uno::Reference< ucb::XContent > xContent = ... |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Read the document data stream of a document content using a |
| // XActiveDataSink implementation as data sink.... |
| ///////////////////////////////////////////////////////////////////// |
| |
| // Fill argument structure... |
| |
| ucb::OpenCommandArgument2 aArg; |
| aArg.Mode = ucb::OpenMode::DOCUMENT; |
| aArg.Priority = 32768; // Ignored by most implementations |
| |
| // Create data sink implementation object. |
| uno::Reference< io::XActiveDataSink > xDataSink |
| = new MyActiveDataSink; |
| aArg.Sink = xDataSink; |
| |
| try |
| { |
| // Execute command "open". The implementation of the command will |
| // supply an XInputStream implementation to the data sink. |
| executeCommand( xContent, |
| rtl::OUString::createFromAscii( "open" ), |
| makeAny( aArg ) ); |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| |
| // Get input stream supplied by the open command implementation. |
| uno::Reference< io::XInputStream > xData |
| = xDataSink->getInputStream(); |
| if ( !xData.is() ) |
| ... error ... |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Read data from input stream... |
| ///////////////////////////////////////////////////////////////////// |
| |
| try |
| { |
| // Data buffer. Will be allocated by input stream implementation! |
| uno::Sequence< sal_Int8 > aBuffer; |
| |
| sal_Int32 nRead = xData->readSomeBytes( aBuffer, 65536 ); |
| while ( nRead > 0 ) |
| { |
| // Process data contained in buffer. |
| ... |
| |
| nRead = xData->readSomeBytes( aBuffer, 65536 ); |
| } |
| |
| // EOF. |
| } |
| catch ( io::NotConnectedException const & ) |
| { |
| ... error ... |
| } |
| catch ( io::BufferSizeExceededException const & ) |
| { |
| ... error ... |
| } |
| catch ( io::IOException const & ) |
| { |
| ... error ... |
| } |
| }</PRE> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 2 (C++, using UCBHELPER library)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| ///////////////////////////////////////////////////////////////////////// |
| // XActiveDataSink interface implementation. |
| ///////////////////////////////////////////////////////////////////////// |
| |
| class MyActiveDataSink : public cppu::OWeakObject, |
| public io::XActiveDataSink |
| { |
| uno::Reference< io::XInputStream > m_xStream; |
| |
| public: |
| // XInterface methods |
| ... queryInterface ... acquire ... release ... |
| |
| // XActiveDataSink methods. |
| virtual void SAL_CALL |
| setInputStream( const uno::Reference< io::XInputStream >& aStream ) |
| throw( uno::RuntimeException ) |
| { m_xStream = aStream; } |
| |
| virtual uno::Reference< io::XInputStream > SAL_CALL |
| getInputStream() |
| throw( uno::RuntimeException ) |
| { return m_xStream; } |
| }; |
| |
| { |
| ::ucb::Content aContent = ... |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Read the document data stream of a document content using a |
| // XActiveDataSink implementation as data sink.... |
| ///////////////////////////////////////////////////////////////////// |
| |
| uno::Reference< io::XActiveDataSink > xDataSink |
| = new MyActiveDataSink; |
| try |
| { |
| aContent.openStream( xDataSink ); |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| |
| // Get input stream supplied by the open command implementation. |
| uno::Reference< io::XInputStream > xData |
| = xDataSink->getInputStream(); |
| if ( !xData.is() ) |
| ... error ... |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Read data from input stream... |
| ///////////////////////////////////////////////////////////////////// |
| |
| try |
| { |
| // Data buffer. Will be allocated by input stream implementation! |
| uno::Sequence< sal_Int8 > aBuffer; |
| |
| sal_Int32 nRead = xData->readSomeBytes( aBuffer, 65536 ); |
| while ( nRead > 0 ) |
| { |
| // Process data contained in buffer. |
| ... |
| |
| nRead = xData->readSomeBytes( aBuffer, 65536 ); |
| } |
| |
| // EOF. |
| } |
| catch ( io::NotConnectedException const & ) |
| { |
| ... error ... |
| } |
| catch ( io::BufferSizeExceededException const & ) |
| { |
| ... error ... |
| } |
| catch ( io::IOException const & ) |
| { |
| ... error ... |
| } |
| }</PRE><P> |
| <BR> |
| </P> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100% BGCOLOR="#666699"> |
| <H3 ALIGN=LEFT STYLE="margin-top: 0cm; text-decoration: none"><A NAME="SetDataStream"></A> |
| <FONT COLOR="#ffffff"><FONT SIZE=4>Setting (storing) the content |
| data stream of a UCB Document Content</FONT></FONT></H3> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100%> |
| <P STYLE="margin-bottom: 0.1cm">A UCB Content that is a document |
| (which means that the value of the required property <B>IsDocument</B> |
| is true) should support the command <B>insert</B>. This command |
| can be used to (over)write the document's data stream. The command |
| requires an argument of type <A HREF="http://api.openoffice.org/common/ref/com/sun/star/ucb/InsertCommandArgument.html">InsertCommandArgument</A> |
| and returns <B>void</B>. The caller needs to supply the |
| implementation of an <A HREF="http://api.openoffice.org/common/ref/com/sun/star/io/XInputStream.html">XInputStream</A> |
| with the command argument. This stream contains the data to be |
| written. An additional flag indicating whether a possibly existing |
| content (and its data) shall be overwritten may be supplied with |
| the command argument. Implementations that are not able to detect |
| whether there are previous data may ignore this parameter and will |
| always write the new data!</P> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 1 (C++)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| { |
| uno::Reference< ucb::XContent > xContent = ... |
| uno::Reference< io::XInputStream > xData = ... // The data to write. |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Write the document data stream of a document content... |
| ///////////////////////////////////////////////////////////////////// |
| |
| // Fill argument structure... |
| |
| ucb::InsertCommandArgument aArg; |
| aArg.Data = xData; |
| aArg.ReplaceExisting = true; |
| |
| try |
| { |
| // Execute command "insert". |
| executeCommand( xContent, |
| rtl::OUString::createFromAscii( "insert" ), |
| makeAny( aArg ) ); |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| }</PRE> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 2 (C++, using UCBHELPER library)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| { |
| ::ucb::Content aContent = ... |
| uno::Reference< io::XInputStream > xData = ... // The data to write. |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Write the document data stream of a document content... |
| ///////////////////////////////////////////////////////////////////// |
| |
| try |
| { |
| aContent.writeStream( xData, true /* replaceexisting */ ); |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| }</PRE><P> |
| <BR> |
| </P> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100% BGCOLOR="#666699"> |
| <H3 ALIGN=LEFT STYLE="margin-top: 0cm; text-decoration: none"><A NAME="CreateResource"></A> |
| <FONT COLOR="#ffffff"><FONT SIZE=4>Creating a new resource</FONT></FONT></H3> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100%> |
| <P STYLE="margin-bottom: 0.1cm">A UCB Content that implements the |
| interface <A HREF="http://api.openoffice.org/common/ref/com/sun/star/ucb/XContentCreator.html">XContentCreator</A> |
| can act as a factory for new resources. For example, a file system |
| folder could be a creator for other file system folders and files.</P> |
| <P STYLE="margin-bottom: 0.1cm">A new content object created by |
| the XContentCreator implementation can be considered as an <I>empty |
| hull</I> for a content object of a special type. So this new |
| content object may need to be filled with some property values in |
| order to become fully functional. For example, a file system |
| folder could require a name, which is represented by the property |
| "Title" in the UCB. The interface XContentCreator offers |
| ways to determine what contents can be created and what properties |
| need to be set to get them alive. You may also obtain information |
| on the general kind (FOLDER, DOCUMENT, LINK) of that objects. |
| After all required property values are set, the creation process |
| needs to be committed. This is done using the command <B>insert</B>. |
| Note that this command is always executed at the new content, not |
| at the content creator! This is because the creator is not |
| necessarily the parent of the new content. For a description of |
| the insert-command refer to section <A HREF="#SetDataStream">Setting |
| (storing) the content data stream of a UCB Document Content</A>. |
| One noticeable fact here is that the flag <I>ReplaceExisting</I> |
| in the insert-command argument usually will be false (the caller |
| generally does not want to destroy an already existing resource). |
| The insert-command implementation will make the new content |
| persistent in the appropriate storage medium.</P> |
| <P STYLE="margin-bottom: 0.1cm">To create a new resource:</P> |
| <UL> |
| <LI><P STYLE="margin-bottom: 0.1cm">Obtain the interface |
| XContentCreator from a suitable UCB Content.</P> |
| <LI><P STYLE="margin-bottom: 0.1cm">Call createNewContent at the |
| content creator. Supply information on the type of content to |
| create with the arguments.</P> |
| <LI><P STYLE="margin-bottom: 0.1cm">Obtain and set the property |
| values that are mandatory for the content just created.</P> |
| <LI><P STYLE="margin-bottom: 0.1cm">Let the new content execute |
| the command insert to complete the creation process.</P> |
| </UL> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 1 (C++)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| { |
| uno::Reference< ucb::XContent > xContent = ... |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Create a new file system file object... |
| ///////////////////////////////////////////////////////////////////// |
| |
| // Obtain content creator interface. |
| uno::Reference< XContentCreator > xCreator( |
| xContent, uno::UNO_QUERY ); |
| |
| if ( !xCreator.is() ) |
| ... error ... |
| |
| // Note: The data for aInfo may have been obtained using |
| // XContentCreator::queryCreatableContentsInfo(). |
| |
| ucb::ContentInfo aInfo; |
| aInfo.Type = rtl::OUString::createFromAscii( |
| "application/vnd.sun.staroffice.fsys-file" ); |
| aInfo.Attributes = 0; |
| |
| // Create new, empty content. |
| uno::Reference< ucb::XContent > xNewContent |
| = xCreator->createNewContent( aInfo ); |
| |
| if ( !xNewContent.is() ) |
| ... error ... |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Set mandatory properties... |
| ///////////////////////////////////////////////////////////////////// |
| |
| // Obtain a name for the new file. |
| rtl::OUString aFilename = ... |
| |
| // Define property value sequence. |
| uno::Sequence< beans::PropertyValue > aProps( 1 ); |
| aProps[ 0 ].Name = rtl::OUString::createFromAscii( "Title" ); |
| aProps[ 0 ].Handle = -1; // n/a |
| aProps[ 0 ].Value <<= aFilename; |
| |
| try |
| { |
| // Execute command "setPropertyValues". |
| executeCommand( xNewContent, |
| rtl::OUString::createFromAscii( |
| "setPropertyValues" ), |
| makeAny( aProps ); |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Write the new file to disk... |
| ///////////////////////////////////////////////////////////////////// |
| |
| // Obtain document data for the new file. |
| uno::Reference< io::XInputStream > xData = ... |
| |
| // Fill argument structure... |
| ucb::InsertCommandArgument aArg; |
| aArg.Data = xData; |
| aArg.ReplaceExisting = false; |
| |
| try |
| { |
| // Execute command "insert". |
| executeCommand( xNewContent, |
| rtl::OUString::createFromAscii( "insert" ), |
| makeAny( aArg ) ); |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| }</PRE> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 2 (C++, using UCBHELPER library)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| { |
| ::ucb::Content aContent = ... |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Create, setup and commit a new file system file object... |
| ///////////////////////////////////////////////////////////////////// |
| |
| // Obtain a name for the new file. |
| rtl::OUString aFilename = ... |
| |
| // Obtain document data for the new file. |
| uno::Reference< io::XInputStream > xData = ... |
| |
| uno::Sequence< rtl::OUString > aProps( 1 ); |
| aProps[ 0 ] = rtl::OUString::createFromAscii( "Title" ); |
| |
| uno::Sequence< uno::Any > aValues( 1 ); |
| aValues[ 0 ] <<= aFilename; |
| |
| ::ucb::Content aNewContent; |
| try |
| { |
| aContent.insertNewContent( |
| rtl::OUString::createFromAscii( |
| "application/vnd.sun.staroffice.fsys-file" ), |
| aProps, |
| aValues, |
| xData, |
| aNewContent ); // out parameter! |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| }</PRE><P> |
| <BR> |
| </P> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100% BGCOLOR="#666699"> |
| <H3 ALIGN=LEFT STYLE="margin-top: 0cm; text-decoration: none"><A NAME="DeleteResource"></A> |
| <FONT COLOR="#ffffff"><FONT SIZE=4>Deleting a resource</FONT></FONT></H3> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100%> |
| <P STYLE="margin-bottom: 0.1cm">Executing the command <B>delete</B> |
| on a UCB Content will destroy the resource it represents. This |
| command takes a boolean parameter. If it is set to <I>true</I>, |
| the resource will be immediately and physically destroyed. <B>The |
| command will also destroy all existing sub resources of the |
| resource to be destroyed! </B>If <I>false</I> is passed to this |
| command, then the caller only wants to delete the resource |
| "logically." This means that the resource can be either |
| restored or physically destroyed later. A soft-deleted Content |
| needs to support the command <B>undelete</B>. This command will |
| bring it back to life. The implementation of the delete command |
| can ignore the parameter and may opt to always destroy the |
| resource physically.</P> |
| <P STYLE="margin-bottom: 0.1cm"><B>Note: Currently we do not have |
| a Trash Service that could be used by UCB clients to manage |
| soft-deleted Contents.</B></P> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 1 (C++)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| { |
| uno::Reference< ucb::XContent > xContent = ... |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Destroy a resource physically... |
| ///////////////////////////////////////////////////////////////////// |
| |
| try |
| { |
| sal_Bool bDeletePhysically = sal_True; |
| |
| // Execute command "delete". |
| executeCommand( xContent, |
| rtl::OUString::createFromAscii( "delete" ), |
| makeAny( bDeletePhysically ) ); |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| }</PRE> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 2 (C++, using UCBHELPER library)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| { |
| ::ucb::Content aContent = ... |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Destroy a resource physically... |
| ///////////////////////////////////////////////////////////////////// |
| |
| try |
| { |
| sal_Bool bDeletePhysically = sal_True; |
| |
| // There is no special wrapper method for this simple command. |
| // Use generic command invocation method. |
| aContent.executeCommand( |
| rtl::OUString::createFromAscii( "delete" ), |
| makeAny( bDeletePhysically ) ); |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| }</PRE><P> |
| <BR> |
| </P> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100% BGCOLOR="#666699"> |
| <H3 ALIGN=LEFT STYLE="margin-top: 0cm; text-decoration: none"><A NAME="TransferResource"></A> |
| <FONT COLOR="#ffffff"><FONT SIZE=4>Copying, Moving and Creating |
| links to a resource</FONT></FONT></H3> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100%> |
| <P STYLE="margin-bottom: 0.1cm">Copying, moving and creating links |
| to a resource works a little differently from the other operations |
| available for UCB Contents. This is because there are <B>three UCB |
| Contents</B> involved in these operations (the source object, the |
| target folder, the target object), not just one. There may even |
| participation by <B>two Content Providers</B> (e.g., when moving a |
| file located on an FTP server to the local file system of a |
| workstation). Each implementation of the <A HREF="http://api.openoffice.org/common/ref/com/sun/star/ucb/UniversalContentBroker.html">UniversalContentBroker</A> |
| service must support the <A HREF="http://api.openoffice.org/common/ref/com/sun/star/ucb/XCommandProcessor.html">XCommandProcessor</A> |
| interface. This command processor must implement the command |
| <B>globalTransfer</B> that can be used to copy and move UCB |
| Contents and to create links to UCB Contents. The command takes an |
| argument of type <A HREF="http://api.openoffice.org/common/ref/com/sun/star/ucb/GlobalTransferCommandArgument.html">GlobalTransferCommandArgument</A>. |
| To copy, move or create a link to a resource simply execute the |
| globalTransfer command at the UCB.</P> |
| <P STYLE="margin-bottom: 0.1cm"><B>Note:</B> The reasons for the |
| different handling are mainly technical. We did not want to force |
| every single implementation of the transfer command of a UCB |
| Content to be able to accept (nearly) all types of Contents. |
| Instead, we wanted to have one single implementation that would be |
| able to handle all types of Contents. However, the UCBHELPER |
| library encapsulates this exception and offers a special method |
| for this functionality at the Content helper class. It must be |
| called at the UCB Content representing the target folder of the |
| operation.</P> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 1 (C++)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| { |
| rtl::OUString aSourceURL = ... // URL of the source object |
| rtl::OUString aTargetFolderURL = ... // URL of the target folder |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Obtain access to UCB... |
| ///////////////////////////////////////////////////////////////////// |
| |
| uno::Reference< uno::XInterface > xUCB = ... |
| |
| // Obtain XCommandProcessor interface from UCB... |
| uno::Reference< ucb::XCommandProcessor > xCmdProc( |
| xUCB, uno::UNO_QUERY ); |
| if ( !xProcessor.is() ) |
| ... error ... |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Copy a resource to another location... |
| ///////////////////////////////////////////////////////////////////// |
| |
| try |
| { |
| ucb::GlobalTransferCommandArgument aArg; |
| aArg.TransferCommandOperation = TransferCommandOperation_COPY; |
| aArg.SourceURL = aSourceURL; |
| aArg.TargetURL = aTargetFolderURL; |
| |
| // object keeps it current name |
| aArg.NewTitle = rtl::OUString(); |
| |
| // fail, if object with same name exists in target folder |
| aArg.NameClash = NameClash::ERROR; |
| |
| // Let UCB execute the command "globalTransfer". |
| executeCommand( xCmdProc, |
| rtl::OUString::createFromAscii( |
| "globalTransfer" ), |
| makeAny( aArg ) ); |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| }</PRE> |
| <HR SIZE=1 NOSHADE> |
| <P ALIGN=LEFT STYLE="margin-bottom: 0.1cm"><FONT SIZE=4><B>Example |
| 2 (C++, using UCBHELPER library)</B></FONT></P> |
| <HR SIZE=1 NOSHADE> |
| <PRE>using namespace com::sun::star; |
| |
| { |
| ::ucb::Content aSourceContent = ... // source content |
| ::ucb::Content aTargetFolderContent = ... // target folder content |
| |
| ///////////////////////////////////////////////////////////////////// |
| // Copy a resource... |
| ///////////////////////////////////////////////////////////////////// |
| |
| ::ucb::Content aNewContent; |
| try |
| { |
| aTargetFolderContent.insertNewContent( |
| aSourceContent, |
| InsertOperation_COPY, // MOVE | LINK |
| aNewContent ); // out parameter! |
| } |
| catch ( ucb::CommandAbortedException const & ) |
| { |
| ... error ... |
| } |
| catch ( uno::Exception const & ) |
| { |
| ... error ... |
| } |
| }</PRE><P> |
| <BR> |
| </P> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100%> |
| <HR SIZE=1 NOSHADE> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100%> |
| <HR SIZE=1 NOSHADE> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100% BGCOLOR="#666699"> |
| <P ALIGN=LEFT><FONT COLOR="#ffffff">Author: <A HREF="mailto:kai.sommerfeld@germany.sun.com">Kai |
| Sommerfeld</A> ($Date: 2002/08/29 10:43:19 $)<BR><I>Copyright 2001 |
| OpenOffice.org Foundation. All Rights Reserved.</I></FONT> |
| </P> |
| </TD> |
| </TR> |
| <TR> |
| <TD WIDTH=100%> |
| <HR SIZE=1 NOSHADE> |
| </TD> |
| </TR> |
| </TABLE> |
| <HR SIZE=3 NOSHADE> |
| </body> |
| </HTML> |