KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > common > parsers > html > RefsParser


1 /*
2  * Copyright 2005 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.blandware.atleap.common.parsers.html;
17
18 import java.io.Reader JavaDoc;
19 import java.io.IOException JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import java.util.HashMap JavaDoc;
23
24
25 /**
26  * An HTML parser that extracts all references.
27  *
28  * @see HTMLPlainTextExtractor
29  * @author Roman Puchkovskiy <a HREF="mailto:roman.puchkovskiy@blandware.com">
30  * &lt;roman.puchkovskiy@blandware.com&gt;</a>
31  * @version $Revision: 1.3 $ $Date: 2006/03/26 11:47:32 $
32  */

33 class RefsParser extends HTMLParser {
34     protected List JavaDoc refList;
35
36     /**
37      * Constructs the RefsParser.
38      *
39      * @param reader the <code>Reader</code> that will supply an HTML to parse
40      */

41     public RefsParser(Reader JavaDoc reader) {
42         super(reader, null, false, null);
43         refList = new ArrayList JavaDoc();
44     }
45
46     protected void addText(String JavaDoc text) throws IOException JavaDoc {}
47
48     protected void addSpace() throws IOException JavaDoc {}
49
50     /**
51      * Considers text -- adds it to the ref list.
52      *
53      * @param text the text ro be added to the list
54      *
55      * @throws java.io.IOException
56      */

57     protected void considerText(String JavaDoc text) throws IOException JavaDoc {
58         refList.add(text);
59     }
60
61     /**
62      * Considers space -- actually does nothing.
63      *
64      * @throws java.io.IOException
65      */

66     protected void considerSpace() throws IOException JavaDoc {}
67
68     protected void processTag(String JavaDoc tagName, HashMap JavaDoc attributes,
69                               boolean closing) throws IOException JavaDoc {
70         checkoutAttribute(attributes, "src");
71         checkoutAttribute(attributes, "href");
72         checkoutAttribute(attributes, "background");
73     }
74
75     public List JavaDoc getExtractedRefs() {
76         return refList;
77     }
78 }
79
Popular Tags