/* -*-Java-*- ******************************************************************************** * * File: CollectionPlug.java * RCS: $Header: /u/testbed/CVSROOT/dldev/doc/Visigenic/InfoBus/StreetRouterProxy/CollectionPlug.Google,v 1.1 1998/05/19 23:23:29 paepcke Exp $ * Description: Mediates Between InfoBus Protocol Engine and Service Interface * Author: Gerard Rodriguez, Stanford University * Created: Wed Jan 15 10:10:21 1998 * Modified: Thu Apr 16 13:13:19 1998 (Andreas Paepcke) paepcke@SNUGGLES * Language: Java * Package: N/A * Status: Experimental (Do Not Distribute) * * (c) Copyright 1998, Stanford University, all rights reserved. * ******************************************************************************** * * Revisions: * * Wed Apr 15 10:11:17 1998 (Andreas Paepcke) paepcke@SNUGGLES * Rewrote to match our new, cleaned-up specification. ******************************************************************************** */ /** CollectionPlug mediates between the DLIOP protocol engine (DLIOPwrapper.java), and StreetRouterServer, which knows how to interact with the street router program MapQuest via the Web. The methods in this class are called by the DLIOPwrapper. The collection plug establishes a connection with MapQuest, submits queries, stores the results, and returns them to DLIOPWrapper as requested.
Note that this street routing example is somewhat degenerate, because the result of each search (i.e. each request for a route) always returns a single result, namely the string with the driving directions. So some of the features, such as sequential access to subsequent documents in a result set that normally would be used in a collection plug are not really exercised in this example. However, we have included the corresponding code anyway (loops that only run for one iteration, etc.), so this should still work well as an example.
Further documentation: About DLIOP, see
http://www-diglib.stanford.edu/cgi-bin/WP/get/SIDL-WP-1997-0054
For an explanation of what collection plugs do, see: ****
*/
import java.io.*;
import java.awt.*;
import java.net.*;
import java.lang.*;
public class CollectionPlug {
private String TheQuery;
private static final int MAX_RESULTS = 100;
private GeneralDoc[] objects = new GeneralDoc[MAX_RESULTS];
private int numDocs; // number of docs found as result of a search
private int theDocCursor; // next new doc to hand to the wrapper if he asks
private int docs_stored; //num of docs pulled from service and cached here.
private boolean flagmore;
//The names we choose for properties is important. Right now, in order to
//make this proxy compatible with the rest of services in InfoBus, the
//name of each property should be included in the USMarc.java file. This
//is because the InfoBus uses a derivative of USMARC as a lingua franca.
private static String[] supportedProps = new String[3];
private String[] requestedProps = new String[supportedProps.length];
// header and tail for the url
private String url_header = "http://z.stanford.edu:4200/web.fcg?searchterm=";
private String url_tail = "&ranking=on&num=";
private String url_tail2 = "&cluster=1";
private String add_url_object = "http://z.stanford.edu:4200";
// Class constructor
public CollectionPlug () {
supportedProps[0] = "title";
supportedProps[1] = "url";
supportedProps[2] = "weight";
TheQuery = "";
numDocs = 0;
theDocCursor = 0;
flagmore = false;
return;
}
// SetProperties(props)
// props : list of the names of properties the caller wants
// included in every returned document. This list must be a subset
// of the list of properties supported by this CollectionPlug. If
// the list is empty, all properties are wanted:
public void SetProperties (String[] props)
throws java.lang.IllegalArgumentException {
System.out.println("SetProperties (String[] propos)");
for(int jj =0;jj ");
try {
lurl = line.substring(index + 12, index2);
index = line.indexOf("");
ltitle = line.substring(index2 + 2, index);
lweight = line.substring(line.indexOf("") + 16,
line.indexOf("%"));
}
catch (Exception e) {
System.out.println("Error parsing the line" + e);
return object;
}
} else {
return object;
}
String[] values = new String[3];
values[0] = ltitle;
values[1] = lurl;
values[2] = lweight;
object = new GeneralDoc(this.supportedProps, values);
System.out.println("The Object is: " + object.toString());
return object;
}
private int getTotalDocs(String line) {
int index = -1;
String aux = "";
index = line.indexOf("
Displaying");
if ( index == 0) {
//We've got the line where the number documents is
try {
//System.out.println("Index of documents: " + index);
index = line.indexOf(" ");
int index2 = line.lastIndexOf(" ");
aux = line.substring(index + 1, index2);
//System.out.println(aux);
}
catch (Exception e) {
System.out.println("Error parsing the line" + e);
return -1;
}
return (Integer.valueOf(aux).intValue());
}
return -1;
}
}