OO-Snippets: Deploy files

Commons

Keywords/singletons/com.sun.star.utils.theMacroExpander, macrofield, micro deployment, addons, registry
LanguageOOBasic
ApplicationOffice
AuthorsPaolo Mantovani (initial)
Jürgen Schmidt
Daniel Boelzle
Tom Schindl
Supported Versions
Supported OS
Question I'm searching a way to deploy arbitrary files (for example a text file or whatever) with my Basic Add-ons

This is what I found in the dev guide:

========================================================================

4.9 Deployment Options for Components

- 4.9.1 UNO Package Installation

-- Package Structure

[....]

Arbitrary Files

Arbitrary files are copied into the UNO packages cache. You can, for instance, deploy an image for add-on menus with the package, or any other file needed by your component. The OpenOffice.org configuration is used to find out in which path this file is located in a particular installation

========================================================================

I'm able to navigate the configuration tree by API, but this sound not very clear to me.

Should I add an xml entry in the addon.xcu file ? how?

How can I retrieve the path of my arbitrary file by using the configuration API from Basic?

Or perhaps should I parse the uno.ini file to know the path of the packages cache ?

Answer

Add e.g. a string entry to your addons.xcu, using %origin%. The token %origin% will be replaced with the actual cache directory of the .xcufile, so you can point to a file next to your addon.xcu, e.g. %origin%/my_file.txt

You have to keep in mind that you get a macrofied url when retrieving

the string out of configuration, e.g.

vnd.sun.star.expand:$USER_UNO_PACKAGES_CACHE/my...../my_file.txt

If you need a file url, you have to

1. cut out the scheme-specific-part (everything behind vnd.sun.star.expand:)

2. decode that part (%xx etc)

3. expand the result using the macro expander object you get fromcomponent content: key is "/singletons/com.sun.star.util.theMacroExpander"

hope this helps, regards,

--Daniel

if you need your own configuration you should define and deploy your own configuration schemata (*.xcs) and an appropriate configuration file (*.xcu) with your component. It make no sense to reuse exsisting values in the Addons.xcu with maybe a different meaning but the same type you need.

Think about a special configuration schemata for your component.

Juergen

Code-Snippet-Listing (snippet-source)

REM  *****  BASIC  *****

' To run this example you should have installed 
' the SnippeCreator package
'http://www.openoffice.org/nonav/issues/showattachment.cgi/10649/SnippetCreator.zip

Sub MacroExpander_Example()
	
	'Load the "Tools" Library
	BasicLibraries.LoadLibrary("Tools")
	
	'retrieve the URL from the registry
	oKey = getRegistryKeyContent("org.openoffice.Office.Addons/AddonUI/Images/")
	oImage = oKey.getByName("org.openoffice.Office.addon.codeSnippetCreatorImage")
	sURL = oImage.UserDefinedImages.ImageSmallURL
	Print sURL
	
	'cut the vnd.sun.star.expand: part
	sURL = Join(Split(sURL, "vnd.sun.star.expand:"))
	Print sUrl

	'Expand the macrofield expression
	oSM = getProcessServiceManager
	
	oMS = oSM.DefaultContext.getValueByName("/singletons/com.sun.star.util.theMacroExpander")	
	sURL = oMS.ExpandMacros(sURL)
	
	Print sURL
	
End Sub

Changelog

DateUserModification
0000-00-00paoInitial version

and