Package com.nordija.portal

Source Code of com.nordija.portal.XMLNewsCache

/**
* Copyright 1999-2001 by Nordija <www.nordija.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
**/


package com.nordija.portal;

import java.text.*;
import java.util.*;
import java.net.*;
import java.io.*;
//import javax.servlet.*;
//import javax.servlet.http.*;
import org.xml.sax.SAXException;
import org.apache.xalan.xslt.XSLTProcessorFactory;
import org.apache.xalan.xslt.XSLTInputSource;
import org.apache.xalan.xslt.XSLTResultTarget;
import org.apache.xalan.xslt.XSLTProcessor;

public class XMLNewsCache  {
    //implements Runnable {
 
  public final int upDate = 4;
 
  private String internetNews;
  private String businessNews;
  private String developerNews;

  private String internetURL = new String("http://headlines.internet.com/internetnews/top-news/news.rss");
  private String businessURL = new String("http://headlines.internet.com/internetnews/bus-news/news.rss");
  private String developerURL = new String("http://headlines.internet.com/internetnews/wd-news/news.rss");
   
  private StringBuffer bufPath;

  String newsSupplier;

 
  static Thread cacheThread = null;
 

  public XMLNewsCache()  {

    /*
    if(cacheThread == null || !isThreadAlive()){
        cacheThread = new Thread(this);
        cacheThread.setPriority(Thread.MIN_PRIORITY);
        cacheThread.start();
    }
    else
      System.out.println("News thread already running");
    */

  }//End init 
 
 
 
 
  public String getTest() {
    return "Dette er en test!!";
  }   
  public String getInternetNews() throws IOException {
 
    return doXML(internetURL);
  }
 
  public String getBusinessNews() throws IOException {
   
    return doXML(businessURL);
  }
 
  public String getDeveloperNews() throws IOException {
    return doXML(developerURL);
  }
 
 

 
  private String doXML(String newsURL) throws IOException {
     
  StringWriter wrt = new StringWriter();
                                                       
    try{
          XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
   
  
          processor.process(new XSLTInputSource(newsURL),
                            new XSLTInputSource("http://home.nordija.dk/news.xsl"),
                            new XSLTResultTarget(wrt));
  
   
         }
          catch(org.xml.sax.SAXException se){
     
            System.out.println("SaxException in XML_news.jsp: " + se.toString());
        }
 
    wrt.close();
 
      return wrt.toString();
   
  }//End doXML

 
    /*
  private static synchronized boolean isThreadAlive(){
   
        if(cacheThread.isAlive())
          return true;   
        else
          return false;
   
   
   
  } 
   
 
  public void run() {
   
    System.out.println("Thread run!");
   
   
    while(true) {
           
      try {
       
        internetNews = doXML(internetURL);
        businessNews = doXML(businessURL);                               
        developerNews = doXML(developerURL);
   
      }
      catch(IOException ie) {
        ie.toString();
      }
     
     
   
      try {
       
       
        //Sleep for 1 hour
        Thread.sleep(1000 * 60 * 60);
   
      }
      catch(InterruptedException e) {
      e.toString();
      }
   
    }
   

  }//End run
 
 
 
 
  public void destroy() {
   
    cacheThread.stop();
   
  }//End destroy 
 
  */
 
 
 
 
 
 

}//End XMLNewsCache
TOP

Related Classes of com.nordija.portal.XMLNewsCache

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.