svn commit: r1004240 - in /lenya/sandbox/modules/feed/branches/add-apache-feedparser: ./ java/externals/ java/src/org/apache/lenya/parser/ java/src/org/apache/lenya/parser/listener/impl/ java/src/org/apache/lenya/transformation/ test/ test/input/

[email protected] Mon, 04 Oct 2010 14:01:22 -0000
Newsgroups gmane.comp.cms.lenya.cvs
Message-ID <[email protected]>
Author: florent
Date: Mon Oct  4 14:01:21 2010
New Revision: 1004240

URL: http://svn.apache.org/viewvc?rev=1004240&view=rev
Log:
- first implementation for RSS is ok, output in collection format

Added:
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/externals/   (with props)
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/externals/patch-jdom-FEEDPARSER-7.patch
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/test/
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/test/input/
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/test/input/atom.xml
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/test/input/rss.xml
Modified:
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/TODOS
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/parser/FeedToDocumentParser.java
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/parser/listener/impl/LenyaFeedParserListener.java
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/transformation/FeedTransformer.java
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/sitemap.xmap

Modified: lenya/sandbox/modules/feed/branches/add-apache-feedparser/TODOS
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/TODOS?rev=1004240&r1=1004239&r2=1004240&view=diff
==============================================================================
--- lenya/sandbox/modules/feed/branches/add-apache-feedparser/TODOS (original)
+++ lenya/sandbox/modules/feed/branches/add-apache-feedparser/TODOS Mon Oct  4 14:01:21 2010
@@ -1,2 +1,8 @@
 
-* clean the libs folder with dependencies that are already presents in lenya.
\ No newline at end of file
+* add the setup.sh for patching and retrive dependencies
+
+* clean the libs folder with dependencies that are already presents in lenya.
+
+* remove java/externals/feedparser retrive and patch when https://issues.apache.org/jira/browse/FEEDPARSER-7 integrate into trunk
+
+

Propchange: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/externals/
------------------------------------------------------------------------------
--- svn:externals (added)
+++ svn:externals Mon Oct  4 14:01:21 2010
@@ -0,0 +1 @@
+commons-feedparser-r925477 -r925477 https://svn.apache.org/repos/asf/commons/dormant/feedparser/trunk

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/externals/patch-jdom-FEEDPARSER-7.patch
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/externals/patch-jdom-FEEDPARSER-7.patch?rev=1004240&view=auto
==============================================================================
--- lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/externals/patch-jdom-FEEDPARSER-7.patch (added)
+++ lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/externals/patch-jdom-FEEDPARSER-7.patch Mon Oct  4 14:01:21 2010
@@ -0,0 +1,13 @@
+Index: pom.xml
+===================================================================
+--- pom.xml	(revision 1001881)
++++ pom.xml	(working copy)
+@@ -62,7 +62,7 @@
+     <dependency>
+       <groupId>jdom</groupId>
+       <artifactId>jdom</artifactId>
+-      <version>b9</version>
++      <version>1.0</version>
+     </dependency>
+ 
+     <dependency>

Modified: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/parser/FeedToDocumentParser.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/parser/FeedToDocumentParser.java?rev=1004240&r1=1004239&r2=1004240&view=diff
==============================================================================
--- lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/parser/FeedToDocumentParser.java (original)
+++ lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/parser/FeedToDocumentParser.java Mon Oct  4 14:01:21 2010
@@ -33,19 +33,21 @@ import org.apache.commons.feedparser.net
 import org.apache.commons.feedparser.network.ResourceRequestFactory;
 import org.apache.commons.feedparser.network.NetworkException;
 
-
+import org.xml.sax.SAXException;
 
 /**
  * Parser for RSS/ATOM that output "collection/document style" xml
  *
  */
-public class FeedToDocumentParser {
+public class FeedToDocumentParser{
 
     public FeedToDocumentParser(){
     
     }
     
-    public void parse(String urlToParse, ContentHandler ch){
+    public void parse(String urlToParse, ContentHandler ch)
+	throws  SAXException, IOException
+    {
 
 	try{
 	    //create a new FeedParser...
@@ -64,15 +66,17 @@ public class FeedToDocumentParser {
 	    parser.parse( listener, is, urlToParse );	
 	}
 	catch(NetworkException ne){
+	    throw new SAXException(ne);
 	    //TODO : deal with this error
 	}
 	catch(FeedParserException fde){
+	    throw new SAXException(fde);
 	    //TODO : deal with this error
 	}
 	catch(IOException io){
+	    throw io;
 	    //TODO : deal with this error
 	}
 	
     }
-}
-    
\ No newline at end of file
+}
\ No newline at end of file

Modified: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/parser/listener/impl/LenyaFeedParserListener.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/parser/listener/impl/LenyaFeedParserListener.java?rev=1004240&r1=1004239&r2=1004240&view=diff
==============================================================================
--- lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/parser/listener/impl/LenyaFeedParserListener.java (original)
+++ lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/parser/listener/impl/LenyaFeedParserListener.java Mon Oct  4 14:01:21 2010
@@ -28,6 +28,11 @@ import org.apache.commons.feedparser.Fee
 
 import org.xml.sax.ContentHandler;
 
+import org.xml.sax.Attributes;
+import org.xml.sax.helpers.AttributesImpl;
+/* for empty attributes */
+import org.apache.cocoon.xml.XMLUtils;
+import org.xml.sax.SAXException;
 /**
  * @see DefaultFeedParserListener 
  */
@@ -35,6 +40,17 @@ public class  LenyaFeedParserListener ex
 
     private Object context = null;
     private ContentHandler ch = null;
+
+    
+    private String COLLECTION_NS = "http://apache.org/cocoon/lenya/collection/1.0";
+    private String COLLECTION_PREFIX = "col";
+    
+    private String DC_NS = "http://purl.org/dc/elements/1.1/";
+    private String DC_PREFIX = "dc";
+    private String XHTML_NS = "http://www.w3.org/1999/xhtml" ;
+    private String XHTML_PREFIX = "xhtml"; 
+
+    protected static final Attributes EMPTY_ATTRIBUTES = XMLUtils.EMPTY_ATTRIBUTES;
     
     public LenyaFeedParserListener(ContentHandler ch){
 	this.ch = ch;
@@ -50,16 +66,26 @@ public class  LenyaFeedParserListener ex
     public Object getContext() throws FeedParserException {
         return this.context;
     }
-
+    
+    
     public void onChannel( FeedParserState state,
                            String title,
                            String link,
                            String description ) throws FeedParserException {
     
-	System.out.println( "Found a new channel: " + title );
+	//System.out.println( "Found a new channel: " + title );
+	/*try{
+	    ch.startElement(COLLECTION_NS,"onChannel","onChannel", EMPTY_ATTRIBUTES);
+	    }catch(SAXException se){}*/
     }
 
-    public void onChannelEnd() throws FeedParserException { }
+    public void onChannelEnd() throws FeedParserException {
+	/*try{
+	    ch.endElement(COLLECTION_NS, "onChannel", "onChannel");
+	    }catch(SAXException se){}*/
+    }
+    
+
     
     /*
     public void onImage( FeedParserState state,
@@ -76,10 +102,60 @@ public class  LenyaFeedParserListener ex
                         String link,
                         String description,
                         String permalink ) throws FeedParserException { 
-	System.out.println( "Found a new published article: " + permalink );
-    }
+	//System.out.println( "Found a new published article: " + permalink );
+	try{
+	    ch.startElement(COLLECTION_NS,"document","document", EMPTY_ATTRIBUTES);
+	    ch.startPrefixMapping(XHTML_PREFIX, XHTML_NS);
+	    ch.startElement(XHTML_NS,"html","html", EMPTY_ATTRIBUTES);
+	    ch.startElement(XHTML_NS,"head","head", EMPTY_ATTRIBUTES);
+	    branchWithText(XHTML_NS, "title", title);
+	    ch.endElement(XHTML_NS, "head","head");
+	    ch.startElement(XHTML_NS,"body","body", EMPTY_ATTRIBUTES);
+	    //add the id=body attribute
+	    AttributesImpl bodyID = new AttributesImpl();
+	    bodyID.addAttribute("","id","","","body");
+	    
+	    ch.startElement(XHTML_NS,"div","div", bodyID);
+	    
+	    branchWithText(XHTML_NS, "p", description);
+	    ch.endElement(XHTML_NS, "div","div");
+	    ch.endElement(XHTML_NS, "body","body");
+	    ch.endElement(XHTML_NS, "html","html");
+	    ch.endPrefixMapping(XHTML_PREFIX);
+	    
+	    ch.startPrefixMapping(DC_PREFIX, DC_NS);
+	    
+	    //we just use the permalink information, more reliable than link. 
+	    // if permalink is not provide in the feed, permalink = link
+	    //branchWithText(DC_NS, "link", link);
+	    //use of the http://purl.org/dc/elements/1.1/identifier dc attribute
+	    
+	    branchWithText(DC_NS, "identifier", permalink);
+	    ch.endPrefixMapping(DC_PREFIX);
+	    
+	}catch(SAXException se){}
+	
+    }
+
+    //TODO : ? add an attribute parameter ?
+    public void branchWithText(String ns, String nodeName, String content){
+	try{
+	    ch.startElement(ns,nodeName,nodeName, EMPTY_ATTRIBUTES);
+	    
+	    char[] textChars = content.toCharArray();
+	    ch.characters(textChars, 0, textChars.length);
+	    
+	    ch.endElement(ns,nodeName,nodeName);
+	}catch(SAXException se){}
+    }
+    
+    public void onItemEnd() throws FeedParserException {
+	try{
+	    ch.endElement(COLLECTION_NS, "document", "document");
+	}catch(SAXException se){}
 
-    public void onItemEnd() throws FeedParserException {}
+    
+    }
     public void finished() throws FeedParserException {}
 
     // **** MetaFeedParserListener **********************************************
@@ -92,10 +168,21 @@ public class  LenyaFeedParserListener ex
      * http://www.mnot.net/drafts/draft-nottingham-atom-format-00.html#rfc.section.3.2.8
      */
     public void onCreated( FeedParserState state, Date date ) throws FeedParserException{
-	System.out.println( "Which was created on: " + date );
+	try{
+	    ch.startPrefixMapping(DC_PREFIX, DC_NS);
+	    ch.startElement(DC_NS,"date","date", EMPTY_ATTRIBUTES);
+	    char[] textChars = date.toString().toCharArray();
+	    ch.characters(textChars, 0, textChars.length);
+	    ch.endElement(DC_NS,"date","date");
+	    ch.endPrefixMapping(DC_PREFIX);
+	}catch(SAXException se){}
     }
     
-    public void onCreatedEnd() throws FeedParserException {}
+    public void onCreatedEnd() throws FeedParserException {
+	/*try{
+	    ch.endElement(COLLECTION_NS, "created-date", "created-date");
+	    }catch(SAXException se){}*/
+    }
 
     /*ublic void onSubject( FeedParserState state, String content ) throws FeedParserException {}
     public void onSubjectEnd() throws FeedParserException {}
@@ -147,7 +234,12 @@ public class  LenyaFeedParserListener ex
     public void onContentItem( FeedParserState state,
                                String format,
                                String encoding,
-                               Element value ) throws FeedParserException {}
+                               Element value ) throws FeedParserException {
+	/*try{
+	    ch.startElement(COLLECTION_NS,"onContent","onContent", EMPTY_ATTRIBUTES);
+	    ch.endElement(COLLECTION_NS,"onContent","onContent");
+	    }catch(SAXException se){}*/
+    }
 
     public void onContentItemEnd() throws FeedParserException {}
 
@@ -165,7 +257,7 @@ public class  LenyaFeedParserListener ex
                            String encoding,
                            String mode,
                            String value,
-                           boolean isSummary ) throws FeedParserException {}
+                           boolean isSummary ) throws FeedParserException { }
 
     public void onContentEnd() throws FeedParserException {}
 

Modified: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/transformation/FeedTransformer.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/transformation/FeedTransformer.java?rev=1004240&r1=1004239&r2=1004240&view=diff
==============================================================================
--- lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/transformation/FeedTransformer.java (original)
+++ lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/transformation/FeedTransformer.java Mon Oct  4 14:01:21 2010
@@ -112,10 +112,11 @@ public class FeedTransformer extends Abs
 	if (name.equals(COLLECTION_ELEMENT)) {
 	    //if this is a "link" collection
 	    if(attr.getValue("type").equals("link")){
+		String urlToParse = attr.getValue("href");
+
 		//send the collection element as is
 		super.startTransformingElement(uri, name, raw, attr);
-	       
-		String urlToParse = attr.getValue("href");
+		
 		//if href is not null, init the parser and parse the feed
 		if (urlToParse != null){
 		    FeedToDocumentParser ftdp = new FeedToDocumentParser();
@@ -134,7 +135,7 @@ public class FeedTransformer extends Abs
 	    super.startTransformingElement(uri, name, raw, attr);
 	}
     }
-
+    
 
     /**
      * Receive notification of the end of an element.
@@ -173,16 +174,20 @@ public class FeedTransformer extends Abs
     /**
      * for debugging tips in the transformer
      */
-    private void sendDebug(String localMessage,	String exceptionMessage) throws SAXException{
-	
-        sendStartElementEvent(DEBUG_ELEMENT);
-	sendStartElementEvent(LOCALMESSAGE_ELEMENT);
-	sendTextEvent(localMessage);
-	sendEndElementEvent(LOCALMESSAGE_ELEMENT);
-	sendStartElementEvent(EXCEPTIONMESSAGE_ELEMENT);
-	sendTextEvent(exceptionMessage);
-	sendEndElementEvent(EXCEPTIONMESSAGE_ELEMENT);
-        sendEndElementEvent(DEBUG_ELEMENT);
+    private void sendDebug(String localMessage,	String exceptionMessage) {
+	try{
+	    sendStartElementEvent(DEBUG_ELEMENT);
+	    sendStartElementEvent(LOCALMESSAGE_ELEMENT);
+	    sendTextEvent(localMessage);
+	    sendEndElementEvent(LOCALMESSAGE_ELEMENT);
+	    sendStartElementEvent(EXCEPTIONMESSAGE_ELEMENT);
+	    sendTextEvent(exceptionMessage);
+	    sendEndElementEvent(EXCEPTIONMESSAGE_ELEMENT);
+	    sendEndElementEvent(DEBUG_ELEMENT);
+	}
+	catch(SAXException se){
+	    //do nothing
+	}
 	
     }
 

Modified: lenya/sandbox/modules/feed/branches/add-apache-feedparser/sitemap.xmap
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/sitemap.xmap?rev=1004240&r1=1004239&r2=1004240&view=diff
==============================================================================
--- lenya/sandbox/modules/feed/branches/add-apache-feedparser/sitemap.xmap (original)
+++ lenya/sandbox/modules/feed/branches/add-apache-feedparser/sitemap.xmap Mon Oct  4 14:01:21 2010
@@ -16,20 +16,31 @@
   limitations under the License.
 -->
 
-<!-- $Id: doctypes.xmap 179488 2005-06-02 02:29:39Z gregor $ -->
-
 <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
   
   <map:components>
     <map:transformers default="xslt">
       <map:transformer name="unescape" src="org.apache.lenya.modules.feed.UnescapeXmlTransformer"/>
+      <!-- declaration of feedTransformer -->
+      <map:transformer name="feedTransformer" src="org.apache.lenya.transformation.FeedTransformer"/>
     </map:transformers>
   </map:components>
 
   <map:pipelines>
 
     <map:pipeline>
-
+      
+      <!-- url for test : 
+	   test-atom
+	   test-rss
+	-->
+      <map:match pattern="test-*">
+	<map:generate src="test/input/{1}.xml"/>
+	<map:transform type="feedTransformer"/>
+	<map:serialize type="xml"/>
+      </map:match>
+      
+      
       <!-- url for test : 
 	   old implementation (cause bug explain bellow)
 	   atom : http://localhost:8080/lenya/modules/feed/atom/http://alexharden.org/blog/atom.xml?format=xhtml

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/test/input/atom.xml
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/test/input/atom.xml?rev=1004240&view=auto
==============================================================================
--- lenya/sandbox/modules/feed/branches/add-apache-feedparser/test/input/atom.xml (added)
+++ lenya/sandbox/modules/feed/branches/add-apache-feedparser/test/input/atom.xml Mon Oct  4 14:01:21 2010
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><collection xmlns="http://apache.org/cocoon/lenya/collection/1.0" allLanguages="false" href="http://alexharden.org/blog/atom.xml" includeItems="3" type="link" uuid="a55e1170-c9c5-11df-8f41-b66c975762a5"/>
\ No newline at end of file

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/test/input/rss.xml
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/test/input/rss.xml?rev=1004240&view=auto
==============================================================================
--- lenya/sandbox/modules/feed/branches/add-apache-feedparser/test/input/rss.xml (added)
+++ lenya/sandbox/modules/feed/branches/add-apache-feedparser/test/input/rss.xml Mon Oct  4 14:01:21 2010
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><collection xmlns="http://apache.org/cocoon/lenya/collection/1.0" allLanguages="false" href="http://www.lequipe.fr/Xml/Football/Titres/actu_rss.xml" includeItems="3" type="link" uuid="a55e1170-c9c5-11df-8f41-b66c975762a5"/>