1 8 package org.jahia.utils; 9 10 import java.io.BufferedReader ; 11 import java.io.IOException ; 12 import java.io.InputStream ; 13 import java.io.InputStreamReader ; 14 import java.io.Reader ; 15 import java.net.URL ; 16 17 import org.jahia.exceptions.JahiaException; 18 ; 19 20 21 22 public class HttpUtils { 23 24 private static org.apache.log4j.Logger logger = 25 org.apache.log4j.Logger.getLogger(HttpUtils.class); 26 27 private static HttpUtils theObject = null; 28 29 30 31 36 private HttpUtils() 37 { 38 JahiaConsole.println( "Utils", "***** Starting HttpUtils *****" ); 39 } 41 42 43 48 public static HttpUtils getInstance() 49 { 50 if (theObject == null) { 51 theObject = new HttpUtils(); 52 } 53 return theObject; 54 } 56 57 58 64 public String getRemoteFileContents( String urlPath ) 65 { 66 try { 67 URL url = new URL ( urlPath ); 68 InputStreamReader input = new InputStreamReader ( (InputStream ) url.openStream() ); 69 BufferedReader in = new BufferedReader ( (Reader ) input ); 70 String contents = ""; 71 String buffer = ""; 72 while ((buffer = in.readLine()) != null) { 73 contents += buffer + "\n"; 74 } 75 return contents; 76 } catch (IOException ie) { 77 String errorMsg = "Error in reading newsfeed " + urlPath + " : " + ie.getMessage(); 78 JahiaConsole.println( "NewsFeedManager", errorMsg + " -> Error !" ); 79 JahiaException je = new JahiaException( "Cannot access to newsfeed", 80 errorMsg, JahiaException.FILE_ERROR, JahiaException.ERROR_SEVERITY, ie ); 81 logger.error("Error:", je); 82 return "- No NewsFeed ! -"; 83 } 84 } 86 87 88 } | Popular Tags |