Example #1
0
 /** fetch the feed from the RSS Url */
 public String fetchFeed() {
   StringBuffer feed = new StringBuffer();
   for (Iterator<Item> I = contents.values().iterator(); I.hasNext(); ) {
     Item item = I.next();
     String itemUrl = item.getUrl();
     try {
       URL feedUrl = new URL(itemUrl);
       Charset encoding = Charset.defaultCharset();
       BufferedReader bufferedReader =
           new BufferedReader(new InputStreamReader(feedUrl.openStream(), encoding));
       // String inputLine;
       int feedChar;
       /*while ((inputLine = bufferedReader.readLine()) != null) {
       feed.append(inputLine);
       }*/
       // read individual characters
       while ((feedChar = bufferedReader.read()) != -1) {
         char value = (char) feedChar;
         if (value == '"') {
           feed.append("\\\"");
         } else if (value == '\r' || value == '\n') {
           feed.append("\\n");
         } else {
           feed.append(value);
         }
         // feed.append(value);
       }
       bufferedReader.close();
     } catch (Exception e) {
       System.out.println(e.getMessage());
     }
   }
   return feedJson(feed.toString());
 }
Example #2
0
 /*
  *@param itemcode
  *@returns feed url associated with itemcode
  */
 public String fetchURL(String itemCode) {
   Catalog catalog = new Catalog();
   // Check for item in catalog based on item code
   if (catalog.containsItem(itemCode)) {
     // Check if item is already in the cart
     if (contents.containsKey(itemCode)) {
       // remove the subscribed feed
       Item item = contents.get(itemCode);
       return item.getUrl();
     }
   }
   return null;
 }