Package com.weberjr.sign

Source Code of com.weberjr.sign.WootModule

package com.weberjr.sign;

import java.net.URL;
import java.util.Iterator;
import java.util.List;
import org.cyberneko.html.parsers.*;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom.input.DOMBuilder;

public class WootModule extends BetabriteModule{

  @Override
  protected void setMessageDefaults() {
//    set the messagedefaults
    message.setColor(MessageBean.FONT_ORANGE);
    message.setDisplay(MessageBean.DISPLAY_MARQUEE);
   
  }

  @Override
  protected void updateMessage() {
    try{
      String displayMessage = new String("Woot.com: ");
   
      //parse the document
      DOMParser parser = new DOMParser();
      parser.parse(settings.getFile());
     
      DOMBuilder builder = new DOMBuilder();
     
      Document xmlDoc =  builder.build(parser.getDocument());
   
      if(xmlDoc != null)
      {
        Element rootElement = xmlDoc.getRootElement();
        Namespace namespace = rootElement.getNamespace();
       
        Element bodyElement = rootElement.getChild("BODY", namespace);
        Element formElement = bodyElement.getChild("FORM",namespace).getChild("DIV",namespace);
       
        List allChildren = formElement.getChildren();
       
        Element contentContainer = null;
        for(int count = 0; count < allChildren.size(); count ++)
        {
          Element tempElement = (Element)allChildren.get(count);
         
          if((tempElement.getName()).equals("DIV") && (tempElement.getAttributeValue("class")).equals("contentContainer"))
          {
            contentContainer = tempElement;
          }
        }
       
        String wootTitle = null;
        String wootPrice = null;
       
        if(contentContainer != null)
        {
          allChildren = contentContainer.getChild("DIV",namespace).getChild("DIV",namespace).getChildren();
         
          for(int count = 0; count < allChildren.size(); count ++)
          {
            Element tempElement = (Element)allChildren.get(count);
           
            if(tempElement.getName().equals("H3"))
            {
              wootTitle = tempElement.getText();
            }
            else if((tempElement.getName().equals("DIV")) && (tempElement.getAttributeValue("class")).equals("price")){
              Element spanElement = tempElement.getChild("SPAN",namespace);
             
              wootPrice = spanElement.getText();
            }
          }
         
        }
       
        displayMessage = displayMessage + wootTitle + " " + wootPrice;
        message.setMessage(displayMessage);
      }
    }
    catch(Exception e)
    {
      //do nothing
      e.printStackTrace();
    }
   
  }

}
TOP

Related Classes of com.weberjr.sign.WootModule

TOP
Copyright © 2018 www.massapi.com. 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.