Blame | Last modification | View Log | Download | RSS feed
/*==============================================================================Project:JAVA Source file for the class IndexStreamCOPYRIGHT (C), 1998, Thomas BaierALL RIGHTS RESERVED.$Source: /scratch/CVS-ARCHIVE/R/doc/html/search/IndexStream.java,v $$Revision: 1.1 $$Date: 1998/05/15 10:38:09 $$Author: leisch $==============================================================================*//* -------------------------------- Imports --------------------------------- */import java.util.*;import java.applet.*;import java.awt.*;import java.net.*;import java.io.*;/*==============================================================================Interface of class IndexStream==============================================================================*//*------------------------------------------------------------------------------CLASS: IndexStreamSUPER: ObjectCONF. TO:PURPOSE: reading and parsing a stream of multiple index entries, also handlessome keywords, e.g. include of other streams, provides a contextfor environment spaceNOTES:HISTORY: 98-05-08: created------------------------------------------------------------------------------*/public class IndexStream extends Object{/*============================================================================Public methods============================================================================*//*----------------------------------------------------------------------------INTERFACE:PURPOSE: default constructorNOTES:PARAMS:THROWS:RETURNS: voidHISTORY: 98-05-08: created----------------------------------------------------------------------------*/public IndexStream (URL inputURL){// init the instance dataiInputURL = inputURL;iIndex = 0;iData = new Vector ();// read the index data from the streamreadStream ();}/*----------------------------------------------------------------------------INTERFACE:PURPOSE:NOTES:PARAMS:THROWS:RETURNS: voidHISTORY: 98-05-08: created----------------------------------------------------------------------------*/public Value popEntry (){if (iIndex < 0) {iIndex = 0;}if (iIndex >= iData.size ()) {return null;}iIndex++;return (Value) iData.elementAt (iIndex - 1);}/*----------------------------------------------------------------------------INTERFACE:PURPOSE:NOTES:PARAMS:THROWS:RETURNS: voidHISTORY: 98-05-08: created----------------------------------------------------------------------------*/public void pushEntry (Value anEntry){if (iIndex < 0) {iIndex = 0;}if (iIndex >= iData.size ()) {iIndex = iData.size ();}iData.insertElementAt (anEntry,iIndex);return;}/*============================================================================Protected methods============================================================================*//*============================================================================Private methods============================================================================*//*----------------------------------------------------------------------------INTERFACE:PURPOSE:NOTES:PARAMS:THROWS:RETURNS: voidHISTORY: 98-05-08: created----------------------------------------------------------------------------*/public void readStream (){try {InputStream stream = iInputURL.openStream ();DataInputStream is = new DataInputStream (stream);// now read and parse all lines of the file.String line = is.readLine ();while (line != null) {parseLine (line);line = is.readLine ();}is.close ();stream.close ();} catch (IOException exc) {// there's some error, ignore it!}return;}/*----------------------------------------------------------------------------INTERFACE:PURPOSE:NOTES:PARAMS:THROWS:RETURNS: voidHISTORY: 98-05-08: created----------------------------------------------------------------------------*/public void parseLine (String line){// if the line is empty, we'll ignore itif (line.length () == 0) {return;}// if the line starts with #, its a commentif (line.startsWith ("#")) {return;}// if the line starts with whitespace, its a continuationif (line.startsWith ("\t")|| line.startsWith (" ")) {parseContinuation (line);}// else, it must be a key/value pairparseKeyValue (line);return;}/*----------------------------------------------------------------------------INTERFACE:PURPOSE:NOTES:PARAMS:THROWS:RETURNS: voidHISTORY: 98-05-08: created----------------------------------------------------------------------------*/public void parseContinuation (String line){// if there's no key/value pair in the list, ignore itif (iData.size () < 1) {return;}// we'll trim whitespaceString value = line.trim ();// get the last objectValue lastObject = (Value) iData.lastElement ();// modify itlastObject.addToValue (value);return;}/*----------------------------------------------------------------------------INTERFACE:PURPOSE:NOTES: for safety, we'll ignore everything not okPARAMS:THROWS:RETURNS: voidHISTORY: 98-05-08: created----------------------------------------------------------------------------*/public void parseKeyValue (String line){int index = line.indexOf (":");// not found or : as first characterif (index < 1) {return;}// everything from the start to the : is a keyString key = line.substring (0,index);String value = null;// value starts after :, trim whitespacetry {value = line.substring (index + 1).trim ();} catch (IndexOutOfBoundsException exc) {line = "";}// create the value and add it to the vectorValue newValue = new Value (key,value);iData.addElement (newValue);return;}/*============================================================================Instance Variables============================================================================*/private URL iInputURL;private int iIndex;private Vector iData;/*============================================================================Static Data============================================================================*/}/*==============================================================================HISTORY:$Log: IndexStream.java,v $Revision 1.1 1998/05/15 10:38:09 leischNew: Search EngineRevision 1.1 1998/05/10 02:43:37 baierInitial revision==============================================================================*/// Local Variables:// mode: Java// mode: font-lock// End: