julien51-babylon 0.0.14 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,12 +4,13 @@ module Babylon
4
4
  # This is the XML SAX Parser that accepts "pushed" content
5
5
  class XmppParser < Nokogiri::XML::SAX::Document
6
6
 
7
- attr_accessor :elem, :doc, :parser, :top
7
+ attr_accessor :elem, :doc, :parser
8
8
 
9
9
  ##
10
10
  # Initialize the parser and adds the callback that will be called upon stanza completion
11
- def initialize(&callback)
11
+ def initialize(callback)
12
12
  @callback = callback
13
+ @buffer = ""
13
14
  super()
14
15
  reset
15
16
  end
@@ -17,9 +18,8 @@ module Babylon
17
18
  ##
18
19
  # Resets the Pushed SAX Parser.
19
20
  def reset
20
- @parser = Nokogiri::XML::SAX::PushParser.new(self)
21
- start_document
22
- @elem = nil
21
+ @parser = Nokogiri::XML::SAX::PushParser.new(self, "UTF-8")
22
+ @elem = @doc = nil
23
23
  end
24
24
 
25
25
  ##
@@ -28,79 +28,76 @@ module Babylon
28
28
  @parser << data
29
29
  end
30
30
 
31
- ##
32
- # Called when the document contains a CData block
33
- def cdata_block(string)
34
- @elem.add_child(Nokogiri::XML::CDATA.new(@doc, string))
35
- end
36
-
37
- ##
38
- # Called when the document received in the stream is started
39
- def start_document
40
- @doc = Nokogiri::XML::Document.new
41
- end
42
-
43
31
  ##
44
32
  # Adds characters to the current element (being parsed)
45
33
  def characters(string)
46
- @elem.add_child(Nokogiri::XML::Text.new(string, @doc)) if @elem
34
+ @buffer ||= ""
35
+ @buffer += string
47
36
  end
48
-
37
+
49
38
  ##
50
- # Instantiate a new current Element, adds the corresponding attributes and namespaces
39
+ # Instantiate a new current Element, adds the corresponding attributes and namespaces.
51
40
  # The new element is eventually added to a parent element (if present).
52
- # If this element is the first element (the root of the document), then instead of adding it to a parent, we add it to the document itself. In this case, the current element will not be terminated, so we activate the callback immediately.
41
+ # If no element is being parsed, then, we create a new document, to which we add this new element as root. (we create one document per stanza to avoid memory problems)
53
42
  def start_element(qname, attributes = [])
54
- e = Nokogiri::XML::Element.new(qname, @doc)
55
- add_namespaces_and_attributes_to_node(attributes, e)
43
+ clear_characters_buffer
44
+ @doc ||= Nokogiri::XML::Document.new
45
+ @elem ||= @doc # If we have no current element, then, we take the doc
46
+ @elem = @elem.add_child(Nokogiri::XML::Element.new(qname, @doc))
47
+ add_namespaces_and_attributes_to_current_node(attributes)
56
48
 
57
- if e.name == "stream:stream"
58
- # Should be called only for stream:stream.
59
- # We re-initialize the document and set its root to be the newly created element.
60
- start_document
61
- @doc.root = @root = e
62
- # Also, we activate the callback since this element will never end.
63
- @callback.call(e)
64
- else
65
- # Adding the newly created element to the @elem that is being parsed, or, if no element is being parsed, then we set the @top and the @elem to be this newly created element.
66
- # @top is the "highest" element to (it's parent is the <stream> element)
67
- @elem = @elem ? @elem.add_child(e) : (@top = @root.add_child(e))
49
+ if @elem.name == "stream:stream"
50
+ # We activate the callback since this element will never end.
51
+ @callback.call(@elem)
52
+ @doc = @elem = nil # Let's prepare for the next stanza
53
+ # And then, we start a new Sax Push Parser
54
+ end
55
+ end
56
+
57
+ ##
58
+ # Clears the characters buffer
59
+ def clear_characters_buffer
60
+ if @buffer && @elem
61
+ @buffer.strip!
62
+ @elem.add_child(Nokogiri::XML::Text.new(Babylon.decode_xml(@buffer), @doc)) unless @buffer.empty?
63
+ @buffer = nil # empty the buffer
68
64
  end
69
65
  end
70
66
 
71
67
  ##
72
68
  # Terminates the current element and calls the callback
73
69
  def end_element(name)
70
+ clear_characters_buffer
74
71
  if @elem
75
- if @elem == @top
72
+ if @elem.parent == @doc
73
+ # If we're actually finishing the stanza (a stanza is always a document's root)
76
74
  @callback.call(@elem)
77
- # Remove the element from its content, since we're done with it!
78
- @elem.unlink if @elem
79
- # And the current elem is the next sibling or the root
80
- @elem = @top = nil
75
+ # We delete the current element and the doc (1 doc per stanza policy)
76
+ @elem = @doc = nil
81
77
  else
82
78
  @elem = @elem.parent
83
- end
84
- else
79
+ end
80
+ else
85
81
  # Not sure what to do since it seems we're not processing any element at this time, so how can one end?
86
- end
87
- end
82
+ end
83
+ end
88
84
 
89
85
  private
90
86
 
91
87
  ##
92
88
  # Adds namespaces and attributes. Nokogiri passes them as a array of [name, value, name, value]...
93
- def add_namespaces_and_attributes_to_node(attrs, node)
89
+ def add_namespaces_and_attributes_to_current_node(attrs)
94
90
  (attrs.size / 2).times do |i|
95
91
  name, value = attrs[2 * i], attrs[2 * i + 1]
96
- if name =~ /xmlns/
97
- node.add_namespace(name.gsub("xmlns:", "").gsub("xmlns", ""), value)
98
- else
99
- node.set_attribute name, value
100
- end
92
+ # TODO : FIX namespaces :they give a lot of problems with XPath
93
+ # if name == "xmlns"
94
+ # @elem.add_namespace(nil, value)
95
+ # elsif name =~ /\Axmlns:/
96
+ # @elem.add_namespace(name.gsub("xmlns:", ""), value)
97
+ # else
98
+ @elem.set_attribute name, Babylon.decode_xml(value)
99
+ # end
101
100
  end
102
101
  end
103
-
104
- end
105
-
106
- end
102
+ end
103
+ end
@@ -12,5 +12,5 @@ require File.dirname(__FILE__) + "/dependencies"
12
12
  # Start the App
13
13
  Babylon::Runner::run(ARGV[0] || "development") do
14
14
  # Run the initializers, too. This is done here since some initializers might need EventMachine to be started.
15
- Dir.glob('initializers/*.rb').each { |f| require f }
15
+ Dir.glob('config/initializers/*.rb').each { |f| require f }
16
16
  end
@@ -7,10 +7,8 @@
7
7
  # application_type: client | component (by default it is component and we strongly discourage any client application in production)
8
8
 
9
9
  development:
10
- jid: component.server.com
10
+ jid: user@server.com
11
11
  password: password
12
- host: localhost
13
- port: 5278
14
12
  application_type: client
15
13
 
16
14
  test:
@@ -17,6 +17,6 @@
17
17
  # disco_info.to(:controller => "discovery", :action => "services")
18
18
  #
19
19
  # See lib/babylon/router/dsl.rb for more helpers.
20
- Babylon::CentralRouter.draw do
20
+ Babylon.router.draw do
21
21
 
22
22
  end
@@ -0,0 +1,52 @@
1
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
2
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
3
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
4
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
5
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
6
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
7
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
8
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
9
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
10
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
11
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
12
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
13
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
14
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
15
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
16
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
17
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
18
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
19
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
20
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
21
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
22
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
23
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
24
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
25
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
26
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
27
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
28
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
29
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
30
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
31
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
32
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
33
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
34
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
35
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
36
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
37
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
38
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
39
+ ERROR BABYLON: Observer can only be Babylon::Base::Controller
40
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
41
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
42
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
43
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
44
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
45
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
46
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
47
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
48
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
49
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
50
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
51
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
52
+ ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
@@ -1,31 +1,47 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  require 'rubygems'
4
3
  require 'daemons'
4
+ require 'optparse'
5
+
6
+ # default options
7
+ OPTIONS = {
8
+ :command => "run",
9
+ :environment => "development",
10
+ :name => "#{Dir.pwd.split("/").last}",
11
+ }
12
+
13
+ ARGV.options do |o|
14
+ script_name = File.basename($0)
15
+
16
+ o.set_summary_indent(' ')
17
+ o.banner = "Usage: script/#{script_name} [OPTIONS]"
18
+ o.define_head "Runs the Babylon Application."
19
+ o.separator ""
20
+ o.separator "Arguments :"
21
+
22
+ o.on("-c", "--command=[run|start|stop|restart]", String,
23
+ "The command you'd like to execute",
24
+ "Default: #{OPTIONS[:command]}") { |OPTIONS[:command]| }
25
+ o.on("-e", "--environment=env", String,
26
+ "The environment to run the application (you should have defined the argument into config/config.yaml)",
27
+ "Default: #{OPTIONS[:environment]}") { |OPTIONS[:environment]| }
28
+ o.on("-n", "--name=app_name", String,
29
+ "Name of your application. The pid_file will be name after this.",
30
+ "Default: #{OPTIONS[:name]}") { |OPTIONS[:name]| }
31
+
32
+ o.separator ""
5
33
 
6
- if ["run", "start", "stop", "restart"].include? ARGV[0]
7
- command = ARGV[0]
8
- env = ARGV[1] || "development"
9
- else
10
- env = ARGV[0] || "development"
11
- case env
12
- when "development"
13
- command = "run"
14
- when "production"
15
- command = "start"
16
- else
17
- # By default, we run in "on-top" mode
18
- command = "run"
19
- end
34
+ o.on_tail("-h", "--help", "Show this help message.") { puts o; exit }
35
+
36
+ o.parse!
20
37
  end
21
38
 
39
+
22
40
  options = {
23
- :ARGV => [command, '--', env],
24
- :app_name => "#{Dir.pwd.split("/").last}",
41
+ :ARGV => [OPTIONS[:command], '--', OPTIONS[:environment]],
42
+ :app_name => OPTIONS[:name],
25
43
  :dir => "../tmp/pids/",
26
- :multiple => true,
44
+ :multiple => false,
27
45
  :backtrace => true
28
46
  }
29
-
30
47
  Daemons.run(File.dirname(__FILE__) + '/../config/boot.rb', options)
31
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: julien51-babylon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - julien Genestoux
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-16 00:00:00 -07:00
12
+ date: 2009-05-07 00:00:00 -07:00
13
13
  default_executable: babylon
14
14
  dependencies: []
15
15