Changeset 38874


Ignore:
Timestamp:
2024-03-25T23:18:19+13:00 (5 weeks ago)
Author:
anupama
Message:
  1. Tried to get the GsdlCollageApplet to run as a webswing applet, but it hits a nullpointer in the DisplayImages constructor: createImage hasn't returned anything, I think. This is not a problem with the applet, and the applet gets past this. So next, I want to try getting GsdlCollageApplet to work as an application (as opposed to applet) to see if it is free of this problem and then see if the problem goes away when the webswing is run as an application instead of an applet. 2. Adding the code to GsdlCollageApplet to make it run as an application as well, besides applet. The code was largely copied from JPhind, where I'd done all the thinking for how GS applet classes need to modified to get them to work as an application. Sadly, when I run the GsdlCollageApplet as an Application, I hit the same error as when running it as an Applet through Webswing. It's perplexing what is different about the GsdlCollageApplet run through the appletviewer as a standalone applet that that manages to get a little further. Or maybe the parameters are incomplete in the webswing applet params and the standalone application commandline parameters compared to how the applet was run? I can't think what I'm missing though.
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/webswing/trunk/web/etc/webswing.config.in

    r38872 r38874  
    122122    "webHomeDir" : "@gsdl3webwritablehomeunix@",
    123123    "goodbyeUrl" : "/"
     124  },
     125    "/collage" : {
     126    "path" : "/collage",
     127    "security" : {
     128      "module" : "NONE",
     129      "config" : { },
     130      "classPath" : [ ]
     131    },
     132
     133    "webFolder" : "",
     134    "swingConfig" : {
     135      "jreExecutable" : "${java.home}/bin/java",
     136      "javaVersion" : "${java.version}",
     137      "vmArgs" : "",
     138      "classPathEntries" : [ "applet/*.jar", "ext/webswing/api/webswing-api.jar" ],
     139      "theme" : "Murrine",
     140      "fontConfig" : {
     141        "dialog" : "${webswing.configDir}/fonts/Roboto-Regular.ttf",
     142        "dialoginput" : "${webswing.configDir}/fonts/RobotoMono-Regular.ttf",
     143        "monospaced" : "${webswing.configDir}/fonts/RobotoMono-Regular.ttf",
     144        "serif" : "${webswing.configDir}/fonts/Roboto-Regular.ttf",
     145        "sansserif" : "${webswing.configDir}/fonts/Roboto-Regular.ttf"
     146      },
     147      "swingSessionTimeout" : 300,
     148      "antiAliasText" : true,
     149      "isolatedFs" : true,
     150      "debug" : false,
     151      "directdraw" : true,
     152      "allowDelete" : false,
     153      "allowDownload" : false,
     154      "allowAutoDownload" : true,
     155      "allowUpload" : false,
     156      "allowJsLink" : true,
     157      "allowLocalClipboard" : true,
     158      "launcherType" : "Applet",
     159      "launcherConfig" : {
     160        "appletClass" : "org.greenstone.applet.GsdlCollageApplet.GsdlCollageApplet",
     161        "parameters" : {
     162         "library" : "library",
     163         "collection" : "smallbea",
     164            "gsdlversion" : "3",
     165            "sitename" : "localsite",
     166        "baseurl" : "'http://localhost:8383/greenstone3/",
     167            "documentroot" : "greenstone3",
     168            "verbosity" : "3",
     169            "imageType" : ".jpg%.png",
     170            "imageMustNotHave" : "interfaces/",
     171        "gwcgi" : "http://localhost:8383/greenstone3/library/collection/smallbea/",
     172        "classifier" : "CL2.3",
     173        "maxDepth" : "500",
     174        "maxDisplay" : "25",
     175        "refreshDelay" : "1500",
     176        "isJava2" : "auto",
     177        "bgcolor" : "#96c29a"
     178        }
     179      },
     180      "homeDir" : "@gsdl3webwritablehomeunix@"
     181    },
     182    "maxClients" : 4,
     183    "maxConnections" : 4,
     184    "allowStealSession" : false,
     185    "name" : "Greenstone Collage Browser",
     186    "sessionMode" : "ALWAYS_NEW_SESSION",
     187    "uploadMaxSize" : 1200,
     188    "webHomeDir" : "@gsdl3webwritablehomeunix@",
     189    "goodbyeUrl" : "/"
    124190  }
    125191}
  • main/trunk/greenstone3/src/java/org/greenstone/applet/GsdlCollageApplet/DownloadImages.java

    r38853 r38874  
    1414 *  Stores images that are downloaded but have not yet been displayed
    1515 *  in the applet. Provides methods to add to and remove from this list
    16  *  and check it's size. It uses an inner class to store the data for these
    17  *  images, comprising of three parts: the image itself, it's source url
     16 *  and check its size. It uses an inner class to store the data for these
     17 *  images, comprising of three parts: the image itself, its source url
    1818 *  and the name of the image */
    1919public class DownloadImages {
  • main/trunk/greenstone3/src/java/org/greenstone/applet/GsdlCollageApplet/GsdlCollageApplet.java

    r38871 r38874  
    55import java.awt.*;
    66import java.net.*;
     7
     8import javax.swing.JFrame;
     9import javax.swing.JLabel;
     10import java.util.Map;
     11import java.util.HashMap;
    712
    813/**
     
    2025 
    2126public class GsdlCollageApplet extends JApplet {
     27    // To run this GsdlCollageApplet as Application instead of as Applet
     28    boolean isWebswingApplication = false; // if run as webswing *and* application (not applet)
     29    boolean isRunAsApplet = true;
     30    // set only if JPhind object is run as an application
     31    URL docBaseURL = null;
     32    JLabel statusBar = null;   
     33    Map<String,String> appParams;
     34   
    2235    // package access, used mainly for GS3
    2336    int gsdlversion = 2;
     
    102115    Thread paint ;
    103116
     117    public GsdlCollageApplet() { super(); }
     118
     119    public GsdlCollageApplet(String[] args) {
     120    // I copied the contents of this contructor for my code for the JPhind.java constructor
     121    // This constructor will be used when this JApplet is run as an application
     122    // instead of as applet
     123    this.isRunAsApplet = false;
     124    try {
     125        this.docBaseURL = new URL(args[0]);     
     126    } catch(MalformedURLException mue) {       
     127        mue.printStackTrace();
     128        System.err.println("*** Unable to instantiate URL from parameter: " + args[0]);
     129        System.exit(-1);
     130    }
     131
     132    appParams = new HashMap<String,String>((args.length+1)/2);
     133
     134    String key = null;
     135    String value = null;
     136    for(int i = 1; i < args.length; i++) { // after arg0, have key-value pairs (params)
     137        if(i%2==1) {
     138        key = args[i].substring(2); // remove -- prefix of paramname
     139        //System.err.println("got key: " + key);
     140        } else {
     141        value = args[i];
     142        appParams.put(key, value);
     143        //System.err.println("got value: " + value);
     144
     145
     146        // HttpUtils.parseQueryString() deprecated, so hacking decode xtra key-value pairs
     147        // https://stackoverflow.com/questions/13592236/parse-a-uri-string-into-name-value-collection?page=1&tab=scoredesc#tab-top
     148        // String.split() is preferred over Tokenizer but 2nd parameter behaves differently
     149        // than I expected.
     150        // https://docs.oracle.com/javase/6/docs/api/java/lang/String.html#split%28java.lang.String,%20int%29
     151        if(key.equals("xtraParams")) {
     152            value = value.replace("&amp;", "&"); // just in case we have html entities
     153            String[] param_list = value.split("&", 0); // 0 for all occurrences
     154            for(String key_val : param_list) {         
     155            String[] paramPair = key_val.split("=", 2); // get first 2 strings, key and val
     156            //System.err.println("key_val: " + key_val);
     157            if(paramPair.length == 2) {
     158                String xtraParamsKey = paramPair[0];
     159                String xtraParamsVal = paramPair[1];
     160                //System.err.println("key - val: " + xtraParamsKey + " - " + xtraParamsVal);
     161                appParams.put(xtraParamsKey, xtraParamsVal);
     162            }
     163            }
     164        }
     165       
     166        key = value = null;
     167        }
     168    }
     169
     170    isWebswingApplication = appParams.getOrDefault("webswing", "0").equals("1") ? true : false;
     171   
     172    // manually calling (J)Applet method init()
     173    init();
     174    }
     175   
     176    /**
     177     * Overriding (J)Applet method getParameter to first check appParams map
     178     * if Phind was run run as an application.
     179     * https://stackoverflow.com/questions/15905127/overridden-methods-in-javadoc
     180    */
     181    @Override   
     182    public String getParameter(String name) {
     183    if(!isRunAsApplet) {
     184        return appParams.get(name);
     185    }
     186    else {
     187        return super.getParameter(name);
     188    }
     189    }
     190   
     191    @Override
     192    public URL getDocumentBase() {
     193    if(!isRunAsApplet) { // launched as application
     194        //System.err.println("*** docBaseURL: " + docBaseURL);
     195        return this.docBaseURL;
     196    } else {
     197        return super.getDocumentBase();
     198    }
     199    }
     200   
     201    @Override
     202    public void showStatus(String msg) {
     203    // Either firefox doesn't provide a status bar window for applets any more or webswing
     204    // doesn't provide a status window, so we don't see Applet.showStatus() output appear
     205    // in webswing-phind and in fact don't even see any Applet statusBar in webswing.
     206    // However, since we print useful and interesting information to the status bar,
     207    // we'll now always show and print to our manually added statusBar now
     208    // not only if(!isRunAsApplet) when we needed to manually create a statusBar.
     209    this.statusBar.setText(msg);
     210    if(isRunAsApplet) {
     211        super.showStatus(msg);
     212    }
     213    }
     214   
    104215    public void init()
    105216    {       
     
    277388            }
    278389        }
    279         // starting URL (image_url) may not be base_url
     390        // starting URL (image_url) might not be base_url
    280391        this.baseURL = getParameter("baseurl");
    281392        // TODO: is it not the other way: gwcgi should be param set to base_url
     
    283394        }
    284395    }
     396
     397    // status bar that applet has, but we want one also if we run JPhind as application
     398    // And in fact, when webswing runs our applet, we never get a status bar. So we
     399    // create a custom status bar now even if we're running as an applet.
     400    // When this applet is run through the appletviewer we might end up with 2 status bars.
     401    setLayout(new BorderLayout());
     402    //if(!isRunAsApplet) {
     403    statusBar = new JLabel();
     404    this.add(statusBar, BorderLayout.SOUTH);
     405    Dimension d = statusBar.getSize();
     406    d.height = 30;
     407    statusBar.setPreferredSize(d);
     408    //}
    285409
    286410    MediaTracker trk = new  MediaTracker(this);
     
    466590
    467591
     592    // To also be able to run this applet as an application, need a main method
     593    /**
     594     * Try running as:
     595java -cp ./web/applet/GsdlCollageApplet.jar:./web/WEB-INF/lib/log4j-1.2.8.jar:./web/WEB-INF/classes org.greenstone.applet.GsdlCollageApplet.GsdlCollageApplet "http://localhost:8383/greenstone3/" --gwcgi "http://localhost:8383/greenstone3/library/collection/smallbea/" --library library --collection smallbea --gsdlversion 3 --baseurl "http://localhost:8383/greenstone3/" --sitename localsite --documentroot greenstone3 --verbosity 3 --imageType ".jpg%.png" --imageMustNotHave "interfaces/" --classifier "CL2.3" --maxDepth 500 --maxDisplay 25 --refreshDelay 1500 --isJava2 auto --bgcolor "#96c29a"
     596     */
     597    public static void main(String[] args) {
     598    if(args.length < 9) {
     599        System.err.println("Need minimum --params: <baseURL> --library <library> --collection <collection> --classifier <classifier> --phindcgi <URL> --library <libURL> [--webswing <1/0>] [--backdrop <ImgURL>] [--xtraParams <key1=value1&key2=value2&...]");
     600    }
     601    else { // collection fao.org, classifier 1, phindcgi url, library url, backdrop imgurl
     602        GsdlCollageApplet collageApp = new GsdlCollageApplet(args);
     603        JFrame frame = new JFrame("Collage Applet as Application");
     604        frame.getContentPane().add(collageApp, BorderLayout.CENTER);
     605        frame.setSize(500,400);
     606        // https://stackoverflow.com/questions/19433358/difference-between-dispose-and-exit-on-close-in-java
     607        // default: https://docs.oracle.com/javase/8/docs/api/javax/swing/JFrame.html#EXIT_ON_CLOSE
     608        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // don't do EXIT_ON_CLOSE in Applets!
     609        frame.setVisible(true);
     610
     611    }
     612    }
    468613}
  • main/trunk/greenstone3/web/interfaces/default/interfaceConfig.xml

    r38814 r38874  
    77            <subaction name="gli" xslt="pages/webswing-gli.xsl"/>
    88            <subaction name="phind" xslt="pages/webswing-phind.xsl"/>
     9            <subaction name="collage" xslt="pages/webswing-collage.xsl"/>
    910            <subaction name="debug" xslt="pages/debuginfo.xsl"/>
    1011            <subaction name="pref" xslt="pages/pref.xsl"/>
  • main/trunk/greenstone3/web/interfaces/default/transform/layouts/header.xsl

    r38854 r38874  
    451451        </xsl:attribute>
    452452          </xsl:if>                       
    453           <xsl:attribute name="href"><xsl:value-of select="$library_name"/>?a=a&amp;rt=d&amp;s=<xsl:value-of select="@name"/>&amp;c=<xsl:value-of select="/page/pageResponse/collection/@name"/></xsl:attribute>
    454           <!--<xsl:attribute name="href"><xsl:value-of select="$library_name"/>/collection/<xsl:value-of select="/page/pageResponse/collection/@name"/>/page/collage</xsl:attribute>-->
     453          <!--<xsl:attribute name="href"><xsl:value-of select="$library_name"/>?a=a&amp;rt=d&amp;s=<xsl:value-of select="@name"/>&amp;c=<xsl:value-of select="/page/pageResponse/collection/@name"/></xsl:attribute>-->
     454          <xsl:attribute name="href"><xsl:value-of select="$library_name"/>/collection/<xsl:value-of select="/page/pageResponse/collection/@name"/>/page/collage</xsl:attribute>
    455455          <xsl:value-of select="displayItem[@name='name']"/>
    456456        </a>
Note: See TracChangeset for help on using the changeset viewer.