Hey,

I was thinking about first writing the original document to disk and later
if an unmerge is needed to just use "loadFromURL" with the path of the
original document to reload it.  However it doesn't get past the loading of
the XComponent.  The application freezes as a result and I need to kill the
soffice.bin process manually.

This is the code:



> public void loadFromURL(final String aURL, final
> com.sun.star.beans.PropertyValue aArguments[],String target) {
>         if(target == null){
>             target = "_self";
>         }
>         try {
>             XMultiComponentFactory serviceFactory =
> getOOoConnection().getComponentContext().getServiceManager();
>             xServiceFactory = (com.sun.star.lang.XMultiServiceFactory)
>                     UnoRuntime.queryInterface(
>                             com.sun.star.lang.XMultiServiceFactory.class,
> serviceFactory);
> 
>             if (xFrameWindow == null) {
>                 serviceFactory =
> getOOoConnection().getComponentContext().getServiceManager();
>                 removeAll();
>                 xFrameWindow =
> iConnection.createOfficeWindow(MyOOoBean.this);
>                 add(xFrameWindow.getAWTComponent());
>             }
>             if (aFrame == null) {
>                 com.sun.star.awt.XWindow xWindow =
>                         (com.sun.star.awt.XWindow)
> UnoRuntime.queryInterface(
>                                 com.sun.star.awt.XWindow.class,
> xFrameWindow.getUNOWindowPeer());
>                 xFrame =
> xServiceFactory.createInstance("com.sun.star.frame.Frame");
>                 aFrame = new Frame((com.sun.star.frame.XFrame)
> UnoRuntime.queryInterface(
>                         com.sun.star.frame.XFrame.class, xFrame));
>                 aFrame.initialize(xWindow);
>                 aFrame.setName(aFrame.toString());
> 
>                 // register the frame at the desktop
>                 com.sun.star.frame.XFrames xFrames =
>                         ((com.sun.star.frame.XFramesSupplier)
> UnoRuntime.queryInterface(
>                                 com.sun.star.frame.XFramesSupplier.class,
> getOOoDesktop())).getFrames();
>                 xFrames.append(aFrame);
>             }
>             xURLTransformer = (com.sun.star.util.XURLTransformer)
> UnoRuntime.queryInterface(
>                     com.sun.star.util.XURLTransformer.class,
>                    
> xServiceFactory.createInstance("com.sun.star.util.URLTransformer"));
> 
>             // get XComponentLoader from frame
>             com.sun.star.frame.XComponentLoader xLoader =
> (com.sun.star.frame.XComponentLoader)
>                    
> UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class,
> aFrame);
> 
>             if (xLoader == null) {
>                 throw new java.lang.RuntimeException(
>                         "com.sun.star.frame.Frame(" + aFrame +
>                                 ") without
> com.sun.star.frame.XComponentLoader");
>             }
> 
>             com.sun.star.beans.PropertyValue aArgs[] =
>                     addArgument(aArguments, new
> com.sun.star.beans.PropertyValue(
>                             "MacroExecutionMode", -1,
>                             new
> Short(com.sun.star.document.MacroExecMode.USE_CONFIG),
>                            
> com.sun.star.beans.PropertyState.DIRECT_VALUE));
> 
>             com.sun.star.lang.XComponent xComponent =
> xLoader.loadComponentFromURL(
>                     aURL, target, 0, aArgs); //2nd load doesn't get past
> this point resulting in a crash
> 
>             // nothing loaded?
>             if (xComponent == null && aDocument != null) {
>                 // reactivate old document
>                 if (aFrame != null && aFrame.getController() != null)
>                     aFrame.getController().suspend(false);
>                 aDocument.setModified(true);
> 
>                 // throw exception
>                 throw new java.io.IOException(
>                         "Can not load a document: \"" + aURL + "\"");
>             }
> 
>             // Get document's XModifiable interface if any.
>             xModel = (com.sun.star.frame.XModel)
> UnoRuntime.queryInterface(
>                             com.sun.star.frame.XModel.class, xComponent);
>             aTxtDocument = (XTextDocument)
> UnoRuntime.queryInterface(XTextDocument.class,xComponent);
>             XComponentContext xRemoteContext =
> com.sun.star.comp.helper.Bootstrap.bootstrap();
> 
>             aDocument = new OfficeDocument(xModel);
> 
>             //adding additional listeners to the frame
>             createBroadCaster();
> 
> 
>         } catch (NoConnectionException e) {
> 
>         }
>         catch (IllegalArgumentException e) {
>             e.printStackTrace();  //To change body of catch statement use
> File | Settings | File Templates.
>         } catch (IOException e) {
>             e.printStackTrace();  //To change body of catch statement use
> File | Settings | File Templates.
>         } catch (Exception e) {
>             e.printStackTrace();  //To change body of catch statement use
> File | Settings | File Templates.
>         } catch (java.io.IOException e) {
>             e.printStackTrace();  //To change body of catch statement use
> File | Settings | File Templates.
>         } catch (BootstrapException e) {
>             e.printStackTrace();  //To change body of catch statement use
> File | Settings | File Templates.
>         }
>     }
> 
> XComponentLoader xComponentLoader = (XComponentLoader)
> UnoRuntime.queryInterface(
>                     XComponentLoader.class,aFrame);
>                     PropertyValue[] myProperties = new PropertyValue[1];
>                     myProperties[0] = new PropertyValue();
>                     myProperties[0].Name = "Hidden";
>                     myProperties[0].Value = new Boolean(false);
> 
>                     loadFromURL(oriPath,myProperties,"_top"); //tried
> "_self","_default", "_parent", "_blank".
> }
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Sections-and-appending-documents-tp22312435p22697675.html
Sent from the openoffice - dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@openoffice.org
For additional commands, e-mail: dev-h...@openoffice.org

Reply via email to