| View previous topic :: View next topic |
| Author |
Message |
manutudescends General User

Joined: 21 Nov 2005 Posts: 25 Location: Toulouse, France
|
Posted: Mon Mar 06, 2006 9:12 am Post subject: [TUTO]Embedding OOo in java using nativeView! |
|
|
The aim of this tutorial is to show how it's possible to embed OpenOffice.org in a java application without using OfficeBean or OOoBean.
First step : compilation of nativeview.dll.
-> copy nativeview.c in the parent directory of your .class nativeview.class.
-> generate nativeview.h using javah -jni Directory.NativeView
-> rename method of NativeView.c using names of NativeView.h
->Create a release Visual C++ project
--> Add NativeView.h, NativeView.c, jni.h, jni_md.h, jawt_md.h, jawt.h to project.
(jni.h, jni_md.h, jawt_md.h, jawt.h can be founded in java directory)
--> Make Compilation.
--> copy nativeview.dll in the parent directory of your .class nativeview.class.
-->copy awt.dll, java.dll, jawt.dll, jvm.dll, verify.dll (witch can be founded in java directory) in the same directory that nativeview.dll
Second step: write your classes.
this is an example of a java.awt.panel witch contain OpenOffice
| Code: |
public class OOoTest extends Panel{
private static final long serialVersionUID = 1L;
private NativeView nativeView;
private OOoTest2 oooFrame;
public OOoTest(Container parent) throws Exception{
// setVisible necessaire pour le nativeView
// setFocusable necessaire pour le nativeView
this.setVisible(true);
this.setFocusable(true);
parent.setName("OOoFrame");
// composant open office
nativeView = new NativeView();
parent.add(nativeView);
parent.setSize(800,600);
nativeView.setVisible(true);
nativeView.setSize(800,600);
// initialisation du composant OpenOffice
oooFrame = new OOoTest2(nativeView,parent.getName());
oooFrame.createFrame();
oooFrame.loadDocument("private:factory/swriter");
public void close(){
System.err.println("fermeture de la AWT_FRAME");
try {
// fermeture de la connexion et de la xFrame
oooFrame.shutdown();
} catch (Exception e) {
e.printStackTrace();
}
}
}
|
| Code: | public class OOoTest2 {
public OOoTest2(NativeView vueNative, String frameName) throws Exception{
nativeView = vueNative;
..........make connect!
XMultiComponentFactory xMCF =....
xMultiServiceFactory =.....
xComponentContext = ......
xDesktop = .....
nativeView.setVisible(true);
}
public void createFrame() throws Exception{
xFrame = (XFrame)UnoRuntime.queryInterface(XFrame.class,
xMSF.createInstance("com.sun.star.frame.Frame"));
xToolkit =(XToolkit)UnoRuntime.queryInterface(
XToolkit.class,xMSF.createInstance("com.sun.star.awt.Toolkit") );
// initialise le xChildFactory
XSystemChildFactory xChildFactory =(XSystemChildFactory)UnoRuntime.queryInterface(
XSystemChildFactory.class, xToolkit);
Integer handle = nativeView.getHWND();
short systeme = (short)nativeView.getNativeWindowSystemType();
byte[] procID = new byte[0];
xWindowPeer = xChildFactory.createSystemChild((Object)handle,procID, systeme);
xWindow = (XWindow)UnoRuntime.queryInterface(XWindow.class,xWindowPeer);
xFrame.initialize( xWindow );
XFramesSupplier xTreeRoot =(XFramesSupplier)UnoRuntime.queryInterface(
XFramesSupplier.class,xDesktop );
XFrames xChildContainer = xTreeRoot.getFrames();
xChildContainer.append(xFrame);
xWindow.setVisible(true);
xFrame.setName(XFrameName);
xWindow.setVisible(true);
}
public void loadDocument(String url) throws Exception{
// xComponentLoader qui permet de charger un document
XComponentLoader xComponentLoader = (XComponentLoader)UnoRuntime.queryInterface(XComponentLoader.class, xDesktop );
// on charge le document et on récupère le xComponent
xComponent = xComponentLoader.loadComponentFromURL(url,xFrame.getName(),FrameSearchFlag.CHILDREN, null);
// initialisation du xModel
xModel = (XModel)UnoRuntime.queryInterface(XModel.class, xComponent);
// initialisation du xController
xController = xFrame.getController();
}
public void save(String url) throws IOException{
if (xController != null || xModel != null){
XStorable xStore = (XStorable)UnoRuntime.queryInterface(
XStorable.class,xModel);
xStore.storeToURL(url,null);
}
else {
// erreur
}
}
public void shutdown() throws Exception {
// disable nativeView
nativeView.setVisible(false)
// close the connection
if (connexion!=null){
System.out.println("femeture de la connexion");
connexion.closeConnection();
}
}
}
|
Last edited by manutudescends on Wed Mar 08, 2006 1:29 am; edited 8 times in total |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
Filippo Machi General User

Joined: 06 Jun 2007 Posts: 11
|
Posted: Thu Jun 07, 2007 2:23 am Post subject: Remote connection |
|
|
I succeded in using nativeview.dll with the DeskView example showed in Developer's Guide chapter 6. At the beginning I used this kind of local connection
String remoteOfficeUrl="uno:socket,host=192.168.35.119,port=2002;urp;StarOffice.ServiceManager";
Object initialObject = xUrlResolver.resolve(remoteOfficeUrl);
...
and everything works. Hovewer, If I tryed to use a remote connection, that's the OpenOffice serve is on another pc, no Writer Gui is showed...
I wonder wether it's possible to use nativeview.dll to connect to a remote server.
Could anyone help me?
thanks a lot
bye
Filippo |
|
| 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
|