Estoy intentando migrar una aplicación que interactua con openOffice 2.2 para que funcione con la 3.2. Esta aplicación genera de forma dinámica unas macros, que se deben ejecutar al iniciar la aplicación para cargar una serie de menus que deben variar de forma dinámica por lo que no podemos crear las macros directamente en las librerías genericas de openoffice y tenemos que crearlas para cada documento.
El problema que tengo es que aunque el código en java se ejecuta sin problemas y no da ningún error, cuando el documento se abre las macros que se acaban de crear a través de java en el documento no aparecen.
El código en el que se generan las macros es el siguiente:
Código: Seleccionar todo
//String document = null;
//WordDocument documento = null;
PropertyValue[] props = new PropertyValue[4];
props[0] = new PropertyValue();
props[0].Name = "ReadOnly";
props[0].Value = new Boolean(false);
props[1] = new PropertyValue();
props[1].Name = "MacroExecutionMode";
props[1].Value = new Short( MacroExecMode.ALWAYS_EXECUTE_NO_WARN );
props[2] = new PropertyValue();
props[2].Name = "AsTemplate";
props[2].Value = new Boolean( false );
props[3] = new PropertyValue();
props[3].Name = "Hidden";
props[3].Value = new Boolean( false );
XComponent docComponent = null;
docComponent = loader.loadComponentFromURL( createUNOFileURL( document ), "_blank", 0, props);
OOoDocument ooodoc = new OOoDocument( docComponent, this );
documento = new WordDocument( ooodoc );
XModel docModel = (XModel)UnoRuntime.queryInterface( XModel.class, docComponent );
XFrame docFrame = docModel.getCurrentController().getFrame();
XCloseable closeable = (XCloseable)UnoRuntime.queryInterface(XCloseable.class, docComponent );
closeable.addCloseListener( ooodoc );
XModifiable modifiable = (XModifiable)UnoRuntime.queryInterface(XModifiable.class, docComponent );
modifiable.addModifyListener( ooodoc );
XDispatchProviderInterception interception = (XDispatchProviderInterception)UnoRuntime.queryInterface(
XDispatchProviderInterception.class, docFrame );
interception.registerDispatchProviderInterceptor( ooodoc );
opendocs.put( docComponent.toString(), documento );
String macros = generaMacros();//Devuelve las macros en un String separados por un token.
//docComponent = ooodoc.getComponent();
XPropertySet docProps = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, docComponent );
XLibraryContainer basicLibs = (XLibraryContainer)UnoRuntime.queryInterface(XLibraryContainer.class, docProps.getPropertyValue( "BasicLibraries" ) );
if (!basicLibs.hasByName("Standard")){
basicLibs.createLibrary("Standard");
}
Object stdlibraryObj = basicLibs.getByName( "Standard" );
XNameContainer stdlibraryObjNC = (XNameContainer)UnoRuntime.queryInterface( XNameContainer.class, stdlibraryObj );
XNameAccess stdlibraryObjNA = (XNameAccess)UnoRuntime.queryInterface( XNameAccess.class, stdlibraryObj );
String module = (String)stdlibraryObjNA.getByName( "macrosPlantillas" );
Format formatter = new SimpleDateFormat("dd/MM/yy - HH:mm:ss");
String s = formatter.format(new Date());
stdlibraryObjNC.removeByName( "macrosPlantillas" );
Collection modulos = new ArrayList();
String[] cad = module.split(INICIO_MODULO);
modulos.add(cad[0]+cad[1]);
for (int i=2;i<cad.length;i++) {
modulos.add(cad[i]);
}
boolean primero = false;
int i=0;
String modulo = "macrosPlantillas";
for(Iterator it = modulos.iterator();it.hasNext();) {
String macrosPlantillas = (String)it.next();
if(!primero) {
macrosPlantillas += "\r\nREM ***** AUTOMATICALLY ADDED (" + s + ") *****\r\n";
primero=true;
}else {
modulo = (new Integer(i)).toString();
try{
stdlibraryObjNC.removeByName( modulo );
}catch (Exception e) {
}
i++;
}
stdlibraryObjNC.insertByName( modulo, macrosPlantillas );
}
docComponent = ooodoc.getComponent();
XStorable storable = (XStorable)UnoRuntime.queryInterface( XStorable.class, docComponent );
storable.store();
ooodoc = (OOoDocument)((WordDocument)opendocs.get( documento.toString() )).getDocument();
if( ooodoc != null ){
logger.debug( "documento marcado para ser cerrado" );
ooodoc.setMarkedAsCloseable( true );
}
fireReleaseDocumentListeners( ooodoc );
com.sun.star.frame.XModel xModel = (com.sun.star.frame.XModel) UnoRuntime
.queryInterface(com.sun.star.frame.XModel.class, documento);
if (xModel != null) {
XModifiable modifyService = (XModifiable) UnoRuntime.queryInterface(XModifiable.class, documento);
if (modifyService != null) {
modifyService.setModified(false);
}
com.sun.star.util.XCloseable xCloseable = (com.sun.star.util.XCloseable)
UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class, xModel);
if (xCloseable != null) {
xCloseable.close(true);
opendocs.remove( documento.toString() );
} else {
com.sun.star.lang.XComponent xDisposeable = (com.sun.star.lang.XComponent)
UnoRuntime.queryInterface(com.sun.star.lang.XComponent.class, xModel);
if (xDisposeable != null) {
xDisposeable.dispose();
}
}
}
Muchas gracias.