2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import java
.lang
.reflect
.Method
;
21 import java
.lang
.reflect
.Array
;
25 import com
.sun
.star
.comp
.beans
.*;
26 import java
.applet
.Applet
;
27 import java
.awt
.Graphics
;
30 public class OOoViewer
extends Applet
{
32 private OOoBean oBean
;
34 static private CustomURLClassLoader m_loader
;
40 if (m_loader
== null) {
41 String s
= getParameter("office");
42 System
.out
.println("sun.awt.noxembed: " + System
.getProperty("sun.awt.noxembed"));
43 System
.setProperty("sun.awt.xembedserver", "true");
46 URL url
= f
.toURI().toURL();
47 String officeURL
= url
.toString();
48 URL
[] arURL
= new URL
[] {
49 new URL(officeURL
+ "/program/classes/officebean.jar"),
50 new URL(officeURL
+ "/program/classes/jurt.jar"),
51 new URL(officeURL
+ "/program/classes/ridl.jar"),
52 new URL(officeURL
+ "/program/classes/unoil.jar"),
53 new URL(officeURL
+ "/program/classes/java_uno.jar"),
54 new URL(officeURL
+ "/program/classes/juh.jar")
56 m_loader
= new CustomURLClassLoader(arURL
);
57 File fileProg
= new File(s
+ "/program");
58 m_loader
.addResourcePath(fileProg
.toURI().toURL());
60 } catch (MalformedURLException e
) {
67 Class beanClass
= m_loader
.loadClass("com.sun.star.comp.beans.OOoBean");
68 m_objBean
= beanClass
.newInstance();
69 setLayout(new BorderLayout());
70 add((java
.awt
.Container
)m_objBean
, BorderLayout
.CENTER
);
72 //this does not work here. Why?
73 // Class arPropValClass = m_loader.loadClass("[Lcom.sun.star.beans.PropertyValue;");
74 Object arProp
= Array
.newInstance(
75 m_loader
.loadClass("com.sun.star.beans.PropertyValue"), 1);
76 Class
<?
extends Object
> clazz
= arProp
.getClass();
78 Method methLoad
= beanClass
.getMethod(
79 "loadFromURL", new Class
[] {
80 String
.class, arProp
.getClass() });
82 methLoad
.invoke(m_objBean
, new Object
[] {"private:factory/swriter", null});
83 } catch (ClassNotFoundException e
) {
85 } catch (InstantiationException e
) {
87 } catch (IllegalAccessException e
) {
89 } catch (ClassCastException e
) {
91 } catch (java
.lang
.reflect
.InvocationTargetException e
) {
93 } catch (java
.lang
.NoSuchMethodException e
) {
94 e
.printStackTrace(); }
103 Method methStop
= m_objBean
.getClass().getMethod(
104 "stopOOoConnection", new Class
[0]);
105 methStop
.invoke(m_objBean
, null);
106 } catch (java
.lang
.NoSuchMethodException e
) {
108 } catch (java
.lang
.IllegalAccessException e
) {
111 catch (java
.lang
.reflect
.InvocationTargetException e
) {
117 public void destroy() {
120 public void paint(Graphics g
) {
125 final class CustomURLClassLoader
extends URLClassLoader
{
127 private ArrayList
<URL
> resourcePaths
;
129 public CustomURLClassLoader( URL
[] urls
) {
133 protected Class
findClass( String name
) throws ClassNotFoundException
{
134 // This is only called via this.loadClass -> super.loadClass ->
135 // this.findClass, after this.loadClass has already called
136 // super.findClass, so no need to call super.findClass again:
137 throw new ClassNotFoundException( name
);
138 // return super.findClass(name);
143 protected Class
loadClass( String name
, boolean resolve
)
144 throws ClassNotFoundException
146 Class c
= findLoadedClass( name
);
149 c
= super.findClass( name
);
150 } catch ( ClassNotFoundException e
) {
151 return super.loadClass( name
, resolve
);
152 } catch ( SecurityException e
) {
153 // A SecurityException "Prohibited package name: java.lang"
154 // may occur when the user added the JVM's rt.jar to the
156 return super.loadClass( name
, resolve
);
165 public void addResourcePath(URL rurl
) {
166 if (resourcePaths
== null) resourcePaths
= new ArrayList
<URL
>();
167 resourcePaths
.add(rurl
);
170 public URL
getResource(String name
) {
171 if (resourcePaths
== null) return null;
173 URL result
= super.getResource(name
);
174 if (result
!= null) {
179 for (URL u
: resourcePaths
) {
180 if (u
.getProtocol().startsWith("file")){
182 File f1
= new File(u
.getPath());
183 File f2
= new File(f1
, name
);
185 return new URL(f2
.toURI().toASCIIString());
187 } catch (MalformedURLException e1
) {
188 System
.err
.println("malformed url: "+e1
.getMessage());