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 FOAFFeedParser.java FOAFFeedParserListener.java FeedParser.java NS.java
Date Sun, 22 Aug 2004 11:28:05 GMT
burton      2004/08/22 04:28:05

  Modified:    feedparser/src/java/org/apache/commons/feedparser
                        FOAFFeedParser.java FOAFFeedParserListener.java
                        FeedParser.java NS.java
  Log:
  50% done FOAF support
  
  Revision  Changes    Path
  1.4       +84 -45    jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/FOAFFeedParser.java
  
  Index: FOAFFeedParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/FOAFFeedParser.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FOAFFeedParser.java	30 May 2004 21:00:44 -0000	1.3
  +++ FOAFFeedParser.java	22 Aug 2004 11:28:04 -0000	1.4
  @@ -20,13 +20,7 @@
   import java.net.*;
   import java.util.*;
   
  -import org.jdom.Element;
  -import org.jdom.Attribute;
  -import org.jdom.CDATA;
  -import org.jdom.Text;
  -import org.jdom.Comment;
  -import org.jdom.output.*;
  -import org.jdom.input.*;
  +import org.jdom.*;
   
   import org.jaxen.jdom.*;
   
  @@ -43,8 +37,8 @@
        *
        * @author <a href="mailto:burton@peerfear.org">Kevin A. Burton</a>
        */
  -    public static void parse( FOAFFeedParserListener listener,
  -                              org.jdom.Document doc ) throws FeedParserException {
  +    public static void parse( FeedParserListener listener,
  +                              org.jdom.Document doc ) throws Exception {
   
           try {
                   
  @@ -57,14 +51,73 @@
   
               //this should be the root directory.
               XPath xpath = new XPath( "/rdf:RDF/foaf:Person" );
  -            List list = xpath.selectNodes( doc );
  +            xpath.setNamespaceContext( NS.context );
  +            
  +            Element person = (Element)xpath.selectSingleNode( doc );
  +
  +            xpath = new XPath( "foaf:knows" );
  +            xpath.setNamespaceContext( NS.context );
   
  +            List list = xpath.selectNodes( person );
               Iterator i = list.iterator();
  +
  +            FOAFFeedParserListener flistener = null;
  +
  +            if ( listener instanceof FOAFFeedParserListener )
  +                flistener = (FOAFFeedParserListener)listener;
  +
               while ( i.hasNext() ) {
   
  -                Element child = (Element)i.next();
  -                //onOutline( fdpl, state, child );
  +                Element knows = (Element)i.next();
  +
  +                Element currentPerson = knows.getChild( "Person", NS.FOAF );
  +                
  +                state.current = currentPerson;
                   
  +                String title = RSSFeedParser.getChildElementTextByName( state, "name" );
  +
  +                System.out.println( " FIXME: (debug): " + title );
  +
  +                String seeAlso = getAttributeValue( state,
  +                                                    "seeAlso", NS.RDFS,
  +                                                    "resource", NS.RDF );
  +
  +                String homepage = getAttributeValue( state,
  +                                                     "homepage", NS.FOAF,
  +                                                     "resource", NS.RDF );
  +
  +                System.out.println( "seeAlso: " + seeAlso );
  +                System.out.println( "homepage: " + homepage );
  +
  +                if ( flistener != null )
  +                    flistener.onKnows( state );
  +                    
  +                listener.onItem( state,
  +                                 title,
  +                                 homepage,
  +                                 null,
  +                                 seeAlso );
  +
  +                if ( flistener != null ) {
  +
  +                    flistener.onHomepage( state,
  +                                          homepage );
  +
  +                    flistener.onHomepageEnd();
  +                    
  +                    flistener.onSeeAlso( state,
  +                                         seeAlso );
  +
  +
  +                    flistener.onSeeAlsoEnd();
  +                    
  +                } 
  +
  +                listener.onItemEnd();
  +
  +                if ( flistener != null )
  +                    flistener.onKnowsEnd();
  +
               }
               
               listener.finished();
  @@ -73,44 +126,30 @@
   
       }
   
  -    private static void onOutlineFolder( FeedDirectoryParserListener listener,
  -                                         FeedParserState state,
  -                                         Element current ) throws Exception {
  +    public static String getAttributeValue( FeedParserState state,
  +                                            String name,
  +                                            Namespace name_ns,
  +                                            String attr,
  +                                            Namespace attr_ns ) {
   
  -        XPath xpath = new XPath( "outline" );
  -        List list = xpath.selectNodes( current );
  +        Element e = state.current.getChild( name, name_ns );
   
  -        Iterator i = list.iterator();
  -        while ( i.hasNext() ) {
  +        if ( e == null )
  +            return null;
   
  -            Element child = (Element)i.next();
  -            onOutline( listener, state, child );
  -                
  -        }
  +        Attribute a = e.getAttribute( attr, attr_ns );
   
  -    }
  -        
  -    private static void onOutline( FeedDirectoryParserListener listener,
  -                                   FeedParserState state,
  -                                   Element current ) throws Exception {
  -
  -        String title = current.getAttributeValue( "title" );
  -        String weblog = current.getAttributeValue( "htmlUrl" );
  -        String description = current.getAttributeValue( "description" );
  -        String feed = current.getAttributeValue( "xmlUrl" );
  -
  -        if ( weblog != null && feed != null ) {
  -            listener.onItem( state, title, weblog, description, feed );
  -        } else if ( title != null ) {
  -            //this is almost certainly a folder
  -
  -            listener.onFolder( state, title );
  -            onOutlineFolder( listener, state, current );
  -            listener.onFolderEnd();
  -                    
  -        }
  +        if ( a == null )
  +            return null;
  +
  +        return a.getValue();
   
       }
  +    
  +    private static void doParseKnows( FeedParserListener listener,
  +                                      FeedParserState state ) throws Exception {
   
  +    }
  +    
   }
   
  
  
  
  1.3       +2 -2      jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/FOAFFeedParserListener.java
  
  Index: FOAFFeedParserListener.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/FOAFFeedParserListener.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FOAFFeedParserListener.java	28 Feb 2004 03:35:21 -0000	1.2
  +++ FOAFFeedParserListener.java	22 Aug 2004 11:28:04 -0000	1.3
  @@ -67,7 +67,7 @@
       public void onSeeAlso( FeedParserState state,
                              String resource ) throws FeedParserException;
   
  -    public void onSeeAlso() throws FeedParserException;
  +    public void onSeeAlsoEnd() throws FeedParserException;
   
   }
   
  
  
  
  1.7       +13 -3     jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/FeedParser.java
  
  Index: FeedParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/FeedParser.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FeedParser.java	3 Aug 2004 01:26:58 -0000	1.6
  +++ FeedParser.java	22 Aug 2004 11:28:04 -0000	1.7
  @@ -116,16 +116,26 @@
   
           try {
   
  +            //Handle OPML
               if ( "opml".equals( doc.getRootElement().getName() ) ) {
                   OPMLFeedParser.parse( listener, doc );
                   return;
               }
  -
  +            
  +            //Handle ATOM
               if ( "feed".equals( doc.getRootElement().getName() ) ) {
                   AtomFeedParser.parse( listener, doc );
                   return;
               }
  -            
  +
  +            //Handle FOAF
  +            if ( doc.getRootElement().getChildren( "Person", NS.FOAF ).size() > 0 )
{
  +
  +                FOAFFeedParser.parse( listener, doc );
  +                
  +                return;
  +            }
  +
               //fall back on RDF.
   
               RSSFeedParser.parse( listener, doc );
  
  
  
  1.4       +10 -1     jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/NS.java
  
  Index: NS.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/NS.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- NS.java	15 Apr 2004 00:58:44 -0000	1.3
  +++ NS.java	22 Aug 2004 11:28:04 -0000	1.4
  @@ -27,6 +27,12 @@
    */
   public class NS {
   
  +    public static final Namespace RDFS =
  +        Namespace.getNamespace( "rdfs", "http://www.w3.org/2000/01/rdf-schema#" );
  +
  +    public static final Namespace FOAF =
  +        Namespace.getNamespace( "foaf", "http://xmlns.com/foaf/0.1/" );
  +
       public static final Namespace KR =
           Namespace.getNamespace( "kr", "http://ksa.peerfear.org/ksa-rdf#" );
   
  @@ -74,6 +80,9 @@
           context = new SimpleNamespaceContext();
           context.addNamespace( ATOM.getPrefix(), ATOM.getURI() );
           context.addNamespace( DC.getPrefix(), DC.getURI() );
  +        context.addNamespace( FOAF.getPrefix(), FOAF.getURI() );
  +        context.addNamespace( RDF.getPrefix(), RDF.getURI() );
  +        context.addNamespace( RDFS.getPrefix(), RDFS.getURI() );
   
       }
       
  
  
  

---------------------------------------------------------------------
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