Class: UWA::Handler

Inherits:
Mongrel::HttpHandler
  • Object
show all
Defined in:
lib/uwa/handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHandler

Returns a new instance of Handler.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/uwa/handler.rb', line 7

def initialize
	super
	@author = 'No author'
	@description = 'No description'
	@title = 'Widget'
	@icon = 'http://www.netvibes.com/favicon.ico'
	@apiVersion = '1.0'
	@inline = true
	@debugMode = false
	@preferences = []
	@keywords = self.class.name.downcase
	@css = []
	@script = []
	@cache = {:css => nil, :script => nil}

	@query = nil
	@out = nil
	@response = nil
	@request = nil
end

Instance Attribute Details

#css=(value) ⇒ Object

Sets the attribute css

Parameters:

  • value

    the value to set the attribute css to.



5
6
7
# File 'lib/uwa/handler.rb', line 5

def css=(value)
  @css = value
end

#script=(value) ⇒ Object

Sets the attribute script

Parameters:

  • value

    the value to set the attribute script to.



5
6
7
# File 'lib/uwa/handler.rb', line 5

def script=(value)
  @script = value
end

Instance Method Details

#process(req, res) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/uwa/handler.rb', line 28

def process(req,res)
	@request = req
	@response = res
	UWA::Server.log(@request.params['REQUEST_METHOD'], @request.params['REQUEST_URI'])
	@query = query_string(req.params['QUERY_STRING'])
	UWA::Server.log(:QUERY, @query.inspect)
	if @request.params['REQUEST_PATH'].split('/', 3)[2].nil? and @query['url'].nil?
		@response.start(200) do |head, out|
			head["Content-Type"] = "text/html"
			xml = Builder::XmlMarkup.new(:indent => 4, :target => out)
			xml.instruct!
			xml.declare! :DOCTYPE, :html, :PUBLIC, 
				'-//W3C//DTD XHTML 1.0 Strict//EN',
				'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
			xml.html(:xmlns => 'http://www.w3.org/1999/xhtml', 
					'xmlns:widget' => 'http://www.netvibes.com/ns/') do |xml|
				xml.head do |xml|
					xml.meta(:name => 'author', :content => @author)
					xml.meta(:name => 'description', :content => @description)
					xml.meta(:name => 'apiVersion', :content => @apiVersion)
					xml.meta(:name => 'inline', :content => @inline.to_s)
					xml.meta(:name => 'debugMode', :content => @debugMode.to_s)
					xml.meta(:name => 'keywords', :content => @keywords)
					xml.link(:rel => :stylesheet, :type => 'text/css',
							 :href => 'http://www.netvibes.com/themes/uwa/style.css')
					xml.script("", :type => 'text/javascript',
							   :src => 'http://www.netvibes.com/js/UWA/load.js.php?env=Standalone')
					xml.tag!('widget:preferences') do |xml|
						@preferences.each do |pref|
							xml.preference(pref)
						end
					end
					xml.title(@title)
					xml.link(:rel => :icon, :type => 'image/png', :href => @icon)
					css.each { |c| xml.style("\n" + c, :type => 'text/css') }
					xml.script(:type => 'text/javascript') do |xml|
						url = 'http://' + req.params['HTTP_HOST'] + req.params['REQUEST_PATH'] + '/'
						xml << "widget.remoteUrl = '#{url}'\n"
						['Text', 'Json', 'Xml', 'Feed'].each do |m|
							xml << "widget.remote#{m} = function(uri, cb) { 
										UWA.Data.get#{m}(widget.remoteUrl + uri, cb); };\n"
						end
						script.each do |s| 
							xml << "\n#{s}\n"
						end
						xml << "if (document.location && document.location.hostname == 'localhost') {
									UWA.proxies.ajax = '/proxy';
									UWA.Data.useJsonRequest = false; }\n"
					end
				end
				xml.body do |xml|
					body xml
				end
			end
			xml.target!
		end
	else
		method = @request.params['REQUEST_PATH'].split('/', 3)[2].to_sym
		if self.respond_to?(method)
			res.start(200) do |head, out|
				begin
					@headers = head
					@out = out
					self.send(method)
				rescue Exception
					UWA::Server.log(:error, "#{$!.message} <#{$!.class.name}>")
					UWA::Server.log(:error, $!.backtrace)
				end
			end
		else
			res.start(404) do |head, out|
				out.write("Method \"#{method}\" not found")
			end
		end
	end
end