Hi Stefan,

I copied some C++ code from dbaccess/source/filter/migration/cfgimport.cxx The difference is that it uses the document container as servicefactory

I hope this helps a little bit.

Best regards,

Ocke


Stefan Schmid wrote:::rtl::OUString sServiceName(SERVICE_SDB_DOCUMENTDEFINITION);
Sequence< Any > aArguments(3);
PropertyValue aValue;
// set as folder
aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name"));
aValue.Value <<= m_sBookmarkName;
aArguments[0] <<= aValue;
//parent
aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Parent"));
aValue.Value <<= xNames;
aArguments[1] <<= aValue;

aValue.Name = PROPERTY_URL;
aValue.Value <<= m_sDocumentLocation;
aArguments[2] <<= aValue;

Reference<XMultiServiceFactory> xORB(xNames,UNO_QUERY);
if ( xORB.is() )
{
Reference<XInterface> xComponent = xORB->createInstanceWithArguments(SERVICE_SDB_DOCUMENTDEFINITION,aArguments);
Reference<XNameContainer> xNameContainer(xNames,UNO_QUERY);
if ( xNameContainer.is() )
xNameContainer->insertByName(m_sBookmarkName,makeAny(xComponent));
}


Hello!!
I have a problem with storing an existing Writer-form document in a db file. 
There is a small chapter in the Developers Guide about this issue (Forms and 
Reports p.842). But I couldn’t get my program work with the information 
provided there and the API idl …

The following program fails to create the DocumentDefinition, which should be 
filled with the form document to store. Afterwards it should be inserted into 
DocumentContainer of the db-file where the forms are stored.

Although I provide exactly the properties shown in the Developers Guide, the 
DocumentDefinition is not created.

I would be glad, if someone could help me.

Greets Stefan


CODE (ooRexx):

/* get the service manager */
xContext = UNO.connect()
XMcf = xContext~getServiceManager

/* retrieve the DatabaseContext and get its XNameAccess interface */
xNameAccess = xMcf~createInstanceWithContext(-
        "com.sun.star.sdb.DatabaseContext", xContext)~XNameAccess

/* we use the mysql-test data sorce */
dataSource = xNameAccess~getByName("mysql-test")

/* retrieve the XDocumentDataSource interface of the data source */
xDocumentDataSource = dataSource~XDocumentDataSource
/* get the attribute 'DatabaseDocument' */
xOfficeDatabaseDocument = xDocumentDataSource~getDatabaseDocument


xFormDocumentsSupplier = xOfficeDatabaseDocument~XFormDocumentsSupplier
formDocuments = xFormDocumentsSupplier~getFormDocuments

say formDocuments~TOSTRING

/* show stored forms */ DO n OVER formDocuments~getElementNames
        say n
END

/* get the connection */

/* get the service manager */
xContext = UNO.connect()
XMcf = xContext~getServiceManager
/* retrieve the DatabaseContext and get its XNameAccess interface */
xNameAccess = xMcf~createInstanceWithContext(-
        "com.sun.star.sdb.DatabaseContext", xContext)~XNameAccess
/* we use the mysql-test data sorce */
dataSource = xNameAccess~getByName("mysql-test")
/* query for the XDataSource interface of the data source */
xDataSource = dataSource~XDataSource
/* simple way to connect - hard code (usr,pw) */
xConnection = xDataSource~getConnection("stefan","apple");



xFormDocs = xFormDocumentsSupplier~getFormDocuments

props = bsf.createArray(.UNO~propertyValue,3)
props[1] = .UNO~PropertyValue~new
props[1]~Name = "Name"
props[1]~Value = "formtest"
props[1]~Name = "ActiveConnection"
props[1]~Value = xConnection
props[1]~Name = "URL"
props[1]~Value = "file:///c:/odbfiles/test.odt"

oDocDef = 
XMcf~createInstanceWithArgumentsAndContext("com.sun.star.sdb.DocumentDefinition",
 props, xContext)

xFormDocs~insertByName("formtest", oDocDef)


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to