umlaut 3.0.0alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (293) hide show
  1. data/LICENSE +7 -0
  2. data/README.md +49 -0
  3. data/Rakefile +37 -0
  4. data/app/assets/images/error.gif +0 -0
  5. data/app/assets/images/export_bg_bot.gif +0 -0
  6. data/app/assets/images/export_bg_mid.gif +0 -0
  7. data/app/assets/images/export_bg_top.gif +0 -0
  8. data/app/assets/images/famfamfam/book_open.png +0 -0
  9. data/app/assets/images/famfamfam/cross.png +0 -0
  10. data/app/assets/images/famfamfam/page_sound.gif +0 -0
  11. data/app/assets/images/famfamfam/page_text.gif +0 -0
  12. data/app/assets/images/famfamfam/page_up.gif +0 -0
  13. data/app/assets/images/famfamfam/page_white.png +0 -0
  14. data/app/assets/images/famfamfam/readme.html +1495 -0
  15. data/app/assets/images/famfamfam/tiny_cross.png +0 -0
  16. data/app/assets/images/frame_remove.gif +0 -0
  17. data/app/assets/images/ico_go.gif +0 -0
  18. data/app/assets/images/jhu_findit.gif +0 -0
  19. data/app/assets/images/list_closed.png +0 -0
  20. data/app/assets/images/list_open.png +0 -0
  21. data/app/assets/images/more_info.gif +0 -0
  22. data/app/assets/images/rails.png +0 -0
  23. data/app/assets/images/request.gif +0 -0
  24. data/app/assets/images/spinner.gif +0 -0
  25. data/app/assets/javascripts/umlaut/ajax_windows.js +35 -0
  26. data/app/assets/javascripts/umlaut/ensure_window_size.js.erb +34 -0
  27. data/app/assets/javascripts/umlaut/expand_contract_toggle.js +25 -0
  28. data/app/assets/javascripts/umlaut/search_autocomplete.js +46 -0
  29. data/app/assets/javascripts/umlaut/simple_visible_toggle.js +8 -0
  30. data/app/assets/javascripts/umlaut/update_html.js +152 -0
  31. data/app/assets/javascripts/umlaut.js +17 -0
  32. data/app/assets/stylesheets/umlaut.css +857 -0
  33. data/app/controllers/application_controller.rb +14 -0
  34. data/app/controllers/export_email_controller.rb +123 -0
  35. data/app/controllers/js_helper_controller.rb +10 -0
  36. data/app/controllers/link_router_controller.rb +87 -0
  37. data/app/controllers/open_search_controller.rb +9 -0
  38. data/app/controllers/resolve_controller.rb +288 -0
  39. data/app/controllers/resource_controller.rb +83 -0
  40. data/app/controllers/search_controller.rb +328 -0
  41. data/app/controllers/search_methods/sfx3.rb +148 -0
  42. data/app/controllers/search_methods/sfx4.rb +257 -0
  43. data/app/controllers/search_methods/sfx_api.rb +47 -0
  44. data/app/controllers/store_controller.rb +64 -0
  45. data/app/controllers/umlaut/controller_behavior.rb +20 -0
  46. data/app/controllers/umlaut/controller_logic.rb +96 -0
  47. data/app/controllers/umlaut/error_handling.rb +48 -0
  48. data/app/controllers/umlaut_controller.rb +112 -0
  49. data/app/helpers/application_helper.rb +4 -0
  50. data/app/helpers/emailer_helper.rb +43 -0
  51. data/app/helpers/export_email_helper.rb +34 -0
  52. data/app/helpers/open_search_helper.rb +7 -0
  53. data/app/helpers/resolve_helper.rb +225 -0
  54. data/app/helpers/search_helper.rb +50 -0
  55. data/app/helpers/umlaut/footer_helper.rb +64 -0
  56. data/app/helpers/umlaut/helper.rb +62 -0
  57. data/app/helpers/umlaut/html_head_helper.rb +37 -0
  58. data/app/helpers/umlaut/url_generation.rb +77 -0
  59. data/app/mailers/emailer.rb +48 -0
  60. data/app/models/clickthrough.rb +2 -0
  61. data/app/models/collection.rb +259 -0
  62. data/app/models/crossref_lookup.rb +2 -0
  63. data/app/models/dispatched_service.rb +58 -0
  64. data/app/models/permalink.rb +29 -0
  65. data/app/models/referent.rb +473 -0
  66. data/app/models/referent_value.rb +14 -0
  67. data/app/models/request.rb +449 -0
  68. data/app/models/service_response.rb +179 -0
  69. data/app/models/service_store.rb +59 -0
  70. data/app/models/service_type_value.rb +58 -0
  71. data/app/models/service_wave.rb +150 -0
  72. data/app/models/sfx_db/az_additional_title.rb +11 -0
  73. data/app/models/sfx_db/az_letter_group.rb +11 -0
  74. data/app/models/sfx_db/az_title.rb +38 -0
  75. data/app/models/sfx_db/az_title_v2.rb +34 -0
  76. data/app/models/sfx_db/isbn.rb +12 -0
  77. data/app/models/sfx_db/issn.rb +12 -0
  78. data/app/models/sfx_db/object.rb +35 -0
  79. data/app/models/sfx_db/object_portfolio.rb +6 -0
  80. data/app/models/sfx_db/publisher.rb +10 -0
  81. data/app/models/sfx_db/sfx_db_base.rb +54 -0
  82. data/app/models/sfx_db/target.rb +9 -0
  83. data/app/models/sfx_db/target_service.rb +10 -0
  84. data/app/models/sfx_db/title.rb +10 -0
  85. data/app/models/sfx_db.rb +10 -0
  86. data/app/models/sfx_url.rb +35 -0
  87. data/app/views/emailer/citation.text.erb +28 -0
  88. data/app/views/emailer/short_citation.text.erb +8 -0
  89. data/app/views/export_email/_email.html.erb +25 -0
  90. data/app/views/export_email/_send_email.html.erb +3 -0
  91. data/app/views/export_email/_send_txt.html.erb +3 -0
  92. data/app/views/export_email/_txt.html.erb +62 -0
  93. data/app/views/export_email/email.html.erb +3 -0
  94. data/app/views/export_email/send_email.html.erb +1 -0
  95. data/app/views/export_email/send_txt.html.erb +1 -0
  96. data/app/views/export_email/txt.html.erb +3 -0
  97. data/app/views/js_helper/loader.erb.js +13 -0
  98. data/app/views/layouts/umlaut.html.erb +52 -0
  99. data/app/views/open_search/index.html.erb +9 -0
  100. data/app/views/resolve/_api_in_progress.xml.erb +21 -0
  101. data/app/views/resolve/_background_progress.html.erb +51 -0
  102. data/app/views/resolve/_background_updater.html.erb +38 -0
  103. data/app/views/resolve/_citation.html.erb +87 -0
  104. data/app/views/resolve/_coins.html.erb +1 -0
  105. data/app/views/resolve/_compact_citation.html.erb +33 -0
  106. data/app/views/resolve/_cover_image.html.erb +35 -0
  107. data/app/views/resolve/_fulltext.html.erb +55 -0
  108. data/app/views/resolve/_help.html.erb +17 -0
  109. data/app/views/resolve/_holding.html.erb +91 -0
  110. data/app/views/resolve/_related_items.html.erb +35 -0
  111. data/app/views/resolve/_search_inside.html.erb +62 -0
  112. data/app/views/resolve/_section_display.html.erb +49 -0
  113. data/app/views/resolve/_service_errors.html.erb +29 -0
  114. data/app/views/resolve/_standard_response_item.html.erb +89 -0
  115. data/app/views/resolve/api.xml.builder +72 -0
  116. data/app/views/resolve/background_status.html.erb +26 -0
  117. data/app/views/resolve/index.html.erb +73 -0
  118. data/app/views/resolve/partial_html_sections.xml.erb +30 -0
  119. data/app/views/search/_a_to_z.html.erb +6 -0
  120. data/app/views/search/_citation.html.erb +94 -0
  121. data/app/views/search/_pager.html.erb +60 -0
  122. data/app/views/search/books.html.erb +103 -0
  123. data/app/views/search/journal_search.html.erb +90 -0
  124. data/app/views/search/journals.html.erb +167 -0
  125. data/app/views/search/opensearch_description.rxml +10 -0
  126. data/app/views/testing/index.html.erb +1 -0
  127. data/app/views/umlaut/README +5 -0
  128. data/app/views/umlaut/error.html.erb +45 -0
  129. data/db/migrate/01_umlaut_init.rb +113 -0
  130. data/db/orig_fixed_data/service_type_values.yml +120 -0
  131. data/db/seeds.rb +7 -0
  132. data/lib/CronTab.rb +192 -0
  133. data/lib/aws_product_sign.rb +146 -0
  134. data/lib/exlibris/aleph/patron.rb +64 -0
  135. data/lib/exlibris/aleph/record.rb +54 -0
  136. data/lib/exlibris/aleph/rest_api.rb +29 -0
  137. data/lib/exlibris/primo/holding.rb +192 -0
  138. data/lib/exlibris/primo/rsrc.rb +17 -0
  139. data/lib/exlibris/primo/searcher.rb +276 -0
  140. data/lib/exlibris/primo/source/aleph.rb +46 -0
  141. data/lib/exlibris/primo/source/distribution/nyu_aleph.rb +323 -0
  142. data/lib/exlibris/primo/toc.rb +17 -0
  143. data/lib/exlibris/primo_ws.rb +140 -0
  144. data/lib/generators/templates/umlaut_services.yml +237 -0
  145. data/lib/generators/umlaut/asset_hooks_generator.rb +44 -0
  146. data/lib/generators/umlaut/install_generator.rb +110 -0
  147. data/lib/hip3/bib.rb +291 -0
  148. data/lib/hip3/bib_searcher.rb +302 -0
  149. data/lib/hip3/custom_field_lookup.rb +44 -0
  150. data/lib/hip3/holding.rb +50 -0
  151. data/lib/hip3/item.rb +65 -0
  152. data/lib/hip3/receipt.rb +7 -0
  153. data/lib/hip3/serial_copy.rb +82 -0
  154. data/lib/holding.rb +32 -0
  155. data/lib/marc_helper.rb +254 -0
  156. data/lib/metadata_helper.rb +312 -0
  157. data/lib/opensearch_feed.rb +398 -0
  158. data/lib/opensearch_query.rb +98 -0
  159. data/lib/referent_filter.rb +16 -0
  160. data/lib/referent_filters/dissertation_catch.rb +45 -0
  161. data/lib/section_renderer.rb +503 -0
  162. data/lib/service.rb +336 -0
  163. data/lib/service_adaptors/ajax_export.rb +37 -0
  164. data/lib/service_adaptors/amazon.rb +412 -0
  165. data/lib/service_adaptors/blacklight.rb +327 -0
  166. data/lib/service_adaptors/book_finder.rb +40 -0
  167. data/lib/service_adaptors/bx.rb +51 -0
  168. data/lib/service_adaptors/cover_thing.rb +73 -0
  169. data/lib/service_adaptors/elsevier_cover.rb +57 -0
  170. data/lib/service_adaptors/email_export.rb +10 -0
  171. data/lib/service_adaptors/ezproxy.rb +171 -0
  172. data/lib/service_adaptors/google_book_search.rb +442 -0
  173. data/lib/service_adaptors/gpo.rb +124 -0
  174. data/lib/service_adaptors/hathi_trust.rb +308 -0
  175. data/lib/service_adaptors/hip3_service.rb +150 -0
  176. data/lib/service_adaptors/hip_holding_search.rb +237 -0
  177. data/lib/service_adaptors/internet_archive.rb +488 -0
  178. data/lib/service_adaptors/isbn_db.rb +86 -0
  179. data/lib/service_adaptors/isi.rb +258 -0
  180. data/lib/service_adaptors/jcr.rb +146 -0
  181. data/lib/service_adaptors/opac.rb +351 -0
  182. data/lib/service_adaptors/open_library.rb +316 -0
  183. data/lib/service_adaptors/open_library_cover.rb +73 -0
  184. data/lib/service_adaptors/primo_service.rb +392 -0
  185. data/lib/service_adaptors/primo_source.rb +78 -0
  186. data/lib/service_adaptors/pubmed.rb +133 -0
  187. data/lib/service_adaptors/request_to_fixture.rb +68 -0
  188. data/lib/service_adaptors/scopus.rb +295 -0
  189. data/lib/service_adaptors/sfx-new.rb +557 -0
  190. data/lib/service_adaptors/sfx.rb +566 -0
  191. data/lib/service_adaptors/sfx_backchannel_record.rb +69 -0
  192. data/lib/service_adaptors/txt_holding_export.rb +32 -0
  193. data/lib/service_adaptors/ulrichs_cover.rb +57 -0
  194. data/lib/service_adaptors/ulrichs_link.rb +47 -0
  195. data/lib/service_adaptors/worldcat.rb +116 -0
  196. data/lib/service_adaptors/worldcat_identities.rb +591 -0
  197. data/lib/tasks/umlaut.rake +134 -0
  198. data/lib/umlaut/default_configuration.rb +5 -0
  199. data/lib/umlaut/routes.rb +136 -0
  200. data/lib/umlaut/version.rb +3 -0
  201. data/lib/umlaut.rb +37 -0
  202. data/lib/umlaut_configurable.rb +343 -0
  203. data/lib/umlaut_http.rb +100 -0
  204. data/lib/xml_schema_helper.rb +109 -0
  205. data/test/dummy/Rakefile +7 -0
  206. data/test/dummy/app/assets/javascripts/application.js +13 -0
  207. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  208. data/test/dummy/app/controllers/application_controller.rb +3 -0
  209. data/test/dummy/app/controllers/umlaut_controller.rb +112 -0
  210. data/test/dummy/app/helpers/application_helper.rb +2 -0
  211. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  212. data/test/dummy/config/application.rb +45 -0
  213. data/test/dummy/config/boot.rb +10 -0
  214. data/test/dummy/config/database-jhu.yml +44 -0
  215. data/test/dummy/config/database.yml +25 -0
  216. data/test/dummy/config/environment.rb +5 -0
  217. data/test/dummy/config/environments/development.rb +34 -0
  218. data/test/dummy/config/environments/production.rb +60 -0
  219. data/test/dummy/config/environments/test.rb +39 -0
  220. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  221. data/test/dummy/config/initializers/inflections.rb +10 -0
  222. data/test/dummy/config/initializers/mime_types.rb +5 -0
  223. data/test/dummy/config/initializers/secret_token.rb +7 -0
  224. data/test/dummy/config/initializers/session_store.rb +8 -0
  225. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  226. data/test/dummy/config/locales/en.yml +5 -0
  227. data/test/dummy/config/routes.rb +61 -0
  228. data/test/dummy/config/umlaut_services.yml +237 -0
  229. data/test/dummy/config.ru +4 -0
  230. data/test/dummy/db/migrate/20111228211210_umlaut_init.rb +113 -0
  231. data/test/dummy/db/schema.rb +124 -0
  232. data/test/dummy/log/development.log +12981 -0
  233. data/test/dummy/log/production.log +0 -0
  234. data/test/dummy/public/404.html +26 -0
  235. data/test/dummy/public/422.html +26 -0
  236. data/test/dummy/public/500.html +26 -0
  237. data/test/dummy/public/favicon.ico +0 -0
  238. data/test/dummy/script/rails +6 -0
  239. data/test/dummy/tmp/cache/assets/C5F/340/sprockets%2F99692920160b7a279b86a80415b79db7 +0 -0
  240. data/test/dummy/tmp/cache/assets/C70/4D0/sprockets%2F034ad2036e623081bd352800786dfe80 +0 -0
  241. data/test/dummy/tmp/cache/assets/C73/920/sprockets%2Fd371318f22900492fd180f17c5e2a504 +9268 -0
  242. data/test/dummy/tmp/cache/assets/C80/980/sprockets%2Fc94807409c1523d43e18d25f35d93c41 +0 -0
  243. data/test/dummy/tmp/cache/assets/C8F/780/sprockets%2Fe47e28558116fb5f8038754e60d1961d +11769 -0
  244. data/test/dummy/tmp/cache/assets/CAA/EB0/sprockets%2F1d179210e8b76f1ea63c802688a015e4 +9271 -0
  245. data/test/dummy/tmp/cache/assets/CBB/9C0/sprockets%2F706f28923fb754cad04b9107c89986a1 +0 -0
  246. data/test/dummy/tmp/cache/assets/CBF/B60/sprockets%2F08ca89671549936265dcb673bf02e36f +0 -0
  247. data/test/dummy/tmp/cache/assets/CC9/9F0/sprockets%2F306166316e2cafd13c15e62b51a2339d +0 -0
  248. data/test/dummy/tmp/cache/assets/CF6/F20/sprockets%2F5b2ffa1103079dfd555197838f87a99f +0 -0
  249. data/test/dummy/tmp/cache/assets/CF7/2B0/sprockets%2F25a7c73655bd3598173b39d9f98bcd46 +862 -0
  250. data/test/dummy/tmp/cache/assets/CFE/080/sprockets%2F37fe9f4255baddbd549a659914929398 +0 -0
  251. data/test/dummy/tmp/cache/assets/D22/060/sprockets%2F9aec77b768e91a802d284271c58e2f7e +21357 -0
  252. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  253. data/test/dummy/tmp/cache/assets/D33/6D0/sprockets%2F500129c57f1146e556ec3aacd6cd38c1 +0 -0
  254. data/test/dummy/tmp/cache/assets/D33/FD0/sprockets%2F2ba0b4e6334a77b923e5f770381bb2bf +0 -0
  255. data/test/dummy/tmp/cache/assets/D42/C20/sprockets%2Fbcf14e437b1582bf93b77670acf8e090 +21353 -0
  256. data/test/dummy/tmp/cache/assets/D50/A30/sprockets%2F7d8b294ac433db5d056538f8cf7c66b9 +0 -0
  257. data/test/dummy/tmp/cache/assets/D54/ED0/sprockets%2F71c9fa01091d432b131da3bb73faf3d4 +872 -0
  258. data/test/dummy/tmp/cache/assets/D65/590/sprockets%2Fc1bb92fc3406a126b7dd302edc96d629 +0 -0
  259. data/test/dummy/tmp/cache/assets/D71/6B0/sprockets%2Fde558b71b494cf09b1bf055c8dff0353 +0 -0
  260. data/test/dummy/tmp/cache/assets/D72/610/sprockets%2Fa8c708eeb30ef93de34d755d4f45d023 +859 -0
  261. data/test/dummy/tmp/cache/assets/D76/AD0/sprockets%2Fe2158cde93188cf5ab6457bc6d6602ec +0 -0
  262. data/test/dummy/tmp/cache/assets/D7A/E40/sprockets%2F9622ffcc499a57627cd1bb18fe31b8e4 +11772 -0
  263. data/test/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384 +0 -0
  264. data/test/dummy/tmp/cache/assets/D9B/770/sprockets%2F8aacf02eb7dbb0949704b28f27b87e0b +0 -0
  265. data/test/dummy/tmp/cache/assets/DA6/A80/sprockets%2F92e26d8e58d5bcc8b8f6c25d1b05b9c1 +0 -0
  266. data/test/dummy/tmp/cache/assets/DE8/790/sprockets%2Fd1333bde2b9aafcc712d11dd09ab35d8 +0 -0
  267. data/test/dummy/tmp/cache/assets/DF7/F30/sprockets%2F7bc16c4109b17fabe29f8ddbbf732d1c +374 -0
  268. data/test/dummy/tmp/cache/assets/E03/570/sprockets%2F493bdc0ac14cd4f57fdfe4253f992bde +0 -0
  269. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  270. data/test/dummy/tmp/cache/assets/E0B/4B0/sprockets%2F7988df51a61c81ce6ede4a2d4c8cce4f +377 -0
  271. data/test/dummy/tmp/cache/assets/E5F/960/sprockets%2Fdc007b6cad5c7ef08e33ec28cfff0ef6 +0 -0
  272. data/test/fixtures/dispatched_services.yml +5 -0
  273. data/test/fixtures/permalinks.yml +5 -0
  274. data/test/fixtures/referent_values.yml +1734 -0
  275. data/test/fixtures/referents.yml +156 -0
  276. data/test/fixtures/requests.yml +284 -0
  277. data/test/fixtures/service_responses.yml +5 -0
  278. data/test/fixtures/sfx_urls.yml +4 -0
  279. data/test/performance/browsing_test.rb +9 -0
  280. data/test/test_helper.rb +10 -0
  281. data/test/umlaut_test.rb +7 -0
  282. data/test/unit/aleph_patron_test.rb +39 -0
  283. data/test/unit/aleph_record_benchmarks.rb +28 -0
  284. data/test/unit/aleph_record_test.rb +30 -0
  285. data/test/unit/aws_product_sign_test.rb +93 -0
  286. data/test/unit/collection_test.rb +76 -0
  287. data/test/unit/google_book_search_test.rb +101 -0
  288. data/test/unit/primo_searcher_test.rb +403 -0
  289. data/test/unit/primo_service_test.rb +939 -0
  290. data/test/unit/primo_ws_test.rb +131 -0
  291. data/test/unit/service_response_test.rb +9 -0
  292. data/test/unit/service_test.rb +33 -0
  293. metadata +580 -0
@@ -0,0 +1,398 @@
1
+ #--
2
+ # Copyright (c) 2005 Robert Aman
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ require 'feed_tools/feed'
25
+ require 'opensearch_query'
26
+ module FeedTools
27
+ # The <tt>FeedTools::OpensearchFeed</tt> class represents a web feed's structure
28
+ # for an Opensearch query.
29
+ class OpensearchFeed < Feed
30
+ attr_accessor :queries
31
+ def initialize(attrs={})
32
+ #super
33
+ @search_terms = attrs[:search_terms]
34
+ @total_results = attrs[:total_results]
35
+ @start_index = attrs[:start_index]
36
+ @items_per_page = attrs[:count]
37
+ @search_page = nil
38
+ @first_page = nil
39
+ @last_page = nil
40
+ @previous_page = nil
41
+ @next_page = nil
42
+ @queries = {}
43
+ @queries[:request] = FeedTools::OpensearchQuery.new("request", attrs) if @search_terms
44
+ end
45
+ # Generates xml based on the content of the feed
46
+ def build_xml(feed_type=(self.feed_type or "atom"), feed_version=nil,
47
+ xml_builder=Builder::XmlMarkup.new(
48
+ :indent => 2, :escape_attrs => false))
49
+ xml_builder.instruct! :xml, :version => "1.0",
50
+ :encoding => (self.configurations[:output_encoding] or "utf-8")
51
+ if feed_type.nil?
52
+ feed_type = self.feed_type
53
+ end
54
+ if feed_version.nil?
55
+ feed_version = self.feed_version
56
+ end
57
+ if feed_type == "rss" &&
58
+ (feed_version == nil || feed_version <= 0.0)
59
+ feed_version = 1.0
60
+ elsif feed_type == "atom" &&
61
+ (feed_version == nil || feed_version <= 0.0)
62
+ feed_version = 1.0
63
+ end
64
+ if feed_type == "rss" &&
65
+ (feed_version == 0.9 || feed_version == 1.0 || feed_version == 1.1)
66
+ # RDF-based rss format
67
+ return xml_builder.tag!("rdf:RDF",
68
+ "xmlns" => FEED_TOOLS_NAMESPACES['rss10'],
69
+ "xmlns:content" => FEED_TOOLS_NAMESPACES['content'],
70
+ "xmlns:rdf" => FEED_TOOLS_NAMESPACES['rdf'],
71
+ "xmlns:dc" => FEED_TOOLS_NAMESPACES['dc'],
72
+ "xmlns:syn" => FEED_TOOLS_NAMESPACES['syn'],
73
+ "xmlns:admin" => FEED_TOOLS_NAMESPACES['admin'],
74
+ "xmlns:taxo" => FEED_TOOLS_NAMESPACES['taxo'],
75
+ "xmlns:itunes" => FEED_TOOLS_NAMESPACES['itunes'],
76
+ "xmlns:media" => FEED_TOOLS_NAMESPACES['media'],
77
+ "xmlns:atom" => FEED_TOOLS_NAMESPACES['atom10'],
78
+ "xmlns:opensearch"=>"http://a9.com/-/spec/opensearch/1.1/") do
79
+ channel_attributes = {}
80
+ unless self.link.nil?
81
+ channel_attributes["rdf:about"] =
82
+ FeedTools::HtmlHelper.escape_entities(self.link)
83
+ end
84
+ xml_builder.channel(channel_attributes) do
85
+ unless self.title.blank?
86
+ xml_builder.title(
87
+ FeedTools::HtmlHelper.strip_html_tags(self.title))
88
+ else
89
+ xml_builder.title
90
+ end
91
+ unless self.link.blank?
92
+ xml_builder.link(self.link)
93
+ else
94
+ xml_builder.link
95
+ end
96
+ unless self.search_page.blank?
97
+ xml_builder.tag!("atom:link",
98
+ {:href=>
99
+ FeedTools::HtmlHelper.escape_entities(self.search_page),
100
+ :rel=>"search",
101
+ :type=>"application/opensearchdescription+xml"
102
+ }
103
+ )
104
+ end
105
+ self.add_opensearch_tags(xml_builder)
106
+ unless images.blank?
107
+ xml_builder.image("rdf:resource" =>
108
+ FeedTools::HtmlHelper.escape_entities(
109
+ images.first.url))
110
+ end
111
+ unless description.nil? || description == ""
112
+ xml_builder.description(description)
113
+ else
114
+ xml_builder.description
115
+ end
116
+ unless self.language.blank?
117
+ xml_builder.tag!("dc:language", self.language)
118
+ end
119
+ unless self.rights.blank?
120
+ xml_builder.tag!("dc:rights", self.rights)
121
+ end
122
+ xml_builder.tag!("syn:updatePeriod", "hourly")
123
+ xml_builder.tag!("syn:updateFrequency",
124
+ (self.time_to_live / 1.hour).to_s)
125
+ xml_builder.tag!("syn:updateBase", Time.mktime(1970).iso8601)
126
+ xml_builder.items do
127
+ xml_builder.tag!("rdf:Seq") do
128
+ unless items.nil?
129
+ for item in items
130
+ if item.link.nil?
131
+ raise "Cannot generate an rdf-based feed with a nil " +
132
+ "item link field."
133
+ end
134
+ xml_builder.tag!("rdf:li", "rdf:resource" =>
135
+ FeedTools::HtmlHelper.escape_entities(item.link))
136
+ end
137
+ end
138
+ end
139
+ end
140
+ xml_builder.tag!(
141
+ "admin:generatorAgent",
142
+ "rdf:resource" => self.configurations[:generator_href])
143
+ build_xml_hook(feed_type, feed_version, xml_builder)
144
+ end
145
+ unless self.images.blank?
146
+ best_image = nil
147
+ for image in self.images
148
+ if image.link != nil
149
+ best_image = image
150
+ break
151
+ end
152
+ end
153
+ best_image = self.images.first if best_image.nil?
154
+ xml_builder.image("rdf:about" =>
155
+ FeedTools::HtmlHelper.escape_entities(best_image.url)) do
156
+ if !best_image.title.blank?
157
+ xml_builder.title(best_image.title)
158
+ elsif !self.title.blank?
159
+ xml_builder.title(self.title)
160
+ else
161
+ xml_builder.title
162
+ end
163
+ unless best_image.url.blank?
164
+ xml_builder.url(best_image.url)
165
+ end
166
+ if !best_image.link.blank?
167
+ xml_builder.link(best_image.link)
168
+ elsif !self.link.blank?
169
+ xml_builder.link(self.link)
170
+ else
171
+ xml_builder.link
172
+ end
173
+ end
174
+ end
175
+ unless items.nil?
176
+ for item in items
177
+ item.build_xml(feed_type, feed_version, xml_builder)
178
+ end
179
+ end
180
+ end
181
+ elsif feed_type == "rss"
182
+ # normal rss format
183
+ return xml_builder.rss("version" => "2.0",
184
+ "xmlns:content" => FEED_TOOLS_NAMESPACES['content'],
185
+ "xmlns:rdf" => FEED_TOOLS_NAMESPACES['rdf'],
186
+ "xmlns:dc" => FEED_TOOLS_NAMESPACES['dc'],
187
+ "xmlns:taxo" => FEED_TOOLS_NAMESPACES['taxo'],
188
+ "xmlns:trackback" => FEED_TOOLS_NAMESPACES['trackback'],
189
+ "xmlns:itunes" => FEED_TOOLS_NAMESPACES['itunes'],
190
+ "xmlns:media" => FEED_TOOLS_NAMESPACES['media'],
191
+ "xmlns:atom" => FEED_TOOLS_NAMESPACES['atom10'],
192
+ "xmlns:opensearch"=>"http://a9.com/-/spec/opensearch/1.1/") do
193
+ xml_builder.channel do
194
+ unless self.title.blank?
195
+ xml_builder.title(
196
+ FeedTools::HtmlHelper.strip_html_tags(self.title))
197
+ end
198
+ unless self.link.blank?
199
+ xml_builder.link(link)
200
+ end
201
+ unless self.description.blank?
202
+ xml_builder.description(description)
203
+ else
204
+ xml_builder.description
205
+ end
206
+ unless self.author.email.blank?
207
+ xml_builder.managingEditor(self.author.email)
208
+ end
209
+ unless self.publisher.email.blank?
210
+ xml_builder.webMaster(self.publisher.email)
211
+ end
212
+ unless self.published.blank?
213
+ xml_builder.pubDate(self.published.rfc822)
214
+ end
215
+ unless self.updated.blank?
216
+ xml_builder.lastBuildDate(self.updated.rfc822)
217
+ end
218
+ unless self.copyright.blank?
219
+ xml_builder.copyright(self.copyright)
220
+ end
221
+ unless self.search_page.blank?
222
+ xml_builder.tag!("atom:link",
223
+ {:href=>
224
+ FeedTools::HtmlHelper.escape_entities(self.search_page),
225
+ :rel=>"search",
226
+ :type=>"application/opensearchdescription+xml"
227
+ }
228
+ )
229
+ end
230
+ self.add_opensearch_tags(xml_builder)
231
+ xml_builder.ttl((time_to_live / 1.minute).to_s)
232
+ xml_builder.generator(
233
+ self.configurations[:generator_href])
234
+ build_xml_hook(feed_type, feed_version, xml_builder)
235
+ unless items.nil?
236
+ for item in items
237
+ item.build_xml(feed_type, feed_version, xml_builder)
238
+ end
239
+ end
240
+ end
241
+ end
242
+ elsif feed_type == "atom" && feed_version == 0.3
243
+ raise "Atom 0.3 is obsolete."
244
+ elsif feed_type == "atom" && feed_version == 1.0
245
+ namespaces = {}
246
+ # normal atom format
247
+ return xml_builder.feed("xmlns" => FEED_TOOLS_NAMESPACES['atom10'],
248
+ "xmlns:opensearch"=>"http://a9.com/-/spec/opensearch/1.1/",
249
+ "xml:lang" => language) do
250
+ unless title.blank?
251
+ xml_builder.title(title,
252
+ "type" => "html")
253
+ end
254
+ xml_builder.author do
255
+ unless self.author.nil? || self.author.name.nil?
256
+ xml_builder.name(self.author.name)
257
+ else
258
+ xml_builder.name("n/a")
259
+ end
260
+ unless self.author.nil? || self.author.email.nil?
261
+ xml_builder.email(self.author.email)
262
+ end
263
+ unless self.author.nil? || self.author.url.nil?
264
+ xml_builder.uri(self.author.url)
265
+ end
266
+ end
267
+ unless self.href.blank?
268
+ xml_builder.link("href" => self.href,
269
+ "rel" => "self",
270
+ "type" => "application/atom+xml")
271
+ end
272
+ unless self.link.blank?
273
+ xml_builder.link(
274
+ "href" =>
275
+ FeedTools::HtmlHelper.escape_entities(self.link),
276
+ "rel" => "alternate")
277
+ end
278
+ unless self.subtitle.blank?
279
+ xml_builder.subtitle(self.subtitle,
280
+ "type" => "html")
281
+ end
282
+ unless self.next_page.blank?
283
+ xml_builder.link(
284
+ "href" =>
285
+ FeedTools::HtmlHelper.escape_entities(self.next_page),
286
+ "type"=>"application/opensearchdescription+xml",
287
+ "rel" => "next")
288
+ end
289
+ unless self.previous_page.blank?
290
+ xml_builder.link(
291
+ "href" =>
292
+ FeedTools::HtmlHelper.escape_entities(self.previous_page),
293
+ "type"=>"application/opensearchdescription+xml",
294
+ "rel" => "previous")
295
+ end
296
+ unless self.first_page.blank?
297
+ xml_builder.link(
298
+ "href" =>
299
+ FeedTools::HtmlHelper.escape_entities(self.first_page),
300
+ "type"=>"application/opensearchdescription+xml",
301
+ "rel" => "first")
302
+ end
303
+ unless self.last_page.blank?
304
+ xml_builder.link(
305
+ "href" =>
306
+ FeedTools::HtmlHelper.escape_entities(self.last_page),
307
+ "type"=>"application/opensearchdescription+xml",
308
+ "rel" => "last")
309
+ end
310
+ unless self.search_page.blank?
311
+ xml_builder.link(
312
+ "href" =>
313
+ FeedTools::HtmlHelper.escape_entities(self.search_page),
314
+ "type"=>"application/opensearchdescription+xml",
315
+ "rel" => "last")
316
+ end
317
+ self.add_opensearch_tags(xml_builder)
318
+ if self.updated != nil
319
+ xml_builder.updated(self.updated.iso8601)
320
+ elsif self.time != nil
321
+ # Not technically correct, but a heck of a lot better
322
+ # than the Time.now fall-back.
323
+ xml_builder.updated(self.time.iso8601)
324
+ else
325
+ xml_builder.updated(Time.now.gmtime.iso8601)
326
+ end
327
+ unless self.rights.blank?
328
+ xml_builder.rights(self.rights)
329
+ end
330
+ xml_builder.generator(self.configurations[:generator_name] +
331
+ " - " + self.configurations[:generator_href])
332
+ if self.id != nil
333
+ unless FeedTools::UriHelper.is_uri? self.id
334
+ if self.link != nil
335
+ xml_builder.id(FeedTools::UriHelper.build_urn_uri(self.link))
336
+ else
337
+ raise "The unique id must be a valid URI."
338
+ end
339
+ else
340
+ xml_builder.id(self.id)
341
+ end
342
+ elsif self.link != nil
343
+ xml_builder.id(FeedTools::UriHelper.build_urn_uri(self.link))
344
+ else
345
+ raise "Cannot build feed, missing feed unique id."
346
+ end
347
+ build_xml_hook(feed_type, feed_version, xml_builder)
348
+ unless items.nil?
349
+ for item in items
350
+ item.build_xml(feed_type, feed_version, xml_builder)
351
+ end
352
+ end
353
+ end
354
+ else
355
+ raise "Unsupported feed format/version."
356
+ end
357
+ end
358
+ def search_page
359
+ return @search_page
360
+ end
361
+ def search_page=(search_page)
362
+ @search_page=search_page
363
+ end
364
+ def first_page
365
+ return @first_page
366
+ end
367
+ def first_page=(first_page)
368
+ @first_page=first_page
369
+ end
370
+ def last_page
371
+ return @last_page
372
+ end
373
+ def last_page=(last_page)
374
+ @last_page=last_page
375
+ end
376
+ def previous_page
377
+ return @previous_page
378
+ end
379
+ def previous_page=(previous_page)
380
+ @previous_page = previous_page
381
+ end
382
+ def next_page
383
+ return @next_page
384
+ end
385
+ def next_page=(next_page)
386
+ @next_page = next_page
387
+ end
388
+
389
+ def add_opensearch_tags(xml)
390
+ xml.opensearch(:totalResults){|tr|tr<<@total_results} if @total_results
391
+ xml.opensearch(:startIndex){|si|si << @start_index} if @start_index
392
+ xml.opensearch(:itemsPerPage){|ipp|ipp<<@items_per_page} if @items_per_page
393
+ @queries.each { | key, obj |
394
+ obj.build_xml(xml)
395
+ }
396
+ end
397
+ end
398
+ end
@@ -0,0 +1,98 @@
1
+ module FeedTools
2
+ class OpensearchQuery
3
+ def initialize(role='request', attributes={})
4
+ @role = self.role=role
5
+ @title = nil
6
+ @search_terms = nil
7
+ @total_results = nil
8
+ @count = nil
9
+ @start_index = nil
10
+ @start_page = nil
11
+ @language = nil
12
+ @input_encoding = nil
13
+ @output_encoding = nil
14
+ attributes.each { | key, val |
15
+ next unless val
16
+ iv = "@"+key.to_s
17
+ self.instance_variable_set(iv.to_sym, val) if self.instance_variables.index(iv)
18
+ }
19
+ end
20
+ def role
21
+ return @role
22
+ end
23
+ def role=(role)
24
+ roles = ["request","example","related","correction","subset","superset"]
25
+ raise(ArgumentError, "Must be a valid role") unless roles.index(role)
26
+ @role=role
27
+ end
28
+ def title
29
+ return @title
30
+ end
31
+ def title=(title)
32
+ @title=title
33
+ end
34
+ def search_terms
35
+ return @search_terms
36
+ end
37
+ def search_terms=(search_terms)
38
+ @search_terms=search_terms
39
+ end
40
+ def total_results
41
+ return @total_results
42
+ end
43
+ def total_results=(total_results)
44
+ @total_results=total_results
45
+ end
46
+ def count
47
+ return @count
48
+ end
49
+ def count=(count)
50
+ @count=count
51
+ end
52
+ def start_index
53
+ return @start_index
54
+ end
55
+ def start_index=(start_index)
56
+ @start_index=start_index
57
+ end
58
+ def start_page
59
+ return @start_page
60
+ end
61
+ def start_page=(start_page)
62
+ @start_page=start_page
63
+ end
64
+ def language
65
+ return @language
66
+ end
67
+ def language=(lang)
68
+ @language=lang
69
+ end
70
+ def input_encoding
71
+ return @input_encoding
72
+ end
73
+ def input_encoding=(ip)
74
+ @input_encoding=ip
75
+ end
76
+ def output_encoding
77
+ return @output_encoding
78
+ end
79
+ def output_encoding=(op)
80
+ @output_encoding=op
81
+ end
82
+ def build_xml(xml)
83
+ attrs = {}
84
+ attrs[:role]=@role if @role
85
+ attrs[:title]=@title if @title
86
+ attrs[:count]=@count if @count
87
+ attrs[:language]=@language if @language
88
+ attrs[:searchTerms]=@search_terms if @search_terms
89
+ attrs[:startIndex]=@start_index if @start_index
90
+ attrs[:startPage]=@start_page if @start_page
91
+ attrs[:inputEncoding]=@input_encoding if @input_encoding
92
+ attrs[:outputEncoding]=@output_encoding if @output_encoding
93
+ attrs[:totalResults]=@total_results if @total_results
94
+ xml.tag!("opensearch:Query", attrs)
95
+ end
96
+ end
97
+
98
+ end