Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 149457

Summary: [OLE] Code Snippset Word in an applet doesn't work
Product: [Eclipse Project] Platform Reporter: Frederik JOLY <fjoly>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WONTFIX QA Contact: Felipe Heidrich <eclipse.felipe>
Severity: normal    
Priority: P3 CC: snorthov
Version: 3.2Keywords: triaged
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug

Description Frederik JOLY CLA 2006-07-03 09:47:53 EDT
I'm trying to embed word in an applet following http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet157.java

It works when run from the applet viewer.

But when I try to call it from a web page, Word doesn't appear (but Word is present as the shorcuts are working, ctrl+f for find....)

the code is as follow :


/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package com.sopra.j2eefwk4i.web.actions.bean.saphir;

/*
 * example snippet: Embed Word in an applet (win32 only)
 *
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 * 
 * @since 3.0
 */
	
import java.applet.Applet;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
	 
public class WordApplet extends Applet {
	
	org.eclipse.swt.widgets.Display display;
	org.eclipse.swt.widgets.Shell swtParent;
	java.awt.Canvas awtParent;
	org.eclipse.swt.ole.win32.OleClientSite site;
	
	String javaHome=System.getProperty("java.home");
	String osArch=System.getProperty("os.arch");
	static String status1=null;
	static String status2=null;
	static String status3=null;	
	Thread thread=null;
	
public void init () {
	super.init();
	URL codeBase=this.getCodeBase();
	try {
		installFile(this,new URL(codeBase, "swt-win32-3139.dll"), javaHome+"\\lib\\ext\\x86\\swt-win32-3139.dll");
		System.load(javaHome+"\\lib\\ext\\x86\\swt-win32-3139.dll");
		System.err.println("loading file " + javaHome+"\\lib\\ext\\x86\\swt-win32-3139.dll"); 
		installFile(this,new URL(codeBase, "swt-gdip-win32-3139.dll"), javaHome+"\\lib\\ext\\x86\\swt-gdip-win32-3139.dll");
		System.load(javaHome+"\\lib\\ext\\x86\\swt-gdip-win32-3139.dll");
        System.err.println("loading file " + javaHome+"\\lib\\ext\\x86\\swt-gdip-win32-3139.dll"); 
		installFile(this,new URL(codeBase, "swt-awt-win32-3139.dll"), javaHome+"\\lib\\ext\\x86\\swt-awt-win32-3139.dll");
		System.load(javaHome+"\\lib\\ext\\x86\\swt-awt-win32-3139.dll");
	} catch (Exception e) {
		e.printStackTrace();
	}
	launchWord();
}

   protected static void installFile(Applet applet, URL sourceUrl, String destFileName)
   { 
     File destFile=new File(destFileName);
     if (!destFile.exists())
       try
       { 
         System.err.println("installing file " + destFileName); 
         destFile.getParentFile().mkdirs();
         URLConnection connection=sourceUrl.openConnection();
         InputStream is=connection.getInputStream();
         FileOutputStream fos=new FileOutputStream(destFile);
         byte[] buff = new byte[8192];
         BufferedInputStream in = new BufferedInputStream(is, buff.length);
         BufferedOutputStream out = new BufferedOutputStream(fos, buff.length);
         int i;
         int count = 0;
         while ((i = in.read(buff,0,buff.length)) != -1)
         { out.write(buff,0,i);
           count += i;
        }  
        applet.showStatus(count+" bytes copied ...");
         in.close();
         out.close();
         status1="The javatwain library has been downloaded. To finish the" ;
         status2="installation, you have to close the browser now. Reopen ";
         status3="the browser to run the scanner application."; 
       }
       catch (Exception exception)
       { 
         exception.printStackTrace();
         applet.showStatus(exception.toString());
       }
     else 
     { 
       System.err.println("file " + destFileName + " already exists"); 
      status1="The javatwain library has been on your computer already";
       status2="No installation is needed";
     } 
   } 
 

/**
 * 
 */
private void launchWord() {
	thread = new Thread (new Runnable () {
		public void run () {
			setLayout(new java.awt.GridLayout (1, 1));
			awtParent = new java.awt.Canvas ();
			add (awtParent);
			display = new org.eclipse.swt.widgets.Display ();
			awtParent.setVisible(true);
			awtParent.addNotify();
			swtParent = org.eclipse.swt.awt.SWT_AWT.new_Shell (display, awtParent);
			swtParent.setLayout (new org.eclipse.swt.layout.FillLayout ());
			org.eclipse.swt.ole.win32.OleFrame frame = new org.eclipse.swt.ole.win32.OleFrame (swtParent, org.eclipse.swt.SWT.NONE);
			

			        Menu bar = new Menu(swtParent, SWT.BAR);
			        swtParent.setMenuBar(bar);

			  MenuItem fileItem1 = new MenuItem(bar, SWT.CASCADE);
			  fileItem1.setText("&File_Item_1");
			  MenuItem fileItem2 = new MenuItem(bar, SWT.CASCADE);
			  fileItem2.setText("&File_Item_2");

			  MenuItem containerItem = new MenuItem(bar, SWT.CASCADE);
			  containerItem.setText("&Container_Item");

			  MenuItem windowItem1 = new MenuItem(bar, SWT.CASCADE);
			  windowItem1.setText("&Window_Item_1");
			  MenuItem windowItem2 = new MenuItem(bar, SWT.CASCADE);
			  windowItem2.setText("&Window_Item_2");

			  frame.setFileMenus(new MenuItem[] {fileItem1, fileItem2});
			  frame.setContainerMenus(new MenuItem[] {containerItem});
			  frame.setWindowMenus(new MenuItem[] {windowItem1, windowItem2}); 			

			try {
				site = new org.eclipse.swt.ole.win32.OleClientSite (frame, org.eclipse.swt.SWT.NONE, "Word.Document");
//				site = new org.eclipse.swt.ole.win32.OleClientSite (frame, org.eclipse.swt.SWT.NONE, new File("c:\\Temp\\32615.doc"));
			} catch (org.eclipse.swt.SWTException e) {
				String str = "Create OleClientSite Error" + e.toString ();
				System.out.println (str);
				return;
			}
			setSize (500, 500);
			validate ();
			site.doVerb (org.eclipse.swt.ole.win32.OLE.OLEIVERB_SHOW);
			
			
			while (swtParent != null && !swtParent.isDisposed ()) {
				if (!display.readAndDispatch ()) display.sleep ();		
			}	
		}
	});
	thread.start ();
}

public void start () {
	if (site != null) {
		//site.doVerb (org.eclipse.swt.ole.win32.OLE.OLEIVERB_INPLACEACTIVATE);
		site.forceFocus();
	}
}
public void stop() {
	if (site != null) {
		site.deactivateInPlaceClient();
	}
}


public void destroy (){
 	if (display != null && !display.isDisposed ()){
 		display.syncExec(new Runnable () {
 			public void run () {
 				if (swtParent != null && !swtParent.isDisposed ()) swtParent.dispose ();
 				swtParent = null;
 				display.dispose ();
 				display = null;
 			}
 		});
 		remove (awtParent);
 		awtParent = null;
 	}
 }

}


and the jsp :

<object id="wordapplet" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
		codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_4-windows-i586.cab#Version=1,4,0,0"
		width="500" 
		height="500">
	<param name="type" value="application/x-java-applet;version=1.4.0" />
	<param name="name" value="wordapplet" />
	<param name="java_code" value="com.sopra.j2eefwk4i.web.actions.bean.saphir.WordApplet.class" />
	<param name="java_codebase" value="<%= request.getContextPath() %>/common/applet/saphir" />
    <param name="archive" value="WordApplet.jar,swt.jar,swt-win32-3139.dll" />
    <param name="MAYSCRIPT" value="true" />
	<param name="sessionId" value="<%= session.getId() %>" />
	<param name="urlServeur" value="<%= request.getRequestURL() %>" />

	<comment>
		<!-- NOT IE -->
		<embed type="application/x-java-applet;version=1.4"
				pluginspage="http://java.sun.com/products/plugin/"
				java_code="com.sopra.j2eefwk4i.web.actions.bean.saphir.WordApplet.class"
				java_codebase="<%= request.getContextPath() %>/common/applet/saphir"
				java_archive="WordApplet.jar,swt.jar" MAYSCRIPT 				
				name="wordapplet"	
				id="wordapplet" 
				width="500"
				height="500"
				sessionId="<%= session.getId() %>"
				urlServeur="<%= request.getRequestURL() %>"   />
		<noembed>
			<strong>Votre navigateur ne possède pas de plugin Java, ou alors ce dernier n'est pas activé.</strong>
			Vous pouvez télécharger ce plugin à l'adresse suivante: <a href="http://java.sun.com/products/plugin/">http://java.sun.com/products/plugin/</a>
		</noembed>
	</comment>
</object>
Comment 1 Felipe Heidrich CLA 2009-08-13 10:36:46 EDT
Your bug has been moved to triage, visit http://www.eclipse.org/swt/triage.php for more info.
Comment 2 Leo Ufimtsev CLA 2017-08-03 12:27:48 EDT
This is a one-off bulk update. (The last one in the triage migration).

Moving bugs from swt-triaged@eclipse to platform-swt-inbox@eclipse.org and adding "triaged" keyword as per new triage process:
https://wiki.eclipse.org/SWT/Devel/Triage

See Bug 518478 for details.

Tag for notification/mail filters:
@TriageBulkUpdate
Comment 3 Eclipse Genie CLA 2020-02-13 08:02:10 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.