views:

470

answers:

1

Hi,

I am trying to view a .doc/.docx microsoft word files in a webpage on firefox. When all failed i tried creating an applet that will hold an instance of Word OLE to view the document.

I created the applet using: org.eclipse.swt.ole.win32.OleClientSite, and with in eclipse it works fine and i can see Word inside.

I created a .jar file and i tried to use the applet inside the webpage in firefox. The applet starts but i can't see anything inside.

Here is my applet code:

import java.applet.Applet;
public class JWordViewer  extends Applet {
  org.eclipse.swt.widgets.Display display;
  org.eclipse.swt.widgets.Shell swtParent;
  java.awt.Canvas awtParent;

  public void init() {
    Thread 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();
        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);
        org.eclipse.swt.ole.win32.OleClientSite site;
        try {
          site = new org.eclipse.swt.ole.win32.OleClientSite(frame,
              org.eclipse.swt.SWT.NONE, "Word.Document");

        } 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 stop() {
    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;
    }
  }
}

`

Any idea why isn't it working?

Here is what the Java Console says:

basic: Told clients applet is started Exception in thread "Thread-11" java.lang.ExceptionInInitializerError at org.eclipse.swt.widgets.Display.<clinit>(Display.java:130) at JWordViewer$1.run(JWordViewer.java:17) at java.lang.Thread.run(Unknown Source) Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission sun.arch.data.model read) at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPropertyAccess(Unknown Source) at java.lang.System.getProperty(Unknown Source) at org.eclipse.swt.internal.Library.loadLibrary(Library.java:167) at org.eclipse.swt.internal.Library.loadLibrary(Library.java:151) at org.eclipse.swt.internal.C.<clinit>(C.java:21) ... 3 more

And that's after i told it to trust this applet...

A: 

Hi,

Here is the answer: It needs permissions to read and execute on the disc. One option is to sign the .jar file. And the other option is to give permissions to the disc.

I used for testing the second option: I modified the java.policy file like that: ` grant codeBase "http://localhost/-" { permission java.io.FilePermission "<>", "read, write, execute, delete"; permission java.net.SocketPermission "", "accept, connect, listen, resolve"; permission java.util.PropertyPermission "", "read, write"; permission java.lang.RuntimePermission "*"; permission java.awt.AWTPermission "showWindowWithoutWarningBanner"; };

And that's solved it.

aviv
If the question is solved you can accept your own answer, I think. So that it doesn't look like it is unanswered.
Per Wiklander