riddl 0.99.220 → 0.99.221

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,72 +0,0 @@
1
- require 'rubygems'
2
- require 'rdf/smart'
3
- require 'json'
4
-
5
- module Riddl
6
- module Utils
7
-
8
- module Turtle
9
-
10
- class File
11
- attr_accessor :data, :changed
12
- attr_reader :url
13
-
14
- def initialize(url)
15
- @url = url
16
- @data = ""
17
- @changed = Time.at(0)
18
- end
19
- end
20
-
21
- def self::implementation(tf)
22
- Proc.new do
23
- if ::File.mtime(tf.url) > tf.changed
24
- tf.data = ""
25
- ::File.open(tf.url,"r") do |f|
26
- f.each_line do |line|
27
- tf.data += line
28
- end
29
- end
30
- tf.changed = ::File.mtime(tf.url)
31
- end
32
- run Show, tf.data, tf.changed if get
33
- run Query, tf.url if get 'query'
34
- on resource do
35
- run GetQuery, tf.url if get
36
- end
37
- end
38
- end
39
- class Query < Riddl::Implementation # {{{
40
- def response #{{{
41
- Riddl::Parameter::Complex.new "list","application/json", JSON::pretty_generate(RDF::Smart.new(@a[0]).execute(@p[0].value))
42
- end #}}}
43
- end # }}}
44
- class Show < Riddl::Implementation # {{{
45
- def response #{{{
46
- Riddl::Parameter::Complex.new "list", "text/plain", @a[0]
47
- end #}}}
48
- end # }}}
49
- class GetQuery < Riddl::Implementation#{{{
50
- def response #{{{
51
- a = RDF::Smart.new(@a[0])
52
- if a.namespaces.size > 0
53
- ns = ""
54
- if @r[-1].start_with?(":")
55
- if (!(a.namespaces[nil]))
56
- return Riddl::Parameter::Complex.new "value","text/plain", "Error parsing namespaces"
57
- end
58
- return Riddl::Parameter::Complex.new "value","application/json", JSON::pretty_generate(a.execute("PREFIX : <" + a.namespaces[nil] + "> SELECT * WHERE { #{@r[-1]} ?p ?o}"))
59
- else
60
- if (!(a.namespaces[@r[-1].partition(":")[0]]))
61
- return Riddl::Parameter::Complex.new "value","text/plain", "Error parsing namespaces"
62
- end
63
- return Riddl::Parameter::Complex.new "value","application/json", JSON::pretty_generate(a.execute("PREFIX #{@r[-1].partition(":")[0]}: <" + a.namespaces[@r[-1].partition(":")[0]] + "> SELECT * WHERE { #{@r[-1]} ?p ?o}"))
64
- end
65
- end
66
- Riddl::Parameter::Complex.new "list","application/json", JSON::pretty_generate(a.execute("select * where {#{@r[-1]} ?p ?o}"))
67
- end #}}}
68
- end#}}}
69
-
70
- end
71
- end
72
- end
@@ -1,40 +0,0 @@
1
- require 'mime/types'
2
- require 'charlock_holmes'
3
- require 'digest/md5'
4
- require 'xml/smart'
5
-
6
- module Riddl
7
- module Utils
8
- class XMLServe < Riddl::Implementation
9
- def response
10
- path = File.file?(@a[0]) ? @a[0] : nil
11
- xpath = @a[1]
12
-
13
- if path.nil? || File.directory?(path)
14
- @status = 404
15
- return []
16
- end
17
- if File.exists?(path)
18
- mtime = File.mtime(path)
19
- @headers << Riddl::Header.new("Last-Modified",mtime.httpdate)
20
- @headers << Riddl::Header.new("Cache-Control","max-age=15552000, public")
21
- @headers << Riddl::Header.new("ETag",Digest::MD5.hexdigest(mtime.httpdate))
22
- htime = @env["HTTP_IF_MODIFIED_SINCE"].nil? ? Time.at(0) : Time.parse(@env["HTTP_IF_MODIFIED_SINCE"])
23
- if htime == mtime
24
- @headers << Riddl::Header.new("Connection","close")
25
- @status = 304 # Not modified
26
- return []
27
- else
28
- if xpath
29
- res = XML::Smart.open(path).find(xpath)
30
- return Riddl::Parameter::Complex.new('file','text/xml',res.any? ? res.first.dump : '<empty/>')
31
- else
32
- return Riddl::Parameter::Complex.new('file','text/xml',File.open(path,'r'))
33
- end
34
- end
35
- end
36
- @status = 404
37
- end
38
- end
39
- end
40
- end
@@ -1,21 +0,0 @@
1
- module Riddl
2
- module Utils
3
-
4
- class XSLOverlay < Riddl::Implementation
5
- def response
6
- doc = if @p[0].value.class == String
7
- XML::Smart::string(@p[0].value)
8
- elsif @p[0].value.respond_to?(:read)
9
- XML::Smart::string(@p[0].value.read)
10
- else
11
- nil
12
- end
13
- unless doc.nil?
14
- doc.root.add_before "?xml-stylesheet", "href='#{@a[0]}' type='text/xsl'"
15
- Riddl::Parameter::Complex.new("content",@p[0].mimetype,doc.to_s)
16
- end
17
- end
18
- end
19
-
20
- end
21
- end