| View previous topic :: View next topic |
| Author |
Message |
Faust Guest
|
Posted: Tue Jan 27, 2004 2:28 am Post subject: How to register an ImportFilter at runtime (via API?) |
|
|
Hi everybody!
I'm writing an application that is supposed to connect to a (remote) OOo server.
I have written an ImportFilter and would love to register it via appropriate API calls
at runtime (I don't want to specify the filter in the OOo configuration files).
Is that possible? I looked through the Developer's Guide, but I did find only hints that
didn't get me very far. Most sources (e.g. http://xml.openoffice.org/filter/) explain only
how to register filters via the configuration files (I'd like to avoid that).
Thanks for any hint!
Faust. |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Tue Jan 27, 2004 10:02 am Post subject: |
|
|
I think your problem of registering a filter is not much different than registering any new Service.
I have wondered for a long time if it is possible to register a new service on the fly.
One possible answer to your problem is to use the Configuration Manager API. I have done a number of experiments with that, including some resulting in useful end-results. (See UnoConnectionListener, Recent Files Changer, manipulation of the Add On menu / top level menus / toolbars with icons, etc.)
The problem with the Configuration Manager approach is that it appears that you must restart the office in order for the change to actually take effect.
Another possibility I have looked into is manipulation of the Registry directly via. the API. I have done some experiments. Here is one experimental test jig.
| Code: | Sub Main
oServiceManager = GetProcessServiceManager()
' MsgBox( oServiceManager.Dbg_Methods )
' MsgBox( oServiceManager.Dbg_Properties )
' MsgBox( oServiceManager.Dbg_SupportedInterfaces )
oReg = oServiceManager.Registry
' oReg = createUnoService( "com.sun.star.registry.SimpleRegistry" )
' oReg = createUnoService( "com.sun.star.registry.DefaultRegistry" )
' oReg = createUnoService( "com.sun.star.registry.NestedRegistry" )
' oReg = createUnoService( "com.sun.star.registry.ImplementationRegistration" )
' MsgBox( oReg.ImplementationName )
' MsgBox( oReg.Dbg_Methods + CHR(13)_
' + oReg.Dbg_Properties + CHR(13)_
' + oReg.Dbg_SupportedInterfaces )
' MsgBox( oReg.isValid() )
' MsgBox( oReg.isReadOnly() )
' MsgBox( oReg.getURL() )
oRegKey = oReg.getRootKey()
' Print oRegKey.getKeyType(""), oRegKey.getValueType()
' Print oRegKey.KeyName
' The Root key has four subkeys...
' /IMPLEMENTATIONS /SINGLETONS /SERVICES /Loader
' oRegKey = oRegKey.openKey( "/SERVICES" )
' oRegKey = oRegKey.openKey( "stardiv.vcl.control.Dialog" )
' oRegKey = oRegKey.openKey( "com.sun.star.text.GlobalSettings" )
Print oRegKey.KeyName, "", oRegKey.getKeyType(""), oRegKey.getValueType()
oKeyNames = oRegKey.getKeyNames()
Print LBound( oKeyNames ), UBound( oKeyNames )
For i = LBound( oKeyNames ) To UBound( oKeyNames )
Print oKeyNames(i)
Next
End Sub
|
The only way to get the active registry is the Registry property of OOo's service manager. I felt I had established that much in my early experiments.
The docs indicate that the registry is "layered". See the Background on Registry in the Developer's Guide. Scroll down to "Alternatives".
I am thinking that it might be possible to create a NestedRegistry object, and plug that one into the Service Manager's "Registry" property.
The NestedRegistry object supports two registries. Number 1 and Number 2. It provides a layered view of two registries. Registry 1 is read/write, and registry 2 is read only. One could then create a SimpleRegistry object to plug in to NestedRegistry as Number 1. Registry 2 would be the original registry object you had taken from the ServiceManager.Registry property. In effect, now the registry structure looks like this....
| Code: | ServiceManager.Registry is a NestedRegistry that layers two registries...
1. A SimpleRegistry connected to a newly created "temp" registry file on disk. (read/write)
2. The original value of the ServiceManager.Registry property (read-only). Since item 2 is the original registry, it is probably actually a NestedRegistry containing....
2.1 A SimpleRegistry connected to the registry files in the "user" directory of OOo. (read-write)
2.2 A SimpleRegistry connected to the registry files in the "shared" directory of OOo. (read-only)
|
Now you could make write calls to register new components and types into the service manager's registry. Everyone who uses the service manager to create any services would use whatever registry the service manager uses. So when the Type Detection needs to access your new Import Filter, it can just create it just like any other built-in service. Your "registry" file (item 1 above) is just a temporary registry file on disk, probably in a Temp folder. Or maybe instead of using SimpleRegistry, you can use something with a similar interface that keeps a small read-write registry only in memory.
It still may be necessary to modify the Configuration Manager in order to alter the Type Detection to recognize your new import filter, if you want automatic type recognition. (For instance, you've written a new filter that imports a PDF into a Drawing (like I have ambitions to do). You need ".pdf" to be recognized as a type that OOo knows how to open, just as it knows what to do with a ".doc" file.) Maybe for your situation you don't need to modify the Type Detection?
There is yet another approach.
If you scroll down further in the Developer's Guide to section 4.9.6, you'll see that it describes how to modify the service manager with a special registry.
I wish I could just give you a canned, working, documented solution. Some of this is still over my head. I'm learning as fast as I can. I haven't dabbled in some of this now for awhile. (It's too distracting and fun to just play on OOoForum rather than do "hard work".)
One of my ultimate goals is to be able to distribute a document that....
1. The user opens, clicks an "Install" button.
2. Basic macro in document creates new ".jar" (java binary archive) or new ".py" (python source) files in the uno-components folder. I already have written basic code to unpack Base64 encoded text to arbitrary binary, even binary of any size! such that a Basic program could create whatever binary files are necessary.
3. Basic macro in document then modifies Service Manager, or its registry such that new component is now actually registered. (And stay's registered next time OOo starts up.)
4. Basic macro in document uses Configuration Manager API to install Add On components, with toolbar icons. (I have this working already.)
The net effect is... Distribute a new component written in a real programming langauge (i.e. Python or Java) yet it is trivially easy for the end user to install or un-install. No need to use pkgchk tool, command lines, etc.
Because a real programming language would be used, it would be possible to do things that cannot be done in Basic...
* Create new services (which can be instanted by anything, including even other basic macros)
* Create import/export filters
* Create Calc formula add-on's
* Create new chart types
* (...the possibilities enumerated in the Developer's Guide for adding new components...)
But also...
* Be able to use data structures (can't do this in basic)
* Be able to write complex algorithms (can't do this in basic without data structures) _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
Faust Guest
|
Posted: Fri Jan 30, 2004 5:48 am Post subject: |
|
|
Thanks for all the hints and ideas! Although I have to admit that I didn't understand all of them. I just started to explore the OOo world and have little experience (but I'm especially
proud of my dirty workaround for a bug concerning the mail-merge with MS Word documents - that doesn't work. Maybe I can post the workaround when I have some more time ;o)
Right now I'm trying to use the Configuration Management, I'll let you know if that
works.
Faust. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|