I composed a python fragment used to insert the first item of Bibliography
databse into document. It is really simple one. If there is any
sophisticated implementation method thanks for telling me.


import uno

local=uno.getComponentContext()
resolver=local.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver",
local)
context=resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
desktop=context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop",
context)
document = desktop.loadComponentFromURL("file:///tmp/test.odt" ,"_blank", 0,
())

#Initialize the value of the bibliography's fields
Identifier=''
BibiliographicType=1
Address=''
Annote=''
Author=''
Booktitle=''
Chapter=''
Edition=''
Editor=''
Howpublished=''
Institution=''
Journal=''
Month=''
Note=''
Number=''
Organizations=''
Pages=''
Publisher=''
School=''
Series=''
Title=''
Report_Type=''
Volume=''
Year=''
URL=''
Custom1=''
Custom2=''
Custom3=''
Custom4=''
Custom5=''
ISBN=''

#Access to the bibliography database
rowset=context.ServiceManager.createInstanceWithContext("com.sun.star.sdb.RowSet",
context)
rowset.setPropertyValue("DataSourceName", "Bibliography")
rowset.setPropertyValue("CommandType", 2)
rowset.setPropertyValue("Command", "SELECT Identifier, Author, Title FROM
biblio")
rowset.execute()
if rowset.next():
    Identifier=rowset.getString(rowset.findColumn("Identifier"))
    Author=rowset.getString(rowset.findColumn("Author"))
    Title=rowset.getString(rowset.findColumn("Title"))

#Create a bibliography item
BIB_FIELDS = ('Identifier', 'BibiliographicType', 'Address', 'Annote',
'Author','Booktitle', 'Chapter', 'Edition', 'Editor', 'Howpublished',
'Institution','Journal', 'Month', 'Note', 'Number', 'Organizations',
'Pages', 'Publisher','School', 'Series', 'Title', 'Report_Type', 'Volume',
'Year', 'URL', 'Custom1','Custom2', 'Custom3', 'Custom4', 'Custom5', 'ISBN')

BIBLIOGRAPHIC_FIELDS = {}
for i in range(len(BIB_FIELDS)):
    BIBLIOGRAPHIC_FIELDS[BIB_FIELDS[i]] = i

DIRECT_VALUE =
uno.getConstantByName("com.sun.star.beans.PropertyState.DIRECT_VALUE")
PropertyValue = uno.getClass("com.sun.star.beans.PropertyValue")

ref = (Identifier, BibiliographicType, Address, Annote, Author,Booktitle,
Chapter, Edition, Editor, Howpublished, Institution,Journal, Month, Note,
Number, Organizations, Pages, Publisher,School, Series, Title, Report_Type,
Volume, Year, URL, Custom1,Custom2, Custom3, Custom4, Custom5, ISBN)

tmp = [ PropertyValue(field,0,ref[BIBLIOGRAPHIC_FIELDS[field]],DIRECT_VALUE)
for field in BIB_FIELDS ]

bib=document.createInstance("com.sun.star.text.textfield.Bibliography")
bibmaster=document.createInstance("com.sun.star.text.fieldmaster.Bibliography")
bib.Fields = tuple(tmp)
bib.attachTextFieldMaster(bibmaster)

#Insert the item into the document
document.Text.insertTextContent(document.Text.getEnd(), bib, False)



2009/8/21 Hexyl Chan <[email protected]>

> Thanks for your reminding. It works fine now.
>
> I have another question that is there any api support insert an reference
> into a writer document? Just like Insert > Indexes and tables >
> Bibliographic entry does.
>
> 2009/8/21 Juergen Schmidt <[email protected]>
>
> Hi,
>>
>> have you already connected successful to a running office process before?
>> If not i would suggest that you try this first. In your case you have to
>> start the office to listen on port 2083
>>
>> soffice
>> -accept=socket,host=localhost,port=2083;urp;StarOffice.ServiceManager
>>
>> When you have successfully connected you have the remote service manager
>> and can continue with it.
>>
>> Juergen
>>
>>
>> huang huang wrote:
>>
>>> Please bear with me-newbie.
>>>
>>> While there is a fragment of example that querying Bibliography database
>>> in
>>> java in Develop Guide, I am failed to convert it into python. The example
>>> uses a getRemoteServiceManager to create a RemoteServiceManager, but I do
>>> not know which should be
>>> corresponding in python-uno.
>>>
>>> My script is:
>>> import uno
>>> local = uno.getComponentContext()
>>> resolver =
>>>
>>> local.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver",
>>> local)
>>> context =
>>>
>>> resolver.resolve("uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager")
>>>
>>> It tells me that "com.sun.star.connection.NoConnectException: Connector :
>>> couldn't connect to socket (Success)"
>>>
>>> Any one can help me to correct the error or provider an example to access
>>> bibliography database directly?
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>

Reply via email to