[mashup-dev] svn commit r6052 - trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/atom

svn at wso2.org svn at wso2.org
Thu Aug 2 08:32:13 PDT 2007


Author: tyrell
Date: Thu Aug  2 08:32:09 2007
New Revision: 6052

Modified:
   trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/atom/AtomFeedHostObject.java
Log:
Adding jsFunction_writeTo

Modified: trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/atom/AtomFeedHostObject.java
==============================================================================
--- trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/atom/AtomFeedHostObject.java	(original)
+++ trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/atom/AtomFeedHostObject.java	Thu Aug  2 08:32:09 2007
@@ -16,20 +16,22 @@
 package org.wso2.mashup.hostobjects.atom;
 
 import org.apache.abdera.Abdera;
-import org.apache.abdera.i18n.iri.IRISyntaxException;
 import org.apache.abdera.factory.Factory;
-import org.apache.abdera.model.Feed;
+import org.apache.abdera.i18n.iri.IRISyntaxException;
 import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
 import org.apache.axis2.AxisFault;
 import org.mozilla.javascript.Context;
 import org.mozilla.javascript.Function;
 import org.mozilla.javascript.Scriptable;
 import org.mozilla.javascript.ScriptableObject;
 
+import java.io.File;
+import java.io.FileWriter;
 import java.io.IOException;
-import java.util.List;
-import java.util.Iterator;
 import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 
 /**
  * <p>This is a Mozilla Rhino Host Object implementation which tries to provide a javascript representation
@@ -135,11 +137,11 @@
         feed.addAuthor(author);
     }
 
-    public String jsGet_author(){
+    public String jsGet_author() {
         return feed.getAuthor().getName();
     }
 
-    
+
     /**
      * <p/>
      * Adds a new Entry to the <i>end</i> of the Feeds collection of entries
@@ -272,7 +274,7 @@
             }
 
             retEntries = (AtomEntryHostObject[]) convertedEntries.toArray();
-            
+
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -280,4 +282,30 @@
         return retEntries;
     }
 
+
+    /**
+     * Serializes the Feed to a given local file using a given path
+     *
+     * @param cx        Provides the current context
+     * @param thisObj   Gives an instance of the js object from which this method was called
+     * @param arguments The expected argument is a String representing the file path
+     * @param funObj
+     * @throws IOException
+     */
+    public static void jsFunction_writeTo(Context cx, Scriptable thisObj, Object[] arguments,
+                                          Function funObj) throws IOException {
+
+        AtomFeedHostObject feedObject = (AtomFeedHostObject) thisObj;
+
+        if (arguments[0] instanceof String) {
+
+            File localFile = new File((String) arguments[0]);
+            feedObject.feed.writeTo(new FileWriter(localFile));
+
+        } else {
+            throw new AxisFault("Invalid parameter");
+        }
+
+    }
+
 }




More information about the Mashup-dev mailing list