Monday, November 08, 2010 at 12:07 AM.


on storyArrivedCallback (adrservice, adritem) {
		<<8/23/06; 6:05:00 AM by DW
			<<We already copy the permalink if it's available, if it's not, and there's a guid, copy that.
			<<This makes it possible for the NYTimesRiver app to work for pubs that only have guids.
			<<Duplicate stories are a nuisance, on a PDA screen they're ridiculous.
		<<6/27/06; 11:18:22 AM by DW
			<<The opmlDirectory code could read a feed, but we don't need to save stories in aggregatorData.stories. The table quickly gets huge and slows down the server. So we klooge in a flag keeps the stories from being saved in this circumstance. See opmldirectorySuite.walk for the other side.
		<<6/12/03; 1:02:12 PM by JES
			<<If the pref is set to save item data (adrdata^.prefs.flSaveItemData == true), copy the item's data table to the story table.
		<<1/23/03; 11:31:45 AM by DW
			<<If the item has a permalink, copy it in into the story.
		<<10/17/02; 5:22:07 PM by JES
			<<If the item has comments, copy the url into the story.
		<<4/25/02; 12:10:02 PM by DW
			<<Don't pass the enclosure table through html.neuterJavaScript, it's a senseless thing to do. Whoever added this code must not have looked to see that the enclosure is a table, not a string.
		<<1/28/02; 6:34:48 PM by JES
			<<Don't convert the channelTitle and storyText to Mac text (on MacOS), since this is already done in xml.rss.compileService.
		<<11/7/01; 7:13:04 PM by DW
			<<Change system.temp.aggregator to adrdata^.stats.lastRun.
		<<2/22/01; 10:09:33 PM by JES
			<<If this is a Mac, convert the channel title and story text to Mac text.
		<<2/20/01; 4:18:21 PM by PBS
			<<Make sure JavaScript is neutered. Curly braces are already neutered by xml.rss.compileService.
		<<1/13/01; 6:47:08 PM by DW
			<<If the item has an enclosure copy it into the story.
		<<1/8/01; 10:37:11 AM by DW
			<<Clear the viewStories cache when a story arrives.
		<<Monday, December 18, 2000 at 8:39:44 AM by DW
			<<Created. adrservice points to the service that contains the story, adritem points to an item in a channel compilation.
	local (flskip = false);
	bundle { //6/27/06; 11:16:14 AM by DW
		try {
			if not system.temp.opmlDirectory.flSaveStories {
				flskip = true}}};
	if not flskip {
		<<bundle //stack dump, 6/27/06; 11:24:31 AM by DW
			<<local (adrdumps = @scratchpad.dumps)
			<<if not defined (adrdumps^)
				<<new (tabletype, adrdumps)
			<<local (adrdump = @adrdumps^.[string.padwithzeros (sizeof (adrdumps^), 5)])
			<<if not defined (adrdump^)
				<<new (tabletype, adrdump)
			<<thread.getstackdump (adrdump)
		local (adrdata = xml.aggregator.init ());
		semaphore.lock (this, 2600);
		local (adrstory = @adrdata^.stories.[string.padwithzeros (adrdata^.prefs.nextStoryNum++, 8)]);
		semaphore.unlock (this);
		new (tabletype, adrstory);
		adrstory^.url = html.neuterJavaScript (nameof (adrservice^));
		adrstory^.channeltitle = html.neuterJavaScript (adrservice^.compilation.channeltitle);
		adrstory^.storytext = html.neuterJavaScript (adritem^.title);
		adrstory^.time = ();
		<<if system.environment.isMac
			<<adrstory^.channeltitle = latinToMac.convert (adrstory^.channeltitle)
			<<adrstory^.storytext = latinToMac.convert (adrstory^.storytext)
		if defined (adritem^.enclosure) {
			adrstory^.enclosure = adritem^.enclosure};
		if defined (adritem^.comments) {
			adrstory^.comments = adritem^.comments};
		if defined (adritem^.permalink) {
			adrstory^.permalink = adritem^.permalink};
		if defined (adritem^.guid) { //8/23/06 by DW
			adrstory^.guid = adritem^.guid};
		if adrdata^.prefs.flSaveItemData { //JES 6/12/03: Save item data if the pref is set
			if defined (adritem^.data) {
				adrstory^.data = adritem^.data}};
		bundle { //PBS 02/20/01: make sure the compilation table for this service has its JavaScript neutered
			<<This should be fast, because html.neuterJavaScript returns right away if a string doesn't contain a < character, and none of these items should contain a < character. In the case where one does, it's a good thing we're doing this neutering.
			if defined (adrService^.compilation) {
				local (adr);
				for adr in @adrService^.compilation {
					if typeOf (adr^) == stringType {
						adr^ = html.neuterJavaScript (adr^)}}}};
		<<adrstory^.data = adritem^
		bundle { //call the callbacks
			try {
				local (adrcallback);
				for adrcallback in @adrdata^.callbacks.storyArrived {
					while typeOf (adrcallback^) == addressType {
						adrcallback = adrcallback^};
					adrcallback^ (adrservice, adrItem)}}};
		xml.aggregator.clearCache ();
		return (adrstory)}}
<<bundle //test code
	<<storyArrivedCallback ([""],[""].compilation.items.["00003"])

This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.