LinkFindingVisitor.java
1 // HTMLParser Library $Name: v1_6_20060319 $ - A java-based parser for HTML 2 // http://sourceforge.org/projects/htmlparser 3 // Copyright (C) 2004 Somik Raha 4 // 5 // Revision Control Information 6 // 7 // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/visitors/LinkFindingVisitor.java,v $ 8 // $Author: derrickoswald $ 9 // $Date: 2004/05/24 00:38:19 $ 10 // $Revision: 1.36 $ 11 // 12 // This library is free software; you can redistribute it and/or 13 // modify it under the terms of the GNU Lesser General Public 14 // License as published by the Free Software Foundation; either 15 // version 2.1 of the License, or (at your option) any later version. 16 // 17 // This library is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 // Lesser General Public License for more details. 21 // 22 // You should have received a copy of the GNU Lesser General Public 23 // License along with this library; if not, write to the Free Software 24 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 // 26 27 package org.htmlparser.visitors; 28 29 import java.util.Locale; 30 import org.htmlparser.tags.LinkTag; 31 32 import org.htmlparser.Tag; 33 34 public class LinkFindingVisitor extends NodeVisitor 35 { 36 private String linkTextToFind; 37 private int count; 38 private Locale locale; 39 40 public LinkFindingVisitor (String linkTextToFind) 41 { 42 this (linkTextToFind, null); 43 } 44 45 public LinkFindingVisitor (String linkTextToFind, Locale locale) 46 { 47 count = 0; 48 this.locale = (null == locale) ? Locale.ENGLISH : locale; 49 this.linkTextToFind = linkTextToFind.toUpperCase (this.locale); 50 } 51 52 public void visitTag(Tag tag) 53 { 54 if (tag instanceof LinkTag) 55 if (-1 != ((LinkTag)tag).getLinkText ().toUpperCase (locale).indexOf (linkTextToFind)) 56 count++; 57 } 58 59 public boolean linkTextFound() 60 { 61 return (0 != count); 62 } 63 64 public int getCount() 65 { 66 return (count); 67 } 68 69 }