Package org.htmlparser.util

Examples of org.htmlparser.util.NodeList


        try
        {
            Parser parser = Parser.createParser(htmlData, null);

            NodeList heads = parser.parse(new TagNameFilter("HEAD"));
            if (heads.size() != 1)
                throw new DiscoveryException(
                        "HTML response must have exactly one HEAD element, " +
                                "found " + heads.size() + " : " + heads.toHtml());
            Node head = heads.elementAt(0);
            for (NodeIterator i = head.getChildren().elements();
                 i.hasMoreNodes();)
            {
                Node node = i.nextNode();
                if (node instanceof TagNode)
View Full Code Here


            if (bytesRead <= 0)
                throw new YadisException("No data read from the HTML message",
                        YadisResult.HTMLMETA_DOWNLOAD_ERROR);

            Parser parser = Parser.createParser(new String(data, 0, bytesRead), null);
            NodeList heads = parser.parse(new TagNameFilter("HEAD"));

            if (heads.size() != 1)
                throw new YadisException(
                        "HTML response must have exactly one HEAD element, " +
                                "found " + heads.size() + " : "
                                + heads.toHtml(),
                        YadisResult.HTMLMETA_INVALID_RESPONSE);

            Node head = heads.elementAt(0);
            for (NodeIterator i = head.getChildren().elements();
                 i.hasMoreNodes();)
            {
                Node node = i.nextNode();
                if (node instanceof MetaTag)
View Full Code Here

  public boolean accept(Node node) {
    for (int i=0; i < filters.length; i++) {
      if (filters[i].accept(node)) {
        if (nodes[i] == null) {
          nodes[i] = new NodeList();
        }
        nodes[i].add(node);
        return true;
      }
    }
View Full Code Here

  public NodeList getNodeList(int index) {
    return nodes[index];
  }
 
  public Node getNode(int index) {
    NodeList list = nodes[index];
    if (list != null && list.size() > 0) {
      return list.elementAt(0);
    } else {
      return null;
    }
  }
View Full Code Here

     */
    public boolean accept(Node node) {
     
      Node parent = node.getParent();
      if (parent != null) {
        NodeList children = parent.getChildren();
        if (children == null) {
          return false;
        }
       
        try {
          Node sibling;
          boolean foundStart = false;
          boolean foundMe = false;
            NodeIterator iter = children.elements();
        while (iter.hasMoreNodes()) {
          sibling = iter.nextNode();
          if (sibling == node) {
            if (!foundStart) {
              //we never found the start boundary
View Full Code Here

        }
    String text;
    if (node instanceof TextNode) {
      text = ((TextNode)node).getText();
    } else {
      NodeList list = node.getChildren();
      if (list != null) {
        text = list.asString();
      } else {
        return null;
      }
    }
    return convertTextData(text);
View Full Code Here

        NodeFilter categoryFilter = new AndFilter(
            new HasAncestorFilter(new HasAttributeFilter("id", "genres")),
            new NodeClassFilter(LinkTag.class)
        );
 
        NodeList categoryNodes = parser.extractAllNodesThatMatch(categoryFilter);
 
        if (categoryNodes.size() > 0) {
          List<Category> categories = new ArrayList<Category>();
 
          NodeIterator iter = categoryNodes.elements();
          while (iter.hasMoreNodes()) {
            Node node = iter.nextNode();
            parseCategory((LinkTag)node, categories);
          }
          this.categories = categories;
View Full Code Here

      NodeFilter queueFilter = new OrFilter(
        new CssClassFilter("dvd-out"),
        new HasAttributeFilter("id", "dvd-queue")
      );

      NodeList queueNodes = parser.extractAllNodesThatMatch(queueFilter);

            int size = queueNodes.size();
      if (size == 1 || size == 2) {
                int i=0;
        List<MovieItem> shippedList = new ArrayList<MovieItem>();
                if (size == 2) {
                    //there is something in the shipped list
                    parseShippedList(queueNodes.elementAt(i++), shippedList);
                }
       
        List<MovieItem> movieQueue = new ArrayList<MovieItem>();
        parseMovieQueue(queueNodes.elementAt(i++), movieQueue);
       
        this.shippedList = shippedList;
        this.movieQueue = movieQueue;
      }
     
View Full Code Here

   
    Pattern ratingPattern = Pattern.compile(RATING_EXPR);
    Pattern movieIdPattern = Pattern.compile(MOVIE_ID_EXPR);
    SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yy");
   
    NodeList discs = new NodeList();
    queue.collectInto(discs, discFilter);

    NodeList info = new NodeList();
    SimpleNodeIterator iter = discs.elements();
    while (iter.hasMoreNodes()) {
      info.removeAll();
      infoCollector.clear();
      Node disc = iter.nextNode();
     
      //collect all the nodes for the movie items
      disc.collectInto(info, infoCollector);
View Full Code Here

        });
   
    Pattern ratingPattern = Pattern.compile(RATING_EXPR);
    Pattern movieIdPattern = Pattern.compile(MOVIE_ID_EXPR);
   
    NodeList discs = new NodeList();
    queue.collectInto(discs, discFilter);

    NodeList info = new NodeList();
    SimpleNodeIterator iter = discs.elements();
    while (iter.hasMoreNodes()) {
      info.removeAll();
      infoCollector.clear();
      Node disc = iter.nextNode();
     
      //collect all the nodes for the movie items
      disc.collectInto(info, infoCollector);

      int i=0;

      //parse out all the information
      LinkTag titleLink = (LinkTag)infoCollector.getNode(i++);
      String movieId = null;
      Matcher matcher = movieIdPattern.matcher(titleLink.getLink());
      if (matcher.matches()) {
        movieId = matcher.group(1);
      } else {
        //not a valid movie
        continue;
      }
     
      String title = titleLink.getLinkText();

      int rating = -1;
      ImageTag ratingNode = (ImageTag)infoCollector.getNode(i++);
      if (ratingNode != null) {
        String ratingStr = ratingNode.getImageURL();
        matcher = ratingPattern.matcher(ratingStr);
        if (matcher.matches()) {
          rating = Integer.parseInt(matcher.group(1));
        }
      }
     
      String mpaa = NodeUtils.getTextData(infoCollector.getNode(i++));
     
      NodeList list = infoCollector.getNodeList(i++);
      String category = NodeUtils.getTextData(list.elementAt(0));
      String availability = NodeUtils.getTextData(list.elementAt(1));
     
      //create a movie item
      MovieItem movie = createMovieItem(movieId);
      movie.setTitle(title);
      movie.setMpaa(mpaa);
View Full Code Here

TOP

Related Classes of org.htmlparser.util.NodeList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.