Coverage Report - org.apache.commons.feedparser.locate.blogservice.Flickr
 
Classes in this File Line Coverage Branch Coverage Complexity
Flickr
0%
0/18
0%
0/10
2.25
 
 1  
 /*
 2  
  * Copyright 1999,2004 The Apache Software Foundation.
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package org.apache.commons.feedparser.locate.blogservice;
 18  
 
 19  
 import org.apache.commons.feedparser.FeedParserException;
 20  
 import org.apache.commons.feedparser.locate.*;
 21  
 
 22  
 /**
 23  
  * Models the Flickr image blog service, encapsulating whether a given weblog
 24  
  * is this type of service and where it usually keeps its feeds.
 25  
  * 
 26  
  * @author Brad Neuberg, bkn3@columbia.edu
 27  
  */
 28  0
 public class Flickr extends BlogService {
 29  
     
 30  
     /** Returns whether we can trust the results of this blog service's 
 31  
      *  autodiscovery links.  For example, TextAmerica returns invalid 
 32  
      *  autodiscovery results.
 33  
      */
 34  
     public boolean hasValidAutoDiscovery() {
 35  0
         return true;
 36  
     }
 37  
     
 38  
     /** Returns whether we should follow HTTP redirects for this blog service.
 39  
      *  Some services don't implement HTTP redirects correctly, while others,
 40  
      *  like Xanga, require it.
 41  
      */
 42  
     public boolean followRedirects() {
 43  0
         return false;
 44  
     }
 45  
     
 46  
     /** Determines if the weblog at the given resource and with the given
 47  
      *  content is this blog service.
 48  
      * @param resource A full URI to this resource, such as 
 49  
      * "http://www.codinginparadise.org".
 50  
      * @param content The full HTML content at the resource's URL.
 51  
      * @throws FeedParserException Thrown if an error occurs while 
 52  
      * determining the type of this weblog.
 53  
      */
 54  
     public boolean isThisService(String resource, String content)
 55  
                                                 throws FeedParserException {
 56  0
         return resource.indexOf( "flickr.com" ) != -1;
 57  
     }
 58  
 
 59  
     /**
 60  
      * Returns an array of FeedReferences that contains information on the
 61  
      * usual locations this blog service contains its feed.  The feeds should
 62  
      * be ordered by quality, so that higher quality feeds come before lower
 63  
      * quality ones (i.e. you would want to have an Atom FeedReference
 64  
      * object come before an RSS 0.91 FeedReference object in this list).
 65  
      * @param resource A URL to the given weblog that might be used to build
 66  
      * up where feeds are usually located.
 67  
      * @param content The full content of the resource URL, which might
 68  
      * be useful to determine where feeds are usually located.  This can be
 69  
      * null.
 70  
      * @throws FeedParserException Thrown if an error occurs while trying
 71  
      * to determine the usual locations of feeds for this service.
 72  
      */
 73  
     public FeedReference[] getFeedLocations(String resource,
 74  
                                             String content)
 75  
                                                 throws FeedParserException {
 76  0
         resource = getBaseFeedPath(resource);
 77  
         //  * Input: http://flickr.com/photos/tags/cats/
 78  
         //  *
 79  
         //  * Output: http://flickr.com/services/feeds/photos_public.gne?tags=cats&format=atom_03
 80  
 
 81  0
         if ( resource == null )
 82  0
             return new FeedReference[0];
 83  
 
 84  0
         int begin = resource.indexOf( "/tags/" );
 85  
 
 86  
         //we can't continue here.
 87  0
         if ( begin == -1 )
 88  0
             return new FeedReference[0];
 89  
 
 90  0
         begin += 6;
 91  
 
 92  0
         int end = resource.lastIndexOf( "/" );
 93  0
         if ( end == -1 || end < begin )
 94  0
             end = resource.length();
 95  
 
 96  0
         String tag = resource.substring( begin, end );
 97  
 
 98  0
         String location = "http://flickr.com/services/feeds/photos_public.gne?tags=" +
 99  
                           tag +
 100  
                           "&format=atom_03";
 101  
         
 102  0
         FeedReference flickrLocations[] =
 103  
                 { new FeedReference(location, 
 104  
                                     FeedReference.ATOM_MEDIA_TYPE) };
 105  
         
 106  0
         return flickrLocations;
 107  
     }
 108  
 }