1 //*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
.
5 * Copyright
2008 by Sun Microsystems
, Inc
.
7 * OpenOffice
.org
- a multi
-platform office productivity suite
9 * $RCSfile
: OOoViewer
.java
,v $
12 * This file is part of OpenOffice
.org
.
14 * OpenOffice
.org is free software
: you can redistribute it and
/or modify
15 * it under the terms of the GNU Lesser General Public License version
3
16 * only
, as published by the Free Software Foundation
.
18 * OpenOffice
.org is distributed in the hope that it will be useful
,
19 * but WITHOUT ANY WARRANTY
; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
. See the
21 * GNU Lesser General Public License version
3 for more details
22 * (a copy is included in the LICENSE file that accompanied
this code
).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version
3 along with OpenOffice
.org
. If not
, see
26 * <http
://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License
.
29 //*************************************************************************
32 import java
.lang
.reflect
.Method
;
33 import java
.lang
.reflect
.Array
;
37 import java
.awt
.event
.*;
38 import com
.sun
.star
.comp
.beans
.*;
39 import java
.applet
.Applet
;
40 import java
.awt
.Graphics
;
43 public class OOoViewer
extends Applet
{
45 private OOoBean oBean
;
47 static private CustomURLClassLoader m_loader
;
53 if (m_loader
== null) {
54 String s
= getParameter("office");
55 System
.out
.println("sun.awt.noxembed: " + System
.getProperty("sun.awt.noxembed"));
56 System
.setProperty("sun.awt.xembedserver", "true");
60 String officeURL
= url
.toString();
61 URL
[] arURL
= new URL
[] {
62 new URL(officeURL
+ "/program/classes/officebean.jar"),
63 new URL(officeURL
+ "/program/classes/jurt.jar"),
64 new URL(officeURL
+ "/program/classes/ridl.jar"),
65 new URL(officeURL
+ "/program/classes/unoil.jar"),
66 new URL(officeURL
+ "/program/classes/java_uno.jar"),
67 new URL(officeURL
+ "/program/classes/juh.jar")
69 m_loader
= new CustomURLClassLoader(arURL
);
70 File fileProg
= new File(s
+ "/program");
71 m_loader
.addResourcePath(fileProg
.toURL());
73 } catch (MalformedURLException e
) {
80 Class beanClass
= m_loader
.loadClass("com.sun.star.comp.beans.OOoBean");
81 m_objBean
= beanClass
.newInstance();
82 setLayout(new BorderLayout());
83 add((java
.awt
.Container
)m_objBean
, BorderLayout
.CENTER
);
85 //this does not work here. Why?
86 // Class arPropValClass = m_loader.loadClass("[Lcom.sun.star.beans.PropertyValue;");
87 Object arProp
= Array
.newInstance(
88 m_loader
.loadClass("com.sun.star.beans.PropertyValue"), 1);
89 Class clazz
= arProp
.getClass();
91 Method methLoad
= beanClass
.getMethod(
92 "loadFromURL", new Class
[] {
93 String
.class, arProp
.getClass() });
95 methLoad
.invoke(m_objBean
, new Object
[] {"private:factory/swriter", null});
96 } catch (ClassNotFoundException e
) {
98 } catch (InstantiationException e
) {
100 } catch (IllegalAccessException e
) {
102 } catch (ClassCastException e
) {
104 } catch (java
.lang
.reflect
.InvocationTargetException e
) {
106 } catch (java
.lang
.NoSuchMethodException e
) {
107 e
.printStackTrace(); }
116 Method methStop
= m_objBean
.getClass().getMethod(
117 "stopOOoConnection", new Class
[0]);
118 methStop
.invoke(m_objBean
, null);
119 } catch (java
.lang
.NoSuchMethodException e
) {
121 } catch (java
.lang
.IllegalAccessException e
) {
124 catch (java
.lang
.reflect
.InvocationTargetException e
) {
130 public void destroy() {
133 public void paint(Graphics g
) {
138 final class CustomURLClassLoader
extends URLClassLoader
{
140 private Vector resourcePaths
;
142 public CustomURLClassLoader( URL
[] urls
) {
146 protected Class
findClass( String name
) throws ClassNotFoundException
{
147 // This is only called via this.loadClass -> super.loadClass ->
148 // this.findClass, after this.loadClass has already called
149 // super.findClass, so no need to call super.findClass again:
150 throw new ClassNotFoundException( name
);
151 // return super.findClass(name);
156 protected Class
loadClass( String name
, boolean resolve
)
157 throws ClassNotFoundException
159 Class c
= findLoadedClass( name
);
162 c
= super.findClass( name
);
163 } catch ( ClassNotFoundException e
) {
164 return super.loadClass( name
, resolve
);
165 } catch ( SecurityException e
) {
166 // A SecurityException "Prohibited package name: java.lang"
167 // may occur when the user added the JVM's rt.jar to the
169 return super.loadClass( name
, resolve
);
178 public void addResourcePath(URL rurl
) {
179 if (resourcePaths
== null) resourcePaths
= new Vector();
180 resourcePaths
.add(rurl
);
183 public URL
getResource(String name
) {
184 if (resourcePaths
== null) return null;
186 URL result
= super.getResource(name
);
187 if (result
!= null) {
193 for (Enumeration e
= resourcePaths
.elements(); e
.hasMoreElements();) {
194 u
= (URL
)e
.nextElement();
195 if (u
.getProtocol().startsWith("file")){
197 File f1
= new File(u
.getPath());
198 File f2
= new File(f1
, name
);
200 return new URL(f2
.toURI().toASCIIString());
202 } catch (MalformedURLException e1
) {
203 System
.err
.println("malformed url: "+e1
.getMessage());