The R Project SVN R

Rev

Rev 1230 | Rev 5458 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1230 Rev 3765
Line 3... Line 3...
3
  Project: 
3
  Project: 
4
  
4
  
5
  JAVA Source file for the class IndexStream
5
  JAVA Source file for the class IndexStream
6
  
6
  
7
  COPYRIGHT (C), 1998, Thomas Baier
7
  COPYRIGHT (C), 1998, Thomas Baier
-
 
8
 
-
 
9
 *  This program is free software; you can redistribute it and/or modify
-
 
10
 *  it under the terms of the GNU General Public License as published by
-
 
11
 *  the Free Software Foundation; either version 2 of the License, or
8
  ALL RIGHTS RESERVED.
12
 *  (at your option) any later version.
-
 
13
 *
-
 
14
 *  This program is distributed in the hope that it will be useful,
-
 
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
-
 
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-
 
17
 *  GNU General Public License for more details.
9
  
18
 *
-
 
19
 *  You should have received a copy of the GNU General Public License
-
 
20
 *  along with this program; if not, write to the Free Software
-
 
21
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
 
22
    
10
  $Source: /scratch/CVS-ARCHIVE/R/doc/html/search/IndexStream.java,v $
23
  $Source: /scratch/CVS-ARCHIVE/R/doc/html/search/IndexStream.java,v $
11
  
24
  
12
  $Revision: 1.1 $
25
  $Revision: 1.2 $
13
 
26
 
14
  $Date: 1998/05/15 10:38:09 $
27
  $Date: 1999/03/04 17:15:18 $
15
  
28
  
16
  $Author: leisch $
29
  $Author: leisch $
17
 
30
 
18
==============================================================================*/
31
==============================================================================*/
19
 
32
 
Line 58... Line 71...
58
    PARAMS:   
71
    PARAMS:   
59
    THROWS:    
72
    THROWS:    
60
    RETURNS:   void
73
    RETURNS:   void
61
  
74
  
62
    HISTORY:   98-05-08: created
75
    HISTORY:   98-05-08: created
-
 
76
               98-05-15: new static member for include directive
63
  ----------------------------------------------------------------------------*/
77
  ----------------------------------------------------------------------------*/
64
  public IndexStream (URL inputURL)
78
  public IndexStream (URL inputURL)
65
  {
79
  {
66
    // init the instance data
80
    // init the instance data
67
    iInputURL = inputURL;
81
    iInputURL = inputURL;
Line 146... Line 160...
146
    PARAMS:    
160
    PARAMS:    
147
    THROWS:    
161
    THROWS:    
148
    RETURNS:   void
162
    RETURNS:   void
149
  
163
  
150
    HISTORY:   98-05-08: created
164
    HISTORY:   98-05-08: created
-
 
165
               98-05-15: catch all exception (e.g. security violation)
-
 
166
               98-06-07: correctly trace exceptions
-
 
167
               98-11-14: replaced deprecated DataInputStream.readLine()
151
  ----------------------------------------------------------------------------*/
168
  ----------------------------------------------------------------------------*/
152
  public void readStream ()
169
  public void readStream ()
153
  {
170
  {
154
    try {
171
    try {
155
      InputStream stream = iInputURL.openStream ();
172
      InputStream stream = iInputURL.openStream ();
-
 
173
      // according to JDK 1.1.3 docs, now use BufferedReader. Here the docs:
-
 
174
      //
-
 
175
      // As of JDK 1.1, the preferred way to read lines of text is via the
-
 
176
      // BufferedReader.readLine() method. Programs that use the
-
 
177
      // DataInputStream class to read lines can be converted to use the
-
 
178
      // BufferedReader class by replacing code of the form 
156
      DataInputStream is = new DataInputStream (stream);
179
      //   DataInputStream d = new DataInputStream(in); 
-
 
180
      // with 
-
 
181
      //   BufferedReader d = new BufferedReader(new InputStreamReader(in)); 
-
 
182
      BufferedReader is = new BufferedReader (new InputStreamReader (stream));
157
 
183
 
158
      // now read and parse all lines of the file.
184
      // now read and parse all lines of the file.
159
      String line = is.readLine ();
185
      String line = is.readLine ();
160
 
186
 
161
      while (line != null) {
187
      while (line != null) {
Line 165... Line 191...
165
 
191
 
166
      is.close ();
192
      is.close ();
167
      stream.close ();
193
      stream.close ();
168
    } catch (IOException exc) {
194
    } catch (IOException exc) {
169
      // there's some error, ignore it!
195
      // there's some error, ignore it!
-
 
196
    } catch (Exception exc) {
-
 
197
      Tracer.write ("exction opening " + iInputURL.toString () + "\n");
-
 
198
      Tracer.write ("string: " + exc.toString () + "\n");
-
 
199
      if (exc.getMessage () != null) {
-
 
200
	Tracer.write ("info: " + exc.getMessage () + "\n");
-
 
201
      }
170
    }
202
    }
171
 
203
 
172
    return;
204
    return;
173
  }
205
  }
174
 
206
 
Line 251... Line 283...
251
    PARAMS:    
283
    PARAMS:    
252
    THROWS:    
284
    THROWS:    
253
    RETURNS:   void
285
    RETURNS:   void
254
  
286
  
255
    HISTORY:   98-05-08: created
287
    HISTORY:   98-05-08: created
-
 
288
               98-05-15: handle include directive
256
  ----------------------------------------------------------------------------*/
289
  ----------------------------------------------------------------------------*/
257
  public void parseKeyValue (String line)
290
  public void parseKeyValue (String line)
258
  {
291
  {
259
    int index = line.indexOf (":");
292
    int index = line.indexOf (":");
260
 
293
 
Line 273... Line 306...
273
      value = line.substring (index + 1).trim ();
306
      value = line.substring (index + 1).trim ();
274
    } catch (IndexOutOfBoundsException exc) {
307
    } catch (IndexOutOfBoundsException exc) {
275
      line = "";
308
      line = "";
276
    }
309
    }
277
 
310
 
-
 
311
    // 98-05-15: handle include directive
-
 
312
    if (key.equalsIgnoreCase (cIncludeDirective)) {
-
 
313
      // the value is assumed to be the URL of the included file
-
 
314
      try {
-
 
315
	URL includedURL = new URL (iInputURL,value);
-
 
316
 
-
 
317
	Tracer.write ("URL to be included expands to " +
-
 
318
		      includedURL.toString () + "\n");
-
 
319
 
-
 
320
	IndexStream idxStream = new IndexStream (includedURL);
-
 
321
 
-
 
322
	if (idxStream != null) {
-
 
323
	  Value copyValue = idxStream.popEntry ();
-
 
324
	  while (copyValue != null) {
-
 
325
	    iData.addElement (copyValue);
-
 
326
	    copyValue = idxStream.popEntry ();
-
 
327
	  }
-
 
328
	}
-
 
329
	idxStream = null;
-
 
330
      } catch (MalformedURLException exc) {
-
 
331
	// ignore errors
-
 
332
	Tracer.write ("error parsing include URL " + value + "\n");
-
 
333
	return;
-
 
334
      }
-
 
335
    } else {
278
    // create the value and add it to the vector
336
      // create the value and add it to the vector
279
    Value newValue = new Value (key,value);
337
      Value newValue = new Value (key,value);
280
 
338
 
281
    iData.addElement (newValue);
339
      iData.addElement (newValue);
-
 
340
    }
282
 
341
 
283
    return;
342
    return;
284
  }
343
  }
285
 
344
 
286
 
345
 
Line 294... Line 353...
294
 
353
 
295
 
354
 
296
  /*============================================================================
355
  /*============================================================================
297
                                Static Data
356
                                Static Data
298
  ============================================================================*/
357
  ============================================================================*/
-
 
358
  private static final String cIncludeDirective = "include";
299
}
359
}
300
 
360
 
301
 
361
 
302
/*==============================================================================
362
/*==============================================================================
303
 
363
 
304
  HISTORY:
364
  HISTORY:
305
  
365
  
306
  $Log: IndexStream.java,v $
366
  $Log: IndexStream.java,v $
307
  Revision 1.1  1998/05/15 10:38:09  leisch
367
  Revision 1.2  1999/03/04 17:15:18  leisch
-
 
368
  various bugfixes
-
 
369
 
-
 
370
  Revision 1.1.4.1  1999/03/02 15:19:55  leisch
-
 
371
  search used only kewords, no titles
-
 
372
 
-
 
373
  Revision 1.2  1998/05/15 22:08:57  baier
308
  New: Search Engine
374
  handle include
309
 
375
 
310
  Revision 1.1  1998/05/10 02:43:37  baier
376
  Revision 1.1  1998/05/10 02:43:37  baier
311
  Initial revision
377
  Initial revision
312
 
378
 
313
 
379