blob: 7fa5d0e2659d231e9d5e5abf4a379b189061a312 [file] [log] [blame]
#--######################################################################
# Copyright (c) 2008 IBM
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
#
# Ricardo Balduino:: Initial implementation, based on design discussions with Onno van der Straaten
#++######################################################################
# {Copyright (c) 2008 IBM}[link:files/COPYRIGHT.html]
record = (@practice)
imageSrc = ""
xml.instruct!
#xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do
xml.rss "version" => "2.0", "xmlns:atom" => "http://www.w3.org/2005/Atom" do
scope = @practice.presentation_name + " Practice" if @practice
scope = ENV['EPFWIKI_APP_NAME'] unless @wiki
wiki_page = record
xml.channel do
xml.title "#{scope}"
if @wiki
xml.link wiki_page.url(true)
xml.atom:link, :href => "http://#{ENV['EPFWIKI_HOST']}/rss/#{@wiki.folder}/practice/#{@practice_name}", :rel => 'self', :type => 'application/rss+xml'
end
xml.pubDate CGI.rfc1123_date(Time.now.gmtime)
xml.image do
xml.url "http://" + ENV['EPFWIKI_HOST'] + "/" + "#{ENV['EPFWIKI_WIKIS_FOLDER']}/" + wiki_page.site.folder + "/" + "images/practice.gif"
xml.link wiki_page.url(true)
xml.title @practice.presentation_name
end
# xml.description h("Practice #{wiki_page.presentation_name} in '#{@wiki.title}' Wiki") # use this and remove the line below in case the practice itself is added as first item in the feed, see commented section below
xml.description wiki_page.overview_table # Gets the brief description from the element page
# The first entry could be the practice itself, but is it redundant with the channel information above.
#xml.item do
# xml.guid "WikiPage#{wiki_page.id.to_s}", :isPermaLink => false
# xml.title "#{wiki_page.presentation_name}"
# xml.link wiki_page.url(true)
# xml.description wiki_page.overview_table # Gets the brief description from the element page
# xml.pubDate CGI.rfc1123_date(Time.now.gmtime)
#xml.dc_creator h(wiki_page.user.name) # this is raising an exception -> user is nil
#end
# crawls the practice page and finds all the elements the practice relates to
match = /class="sectionTableHeading"(.*?)<\/td>/m.match(wiki_page.html) #finds first sectionTableHeading (Relationships table)
if match
sectionTableHeading = '<th class="sectionTableHeading"'+match[1]+'</td>'
more_nodes = true
while (more_nodes) do
# finds the image that is included by the brief description of the element
match1 = /img src="(.*?)"/m.match(sectionTableHeading)
if match1
imageTag = '<img src="'+match1[1]+'"'+' height="16" width="16">'
imageSrc = match1[1]
imageSrc = imageSrc.gsub("../", '')
imageSrc = imageSrc.gsub("./", '')
imageSrc = "http://" + ENV['EPFWIKI_HOST'] + "/" + "#{ENV['EPFWIKI_WIKIS_FOLDER']}/" + wiki_page.site.folder + "/" + imageSrc
sectionTableHeading = sectionTableHeading.sub(imageTag, '') # removes the img section from the sectionTableHeading, so next time next image will be returned
imageSrc = '<img src="'+imageSrc+'" width="16" height="16" />' # this is added to the brief description later
end
match2 = /a (.*?)<\/a>/m.match(sectionTableHeading) #finds first <a href...</a> section in the sectionTableHeading block returned
if match2
xml.item do
aSection = '<a '+match2[1]+'</a>'
match3 = /"\>(.*?)<\/a>/m.match(aSection) # returns the text in the <a></a> section
title = match3[1]
xml.title title
match4 = /href="(.*?)"/m.match(aSection) # returns the relative path in the href attribute
if match4
aHref = match4[1]
# extracts the "./../../../" and adds the full url of the wiki site to the relative path
aHref = aHref.gsub("../", '')
aHref = aHref.gsub("./", '')
relPath = aHref # but the relative path is preserved for the purposes of using it on the wiki page query below
aHref = "http://" + ENV['EPFWIKI_HOST'] + "/" + "#{ENV['EPFWIKI_WIKIS_FOLDER']}/" + wiki_page.site.folder + "/" + aHref
xml.link aHref
end
page = WikiPage.find (:first, :conditions => ['rel_path=?', relPath]) # finds the page that is pointed by this relative path
briefDescr = page.overview_table
if briefDescr
xml.description imageSrc+" "+briefDescr # returns the brief description of the element represented by this page, but first adds the relate image
end
xml.guid "WikiPage#{page.id.to_s}", :isPermaLink => false
xml.pubDate CGI.rfc1123_date(Time.now.gmtime)
sectionTableHeading = sectionTableHeading.gsub(aSection, '') # removes the used <a>...</a> section from the whole, so this block repeats for the next <a>..</a> section found
end
else
more_nodes = false
end
end
end # ends crawler
end
end