--- Begin Message ---
Hi Rony,

if you have a look at

http://installation.openoffice.org/source/browse/installation/wizards/com/sun/star/wizards/db/DBMetaData.java

you will find out how it works. Consecutively you I copied the relevant methods.



public XHierarchicalNameAccess getFormDocuments(){
XFormDocumentsSupplier xFormDocumentSuppl = (XFormDocumentsSupplier) UnoRuntime.queryInterface(XFormDocumentsSupplier.class, xModel); XHierarchicalNameAccess xFormHier = (XHierarchicalNameAccess) UnoRuntime.queryInterface(XHierarchicalNameAccess.class, xFormDocumentSuppl.getFormDocuments());
    return xFormHier;
}

public boolean hasFormDocumentByName(String _sFormName){
XFormDocumentsSupplier xFormDocumentSuppl = (XFormDocumentsSupplier) UnoRuntime.queryInterface(XFormDocumentsSupplier.class, xModel); XNameAccess xFormNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xFormDocumentSuppl.getFormDocuments());
    return xFormNameAccess.hasByName(_sFormName);
}


public void addFormDocument(XComponent _xComponent){
    XHierarchicalNameAccess _xFormDocNameAccess = getFormDocuments();
    addDatabaseDocument(_xComponent, _xFormDocNameAccess, false);
}



/**
* adds the passed document as a report or a form to the database. Afterwards the document is deleted.
 * the document may not be open
 * @param xComponent
 * @param _bIsForm describes the type of the document: "form" or "report"
 */
public void addDatabaseDocument(XComponent _xComponent, XHierarchicalNameAccess _xDocNameAccess, boolean _bcreateTemplate){
try {
    PropertyValue[] aDocProperties;
XModel xDocumentModel = (XModel) UnoRuntime.queryInterface(XModel.class, _xComponent);
    String sPath = xDocumentModel.getURL();
    String basename = FileAccess.getBasename(sPath, "/");
XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, _xComponent);
    _xComponent.dispose();
    xCloseable.close(false);
    if (_bcreateTemplate)
        aDocProperties = new PropertyValue[5];
    else
        aDocProperties = new PropertyValue[4];
    aDocProperties[0] = Properties.createProperty("Name", basename);
aDocProperties[1] = Properties.createProperty("Parent", _xDocNameAccess);
    aDocProperties[2] = Properties.createProperty("URL", sPath);
aDocProperties[3] = Properties.createProperty("DocumentTitle", basename);
    if (_bcreateTemplate)
aDocProperties[4] = Properties.createProperty("AsTemplate", new Boolean(_bcreateTemplate)); XMultiServiceFactory xDocMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, _xDocNameAccess); Object oDBDocument = xDocMSF.createInstanceWithArguments("com.sun.star.sdb.DocumentDefinition", aDocProperties); XHierarchicalNameContainer xHier = (XHierarchicalNameContainer) UnoRuntime.queryInterface(XHierarchicalNameContainer.class, _xDocNameAccess);
    String sdocname = Desktop.getUniqueName(_xDocNameAccess, basename);
    xHier.insertByHierarchicalName(sdocname, oDBDocument);
XInterface xInterface = (XInterface) xMSF.createInstance("com.sun.star.ucb.SimpleFileAccess"); XSimpleFileAccess xSimpleFileAccess = (XSimpleFileAccess) UnoRuntime.queryInterface(XSimpleFileAccess.class, xInterface);
    xSimpleFileAccess.kill(sPath);
} catch (Exception e) {
    e.printStackTrace(System.out);
}}



public XComponent[] openDatabaseDocument(String _docname, boolean _bAsTemplate, boolean _bOpenInDesign, XHierarchicalNameAccess _xDocuments){
    XComponent[] xRetComponent = new XComponent[2];
    try {
XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, _xDocuments);
        PropertyValue[] aPropertyValues = new PropertyValue[4];
aPropertyValues[0] = Properties.createProperty("OpenMode", _bOpenInDesign ? "openDesign": "open" ); aPropertyValues[1] = Properties.createProperty("ActiveConnection", this.DBConnection); aPropertyValues[2] = Properties.createProperty("DocumentTitle", _docname); aPropertyValues[3] = Properties.createProperty("AsTemplate", new Boolean(_bAsTemplate)); XHierarchicalNameContainer xHier = (XHierarchicalNameContainer) UnoRuntime.queryInterface(XHierarchicalNameContainer.class, _xDocuments);
        if (xHier.hasByHierarchicalName(_docname)){
xRetComponent[0] = (XComponent)UnoRuntime.queryInterface(XComponent.class, xHier.getByHierarchicalName(_docname)); xRetComponent[1] = xComponentLoader.loadComponentFromURL(_docname, "", 0, aPropertyValues);
        }
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
    return xRetComponent;
}

...

Hope this helps you further

Berend

Rony G. Flatscher schrieb:
Hi there,

tried to get some hints via dev@dba.openoffice.org, but so far no one
reacted to a (at least I have thought so) brief and easy to answer
question. Would there be someone in this group who could give some
hints, links, examples for storing forms in an odb-file?

TIA,

---rony


-------- Original Message --------
Subject:        [dba-dev] Howto question about storing a form with the
datatabase ...
Date:   Thu, 25 Jan 2007 10:16:12 +0100
From:   Rony G. Flatscher <[EMAIL PROTECTED]>
Reply-To:       dev@dba.openoffice.org
To:     dev@dba.openoffice.org



Hi there,

does someone know a link or has some hints to donate ;) about how to
proceed with storing a form with the database (like a "RGFTest.odb"
containing a table definition, form and report definitions, which partly
should be created programmatically)?

Any pseudo-code outline referring to the starting class (and service
manager to use) would be sufficient and highly appreciated!

TIA,

---rony




---------------------------------------------------------------------
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]



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

Reply via email to