core/com.nokia.carbide.cpp.news.reader/src/com/nokia/carbide/cpp/internal/news/reader/gen/FeedInfo/FeedInfoManager.java
branchRCL_2_0
changeset 104 4ca9a303c257
parent 99 3604ec4c983e
child 153 c847f1618fc8
equal deleted inserted replaced
103:de4b04f4ec57 104:4ca9a303c257
   104 	}
   104 	}
   105 
   105 
   106 	/**
   106 	/**
   107 	 * Retrieve the feed info file from remote server, make a local copy of this file
   107 	 * Retrieve the feed info file from remote server, make a local copy of this file
   108 	 * and returns the URL to the local copy.
   108 	 * and returns the URL to the local copy.
       
   109 	 * @param useLocal - use local copy of feed listing file? 
   109 	 * @return URL of local copy of feed info file
   110 	 * @return URL of local copy of feed info file
   110 	 * @throws Exception
   111 	 * @throws Exception
   111 	 */
   112 	 */
   112 	public URL getFeedInfoFileURL() throws Exception {
   113 	public URL getFeedInfoFileURL(boolean useLocalCopy) throws Exception {
       
   114 		if (feedInfoFile == null) {
       
   115 			feedInfoFile = createFeedInfoFile();
       
   116 		}
       
   117 
       
   118 		if (useLocalCopy) {
       
   119 			// try to use local copy of the fee info file if it exists.
       
   120 			if (feedInfoFile != null && feedInfoFile.exists()) {
       
   121 				return feedInfoFile.toURL();
       
   122 			}
       
   123 			else {
       
   124 				return null;
       
   125 			}
       
   126 		}
       
   127 
       
   128 		// retrieve the feed info file from remote server and make a local copy of this file
   113 		String pathStr = CarbideNewsReaderPlugin.getFeedManager().getProperty(FEED_INFO_FILE_KEY);
   129 		String pathStr = CarbideNewsReaderPlugin.getFeedManager().getProperty(FEED_INFO_FILE_KEY);
   114 		if (pathStr != null) {
   130 		if (pathStr != null) {
   115 			URL fileUrl = new URL(pathStr);
   131 			URL fileUrl = new URL(pathStr);
   116 			if (fileUrl != null) {
   132 			if (fileUrl != null) {
   117 				HttpURLConnection connection = null;
   133 				HttpURLConnection connection = null;
   122 					connection.connect();
   138 					connection.connect();
   123 					int responseCode = connection.getResponseCode();
   139 					int responseCode = connection.getResponseCode();
   124 					handlesHttpErrorCode(responseCode);
   140 					handlesHttpErrorCode(responseCode);
   125 					inputStream = connection.getInputStream();
   141 					inputStream = connection.getInputStream();
   126 					if (inputStream != null) {
   142 					if (inputStream != null) {
   127 						if (feedInfoFile == null) {
       
   128 							feedInfoFile = createFeedInfoFile();
       
   129 						}
       
   130 						if (feedInfoFile != null) {
   143 						if (feedInfoFile != null) {
   131 							if (feedInfoFile.exists()) {
   144 							if (feedInfoFile.exists()) {
   132 								feedInfoFile.delete();
   145 								feedInfoFile.delete();
   133 							}
   146 							}
   134 							FileUtils.copyFile(inputStream, feedInfoFile);
   147 							FileUtils.copyFile(inputStream, feedInfoFile);
   145 						inputStream.close();
   158 						inputStream.close();
   146 					}
   159 					}
   147 				}
   160 				}
   148 			}
   161 			}
   149 		}
   162 		}
       
   163 
   150 		return null;
   164 		return null;
   151 	}
   165 	}
   152 
   166 
   153 	/**
   167 	/**
   154 	 * Save feed information to a file.
   168 	 * Save feed information to a file.