01: package org.apache.lucene.demo.html;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19:
20: import java.io.*;
21:
22: class Test {
23: public static void main(String[] argv) throws IOException,
24: InterruptedException {
25: if ("-dir".equals(argv[0])) {
26: String[] files = new File(argv[1]).list();
27: java.util.Arrays.sort(files);
28: for (int i = 0; i < files.length; i++) {
29: System.err.println(files[i]);
30: File file = new File(argv[1], files[i]);
31: parse(file);
32: }
33: } else
34: parse(new File(argv[0]));
35: }
36:
37: public static void parse(File file) throws IOException,
38: InterruptedException {
39: FileInputStream fis = null;
40: try {
41: fis = new FileInputStream(file);
42: HTMLParser parser = new HTMLParser(fis);
43: System.out.println("Title: "
44: + Entities.encode(parser.getTitle()));
45: System.out.println("Summary: "
46: + Entities.encode(parser.getSummary()));
47: System.out.println("Content:");
48: LineNumberReader reader = new LineNumberReader(parser
49: .getReader());
50: for (String l = reader.readLine(); l != null; l = reader
51: .readLine())
52: System.out.println(l);
53: } finally {
54: if (fis != null)
55: fis.close();
56: }
57: }
58: }
|