home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / un2maiq4 / pjjava / src / pj / applet / pjlauncher.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  4.4 KB  |  159 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.     Written by the Personal Journal developers of Dow Jones & Company, Inc.
  4.  
  5.     Dow Jones makes no representations or warranties about 
  6.     the suitability of this software, either express or 
  7.     implied, including but not limited to the implied warranties 
  8.     of merchantability, fitness for a particular purpose, 
  9.     or non-infringement.  Dow Jones will not be liable for 
  10.     any damages suffered by a user as a result of using, 
  11.     modifying or distributing this software or its derivatives.
  12.  
  13.  
  14.     @(#)PjLauncher.java  0.00 15-Jan-96
  15.  
  16.         A Java applet that launches PjJava.
  17.  
  18.     Authors:
  19.  
  20.         rphall   Rick Hall
  21.  
  22.     Version Ident:
  23.  
  24.         $Header: /PjJavaClient/src/pj/applet/PjLauncher.java 5     2/07/96 11:25a Rphall $
  25.  
  26.     History:
  27.  
  28.         0.00 15-Jan-96  rphall   Initial Creation
  29.              20-Mar-96  jlee     Added static applet variable and getPjApplet()
  30.  
  31. ---------------------------------------------------------------------------*/
  32.  
  33. package pj.applet;
  34.  
  35. import pj.applet.PjJava;
  36.  
  37. import java.applet.Applet;
  38. import java.applet.AppletContext;
  39. import java.net.URL;
  40.  
  41. /**
  42.  * An applet that launches PjJava.  PjJava is launched by
  43.  * by invoking its "main" routine.  PjLauncher can optionally
  44.  * pass arguments to PjJava; see
  45.  * <a href="pj.applet.PjJava.html#main">PjJava.main</a> for
  46.  * a list of valid arguments.
  47.  * <P>
  48.  * Arguments intended for PjJava can be passed as applet
  49.  * parameters to PjLauncher.  The valid parameter names
  50.  * and values are:
  51.  * <pre>
  52.  * name=PjJavaContentUrl value=<a url for content>
  53.  * name=PjJavaAdsUrl     value=<a base url for advertisements>
  54.  * name=PjJavaImagesUrl  value=<a base url for images>
  55.  * </pre>
  56.  *
  57.  * @version 0.00, 15-Jan-96
  58.  * @author  Rick Hall
  59.  */
  60. public class PjLauncher extends Applet 
  61.     {
  62.  
  63.     // --- Class variables
  64.     private static Applet pjApplet;
  65.  
  66.     // --- Instance variables
  67.     private final String nameContentUrl = "PjJavaContentUrl";
  68.     private final String nameAdsUrl     = "PjJavaAdsUrl";
  69.     private final String nameImagesUrl  = "PjJavaImagesUrl";
  70.  
  71.  
  72.     // --- Public operations
  73.     public static void main(String[] args)
  74.         { 
  75.         (new PjLauncher()).init(); 
  76.         }
  77.  
  78.     public void init()
  79.         {
  80.         pjApplet = this;
  81.  
  82.         // Initialize PjJava arguments to empty strings
  83.         String[] args =
  84.             {
  85.             /*--content*/ "", /*ContentUrl*/ "",
  86.             /*--ads    */ "", /*AdsUrl    */ "",
  87.             /*--images */ "", /*ImagesUrl */ ""
  88.             };
  89.  
  90.         // Try to get content parameter
  91.         try {
  92.             URL content = getUrlFromParameter((URL)null,nameContentUrl);
  93.             if (content != null)
  94.                 {
  95.                 args[0] = PjJava.flagContentUrl;
  96.                 args[1] = content.toExternalForm();
  97.                 }
  98.             } // try
  99.         catch(Exception e) {}
  100.  
  101.         // Try to get ads parameter
  102.         try {
  103.             URL ads = getUrlFromParameter((URL)null,nameAdsUrl);
  104.             if (ads != null)
  105.                 {
  106.                 args[2] = PjJava.flagAdsUrl;
  107.                 args[3] = ads.toExternalForm();
  108.                 }
  109.             } // try
  110.         catch(Exception e) {}
  111.  
  112.         // Try to get images parameter
  113.         try {
  114.             URL images = getUrlFromParameter((URL)null,nameImagesUrl);
  115.             if (images != null)
  116.                 {
  117.                 args[4] = PjJava.flagImagesUrl;
  118.                 args[5] = images.toExternalForm();
  119.                 }
  120.             } // try
  121.         catch(Exception e) {}
  122.  
  123.         PjJava.main(args);
  124.         }
  125.  
  126.     public static Applet getPjApplet()
  127.         {
  128.         return pjApplet;
  129.         }
  130.  
  131.     // --- Private operations
  132.  
  133.     /**
  134.      * Get a url from an applet tag parameter
  135.     */
  136.     private URL getUrlFromParameter(URL urlDefault, String param)
  137.         {
  138.         URL url;
  139.         String str = getParameter(param);
  140.  
  141.         // Try interpretting str as absolute URL
  142.         url = PjJava.getURL(str);
  143.         if (url != null) 
  144.             return url;
  145.  
  146.         // Try interpretting as relative
  147.         url = PjJava.getURL(getDocumentBase(), str);
  148.         if (url != null) 
  149.             return url;
  150.  
  151.         // If neither absolute and nor relative, ignore it
  152.         return urlDefault;
  153.  
  154.         } // getUrlFromParameter
  155.  
  156.    
  157.  
  158.     } // PjLauncher
  159.