/* -*-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 maxhits) return(maxhits); return(this.numDocs); } // GetPropertyValues (pointer) // The 'pointer' is a pointer to the array of documents found by // a previous search. This method returns the value of all the // document's properties. public String[] GetPropertyValues (int p) throws java.lang.ArrayIndexOutOfBoundsException { System.out.println("GetPropertyValues(int p)" + p); if (p > this.docs_stored) throw new ArrayIndexOutOfBoundsException(); String[] aux = new String[requestedProps.length]; for(int i=0;i this.docs_stored) throw new ArrayIndexOutOfBoundsException(); if (!CheckPropAvailability(propnames)) throw new ArrayIndexOutOfBoundsException(); String[] aux = new String[propnames.length]; for(int i=0;i 0) && (theDocCursor < numDocs)) return true; else return false; } public int DocCursor () { System.out.println("DocCursor()"); return theDocCursor; } // CheckPropAvailability (list of property names) // Returns true if each property in a list of property names is // supported by this CollectionPlug. public static boolean CheckPropAvailability (String[] propList) { System.out.println("CheckPropAvailability(String[])"); for (int i=0; iCopyright ©") == -1) { //System.out.println("j=" + j); //System.out.println(line); if (j==-3) { //We have found docs.... //Getting docs one by one and storing them in tdocs objects[counter++] = GetDoc(line); } if (j==-1) { //Getting number of docs found this.numDocs = getTotalDocs(line); if (this.numDocs != -1) { //There are docs j = -3; counter = 0; } } line = dis.readLine(); } System.out.println("Total docs found:" + this.numDocs); System.out.println("Docs found by the parser: " + counter); if (this.numDocs > counter) { // This means we have a parser problem and we are not // able to get all the docs, or the connection went down // just in the middle of the transmission // So, we set the flag to: yet more docs to come this.flagmore = true; } return(counter); } private GeneralDoc GetDoc(String line) throws Exception { //Gets the document and all its fields in a Doc object GeneralDoc object = new GeneralDoc(); int index = -1; String aux; String ltitle; String lurl; String lweight; index = line.indexOf("

"); 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; } }