KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > util > HTMLHandler


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
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  */

17
18 /* $Id: HTMLHandler.java 42598 2004-03-01 16:18:28Z gregor $ */
19
20 package org.apache.lenya.util;
21
22 import java.util.ArrayList JavaDoc;
23
24 import javax.swing.text.MutableAttributeSet JavaDoc;
25 import javax.swing.text.html.HTML JavaDoc;
26 import javax.swing.text.html.HTML.Tag;
27 import javax.swing.text.html.HTMLEditorKit.ParserCallback;
28
29 import org.apache.log4j.Category;
30
31
32 /**
33  * DOCUMENT ME!
34  */

35 public class HTMLHandler extends ParserCallback {
36     Category log = Category.getInstance(HTMLHandler.class);
37     private ArrayList JavaDoc img_src;
38     private ArrayList JavaDoc img_src_all;
39     private ArrayList JavaDoc a_href;
40     private ArrayList JavaDoc a_href_all;
41     private ArrayList JavaDoc link_href;
42     private ArrayList JavaDoc link_href_all;
43
44     /**
45      * Creates a new HTMLHandler object.
46      */

47     public HTMLHandler() {
48         img_src_all = new ArrayList JavaDoc();
49         img_src = new ArrayList JavaDoc();
50         a_href_all = new ArrayList JavaDoc();
51         a_href = new ArrayList JavaDoc();
52         link_href_all = new ArrayList JavaDoc();
53         link_href = new ArrayList JavaDoc();
54     }
55
56     /**
57      * DOCUMENT ME!
58      *
59      * @param tag DOCUMENT ME!
60      * @param attributes DOCUMENT ME!
61      * @param pos DOCUMENT ME!
62      */

63     public void handleStartTag(Tag tag, MutableAttributeSet JavaDoc attributes, int pos) {
64         if (tag.equals(HTML.Tag.A)) {
65             String JavaDoc href = (String JavaDoc) attributes.getAttribute(HTML.Attribute.HREF);
66
67             if (href != null) {
68                 a_href_all.add(href);
69
70                 if (!a_href.contains(href)) {
71                     a_href.add(href);
72                 }
73             }
74         }
75     }
76
77     /**
78      * DOCUMENT ME!
79      *
80      * @param tag DOCUMENT ME!
81      * @param attributes DOCUMENT ME!
82      * @param pos DOCUMENT ME!
83      */

84     public void handleSimpleTag(Tag tag, MutableAttributeSet JavaDoc attributes, int pos) {
85         if (tag.equals(HTML.Tag.IMG)) {
86             String JavaDoc src = (String JavaDoc) attributes.getAttribute(HTML.Attribute.SRC);
87
88             if (src != null) {
89                 img_src_all.add(src);
90
91                 if (!img_src.contains(src)) {
92                     img_src.add(src);
93                 }
94             }
95         }
96
97         if (tag.equals(HTML.Tag.LINK)) {
98             String JavaDoc href = (String JavaDoc) attributes.getAttribute(HTML.Attribute.HREF);
99
100             if (href != null) {
101                 link_href_all.add(href);
102
103                 if (!link_href.contains(href)) {
104                     link_href.add(href);
105                 }
106             }
107         }
108     }
109
110     /**
111      * DOCUMENT ME!
112      *
113      * @return DOCUMENT ME!
114      */

115     public ArrayList JavaDoc getImageSrcs() {
116         return img_src;
117     }
118
119     /**
120      * DOCUMENT ME!
121      *
122      * @return DOCUMENT ME!
123      */

124     public ArrayList JavaDoc getAllImageSrcs() {
125         return img_src_all;
126     }
127
128     /**
129      * DOCUMENT ME!
130      *
131      * @return DOCUMENT ME!
132      */

133     public ArrayList JavaDoc getLinkHRefs() {
134         return link_href;
135     }
136
137     /**
138      * DOCUMENT ME!
139      *
140      * @return DOCUMENT ME!
141      */

142     public ArrayList JavaDoc getAllLinkHRefs() {
143         return link_href_all;
144     }
145
146     /**
147      * DOCUMENT ME!
148      *
149      * @return DOCUMENT ME!
150      */

151     public ArrayList JavaDoc getAHRefs() {
152         return a_href;
153     }
154
155     /**
156      * DOCUMENT ME!
157      *
158      * @return DOCUMENT ME!
159      */

160     public ArrayList JavaDoc getAllAHRefs() {
161         return a_href_all;
162     }
163 }
164
Popular Tags