source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/1.8/rss/taxonomy.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

File size: 3.0 KB
Line 
1require "rss/1.0"
2require "rss/dublincore"
3
4module RSS
5
6 TAXO_PREFIX = "taxo"
7 TAXO_URI = "http://purl.org/rss/1.0/modules/taxonomy/"
8
9 RDF.install_ns(TAXO_PREFIX, TAXO_URI)
10
11 TAXO_ELEMENTS = []
12
13 %w(link).each do |name|
14 full_name = "#{TAXO_PREFIX}_#{name}"
15 BaseListener.install_get_text_element(TAXO_URI, name, "#{full_name}=")
16 TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{name}"
17 end
18
19 %w(topic topics).each do |name|
20 class_name = Utils.to_class_name(name)
21 BaseListener.install_class_name(TAXO_URI, name, "Taxonomy#{class_name}")
22 TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{name}"
23 end
24
25 module TaxonomyTopicsModel
26 extend BaseModel
27
28 def self.append_features(klass)
29 super
30
31 klass.install_must_call_validator(TAXO_PREFIX, TAXO_URI)
32 %w(topics).each do |name|
33 klass.install_have_child_element(name, TAXO_URI, "?",
34 "#{TAXO_PREFIX}_#{name}")
35 end
36 end
37
38 class TaxonomyTopics < Element
39 include RSS10
40
41 Bag = ::RSS::RDF::Bag
42
43 class << self
44 def required_prefix
45 TAXO_PREFIX
46 end
47
48 def required_uri
49 TAXO_URI
50 end
51 end
52
53 @tag_name = "topics"
54
55 install_have_child_element("Bag", RDF::URI, nil)
56 install_must_call_validator('rdf', RDF::URI)
57
58 def initialize(*args)
59 if Utils.element_initialize_arguments?(args)
60 super
61 else
62 super()
63 self.Bag = args[0]
64 end
65 self.Bag ||= Bag.new
66 end
67
68 def full_name
69 tag_name_with_prefix(TAXO_PREFIX)
70 end
71
72 def maker_target(target)
73 target.taxo_topics
74 end
75
76 def resources
77 if @Bag
78 @Bag.lis.collect do |li|
79 li.resource
80 end
81 else
82 []
83 end
84 end
85 end
86 end
87
88 module TaxonomyTopicModel
89 extend BaseModel
90
91 def self.append_features(klass)
92 super
93 var_name = "#{TAXO_PREFIX}_topic"
94 klass.install_have_children_element("topic", TAXO_URI, "*", var_name)
95 end
96
97 class TaxonomyTopic < Element
98 include RSS10
99
100 include DublinCoreModel
101 include TaxonomyTopicsModel
102
103 class << self
104 def required_prefix
105 TAXO_PREFIX
106 end
107
108 def required_uri
109 TAXO_URI
110 end
111 end
112
113 @tag_name = "topic"
114
115 install_get_attribute("about", ::RSS::RDF::URI, true, nil, nil,
116 "#{RDF::PREFIX}:about")
117 install_text_element("link", TAXO_URI, "?", "#{TAXO_PREFIX}_link")
118
119 def initialize(*args)
120 if Utils.element_initialize_arguments?(args)
121 super
122 else
123 super()
124 self.about = args[0]
125 end
126 end
127
128 def full_name
129 tag_name_with_prefix(TAXO_PREFIX)
130 end
131
132 def maker_target(target)
133 target.new_taxo_topic
134 end
135 end
136 end
137
138 class RDF
139 include TaxonomyTopicModel
140 class Channel
141 include TaxonomyTopicsModel
142 end
143 class Item; include TaxonomyTopicsModel; end
144 end
145end
Note: See TracBrowser for help on using the repository browser.