home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / modules / edtplug / classes / netscape / plugin / composer / Document.java < prev    next >
Encoding:
Java Source  |  1998-04-08  |  6.1 KB  |  144 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. package netscape.plugin.composer;
  20.  
  21. import java.io.*;
  22. import java.util.*;
  23. import java.net.URL;
  24. import netscape.javascript.JSObject;
  25.  
  26. /** An abstract HTML document.
  27.  * Contains html text. Also contains
  28.  * a work directory. The work directory is where
  29.  * you place images (or other embedded files) that you
  30.  * are inserting into the document.
  31.  *
  32.  */
  33. public abstract class Document {
  34.     /** Get the base URL of the document. This is the url that the
  35.      * relative URLs are relative to.
  36.      * @return the base URL of the document.
  37.      */
  38.     public abstract URL getBase();
  39.    /** Get the work directory of the document. You need this
  40.      * to be able to add files to the document.
  41.      * @return the work directory for the document.
  42.      */
  43.     public abstract File getWorkDirectory();
  44.  
  45.    /** Get the work directory of the document as a URL. You need this
  46.      * to be able to add files to the document.
  47.      * @return the work directory for the document as a URL.
  48.      */
  49.     public abstract URL getWorkDirectoryURL();
  50.  
  51.     /** Get an input stream for a document. Use this to read
  52.      * information out of the document.
  53.      * @return an input stream for the document. The caller must call the close()
  54.      * method when finished with the stream. The caller must
  55.      * finish with the stream before creating another input stream
  56.      * for the same document.
  57.      * @throw IOException if there is an existing unclosed input stream for this document.
  58.      */
  59.     public abstract Reader getInput() throws IOException;
  60.     /** Get an output stream for a document. Use this to write
  61.      * information into a document.
  62.      * @return an output stream for the document.The caller must call the close()
  63.      * method when finished with the stream. The caller must
  64.      * finish with the stream before creating another output stream
  65.      * for the same part.
  66.      * @throw IOException if there is an existing unclosed output stream for this document.
  67.      */
  68.     public abstract Writer getOutput() throws IOException;
  69.  
  70.     /** Get the entire text of the document as a String. Use this to read information
  71.      * out of the document. This is more convenient than getInput if your intent is
  72.      * to perform string-based operations on the document's raw HTML code.
  73.      * getInput is more convenient if you intend to tokenize the HTML.
  74.      * @return the entire raw html text of the document, as a String.
  75.      * @throw IOException if there is a problem reading the document.
  76.      */
  77.     public abstract String getText() throws IOException;
  78.  
  79.     /** Set the entire text of the document. Use this to write information
  80.      * into the document. This is more convenient than getOutput if you have
  81.      * performed string-based operations on the document's raw HTML text.
  82.      * getOutput is more convenient if you process tokenized HTML.
  83.      * @param text the new entire raw HTML text of the document.
  84.      * @throw IOException if there is a problem writing the document, or if
  85.      * there is an existing getOutput stream that has not been closed.
  86.      */
  87.     public abstract void setText(String text) throws IOException;
  88.  
  89.     /** Get the event that triggered this plug-in invocation.
  90.      * This method returns null if this is a normal invocation.
  91.      * <pre>
  92.      * The standard events are:
  93.      *     edit - called when an existing document is about to be edited.
  94.      *     open - called when a document (new or old) is opened for editing.
  95.      *     close - called when a document is about to be closed.
  96.      *     publish - called before a document is published.
  97.      *     publishComplete - called after a document is published.
  98.      *     save - called before a document is saved.
  99.      *     send - called before a document is sent (mailed).
  100.      * </pre>
  101.      * @return the event that triggered the plug-in invocation,
  102.      * or null if this is a normal invocation.
  103.      */
  104.     public String getEventName(){
  105.         return null;
  106.     }
  107.  
  108.     /** Get the document URL (if it is known) for this document.
  109.      * This method returns null if there is no document URL available.
  110.      * During a publish or a save event, the URL will be the URL of
  111.      * the destination to which the document is being published or saved.
  112.      * @return the URL of the document, or null if
  113.      * the document URL is unknown.
  114.      */
  115.     public URL getDocumentURL(){
  116.         return null;
  117.     }
  118.     /** Redirect the open to a new document URL. This method only has an
  119.      * effect when the event is "edit". Useful for situations where the
  120.      * publishing URL is different from the editing URL. This could happen
  121.      * when you use an FTP server to access the backing store of an HTTP server.
  122.      * @param newURL The URL, expressed as a string, that should be used to
  123.      * edit the document.
  124.      */
  125.     public void redirectDocumentOpen(String newURL){
  126.     }
  127.  
  128.     /** Open a URL for editing. This call is asynchronous. No errors are returned.
  129.      * @param URL The URL, expressed as a string, that is to be edited.
  130.      */
  131.     static public void editDocument(String url){
  132.         try {
  133.             Composer.editDocument(url);
  134.         } catch (Throwable t){
  135.             t.printStackTrace();
  136.         }
  137.     }
  138.  
  139.     /** get the jsobject from the document.  If no javascript in the
  140.      *  runtime, this will return null
  141.      */
  142.      public JSObject getJSObject(){return null;}
  143. }
  144.