001: package com.meterware.httpunit;
002:
003: /********************************************************************************************************************
004: * $Id: AppletContextImpl.java,v 1.2 2002/11/15 01:22:37 russgold Exp $
005: *
006: * Copyright (c) 2002, Russell Gold
007: *
008: * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
009: * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
010: * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
011: * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
012: *
013: * The above copyright notice and this permission notice shall be included in all copies or substantial portions
014: * of the Software.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
017: * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
018: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
019: * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
020: * DEALINGS IN THE SOFTWARE.
021: *
022: *******************************************************************************************************************/
023: import java.util.*;
024: import java.applet.AppletContext;
025: import java.applet.AudioClip;
026: import java.applet.Applet;
027: import java.net.URL;
028: import java.awt.*;
029: import java.io.InputStream;
030: import java.io.IOException;
031:
032: /**
033: *
034: * @author <a href="mailto:russgold@httpunit.org">Russell Gold</a>
035: **/
036: class AppletContextImpl implements AppletContext {
037:
038: private WebApplet _webApplet;
039:
040: AppletContextImpl(WebApplet webApplet) {
041: _webApplet = webApplet;
042: }
043:
044: /**
045: * Creates an audio clip.
046: *
047: * @param url an absolute URL giving the location of the audio clip.
048: * @return the audio clip at the specified URL.
049: */
050: public AudioClip getAudioClip(URL url) {
051: return null;
052: }
053:
054: /**
055: * Returns an <code>Image</code> object that can then be painted on
056: * the screen. The <code>url</code> argument<code> </code>that is
057: * passed as an argument must specify an absolute URL.
058: * <p>
059: * This method always returns immediately, whether or not the image
060: * exists. When the applet attempts to draw the image on the screen,
061: * the data will be loaded. The graphics primitives that draw the
062: * image will incrementally paint on the screen.
063: *
064: * @param url an absolute URL giving the location of the image.
065: * @return the image at the specified URL.
066: * @see Image
067: */
068: public Image getImage(URL url) {
069: return null;
070: }
071:
072: /**
073: * Finds and returns the applet in the document represented by this
074: * applet context with the given name. The name can be set in the
075: * HTML tag by setting the <code>name</code> attribute.
076: *
077: * @param name an applet name.
078: * @return the applet with the given name, or <code>null</code> if
079: * not found.
080: */
081: public Applet getApplet(String name) {
082: try {
083: WebApplet[] webApplets = _webApplet.getAppletsInPage();
084: for (int i = 0; i < webApplets.length; i++) {
085: if (webApplets[i].getName().equals(name))
086: return webApplets[i].getApplet();
087: }
088: } catch (Exception e) {
089: }
090: return null;
091: }
092:
093: /**
094: * Finds all the applets in the document represented by this applet
095: * context.
096: *
097: * @return an enumeration of all applets in the document represented by
098: * this applet context.
099: */
100: public Enumeration getApplets() {
101: WebApplet[] webApplets = _webApplet.getAppletsInPage();
102: Vector v = new Vector();
103: try {
104: for (int i = 0; i < webApplets.length; i++) {
105: v.add(webApplets[i].getApplet());
106: }
107: } catch (Exception e) {
108: e.printStackTrace();
109: throw new RuntimeException(e.toString());
110: }
111: return v.elements();
112: }
113:
114: /**
115: * Replaces the Web page currently being viewed with the given URL.
116: * This method may be ignored by applet contexts that are not
117: * browsers.
118: *
119: * @param url an absolute URL giving the location of the document.
120: */
121: public void showDocument(URL url) {
122: showDocument(url, _webApplet.getBaseTarget());
123: }
124:
125: /**
126: * Requests that the browser or applet viewer show the Web page
127: * indicated by the <code>url</code> argument. The
128: * <code>target</code> argument indicates in which HTML frame the
129: * document is to be displayed.
130: * The target argument is interpreted as follows:
131: * <p>
132: * <center><table border="3">
133: * <tr><td><code>"_self"</code> <td>Show in the window and frame that
134: * contain the applet.</tr>
135: * <tr><td><code>"_parent"</code><td>Show in the applet's parent frame. If
136: * the applet's frame has no parent frame,
137: * acts the same as "_self".</tr>
138: * <tr><td><code>"_top"</code> <td>Show in the top-level frame of the applet's
139: * window. If the applet's frame is the
140: * top-level frame, acts the same as "_self".</tr>
141: * <tr><td><code>"_blank"</code> <td>Show in a new, unnamed
142: * top-level window.</tr>
143: * <tr><td><i>name</i><td>Show in the frame or window named <i>name</i>. If
144: * a target named <i>name</i> does not already exist, a
145: * new top-level window with the specified name is created,
146: * and the document is shown there.</tr>
147: * </table> </center>
148: * <p>
149: * An applet viewer or browser is free to ignore <code>showDocument</code>.
150: *
151: * @param url an absolute URL giving the location of the document.
152: * @param target a <code>String</code> indicating where to display
153: * the page.
154: */
155: public void showDocument(URL url, String target) {
156: _webApplet.sendRequest(url, target);
157: }
158:
159: /**
160: * Requests that the argument string be displayed in the
161: * "status window". Many browsers and applet viewers
162: * provide such a window, where the application can inform users of
163: * its current state.
164: *
165: * @param status a string to display in the status window.
166: */
167: public void showStatus(String status) {
168: }
169:
170: /**
171: * Returns the stream to which specified key is associated within this
172: * applet context. Returns <tt>null</tt> if the applet context contains
173: * no stream for this key.
174: * <p>
175: * For security reasons, mapping of streams and keys exists for each
176: * codebase. In other words, applet from one codebase cannot access
177: * the streams created by an applet from a different codebase
178: * <p>
179: * @return the stream to which this applet context maps the key
180: * @param key key whose associated stream is to be returned.
181: * @since JDK1.4
182: */
183: public InputStream getStream(String key) {
184: return null;
185: }
186:
187: /**
188: * Finds all the keys of the streams in this applet context.
189: * <p>
190: * For security reasons, mapping of streams and keys exists for each
191: * codebase. In other words, applet from one codebase cannot access
192: * the streams created by an applet from a different codebase
193: * <p>
194: * @return an Iterator of all the names of the streams in this applet
195: * context.
196: * @since JDK1.4
197: */
198: public Iterator getStreamKeys() {
199: return null;
200: }
201:
202: /**
203: * Associates the specified stream with the specified key in this
204: * applet context. If the applet context previously contained a mapping
205: * for this key, the old value is replaced.
206: * <p>
207: * For security reasons, mapping of streams and keys exists for each
208: * codebase. In other words, applet from one codebase cannot access
209: * the streams created by an applet from a different codebase
210: * <p>
211: * @param key key with which the specified value is to be associated.
212: * @param stream stream to be associated with the specified key. If this
213: * parameter is <code>null<code>, the specified key is removed
214: * in this applet context.
215: * @throws <code>IOException</code> if the stream size exceeds a certain
216: * size limit. Size limit is decided by the implementor of this
217: * interface.
218: * @since JDK1.4
219: */
220: public void setStream(String key, InputStream stream)
221: throws IOException {
222: }
223: }
|