1
package org.apache.lucene.benchmark.byTask.feeds;
4
* Licensed to the Apache Software Foundation (ASF) under one or more
5
* contributor license agreements. See the NOTICE file distributed with
6
* this work for additional information regarding copyright ownership.
7
* The ASF licenses this file to You under the Apache License, Version 2.0
8
* (the "License"); you may not use this file except in compliance with
9
* the License. You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
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.
20
import java.io.IOException;
21
import java.io.Reader;
22
import java.text.DateFormat;
23
import java.text.ParseException;
24
import java.util.Date;
25
import java.util.Properties;
28
* HTML Parser that is based on Lucene's demo HTML parser.
30
public class DemoHTMLParser implements org.apache.lucene.benchmark.byTask.feeds.HTMLParser {
32
public DocData parse(DocData docData, String name, Date date, String title, Reader reader, DateFormat dateFormat) throws IOException, InterruptedException {
33
org.apache.lucene.benchmark.byTask.feeds.demohtml.HTMLParser p = new org.apache.lucene.benchmark.byTask.feeds.demohtml.HTMLParser(reader);
41
Properties props = p.getMetaTags();
43
Reader r = p.getReader();
44
char c[] = new char[1024];
45
StringBuilder bodyBuf = new StringBuilder();
47
while ((n = r.read(c)) >= 0) {
49
bodyBuf.append(c,0,n);
53
if (date == null && props.getProperty("date")!=null) {
55
date = dateFormat.parse(props.getProperty("date").trim());
56
} catch (ParseException e) {
57
// do not fail test just because a date could not be parsed
58
System.out.println("ignoring date parse exception (assigning 'now') for: "+props.getProperty("date"));
59
date = new Date(); // now
64
docData.setName(name);
65
docData.setBody(bodyBuf.toString());
66
docData.setTitle(title);
67
docData.setProps(props);
68
docData.setDate(date);