Ignore:
Timestamp:
2018-02-13T20:45:29+13:00 (6 years ago)
Author:
ak19
Message:

Rewrote WebGatherer as a Java Web Start application, rather than an Applet which it still was during the previous commit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/WebGatherer.java

    r32138 r32139  
    2828package org.greenstone.gatherer;
    2929
    30 import java.applet.*;
    3130import java.awt.event.ActionEvent;
    3231import java.awt.event.ActionListener;
     
    3534
    3635import java.io.*;
     36//import javax.jnlp.*;
    3737import javax.swing.*;
    3838import org.greenstone.gatherer.util.JarTools;
     
    4040import org.greenstone.gatherer.util.Utility;
    4141
    42 
    43 public class WebGatherer extends JApplet implements ActionListener
     42import java.util.*;
     43
     44public class WebGatherer
    4445{
    45     private Gatherer gatherer = null;
    46 
    47 
    48     protected String fullLibraryURL(String address)
     46
     47    protected static String fullLibraryURL(String address)
    4948    {
    5049    String full_address = "";
     
    5554        full_address = address;
    5655        }
    57     else if (address.startsWith("/")) {
     56    /*else if (address.startsWith("/")) {
    5857            // there is not protocol and host
    59             URL document = getDocumentBase();
     58            // JNLP replacement for applet getDocumentBase, https://stackoverflow.com/questions/6371493/java-web-start-getdocumentbase
     59            BasicService bs = (BasicService) ServiceManager.lookup("javax.jnlp.BasicService");
     60            URL document = bs.getCodeBase();
    6061        int port_no = document.getPort();
    6162
    6263            String port = (port_no>0) ? ":" + port_no : "";
    6364            full_address = "http://" + document.getHost() + port  + address;
    64     }
     65    }*/
    6566
    6667    return full_address;
    6768    }
    6869
    69 
    70     /* This is the entry point for the GLI applet */
    71     public void init()
     70    static private String getParameter(String cmd_arg, String flagName) {
     71        int start_index = cmd_arg.indexOf(flagName) + flagName.length();
     72        cmd_arg = cmd_arg.substring(start_index);
     73        return cmd_arg;
     74    }
     75
     76    /* This is the entry point for the Java Web Start version of GLI (a rewrite of GathererApplet as a Java Web Start application) */
     77    static public void main(String cmdArgs[])
    7278    {
    73     JarTools.initialise(this);
     79    Gatherer gatherer = null;
     80    JarTools.initialise(WebGatherer.class);
     81   
     82    String gwcgi_arg = null;
     83    String gsdl3_arg = "false"; // String, "true" or "false"
     84    String windowsHome_arg = null;
     85    String debug_arg = "false"; // String, "true" or "false"
     86   
     87    for(int i = 0; i<cmdArgs.length; i++) {
     88        ///System.err.println("*** cmdarg " + i + " = " + cmdArgs[i]);
     89       
     90        if(cmdArgs[i].contains("gwcgi=")) {
     91            gwcgi_arg = getParameter(cmdArgs[i], "gwcgi=");
     92        } else if(cmdArgs[i].contains("gsdl3=")) {
     93            gsdl3_arg = getParameter(cmdArgs[i], "gsdl3=");
     94        } else if(cmdArgs[i].contains("windowsHome=")) {
     95            windowsHome_arg = getParameter(cmdArgs[i], "windowsHome=");
     96        } else if(cmdArgs[i].contains("debug=")) {
     97            debug_arg = getParameter(cmdArgs[i], "debug=");
     98        }
     99    }
     100   
     101    ///System.err.println("*** gwcgi_arg = " + gwcgi_arg);
     102    ///System.err.println("*** gsdl3_arg = " + gsdl3_arg);
     103    // More debugging:
     104    Map<String,String> envMap = System.getenv();
     105    Set<Map.Entry<String,String>> entries = envMap.entrySet();
     106    Iterator<Map.Entry<String, String>> i = entries.iterator();
     107    System.err.println("*** ENVIRONMENT: ");
     108    while(i.hasNext()) {
     109        Map.Entry<String, String> entry = i.next();
     110        String key = entry.getKey();
     111        String value = entry.getValue();
     112        System.err.println("*** key = " + key);
     113        System.err.println("*** val = " + value);
     114    }
     115    // End debugging
    74116
    75117    // Check if the user has agreed to the requested security settings
     
    81123    }
    82124    catch (Exception exception) {
    83         getContentPane().add(new JLabel("Greenstone Librarian Interface Applet deactivated", JLabel.CENTER));
     125        System.err.println("Greenstone Librarian Interface Applet deactivated");
    84126        return;
    85127    }
     
    97139    String gli_user_directory_path = System.getProperty("user.home") + File.separator;
    98140        if (Utility.isWindows()) {
    99         String windows_home_parameter = getParameter("windowsHome");
     141        String windows_home_parameter = windowsHome_arg;
    100142        if (windows_home_parameter != null && !windows_home_parameter.equals("")) {
    101143        gli_user_directory_path = windows_home_parameter + File.separator + "GLI" + File.separator;
     
    114156
    115157    // Set some global variables so we know how we're running
    116     Gatherer.isApplet = true;
    117     String library_url_string = fullLibraryURL(getParameter("gwcgi"));
    118 
    119     String gs3 = getParameter("gsdl3");
     158    Gatherer.isApplet = false;
     159    String library_url_string = fullLibraryURL(gwcgi_arg);
     160
     161    String gs3 = gsdl3_arg;
    120162    boolean isGS3 = (gs3 == null || !gs3.equals("true")) ? false : true;
    121163
     
    127169    }
    128170
    129         // String debug_param = getParameter("debug");
     171        // String debug_param = debug_arg;
    130172        // if ((debug_param != null) && (debug_param.matches("true"))) {
    131173        //     go.debug = true;
     
    183225
    184226
    185     public void start()
    186     {
    187     System.err.println("Start called");
    188     }
    189 
    190 
    191     public void stop()
    192     {
    193     System.err.println("Stop called");
    194     }
    195 
    196 
    197     public void destroy()
    198     {
    199     System.err.println("Destroy called");
    200     gatherer.exit();
    201     gatherer = null;
    202     System.err.println("Done gatherer exit.");
    203     }
    204 
    205 
    206     public void actionPerformed(ActionEvent e)
    207     {
    208     gatherer.openGUI();
    209     }
    210 
    211 
    212227    /**
    213228     * Method which unzips a given metadata resource.
Note: See TracChangeset for help on using the changeset viewer.