You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by fl...@apache.org on 2010/09/29 02:41:58 UTC

svn commit: r1002433 - in /lenya/sandbox/modules/feed/branches/add-apache-feedparser: ./ java/lib/ java/src/org/apache/lenya/parser/ java/src/org/apache/lenya/parser/listener/ java/src/org/apache/lenya/parser/listener/impl/ java/src/org/apache/lenya/tr...

Author: florent
Date: Wed Sep 29 00:41:57 2010
New Revision: 1002433

URL: http://svn.apache.org/viewvc?rev=1002433&view=rev
Log:
- ok, first draft compile, have to try and implement xml output

Added:
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/TODOS
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/commons-codec-1.2.jar   (with props)
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/commons-httpclient-3.0-rc1.jar   (with props)
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/commons-logging-1.0.3.jar   (with props)
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/dom4j-1.5.2.jar   (with props)
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/icu4j-2.6.1.jar   (with props)
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/jaxen-1.1-beta-6.jar   (with props)
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/jaxme-api-0.3.jar   (with props)
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/jdom-b9.jar   (with props)
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/junit-3.8.1.jar   (with props)
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/log4j-1.2.6.jar   (with props)
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/saxpath-1.0-FCS.jar   (with props)
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/servlet-api-2.2.jar   (with props)
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/tagsoup-0.9.7.jar   (with props)
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xalan-2.6.0.jar   (with props)
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xercesImpl-2.6.2.jar   (with props)
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xml-apis-1.0.b2.jar   (with props)
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xmlParserAPIs-2.6.2.jar   (with props)
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xmlrpc-1.2.jar   (with props)
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xom-1.0b3.jar   (with props)
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/parser/
    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/
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/parser/listener/impl/
    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/
    lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/transformation/FeedTransformer.java

Added: 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=1002433&view=auto
==============================================================================
--- lenya/sandbox/modules/feed/branches/add-apache-feedparser/TODOS (added)
+++ lenya/sandbox/modules/feed/branches/add-apache-feedparser/TODOS Wed Sep 29 00:41:57 2010
@@ -0,0 +1,2 @@
+
+* clean the libs folder with dependencies that are already presents in lenya.
\ No newline at end of file

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/commons-codec-1.2.jar
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/commons-codec-1.2.jar?rev=1002433&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/commons-codec-1.2.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/commons-httpclient-3.0-rc1.jar
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/commons-httpclient-3.0-rc1.jar?rev=1002433&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/commons-httpclient-3.0-rc1.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/commons-logging-1.0.3.jar
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/commons-logging-1.0.3.jar?rev=1002433&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/commons-logging-1.0.3.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/dom4j-1.5.2.jar
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/dom4j-1.5.2.jar?rev=1002433&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/dom4j-1.5.2.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/icu4j-2.6.1.jar
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/icu4j-2.6.1.jar?rev=1002433&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/icu4j-2.6.1.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/jaxen-1.1-beta-6.jar
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/jaxen-1.1-beta-6.jar?rev=1002433&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/jaxen-1.1-beta-6.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/jaxme-api-0.3.jar
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/jaxme-api-0.3.jar?rev=1002433&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/jaxme-api-0.3.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/jdom-b9.jar
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/jdom-b9.jar?rev=1002433&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/jdom-b9.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/junit-3.8.1.jar
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/junit-3.8.1.jar?rev=1002433&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/junit-3.8.1.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/log4j-1.2.6.jar
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/log4j-1.2.6.jar?rev=1002433&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/log4j-1.2.6.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/saxpath-1.0-FCS.jar
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/saxpath-1.0-FCS.jar?rev=1002433&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/saxpath-1.0-FCS.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/servlet-api-2.2.jar
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/servlet-api-2.2.jar?rev=1002433&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/servlet-api-2.2.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/tagsoup-0.9.7.jar
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/tagsoup-0.9.7.jar?rev=1002433&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/tagsoup-0.9.7.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xalan-2.6.0.jar
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xalan-2.6.0.jar?rev=1002433&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xalan-2.6.0.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xercesImpl-2.6.2.jar
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xercesImpl-2.6.2.jar?rev=1002433&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xercesImpl-2.6.2.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xml-apis-1.0.b2.jar
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xml-apis-1.0.b2.jar?rev=1002433&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xml-apis-1.0.b2.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xmlParserAPIs-2.6.2.jar
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xmlParserAPIs-2.6.2.jar?rev=1002433&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xmlParserAPIs-2.6.2.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xmlrpc-1.2.jar
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xmlrpc-1.2.jar?rev=1002433&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xmlrpc-1.2.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xom-1.0b3.jar
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xom-1.0b3.jar?rev=1002433&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/lib/xom-1.0b3.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: 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=1002433&view=auto
==============================================================================
--- lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/parser/FeedToDocumentParser.java (added)
+++ lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/parser/FeedToDocumentParser.java Wed Sep 29 00:41:57 2010
@@ -0,0 +1,78 @@
+/*
+ * 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.lenya.parser;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.util.Date;
+
+import org.xml.sax.ContentHandler;
+
+//import org.apache.commons.feedparser.DefaultFeedParserListener;
+import org.apache.lenya.parser.listener.impl.LenyaFeedParserListener;
+import org.apache.commons.feedparser.FeedParser;
+import org.apache.commons.feedparser.FeedParserException;
+import org.apache.commons.feedparser.FeedParserFactory;
+import org.apache.commons.feedparser.FeedParserListener;
+import org.apache.commons.feedparser.FeedParserState;
+import org.apache.commons.feedparser.network.ResourceRequest;
+import org.apache.commons.feedparser.network.ResourceRequestFactory;
+import org.apache.commons.feedparser.network.NetworkException;
+
+
+
+/**
+ * Parser for RSS/ATOM that output "collection/document style" xml
+ *
+ */
+public class FeedToDocumentParser {
+
+    public FeedToDocumentParser(){
+    
+    }
+    
+    public void parse(String urlToParse, ContentHandler ch){
+
+	try{
+	    //create a new FeedParser...
+	    FeedParser parser = FeedParserFactory.newFeedParser();
+	    
+	    //create a listener for handling our callbacks
+	    FeedParserListener listener = new LenyaFeedParserListener(ch);
+	    
+	    //use the FeedParser network IO package to fetch our resource URL
+	    ResourceRequest request = ResourceRequestFactory.getResourceRequest( urlToParse );
+	    
+	    //grab our input stream
+	    InputStream is = request.getInputStream();
+	    
+	    //start parsing our feed and have the above onItem methods called
+	    parser.parse( listener, is, urlToParse );	
+	}
+	catch(NetworkException ne){
+	    //TODO : deal with this error
+	}
+	catch(FeedParserException fde){
+	    //TODO : deal with this error
+	}
+	catch(IOException io){
+	    //TODO : deal with this error
+	}
+	
+    }
+}
+    
\ No newline at end of file

Added: 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=1002433&view=auto
==============================================================================
--- lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/parser/listener/impl/LenyaFeedParserListener.java (added)
+++ lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/parser/listener/impl/LenyaFeedParserListener.java Wed Sep 29 00:41:57 2010
@@ -0,0 +1,172 @@
+/*
+ * 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.lenya.parser.listener.impl;
+
+import java.util.Date;
+import java.util.Locale;
+
+import org.jdom.Element;
+
+import org.apache.commons.feedparser.DefaultFeedParserListener;
+import org.apache.commons.feedparser.FeedParserException;
+import org.apache.commons.feedparser.FeedParserState;
+import org.apache.commons.feedparser.FeedVersion;
+
+import org.xml.sax.ContentHandler;
+
+/**
+ * @see DefaultFeedParserListener 
+ */
+public class  LenyaFeedParserListener extends DefaultFeedParserListener {
+
+    private Object context = null;
+    private ContentHandler ch = null;
+    
+    public LenyaFeedParserListener(ContentHandler ch){
+	this.ch = ch;
+    }
+    
+    public void onFeedVersion( FeedVersion version ) throws FeedParserException {}
+    public void init() throws FeedParserException {}
+
+    public void setContext( Object context ) throws FeedParserException {
+        this.context = context;
+    }
+
+    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 );
+    }
+
+    public void onChannelEnd() throws FeedParserException { }
+    
+    /*
+    public void onImage( FeedParserState state,
+                         String title,
+                         String link,
+                         String url ) throws FeedParserException {}
+
+    public void onImageEnd() throws FeedParserException {}
+    */
+    
+    
+    public void onItem( FeedParserState state,
+                        String title,
+                        String link,
+                        String description,
+                        String permalink ) throws FeedParserException { 
+	System.out.println( "Found a new published article: " + permalink );
+    }
+
+    public void onItemEnd() throws FeedParserException {}
+    public void finished() throws FeedParserException {}
+
+    // **** MetaFeedParserListener **********************************************
+
+    /*public void onCopyright( FeedParserState state, String content ) throws FeedParserException {}
+    public void onCopyrightEnd() throws FeedParserException {}
+    */
+    
+    /**
+     * 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 );
+    }
+    
+    public void onCreatedEnd() throws FeedParserException {}
+
+    /*ublic void onSubject( FeedParserState state, String content ) throws FeedParserException {}
+    public void onSubjectEnd() throws FeedParserException {}
+    */
+
+    /**
+     * http://www.mnot.net/drafts/draft-nottingham-atom-format-00.html#rfc.section.3.2.7
+     */
+    public void onIssued( FeedParserState state, String content ) throws FeedParserException {} 
+    public void onIssuedEnd() throws FeedParserException {}
+
+    public void onLocale( FeedParserState state, Locale locale ) throws FeedParserException {}
+
+    public void onLocaleEnd() throws FeedParserException {}
+
+    public void onGUID( FeedParserState state,
+                        String value,
+                        boolean isPermalink ) throws FeedParserException {}
+
+    public void onGUIDEnd() throws FeedParserException{}
+
+    public void onGenerator( FeedParserState state, String content ) throws FeedParserException {}
+    public void onGeneratorEnd() throws FeedParserException {}
+
+    public void onAuthor( FeedParserState state,
+                          String name,
+                          String email,
+                          String resource ) throws FeedParserException {}
+
+    public void onAuthorEnd() throws FeedParserException {}
+
+    public void onComments( FeedParserState state,
+                            String resource ) throws FeedParserException {}
+
+    public void onCommentsEnd() throws FeedParserException {}
+
+    public void onCommentsFeed( FeedParserState state,
+                                String resource ) throws FeedParserException {}
+
+    public void onCommentsFeedEnd() throws FeedParserException {}
+    
+    // **** ModContentFeedParserListener ****************************************
+
+    public void onContentEncoded( FeedParserState state,
+                                  String value ) throws FeedParserException {}
+
+    public void onContentEncodedEnd() throws FeedParserException {}
+
+    public void onContentItem( FeedParserState state,
+                               String format,
+                               String encoding,
+                               Element value ) throws FeedParserException {}
+
+    public void onContentItemEnd() throws FeedParserException {}
+
+    // **** XHTMLFeedParserListener *********************************************
+
+    public void onXHTMLBody( FeedParserState state, Element value ) throws FeedParserException {}
+
+    public void onXHTMLBodyEnd() throws FeedParserException {}
+
+    // **** ContentFeedParserListener *******************************************
+
+    public void onContent( FeedParserState state,
+                           String type,
+                           String format,
+                           String encoding,
+                           String mode,
+                           String value,
+                           boolean isSummary ) throws FeedParserException {}
+
+    public void onContentEnd() throws FeedParserException {}
+
+}

Added: 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=1002433&view=auto
==============================================================================
--- lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/transformation/FeedTransformer.java (added)
+++ lenya/sandbox/modules/feed/branches/add-apache-feedparser/java/src/org/apache/lenya/transformation/FeedTransformer.java Wed Sep 29 00:41:57 2010
@@ -0,0 +1,220 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.lenya.transformation;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.HashMap;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+
+import org.apache.excalibur.xml.xpath.XPathProcessor;
+import org.apache.excalibur.source.Source;
+
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.transformation.AbstractSAXTransformer;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+import org.apache.lenya.parser.FeedToDocumentParser;
+
+public class FeedTransformer extends AbstractSAXTransformer {
+
+    public static final String COLLECTION_NS = "http://apache.org/cocoon/lenya/collection/1.0";
+    
+    public static final String DEFAULT_SERIALIZER = "xml";
+    public static final String SERIALIZER_ATTRIBUTE = "serializer";
+    /** The configured serializer name */
+    protected String configuredSerializerName;
+    /** The XPath processor */
+    protected XPathProcessor xpathProcessor;
+    
+    /** incomming elements */
+    public static final String COLLECTION_ELEMENT = "collection";
+    
+    /** debug elements */
+    public static final String DEBUG_ELEMENT = "debug";
+    public static final String LOCALMESSAGE_ELEMENT = "localMessage";
+    public static final String EXCEPTIONMESSAGE_ELEMENT = "exceptionMessage";
+    
+    /**
+     * Constructor. Set the namespace.
+     */
+    public FeedTransformer() {
+        this.defaultNamespaceURI = COLLECTION_NS;
+    }
+
+    /**
+     * Get the current <code>Configuration</code> instance used by this
+     * <code>Configurable</code>.
+     */
+    public void configure(Configuration configuration)
+	throws ConfigurationException {
+        super.configure(configuration);
+        this.configuredSerializerName = configuration.getChild(SERIALIZER_ATTRIBUTE).getValue(DEFAULT_SERIALIZER);
+    }
+
+    /**
+     * Get the <code>Parameter</code> called "serializer" from the
+     * <code>Transformer</code> invocation.
+     */
+    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
+	throws ProcessingException, SAXException, IOException {
+        super.setup(resolver, objectModel, src, par);
+
+        this.configuredSerializerName = par.getParameter(SERIALIZER_ATTRIBUTE,
+                                                         this.configuredSerializerName);
+    }
+
+    /**
+     * Receive notification of the beginning of an element.
+     *
+     * @param uri The Namespace URI, or the empty string if the element has no
+     *            Namespace URI or if Namespace
+     *            processing is not being performed.
+     * @param name The local name (without prefix), or the empty string if
+     *            Namespace processing is not being performed.
+     * @param raw The raw XML 1.0 name (with prefix), or the empty string if
+     *            raw names are not available.
+     * @param attr The attributes attached to the element. If there are no
+     *            attributes, it shall be an empty Attributes object.
+     */
+    public void startTransformingElement(String uri, String name, String raw, Attributes attr)
+	throws SAXException, IOException, ProcessingException {
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Start transforming element. uri=" + uri +
+                              ", name=" + name + ", raw=" + raw + ", attr=" + attr);
+        }
+	
+	//element /collection
+	if (name.equals(COLLECTION_ELEMENT)) {
+	    //if this is a "link" collection
+	    if(attr.getValue("type").equals("link")){
+		//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();
+		    ftdp.parse(urlToParse,this.contentHandler);
+		}
+	    }
+	    else{
+		//this collection does not refer to a link collection, so copy it "as is"
+		super.startTransformingElement(uri, name, raw, attr);
+	    }
+	    
+	}
+       
+	// do not transform the input document
+        else {
+	    super.startTransformingElement(uri, name, raw, attr);
+	}
+    }
+
+
+    /**
+     * Receive notification of the end of an element.
+     *
+     * @param uri The Namespace URI, or the empty string if the element has no
+     *            Namespace URI or if Namespace
+     *            processing is not being performed.
+     * @param name The local name (without prefix), or the empty string if
+     *            Namespace processing is not being performed.
+     * @param raw The raw XML 1.0 name (with prefix), or the empty string if
+     *            raw names are not available.
+     */
+    public void endTransformingElement(String uri, String name, String raw)
+	throws SAXException, IOException, ProcessingException
+    {
+	
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("End transforming element. uri=" + uri +
+                              ", name=" + name + ", raw=" + raw);
+        }
+	// end element collection
+	if (name.equals(COLLECTION_ELEMENT)) {
+	    //copy as is
+	    super.endTransformingElement(uri, name, raw);
+	    //TODO ?? : release the parser here ? 
+	    // or do it in the dispose ? 
+	    //parser = null;
+	}
+	
+        // default
+        else {
+	    super.endTransformingElement(uri, name, raw);
+	}
+    }
+    
+    /**
+     * 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);
+	
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
+     */
+    public void service(ServiceManager manager) throws ServiceException {
+        super.service(manager);
+        this.xpathProcessor = (XPathProcessor) this.manager.lookup(XPathProcessor.ROLE);
+	try{sendDebug("in service","");}catch (Exception e){}
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.avalon.framework.activity.Disposable#dispose()
+     */
+    public void dispose(){
+	//try{sendDebug("in dispose","");}catch (Exception e){}
+        if (this.manager != null) {
+            this.manager.release(this.xpathProcessor);
+            this.xpathProcessor = null;
+        }
+	
+        super.dispose();
+    }
+    
+    /**
+     * Recycle this component.
+     * All instance variables are set to <code>null</code>.
+     */
+    public void recycle() {
+        super.recycle();
+    }
+
+    
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org