Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4223682

Applet Viewing HTML page within Netscape 4.5

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.2
    • deploy
    • x86
    • windows_98



      Name: gsC80088 Date: 03/24/99


      When an Applet try to lauch an HTML page within a Browser
      this does not view any page. I currently use Plug-in 1.1.2
      and Swing 1.1

      The following code always worked in the 1.1 plug-ins with
      Swing 1.0.

      I wonder wether this is a problem of the plug-ins or Netscape
      4.5. Could you please offer advice on this if you can
      prove this is not a bug.

      import java.applet.*;
      import java.awt.*;
      import java.awt.event.*;
      import java.util.*;
      import java.net.*;
      import javax.swing.*;
      import javax.swing.event.*;
      import javax.swing.table.*;

      public class BrowserViewer extends Object
      {
        // A full path name local to where the applet run
        // e.g. "user/BusinessPlan.html";
        String theFileName;
        // valid values are "anyname", "_self", "_parent", "_top" and "_blank"
        String theBrowserDestination = "name";
        URL theTargetURL;
        java.applet.Applet theApplet;

        public BrowserViewer(java.applet.Applet anApplet, String aFileName)
        {
          theApplet = anApplet;
          theFileName = aFileName;
          
          theFileName = replace(theFileName, "\\", "/");
          
          if (theFileName.indexOf("file:/") == -1)
          {
            theFileName = "file:/" + theFileName;
          }
          
          //System.out.println(theFileName);
        }
          
        public boolean view()
        {
            // Display the file name in the browser.
            AppletContext context = theApplet.getAppletContext();
            theTargetURL = getURL(theFileName);
            
            if ( theTargetURL == null)
            {
              return false;
            }
            else
            {
              context.showDocument(theTargetURL,theBrowserDestination);
              return true;
            }
        }
        
        private URL getURL(String aFileName)
        {
            // aFileName is full qualified URL file name e.g. file://C:\windows..
            URL url;
            // get the URL given a file name
            try
            {
                  if (theApplet == null)
                  {
                    System.err.print("Viewing in a stand-alone application is not yet supported.");
                    // add here spawinig the browser with the required HTML or view in the
                    // the view Tabbed Panel.
                    return null;
                  }
                  else
                  {
                    try
                    {
                      url = new URL(aFileName);
                      return url;
                    }
                    catch(MalformedURLException e)
                    {
                      System.err.println("MalformedURLException in " + aFileName);
                      return null;
                    }
                 }
            }
            catch (Exception anException)
            {
              System.err.println("Exception: " + anException.toString());
              return null;
            }
          } // End of getURL method.
          

          public String getBrowserDestination()
          {
             return this.theBrowserDestination;
          }

          public void setBrowserDestination(String theBrowserDestination)
          {
              this.theBrowserDestination = theBrowserDestination;
          }
                   
          public String getFileName()
          {
              return this.theFileName;
          }
          public void setFileName(String theFileName)
          {
               this.theFileName = theFileName;
          }
          public URL getTargetURL()
          {
               return this.theTargetURL;
          }

          private void setTargetURL(URL theTargetURL)
          {
               this.theTargetURL = theTargetURL;
          }
          
          private String replace(String aDir, String anOld, String aNew)
          {
            String myDir = new String("");
            int nTok = getNoOfTokens(aDir, anOld);
              
            StringTokenizer myTok = new StringTokenizer(aDir,anOld);
            for (int i = 0; i < nTok; i++)
            {
              if ( i == nTok - 1)
              {
                myDir = myDir + myTok.nextToken();
              }
              else
              {
                myDir = myDir + myTok.nextToken() + aNew;
              }
            }
            return myDir;
        }
          
          
          private int getNoOfTokens(String aDir, String aSeparator)
          {
            int mySize = 0;
            StringTokenizer myTok = new StringTokenizer(aDir,aSeparator);
            while (myTok.hasMoreTokens())
            {
              myTok.nextToken();
              mySize++;
            }
            return mySize;
          }
          
      }
      (Review ID: 52996)
      ======================================================================

            stanleyh Stanley Ho (Inactive)
            gstone Greg Stone
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: