commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bur...@apache.org
Subject cvs commit: jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/locate ProbeLocator.java FeedReference.java ResourceExpander.java
Date Tue, 11 May 2004 19:53:18 GMT
burton      2004/05/11 12:53:18

  Modified:    feedparser/src/java/org/apache/commons/feedparser/locate
                        FeedReference.java ResourceExpander.java
  Added:       feedparser/src/java/org/apache/commons/feedparser/locate
                        ProbeLocator.java
  Log:
  support for livejournal atom feeds
  
  Revision  Changes    Path
  1.6       +4 -0      jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/locate/FeedReference.java
  
  Index: FeedReference.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/locate/FeedReference.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- FeedReference.java	16 Apr 2004 20:20:01 -0000	1.5
  +++ FeedReference.java	11 May 2004 19:53:18 -0000	1.6
  @@ -46,5 +46,9 @@
           this.resource = resource;
           this.type = type;
       }
  +
  +    public String toString() {
  +        return resource;
  +    }
       
   }
  
  
  
  1.3       +32 -1     jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/locate/ResourceExpander.java
  
  Index: ResourceExpander.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/locate/ResourceExpander.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ResourceExpander.java	15 Apr 2004 16:57:20 -0000	1.2
  +++ ResourceExpander.java	11 May 2004 19:53:18 -0000	1.3
  @@ -183,6 +183,37 @@
       }
   
       /**
  +     * Given a URL get the domain name.  
  +     *
  +     * @author <a href="mailto:burton@peerfear.org">Kevin Burton</a>
  +     */
  +    public static String getDomain( String resource ) {
  +
  +        String site = getSite( resource );
  +
  +        int firstIndex = -1;
  +        int indexCount = 0;
  +
  +        int index = site.length();
  +
  +        while ( (index = site.lastIndexOf( ".", index-1 )) != -1 ) {
  +
  +            ++indexCount;
  +
  +            if ( indexCount == 2 )
  +                break;
  +
  +        }
  +
  +        int begin = 7; // http:// length
  +        if ( indexCount >= 2 )
  +            begin = index + 1;
  +
  +        return site.substring( begin, site.length() );
  +        
  +    }
  +    
  +    /**
        * Get the base of this URL.  For example if we are given:
        *
        * http://www.foo.com/directory/index.html
  
  
  
  1.1                  jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/locate/ProbeLocator.java
  
  Index: ProbeLocator.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.commons.feedparser.locate;
  
  import org.apache.commons.feedparser.*;
  
  import java.io.*;
  import java.util.*;
  import java.util.regex.*;
  
  /**
   * Locator which uses Link probing
   * 
   * @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
   */
  public class ProbeLocator {
  
      static HashMap probeMapping = new HashMap();
  
      static {
  
          //FIXME: Live Journal has both FOAF and Atom...  We need support for BOTH
          probeMapping.put( "blogspot.com", "/atom.xml" );
          probeMapping.put( "livejournal.com", "/data/atom" );
          
      }
      
      /**
       *
       * @author <a href="mailto:burton@peerfear.org">Kevin A. Burton</a>
       */
      public static final List locate( String resource, String content, FeedList list )
          throws Exception {
  
          //FIXME: 
  
          String domain = ResourceExpander.getDomain( resource );
  
          if ( probeMapping.containsKey( domain ) ) {
  
              String mapping = (String)probeMapping.get( domain );
  
              String href = resource;
              
              if ( href.endsWith( "/" ) )
                  href = href.substring( 0, href.length() - 1 );
                  
              href += mapping;
              
              FeedReference feedReference = new FeedReference( href,
                                                               DiscoveryLocator.ATOM_MEDIA_TYPE
);
                  
              list.add( feedReference );
              list.setAdAtomFeed( feedReference );
  
          }
  
          return list;
  
      }
  
      public static void main( String[] args ) throws Exception {
  
          FeedList list = new FeedList();
          
          locate( "http://davebarry.blogspot.com/", null, list );
          locate( "http://www.livejournal.com/users/jwz", null, list );
  
          Iterator it = list.iterator();
  
          while ( it.hasNext() ) {
  
              System.out.println( it.next() );
              
          }
          
      }
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message