Hal Vaughan wrote:
...
Has a simpler interface for the API been set up for versions 2.0 and
higher (or 2.2 and those to come)? Or am I better off just leaving
things as they are and not trying to improve anything?
I'm no expert on OOo UNO API and just recently started working with OOo
2.2, but AFAICT things are just as complicated as ever, in fact perhaps
a bit more so as it seems to me they've added additional API and
deprecated some older stuff but it's still there.
This probably won't help you now (although it could be useful in the
future), but I've integrated Groovy with OOo, so macros can be written
with somewhat more pleasant and a lot terser syntax than with Java.
However the UNO API and OOo document models are just as cumbersome
either way.
http://www.ifcx.org/wiki/GroovyForOpenOffice.html
The current examples are direct conversions of the BeanShell examples,
but I'll be posting new macros I'm writing that look like this:
class UnoCategory {
static Object uno(Object unoObj, Class clazz)
{ UnoRuntime.queryInterface(clazz, unoObj) }
}
// This is the XModel for the currently active document.
def document = XSCRIPTCONTEXT.document
def doDump(elem) {
println '-------'
println elem
println ' types'
elem.uno(XTypeProvider).types.each { println it }
println ' services'
elem.uno(XServiceInfo)?.supportedServiceNames.each { println it }
println ' properties'
elem.uno(XPropertySet)?.propertySetInfo.properties.each { p ->
try {
println "${p.Name} = \
${elem.uno(XPropertySet).getPropertyValue(p.Name)}"
} catch (Exception e) {
println "Missing ${p.Name}? Exception: $e"
}
}
println ' text'
println elem.uno(XTextRange)?.string?.size()
println elem.uno(XTextRange)?.string
}
use (UnoCategory) {
def docText = document.uno(XTextDocument).text
def viewCursor =
document.currentController.uno(XTextViewCursorSupplier).viewCursor
def textCursor = docText.createTextCursorByRange(viewCursor)
println 'document.uno(XTextDocument):'
doDump(document.uno(XTextDocument))
println 'docText:'
doDump(docText)
println 'viewCursor:'
doDump(viewCursor)
println 'textCursor:'
doDump(textCursor)
def textEnum = textCursor.uno(XEnumerationAccess).createEnumeration()
def types = textEnum.uno(XTypeProvider).types
types.each { println it }
println textEnum
println textEnum.hasMoreElements()
def n = 0
while (textEnum.hasMoreElements()) {
println "${++n} :"
doDump(textEnum.nextElement())
}
} // End 'use (UnoCategory) {'
Jim
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]