KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashMap JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import java.util.List JavaDoc;
23
24
25 /**
26  * An HTML parser that extracts the inline resources.
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.2 $ $Date: 2005/08/02 14:53:29 $
32  */

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

41     public InlineResourcesParser(Reader JavaDoc reader) {
42         super(reader, null, false, null);
43         resourceList = 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 resource 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         resourceList.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         if (tagName.equalsIgnoreCase("<img")) {
71             checkoutAttribute(attributes, "src");
72         } else if (tagName.equalsIgnoreCase("<link")) {
73             checkoutAttribute(attributes, "src");
74             checkoutAttribute(attributes, "href");
75         }
76         checkoutAttribute(attributes, "background");
77     }
78
79     public List JavaDoc getExtractedResources() {
80         return resourceList;
81     }
82 }
83
Popular Tags