woolfel     2003/10/16 12:24:26

  Added:       src/htmlparser/org/htmlparser/visitors
                        CompositeTagFindingVisitor.java HtmlPage.java
                        LinkFindingVisitor.java NodeVisitor.java
                        ObjectFindingVisitor.java StringFindingVisitor.java
                        TagFindingVisitor.java TextExtractingVisitor.java
                        UrlModifyingVisitor.java
  Log:
  visitor classes for htmlparser
  
  Revision  Changes    Path
  1.1                  
jakarta-jmeter/src/htmlparser/org/htmlparser/visitors/CompositeTagFindingVisitor.java
  
  Index: CompositeTagFindingVisitor.java
  ===================================================================
  /*
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   * if any, must include the following acknowledgment:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowledgment may appear in the software itself,
   * if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   * "Apache JMeter" must not be used to endorse or promote products
   * derived from this software without prior written permission. For
   * written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   * "Apache JMeter", nor may "Apache" appear in their name, without
   * prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   */
  
  // The developers of JMeter and Apache are greatful to the developers
  // of HTMLParser for giving Apache Software Foundation a non-exclusive
  // license. The performance benefits of HTMLParser are clear and the
  // users of JMeter will benefit from the hard work the HTMLParser
  // team. For detailed information about HTMLParser, the project is
  // hosted on sourceforge at http://htmlparser.sourceforge.net/.
  //
  // HTMLParser was originally created by Somik Raha in 2000. Since then
  // a healthy community of users has formed and helped refine the
  // design so that it is able to tackle the difficult task of parsing
  // dirty HTML. Derrick Oswald is the current lead developer and was kind
  // enough to assist JMeter.
  //
  // contributed by Joshua Kerievsky
  
  package org.htmlparser.visitors;
  
  
  public class CompositeTagFindingVisitor extends NodeVisitor
  {
  
      public CompositeTagFindingVisitor(String compositeTag)
      {
  
      }
  
  }
  
  
  
  1.1                  
jakarta-jmeter/src/htmlparser/org/htmlparser/visitors/HtmlPage.java
  
  Index: HtmlPage.java
  ===================================================================
  /*
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   * if any, must include the following acknowledgment:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowledgment may appear in the software itself,
   * if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   * "Apache JMeter" must not be used to endorse or promote products
   * derived from this software without prior written permission. For
   * written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   * "Apache JMeter", nor may "Apache" appear in their name, without
   * prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   */
  
  // The developers of JMeter and Apache are greatful to the developers
  // of HTMLParser for giving Apache Software Foundation a non-exclusive
  // license. The performance benefits of HTMLParser are clear and the
  // users of JMeter will benefit from the hard work the HTMLParser
  // team. For detailed information about HTMLParser, the project is
  // hosted on sourceforge at http://htmlparser.sourceforge.net/.
  //
  // HTMLParser was originally created by Somik Raha in 2000. Since then
  // a healthy community of users has formed and helped refine the
  // design so that it is able to tackle the difficult task of parsing
  // dirty HTML. Derrick Oswald is the current lead developer and was kind
  // enough to assist JMeter.
  
  package org.htmlparser.visitors;
  
  import org.htmlparser.Node;
  import org.htmlparser.Parser;
  import org.htmlparser.RemarkNode;
  import org.htmlparser.StringNode;
  import org.htmlparser.scanners.TableScanner;
  import org.htmlparser.tags.EndTag;
  import org.htmlparser.tags.TableTag;
  import org.htmlparser.tags.Tag;
  import org.htmlparser.tags.TitleTag;
  import org.htmlparser.util.NodeList;
  
  public class HtmlPage extends NodeVisitor
  {
      private String title;
      private NodeList nodesInBody;
      private NodeList tables;
      private boolean bodyTagBegin;
  
      public HtmlPage(Parser parser)
      {
          super(false);
          parser.registerScanners();
          parser.addScanner(new TableScanner(parser));
          nodesInBody = new NodeList();
          tables = new NodeList();
          bodyTagBegin = false;
      }
  
      public String getTitle()
      {
          return title;
      }
  
      public void setTitle(String title)
      {
          this.title = title;
      }
  
      public void visitTag(Tag tag)
      {
          addTagToBodyIfApplicable(tag);
  
          if (isTable(tag))
          {
              tables.add(tag);
          }
          else
          {
              if (isBodyTag(tag))
                  bodyTagBegin = true;
          }
      }
  
      private boolean isTitle(Tag tag)
      {
          return tag instanceof TitleTag;
      }
  
      private boolean isTable(Tag tag)
      {
          return tag instanceof TableTag;
      }
  
      private void addTagToBodyIfApplicable(Node node)
      {
          if (bodyTagBegin)
              nodesInBody.add(node);
      }
  
      public void visitEndTag(EndTag endTag)
      {
          if (isBodyTag(endTag))
              bodyTagBegin = false;
          addTagToBodyIfApplicable(endTag);
      }
  
      public void visitRemarkNode(RemarkNode remarkNode)
      {
          addTagToBodyIfApplicable(remarkNode);
      }
  
      public void visitStringNode(StringNode stringNode)
      {
          addTagToBodyIfApplicable(stringNode);
      }
  
      private boolean isBodyTag(Tag tag)
      {
          return tag.getTagName().equals("BODY");
      }
  
      public NodeList getBody()
      {
          return nodesInBody;
      }
  
      public TableTag[] getTables()
      {
          TableTag[] tableArr = new TableTag[tables.size()];
          for (int i = 0; i < tables.size(); i++)
              tableArr[i] = (TableTag) tables.elementAt(i);
          return tableArr;
      }
  
      public void visitTitleTag(TitleTag titleTag)
      {
          title = titleTag.getTitle();
      }
  
  }
  
  
  
  1.1                  
jakarta-jmeter/src/htmlparser/org/htmlparser/visitors/LinkFindingVisitor.java
  
  Index: LinkFindingVisitor.java
  ===================================================================
  /*
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   * if any, must include the following acknowledgment:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowledgment may appear in the software itself,
   * if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   * "Apache JMeter" must not be used to endorse or promote products
   * derived from this software without prior written permission. For
   * written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   * "Apache JMeter", nor may "Apache" appear in their name, without
   * prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   */
  
  // The developers of JMeter and Apache are greatful to the developers
  // of HTMLParser for giving Apache Software Foundation a non-exclusive
  // license. The performance benefits of HTMLParser are clear and the
  // users of JMeter will benefit from the hard work the HTMLParser
  // team. For detailed information about HTMLParser, the project is
  // hosted on sourceforge at http://htmlparser.sourceforge.net/.
  //
  // HTMLParser was originally created by Somik Raha in 2000. Since then
  // a healthy community of users has formed and helped refine the
  // design so that it is able to tackle the difficult task of parsing
  // dirty HTML. Derrick Oswald is the current lead developer and was kind
  // enough to assist JMeter.
  
  package org.htmlparser.visitors;
  
  import org.htmlparser.tags.LinkTag;
  
  public class LinkFindingVisitor extends NodeVisitor
  {
      private String linkTextToFind;
      private boolean linkTagFound = false;
      private int count = 0;
  
      public LinkFindingVisitor(String linkTextToFind)
      {
          this.linkTextToFind = linkTextToFind.toUpperCase();
      }
  
      public void visitLinkTag(LinkTag linkTag)
      {
          System.out.println("Matching with " + linkTag.getLinkText());
          if (linkTag.getLinkText().toUpperCase().indexOf(linkTextToFind) != -1)
          {
              linkTagFound = true;
              count++;
          }
      }
  
      public boolean linkTextFound()
      {
          return linkTagFound;
      }
  
      public int getCount()
      {
          return count;
      }
  
  }
  
  
  
  1.1                  
jakarta-jmeter/src/htmlparser/org/htmlparser/visitors/NodeVisitor.java
  
  Index: NodeVisitor.java
  ===================================================================
  /*
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   * if any, must include the following acknowledgment:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowledgment may appear in the software itself,
   * if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   * "Apache JMeter" must not be used to endorse or promote products
   * derived from this software without prior written permission. For
   * written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   * "Apache JMeter", nor may "Apache" appear in their name, without
   * prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   */
  
  // The developers of JMeter and Apache are greatful to the developers
  // of HTMLParser for giving Apache Software Foundation a non-exclusive
  // license. The performance benefits of HTMLParser are clear and the
  // users of JMeter will benefit from the hard work the HTMLParser
  // team. For detailed information about HTMLParser, the project is
  // hosted on sourceforge at http://htmlparser.sourceforge.net/.
  //
  // HTMLParser was originally created by Somik Raha in 2000. Since then
  // a healthy community of users has formed and helped refine the
  // design so that it is able to tackle the difficult task of parsing
  // dirty HTML. Derrick Oswald is the current lead developer and was kind
  // enough to assist JMeter.
  
  package org.htmlparser.visitors;
  
  import org.htmlparser.RemarkNode;
  import org.htmlparser.StringNode;
  import org.htmlparser.tags.EndTag;
  import org.htmlparser.tags.ImageTag;
  import org.htmlparser.tags.LinkTag;
  import org.htmlparser.tags.Tag;
  import org.htmlparser.tags.TitleTag;
  
  public abstract class NodeVisitor
  {
      private boolean recurseChildren;
      private boolean recurseSelf;
  
      public NodeVisitor()
      {
          this(true);
      }
  
      public NodeVisitor(boolean recurseChildren)
      {
          this.recurseChildren = recurseChildren;
          this.recurseSelf = true;
      }
  
      public NodeVisitor(boolean recurseChildren, boolean recurseSelf)
      {
          this.recurseChildren = recurseChildren;
          this.recurseSelf = recurseSelf;
      }
  
      public void visitTag(Tag tag)
      {
  
      }
  
      public void visitStringNode(StringNode stringNode)
      {
      }
  
      public void visitLinkTag(LinkTag linkTag)
      {
      }
  
      public void visitImageTag(ImageTag imageTag)
      {
      }
  
      public void visitEndTag(EndTag endTag)
      {
  
      }
  
      public void visitTitleTag(TitleTag titleTag)
      {
  
      }
      public void visitRemarkNode(RemarkNode remarkNode)
      {
  
      }
  
      public boolean shouldRecurseChildren()
      {
          return recurseChildren;
      }
  
      public boolean shouldRecurseSelf()
      {
          return recurseSelf;
      }
  
      /**
       * Override this method if you wish to do special
       * processing upon completion of parsing 
       */
      public void finishedParsing()
      {
      }
  }
  
  
  
  1.1                  
jakarta-jmeter/src/htmlparser/org/htmlparser/visitors/ObjectFindingVisitor.java
  
  Index: ObjectFindingVisitor.java
  ===================================================================
  /*
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   * if any, must include the following acknowledgment:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowledgment may appear in the software itself,
   * if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   * "Apache JMeter" must not be used to endorse or promote products
   * derived from this software without prior written permission. For
   * written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   * "Apache JMeter", nor may "Apache" appear in their name, without
   * prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   */
  
  // The developers of JMeter and Apache are greatful to the developers
  // of HTMLParser for giving Apache Software Foundation a non-exclusive
  // license. The performance benefits of HTMLParser are clear and the
  // users of JMeter will benefit from the hard work the HTMLParser
  // team. For detailed information about HTMLParser, the project is
  // hosted on sourceforge at http://htmlparser.sourceforge.net/.
  //
  // HTMLParser was originally created by Somik Raha in 2000. Since then
  // a healthy community of users has formed and helped refine the
  // design so that it is able to tackle the difficult task of parsing
  // dirty HTML. Derrick Oswald is the current lead developer and was kind
  // enough to assist JMeter.
  //
  // contributed by Joshua Kerievsky
  
  package org.htmlparser.visitors;
  
  import org.htmlparser.Node;
  import org.htmlparser.tags.Tag;
  import org.htmlparser.util.NodeList;
  
  public class ObjectFindingVisitor extends NodeVisitor
  {
      private Class classTypeToFind;
      private int count = 0;
      private NodeList tags;
  
      public ObjectFindingVisitor(Class classTypeToFind)
      {
          this(classTypeToFind, false);
      }
  
      public ObjectFindingVisitor(Class classTypeToFind, boolean recurse)
      {
          super(recurse);
          this.classTypeToFind = classTypeToFind;
          this.tags = new NodeList();
      }
  
      public int getCount()
      {
          return count;
      }
  
      public void visitTag(Tag tag)
      {
          if (tag.getClass().getName().equals(classTypeToFind.getName()))
          {
              count++;
              tags.add(tag);
          }
      }
  
      public Node[] getTags()
      {
          return tags.toNodeArray();
      }
  }
  
  
  
  1.1                  
jakarta-jmeter/src/htmlparser/org/htmlparser/visitors/StringFindingVisitor.java
  
  Index: StringFindingVisitor.java
  ===================================================================
  /*
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   * if any, must include the following acknowledgment:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowledgment may appear in the software itself,
   * if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   * "Apache JMeter" must not be used to endorse or promote products
   * derived from this software without prior written permission. For
   * written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   * "Apache JMeter", nor may "Apache" appear in their name, without
   * prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   */
  
  // The developers of JMeter and Apache are greatful to the developers
  // of HTMLParser for giving Apache Software Foundation a non-exclusive
  // license. The performance benefits of HTMLParser are clear and the
  // users of JMeter will benefit from the hard work the HTMLParser
  // team. For detailed information about HTMLParser, the project is
  // hosted on sourceforge at http://htmlparser.sourceforge.net/.
  //
  // HTMLParser was originally created by Somik Raha in 2000. Since then
  // a healthy community of users has formed and helped refine the
  // design so that it is able to tackle the difficult task of parsing
  // dirty HTML. Derrick Oswald is the current lead developer and was kind
  // enough to assist JMeter.
  //
  // contributed by Joshua Kerievsky
  
  package org.htmlparser.visitors;
  
  import org.htmlparser.StringNode;
  
  public class StringFindingVisitor extends NodeVisitor
  {
      private boolean stringFound = false;
      private String stringToFind;
      private int foundCount;
      private boolean multipleSearchesWithinStrings;
  
      public StringFindingVisitor(String stringToFind)
      {
          this.stringToFind = stringToFind.toUpperCase();
          foundCount = 0;
          multipleSearchesWithinStrings = false;
      }
  
      public void doMultipleSearchesWithinStrings()
      {
          multipleSearchesWithinStrings = true;
      }
  
      public void visitStringNode(StringNode stringNode)
      {
          String stringToBeSearched = stringNode.getText().toUpperCase();
          if (!multipleSearchesWithinStrings
              && stringToBeSearched.indexOf(stringToFind) != -1)
          {
              stringFound = true;
              foundCount++;
          }
          else if (multipleSearchesWithinStrings)
          {
              int index = -1;
              do
              {
                  index = stringToBeSearched.indexOf(stringToFind, index + 1);
                  if (index != -1)
                      foundCount++;
              }
              while (index != -1);
          }
      }
  
      public boolean stringWasFound()
      {
          return stringFound;
      }
  
      public int stringFoundCount()
      {
          return foundCount;
      }
  
  }
  
  
  
  1.1                  
jakarta-jmeter/src/htmlparser/org/htmlparser/visitors/TagFindingVisitor.java
  
  Index: TagFindingVisitor.java
  ===================================================================
  /*
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   * if any, must include the following acknowledgment:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowledgment may appear in the software itself,
   * if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   * "Apache JMeter" must not be used to endorse or promote products
   * derived from this software without prior written permission. For
   * written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   * "Apache JMeter", nor may "Apache" appear in their name, without
   * prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   */
  
  // The developers of JMeter and Apache are greatful to the developers
  // of HTMLParser for giving Apache Software Foundation a non-exclusive
  // license. The performance benefits of HTMLParser are clear and the
  // users of JMeter will benefit from the hard work the HTMLParser
  // team. For detailed information about HTMLParser, the project is
  // hosted on sourceforge at http://htmlparser.sourceforge.net/.
  //
  // HTMLParser was originally created by Somik Raha in 2000. Since then
  // a healthy community of users has formed and helped refine the
  // design so that it is able to tackle the difficult task of parsing
  // dirty HTML. Derrick Oswald is the current lead developer and was kind
  // enough to assist JMeter.
  //
  // contributed by Joshua Kerievsky
  
  package org.htmlparser.visitors;
  
  import org.htmlparser.Node;
  import org.htmlparser.tags.EndTag;
  import org.htmlparser.tags.Tag;
  import org.htmlparser.util.NodeList;
  
  public class TagFindingVisitor extends NodeVisitor
  {
      private String[] tagsToBeFound;
      private int count[];
      private int endTagCount[];
      private NodeList[] tags;
      private NodeList[] endTags;
      private boolean endTagCheck;
  
      public TagFindingVisitor(String[] tagsToBeFound)
      {
          this(tagsToBeFound, false);
      }
  
      public TagFindingVisitor(String[] tagsToBeFound, boolean endTagCheck)
      {
          this.tagsToBeFound = tagsToBeFound;
          this.tags = new NodeList[tagsToBeFound.length];
          if (endTagCheck)
          {
              endTags = new NodeList[tagsToBeFound.length];
              endTagCount = new int[tagsToBeFound.length];
          }
          for (int i = 0; i < tagsToBeFound.length; i++)
          {
              tags[i] = new NodeList();
              if (endTagCheck)
                  endTags[i] = new NodeList();
          }
          this.count = new int[tagsToBeFound.length];
          this.endTagCheck = endTagCheck;
      }
  
      public int getTagCount(int index)
      {
          return count[index];
      }
  
      public void visitTag(Tag tag)
      {
          for (int i = 0; i < tagsToBeFound.length; i++)
              if (tag.getTagName().equalsIgnoreCase(tagsToBeFound[i]))
              {
                  count[i]++;
                  tags[i].add(tag);
              }
      }
  
      public Node[] getTags(int index)
      {
          return tags[index].toNodeArray();
      }
  
      public void visitEndTag(EndTag endTag)
      {
          if (!endTagCheck)
              return;
          for (int i = 0; i < tagsToBeFound.length; i++)
              if (endTag.getTagName().equalsIgnoreCase(tagsToBeFound[i]))
              {
                  endTagCount[i]++;
                  endTags[i].add(endTag);
              }
      }
  
      public int getEndTagCount(int index)
      {
          return endTagCount[index];
      }
  
  }
  
  
  
  1.1                  
jakarta-jmeter/src/htmlparser/org/htmlparser/visitors/TextExtractingVisitor.java
  
  Index: TextExtractingVisitor.java
  ===================================================================
  /*
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   * if any, must include the following acknowledgment:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowledgment may appear in the software itself,
   * if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   * "Apache JMeter" must not be used to endorse or promote products
   * derived from this software without prior written permission. For
   * written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   * "Apache JMeter", nor may "Apache" appear in their name, without
   * prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   */
  
  // The developers of JMeter and Apache are greatful to the developers
  // of HTMLParser for giving Apache Software Foundation a non-exclusive
  // license. The performance benefits of HTMLParser are clear and the
  // users of JMeter will benefit from the hard work the HTMLParser
  // team. For detailed information about HTMLParser, the project is
  // hosted on sourceforge at http://htmlparser.sourceforge.net/.
  //
  // HTMLParser was originally created by Somik Raha in 2000. Since then
  // a healthy community of users has formed and helped refine the
  // design so that it is able to tackle the difficult task of parsing
  // dirty HTML. Derrick Oswald is the current lead developer and was kind
  // enough to assist JMeter.
  
  package org.htmlparser.visitors;
  
  import org.htmlparser.StringNode;
  import org.htmlparser.tags.EndTag;
  import org.htmlparser.tags.Tag;
  import org.htmlparser.tags.TitleTag;
  import org.htmlparser.util.Translate;
  
  
  /**
   * Extracts text from a web page.
   * Usage:
   * <code>
   * Parser parser = new Parser(...);
   * TextExtractingVisitor visitor = new TextExtractingVisitor();
   * parser.visitAllNodesWith(visitor);
   * String textInPage = visitor.getExtractedText();
   * </code>
   */
  public class TextExtractingVisitor extends NodeVisitor
  {
      private StringBuffer textAccumulator;
      private boolean preTagBeingProcessed;
  
      public TextExtractingVisitor()
      {
          textAccumulator = new StringBuffer();
          preTagBeingProcessed = false;
      }
  
      public String getExtractedText()
      {
          return textAccumulator.toString();
      }
  
      public void visitStringNode(StringNode stringNode)
      {
          String text = stringNode.getText();
          if (!preTagBeingProcessed)
          {
              text = Translate.decode(text);
              text = replaceNonBreakingSpaceWithOrdinarySpace(text);
          }
          textAccumulator.append(text);
      }
  
      public void visitTitleTag(TitleTag titleTag)
      {
          textAccumulator.append(titleTag.getTitle());
      }
  
      private String replaceNonBreakingSpaceWithOrdinarySpace(String text)
      {
          return text.replace('\u00a0', ' ');
      }
  
      public void visitEndTag(EndTag endTag)
      {
          if (isPreTag(endTag))
              preTagBeingProcessed = false;
      }
  
      public void visitTag(Tag tag)
      {
          if (isPreTag(tag))
              preTagBeingProcessed = true;
      }
  
      private boolean isPreTag(Tag tag)
      {
          return tag.getTagName().equals("PRE");
      }
  
  }
  
  
  
  1.1                  
jakarta-jmeter/src/htmlparser/org/htmlparser/visitors/UrlModifyingVisitor.java
  
  Index: UrlModifyingVisitor.java
  ===================================================================
  /*
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   * if any, must include the following acknowledgment:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowledgment may appear in the software itself,
   * if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   * "Apache JMeter" must not be used to endorse or promote products
   * derived from this software without prior written permission. For
   * written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   * "Apache JMeter", nor may "Apache" appear in their name, without
   * prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   */
  
  // The developers of JMeter and Apache are greatful to the developers
  // of HTMLParser for giving Apache Software Foundation a non-exclusive
  // license. The performance benefits of HTMLParser are clear and the
  // users of JMeter will benefit from the hard work the HTMLParser
  // team. For detailed information about HTMLParser, the project is
  // hosted on sourceforge at http://htmlparser.sourceforge.net/.
  //
  // HTMLParser was originally created by Somik Raha in 2000. Since then
  // a healthy community of users has formed and helped refine the
  // design so that it is able to tackle the difficult task of parsing
  // dirty HTML. Derrick Oswald is the current lead developer and was kind
  // enough to assist JMeter.
  //
  // This class was contributed by Joshua Kerievsky
  
  package org.htmlparser.visitors;
  import org.htmlparser.Parser;
  import org.htmlparser.StringNode;
  import org.htmlparser.scanners.LinkScanner;
  import org.htmlparser.tags.EndTag;
  import org.htmlparser.tags.ImageTag;
  import org.htmlparser.tags.LinkTag;
  import org.htmlparser.tags.Tag;
  
  public class UrlModifyingVisitor extends NodeVisitor
  {
      private String linkPrefix;
      private StringBuffer modifiedResult;
      private Parser parser;
  
      public UrlModifyingVisitor(Parser parser, String linkPrefix)
      {
          super(true, false);
          this.parser = parser;
          LinkScanner linkScanner = new LinkScanner();
          parser.addScanner(linkScanner);
          parser.addScanner(
              linkScanner.createImageScanner(ImageTag.IMAGE_TAG_FILTER));
          this.linkPrefix = linkPrefix;
          modifiedResult = new StringBuffer();
      }
  
      public void visitLinkTag(LinkTag linkTag)
      {
          linkTag.setLink(linkPrefix + linkTag.getLink());
      }
  
      public void visitImageTag(ImageTag imageTag)
      {
          imageTag.setImageURL(linkPrefix + imageTag.getImageURL());
          modifiedResult.append(imageTag.toHtml());
      }
  
      public void visitEndTag(EndTag endTag)
      {
          modifiedResult.append(endTag.toHtml());
      }
  
      public void visitStringNode(StringNode stringNode)
      {
          modifiedResult.append(stringNode.toHtml());
      }
  
      public void visitTag(Tag tag)
      {
          modifiedResult.append(tag.toHtml());
      }
  
      public String getModifiedResult()
      {
          return modifiedResult.toString();
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to