Ignore:
Timestamp:
2000-11-01T12:19:42+13:00 (24 years ago)
Author:
paynter
Message:

Resolve partial URLs like "phindcgi" and /cgi-bin/library" with respect to
the URL of the document containing the applet. Also lets us pass in extra
parameters to cgi scripts, which will let us keep the Greenstone settings
stored in the "e=...." argument to library.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/phind/client/Phind.java

    r1636 r1640  
    191191        stop();
    192192    }
     193    phindcgi_address = tidy_URL(phindcgi_address, true);
    193194    System.out.println("Phind phindcgi: " + phindcgi_address);
    194195
     
    200201        stop();
    201202    }
     203    library_address = tidy_URL(library_address, true);
    202204    System.out.println("Phind library: " + library_address);
    203205
     
    206208    try {
    207209        backdrop_address = new String(getParameter("backdrop"));
     210        backdrop_address = tidy_URL(backdrop_address, false);
    208211        URL backdrop_url = new URL(backdrop_address);
    209212        backgroundImage = getImage(backdrop_url);
     
    489492    //
    490493    // Send a query (a word or symbol number) to the server
    491     // Open a socket connection to the server, send it a query,
    492     // and pass the result to a ResultBox.
     494    // and pass the response to a ResultBox.
    493495
    494496    void queryServer(boolean keyKnown, String word, int queryMode, ResultBox area)
     
    496498
    497499    // Build the query
    498     String query = phindcgi_address + "?x=1&c=" + collection;
     500    String query = phindcgi_address + "x=1&c=" + collection;
    499501
    500502    if (keyKnown) {
     
    644646    }
    645647
     648
     649
     650    // Tidy up URLs
     651    //
     652    // Ensure a URL address (as string) has a protocol, host, and file.
     653    //
     654    // If the URL is a CGI script URL, it should be tidied up so that it is
     655    // appropriate to tage attrib=value pairs on the end.  This means it
     656    // must either end with a "?" or (if it contains a question-mark
     657    // internally) end with a "&".
     658    String tidy_URL(String address, boolean isCGI) {
     659
     660    System.out.println("tidy URL: " + address);
     661   
     662    // make sure the URL has protocol, host, and file
     663    if (address.startsWith("http")) {
     664        // the address has all the necessary components
     665    } else if (address.startsWith("/")) {
     666        // there is not protocol and host
     667        URL document = getDocumentBase();
     668        address = "http://" + document.getHost() + address;
     669    } else {
     670        // this URL is relative to the dirwectory the document is in
     671        URL document = getDocumentBase();
     672        String directory = document.getFile();
     673        int end = directory.lastIndexOf('/');
     674        directory = directory.substring(0,end + 1);
     675        address = "http://" + document.getHost() + directory + address;
     676
     677    }
     678
     679    // if the URL is a cgi script, make sure it has a "?"
     680    if (isCGI) {
     681        if (address.indexOf((int) '?') == -1) {
     682        address = address + "?";
     683        } else if (!address.endsWith("?")) {
     684        address = address + "&";
     685        }
     686    }
     687
     688
     689    System.out.println("tidy URL returning: " + address);
     690    return address;
     691    }
     692
    646693}
Note: See TracChangeset for help on using the changeset viewer.