Changeset 32139


Ignore:
Timestamp:
2018-02-13T20:45:29+13:00 (4 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.

Location:
main/trunk/gli
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/GLIapplet.jnlp

    r32138 r32139  
    2020 */
    2121-->
    22 <!--
    23 /*
    24  *  https://docs.oracle.com/javase/9/deploy/migrating-java-applets-jnlp.htm#JSDPG-GUID-1F95EBB3-D5CB-434A-B069-2261900738F5
    25  *  section "Migrating an Existing Java Applet"
    26  */
    27 -->
    2822
    2923<!-- JNLP File for GLI applet -->
     
    4438    <jar href="SignedGatherer.jar"/>
    4539  </resources>
    46   <!--<application-desc main-class="org.greenstone.gatherer.WebGatherer"/>-->
    47   <applet-desc main-class="org.greenstone.gatherer.WebGatherer" name="GLIapplet" height="50" width="380">
     40  <application-desc main-class="org.greenstone.gatherer.WebGatherer">
     41    <argument>-gwcgi=/greenstone3</argument>
     42    <argument>-gsdl3=true</argument>
     43  </application-desc>
     44  <!--
     45  <applet-desc main-class="org.greenstone.gatherer.GathererApplet" name="GLIapplet" height="50" width="380">
    4846    <param name="gwcgi" value="/greenstone3" />
    4947    <param name="gsdl3" value="true" />
    5048  </applet>
     49  -->
    5150  <!-- https://stackoverflow.com/questions/12600076/getting-user-home-folder-from-jws-signed-jar -->
    5251  <security>
  • main/trunk/gli/README_WebGLI.txt

    r32138 r32139  
    4343https://docs.oracle.com/javase/9/whatsnew/toc.htm
    4444https://docs.oracle.com/javase/9/deploy/migrating-java-applets-jnlp.htm
     45    section "Migrating an Existing Java Applet"
    4546https://docs.oracle.com/javase/9/deploy/self-contained-application-packaging.htm
    4647http://www.oracle.com/technetwork/java/javase/migratingfromapplets-2872444.pdf
     
    6566https://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#JARManifest
    6667https://community.oracle.com/thread/1536875?start=0
     68
     69https://stackoverflow.com/questions/1199211/java-webstart-with-parameters
     70https://stackoverflow.com/questions/14116640/how-to-use-jnlp-to-pass-command-line-arguments-to-the-application
  • 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.
  • main/trunk/gli/src/org/greenstone/gatherer/util/JarTools.java

    r12105 r32139  
    4242
    4343    static public void initialise(Object root_object)
     44    {   
     45    initialise(root_object.getClass());
     46    }
     47   
     48    static public void initialise(Class rootClass)
    4449    {
    45     root_class = root_object.getClass();
     50    root_class = rootClass;
    4651    ERROR_ICON = getImage("error.gif");
    4752    }
Note: See TracChangeset for help on using the changeset viewer.