update dev300-m58
[ooovba.git] / sj2 / stardiv / applet / DocumentProxy.java
blob02017c48982bd8ebae7d94497a4a8eef2fb9b437
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DocumentProxy.java,v $
10 * $Revision: 1.4 $
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 ************************************************************************/
30 package stardiv.applet;
32 import java.awt.Toolkit;
33 import java.awt.Image;
35 import java.applet.Applet;
36 import java.applet.AppletContext;
37 import java.applet.AudioClip;
39 import java.io.IOException;
41 import java.util.Enumeration;
42 import java.util.Hashtable;
43 import java.util.Observer;
44 import java.util.Observable;
45 import java.util.Iterator;
46 import java.io.InputStream;
48 import java.net.URL;
50 import com.sun.star.lib.sandbox.Cachable;
51 import com.sun.star.lib.sandbox.ExecutionContext;
52 import com.sun.star.lib.sandbox.WeakRef;
53 import com.sun.star.lib.sandbox.WeakTable;
54 import com.sun.star.lib.sandbox.ResourceProxy;
56 public class DocumentProxy implements AppletContext, Cachable, Observer, LiveConnectable {
57 static private int instances;
59 synchronized static public DocumentProxy getDocumentProxy(URL url, Toolkit toolkit) {
60 DocumentProxy documentProxy = (DocumentProxy)WeakTable.get("Document: " + url);
62 if(documentProxy == null) {
63 documentProxy = new DocumentProxy(url, toolkit);
64 WeakTable.put("Document: " + url, documentProxy);
67 return documentProxy;
70 // AppletContext. This method is new since 1.4. We insert it so as to
71 // have the project buildable
72 public void setStream( String key,InputStream stream)
73 throws java.io.IOException {
75 // AppletContext. This method is new since 1.4. We insert it so as to
76 // have the project buildable
77 public InputStream getStream( String key) {
78 return null;
80 // AppletContext. This method is new since 1.4. We insert it so as to
81 // have the project buildable
82 public Iterator getStreamKeys() {
83 return null;
88 ** interface cachable methods
90 private Document document;
91 private WeakRef weakRef;
93 public DocumentProxy() {
94 instances ++;
97 public Object getHardObject() {
98 return document;
101 public void setWeakRef(WeakRef weakRef) {
102 document = (Document)weakRef.getRef();
104 weakRef.incRefCnt();
105 this.weakRef = weakRef;
108 public void finalize() {
109 weakRef.decRefCnt();
110 instances --;
114 ** DocumentProxy methods
116 private Toolkit toolkit;
118 private DocumentProxy(URL url, Toolkit toolkit) {
119 this();
120 document = new Document(url, toolkit);
123 void addExecutionContext(ExecutionContext executionContext, String name) {
124 document.addExecutionContext(executionContext, name);
127 void removeExecutionContext(String name) {
128 document.removeExecutionContext(name);
131 public URL getDocumentBase() {
132 return document.getDocumentBase();
136 ** AppletContext interface methods
138 public Applet getApplet(String name) {
139 return ((AppletExecutionContext)document.getExecutionContext(name)).getApplet();
142 public Enumeration getApplets() {
143 return new Enumeration() {
144 Enumeration contexts = document.getExecutionContexts();
146 public boolean hasMoreElements() {
147 return contexts.hasMoreElements();
150 public Object nextElement() {
151 return ((AppletExecutionContext)contexts.nextElement()).getApplet();
156 public AudioClip getAudioClip(URL url) {
157 return document.getAudioClip(url);
160 public Image getImage(URL url) {
161 return document.getImage(url);
164 public void showDocument(URL url) {
165 document.showDocument(url);
169 * Get the javascript environment for this applet.
172 public native Object getJavaScriptJSObjectWindow();
173 public native void appletResize( int width, int height );
174 public native void showDocument( URL url, String aTarget );
175 public native void showStatus( String status );
178 public void showDocument(URL url, String aTarget) {
179 document.showDocument(url, aTarget);
182 public void showStatus(String status) {
183 document.showStatus(status);
186 public void update(Observable observable, Object object) {
187 showStatus((String)object);
190 public Object getJavaScriptJSObjectWindow() {
191 return document.getJavaScriptJSObjectWindow();