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