1 // The Antville Project
  2 // http://code.google.com/p/antville
  3 //
  4 // Copyright 2007-2011 by Tobi Schäfer.
  5 //
  6 // Copyright 2001–2007 Robert Gaggl, Hannes Wallnöfer, Tobi Schäfer,
  7 // Matthias & Michael Platzer, Christoph Lincke.
  8 //
  9 // Licensed under the Apache License, Version 2.0 (the ``License'');
 10 // you may not use this file except in compliance with the License.
 11 // You may obtain a copy of the License at
 12 //
 13 //    http://www.apache.org/licenses/LICENSE-2.0
 14 //
 15 // Unless required by applicable law or agreed to in writing, software
 16 // distributed under the License is distributed on an ``AS IS'' BASIS,
 17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 18 // See the License for the specific language governing permissions and
 19 // limitations under the License.
 20 //
 21 // $Revision$
 22 // $Author$
 23 // $Date$
 24 // $URL$
 25 
 26 /**
 27  * @fileOverview Defines the Importer prototype.
 28  */
 29 
 30 var Importer = {}
 31 
 32 Importer.run = function(site, user) {
 33    try {
 34       var xml = File.getById(site.import_id);
 35       if (xml) {
 36          var file = new java.io.File(xml.getFile());
 37          var reader = new rome.XmlReader(file);
 38          var input = new rome.SyndFeedInput(true);
 39          var feed = input.build(reader);
 40          Api.constrain(site, user);
 41          for (var i=0; i<feed.entries.size(); i+=1) {
 42             var entry = feed.entries.get(i);
 43             var category = entry.categories.get(0);
 44             if (category.name !== "http://schemas.google.com/blogger/2008/kind#post") {
 45                continue;
 46             }
 47             var story = Story.add({
 48                title: entry.title,
 49                text: entry.description || entry.contents.get(0).value,
 50                created: entry.publishedDate.format("yyyy-MM-dd HH:mm"),
 51                status: Story.CLOSED,
 52                mode: Story.FEATURED
 53             }, site, user);
 54          }
 55          File.remove.call(xml);
 56       }
 57    } catch (ex) {
 58       app.log(ex);
 59    }
 60 
 61    // Reset the site’s export status
 62    site.job = null;
 63    site.import_id = null;
 64    return;
 65 }
 66