troelskn-handsoap 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/generators/handsoap/handsoap_generator.rb +3 -3
- data/lib/handsoap/compiler.rb +7 -1
- data/lib/handsoap/xml_query_front.rb +40 -27
- metadata +1 -1
data/VERSION.yml
CHANGED
@@ -75,10 +75,10 @@ module Handsoap #:nodoc:
|
|
75
75
|
def file_contents(relative_destination, &block)
|
76
76
|
destination = destination_path(relative_destination)
|
77
77
|
temp_file = Tempfile.new("handsoap_generator")
|
78
|
-
if RUBY_PLATFORM =~ /
|
79
|
-
canonical_path = File.expand_path(source_path("/."))
|
80
|
-
else
|
78
|
+
if RUBY_PLATFORM =~ /linux/
|
81
79
|
canonical_path = `readlink -fn '#{source_path("/.")}'`
|
80
|
+
else
|
81
|
+
canonical_path = File.expand_path(source_path("/."))
|
82
82
|
end
|
83
83
|
temp_file_relative_path = relative_path(temp_file.path, canonical_path)
|
84
84
|
begin
|
data/lib/handsoap/compiler.rb
CHANGED
@@ -123,10 +123,16 @@ module Handsoap
|
|
123
123
|
w.puts
|
124
124
|
w.begin "class #{service_name} < Handsoap::Service"
|
125
125
|
w.puts "endpoint #{endpoint_name}"
|
126
|
-
w.begin "on_create_document
|
126
|
+
w.begin "def on_create_document(doc)"
|
127
|
+
w.puts "# register namespaces for the request"
|
127
128
|
w.puts "doc.alias 'tns', '#{@wsdl.target_ns}'"
|
128
129
|
w.end
|
129
130
|
w.puts
|
131
|
+
w.begin "def on_response_document(doc)"
|
132
|
+
w.puts "# register namespaces for the response"
|
133
|
+
w.puts "doc.add_namespace 'ns', '#{@wsdl.target_ns}'"
|
134
|
+
w.end
|
135
|
+
w.puts
|
130
136
|
w.puts "# public methods"
|
131
137
|
@wsdl.interface.operations.each do |operation|
|
132
138
|
action = binding.actions.find { |a| a.name == operation.name }
|
@@ -28,6 +28,9 @@ module Handsoap
|
|
28
28
|
require 'rexml/document'
|
29
29
|
elsif driver == :nokogiri
|
30
30
|
require 'nokogiri'
|
31
|
+
if Gem.loaded_specs['nokogiri'].version < Gem::Version.new('1.3.0')
|
32
|
+
raise "Incompatible version of Nokogiri. Please upgrade gem."
|
33
|
+
end
|
31
34
|
elsif driver == :libxml
|
32
35
|
require 'libxml'
|
33
36
|
else
|
@@ -78,18 +81,21 @@ module Handsoap
|
|
78
81
|
def to_date
|
79
82
|
self.first.to_date if self.any?
|
80
83
|
end
|
84
|
+
def to_s
|
85
|
+
self.first.to_s if self.any?
|
86
|
+
end
|
81
87
|
def node_name
|
82
88
|
self.first.node_name if self.any?
|
83
89
|
end
|
84
90
|
def xpath(expression, ns = nil)
|
85
91
|
self.first.xpath(expression, ns)
|
86
92
|
end
|
87
|
-
def to_s
|
88
|
-
self.first.to_s if self.any?
|
89
|
-
end
|
90
93
|
def to_xml
|
91
94
|
self.first.to_xml if self.any?
|
92
95
|
end
|
96
|
+
def to_raw
|
97
|
+
self.first.to_raw if self.any?
|
98
|
+
end
|
93
99
|
end
|
94
100
|
|
95
101
|
# Wraps the underlying (native) xml driver, and provides a uniform interface.
|
@@ -142,6 +148,12 @@ module Handsoap
|
|
142
148
|
return if t.nil?
|
143
149
|
Time.iso8601(t)
|
144
150
|
end
|
151
|
+
# Returns the inner text content of this element, or the value (if it's an attr or textnode).
|
152
|
+
#
|
153
|
+
# The output is a UTF-8 encoded string, without xml-entities.
|
154
|
+
def to_s
|
155
|
+
raise NotImplementedError.new
|
156
|
+
end
|
145
157
|
# Returns the underlying native element.
|
146
158
|
#
|
147
159
|
# You shouldn't need to use this, since doing so would void portability.
|
@@ -156,25 +168,23 @@ module Handsoap
|
|
156
168
|
#
|
157
169
|
# +ns+ Should be a Hash of prefix => namespace
|
158
170
|
#
|
159
|
-
# Returns
|
171
|
+
# Returns a +NodeSelection+
|
160
172
|
#
|
161
173
|
# See add_namespace
|
162
174
|
def xpath(expression, ns = nil)
|
163
175
|
raise NotImplementedError.new
|
164
176
|
end
|
165
|
-
# Returns the inner text content of this element, or the value (if it's an attr or textnode).
|
166
|
-
#
|
167
|
-
# The output is a UTF-8 encoded string, without xml-entities.
|
168
|
-
def to_s
|
169
|
-
raise NotImplementedError.new
|
170
|
-
end
|
171
177
|
# Returns the outer XML for this element.
|
172
178
|
def to_xml
|
173
179
|
raise NotImplementedError.new
|
174
180
|
end
|
175
|
-
#
|
181
|
+
# Returns the outer XML for this element, preserving the original formatting.
|
182
|
+
def to_raw
|
183
|
+
raise NotImplementedError.new
|
184
|
+
end
|
185
|
+
# alias of +xpath+
|
176
186
|
def /(expression)
|
177
|
-
|
187
|
+
self.xpath(expression)
|
178
188
|
end
|
179
189
|
# Returns the attribute value of the underlying element.
|
180
190
|
#
|
@@ -198,14 +208,17 @@ module Handsoap
|
|
198
208
|
ns = {} if ns.nil?
|
199
209
|
ns = @namespaces.merge(ns)
|
200
210
|
assert_prefixes!(expression, ns)
|
201
|
-
@element.find(expression, ns.map{|k,v| "#{k}:#{v}" }).to_a.map{|node| LibXMLDriver.new(node, ns) }
|
211
|
+
NodeSelection.new(@element.find(expression, ns.map{|k,v| "#{k}:#{v}" }).to_a.map{|node| LibXMLDriver.new(node, ns) })
|
202
212
|
end
|
203
213
|
def [](attribute_name)
|
204
214
|
raise ArgumentError.new unless attribute_name.kind_of? String
|
205
215
|
@element[attribute_name]
|
206
216
|
end
|
207
217
|
def to_xml
|
208
|
-
@element.to_s
|
218
|
+
@element.to_s(:indent => true)
|
219
|
+
end
|
220
|
+
def to_raw
|
221
|
+
@element.to_s(:indent => false)
|
209
222
|
end
|
210
223
|
def to_s
|
211
224
|
if @element.kind_of? LibXML::XML::Attr
|
@@ -228,7 +241,7 @@ module Handsoap
|
|
228
241
|
ns = {} if ns.nil?
|
229
242
|
ns = @namespaces.merge(ns)
|
230
243
|
assert_prefixes!(expression, ns)
|
231
|
-
REXML::XPath.match(@element, expression, ns).map{|node| REXMLDriver.new(node, ns) }
|
244
|
+
NodeSelection.new(REXML::XPath.match(@element, expression, ns).map{|node| REXMLDriver.new(node, ns) })
|
232
245
|
end
|
233
246
|
def [](attribute_name)
|
234
247
|
raise ArgumentError.new unless attribute_name.kind_of? String
|
@@ -239,7 +252,11 @@ module Handsoap
|
|
239
252
|
formatter = REXML::Formatters::Pretty.new
|
240
253
|
out = String.new
|
241
254
|
formatter.write(@element, out)
|
242
|
-
|
255
|
+
# patch for REXML's broken formatting
|
256
|
+
out.gsub(/>\n\s+([^<]+)\n\s+<\//, ">\\1</")
|
257
|
+
end
|
258
|
+
def to_raw
|
259
|
+
@element.to_s
|
243
260
|
end
|
244
261
|
def to_s
|
245
262
|
if @element.kind_of? REXML::Attribute
|
@@ -258,25 +275,21 @@ module Handsoap
|
|
258
275
|
def node_name
|
259
276
|
@element.name
|
260
277
|
end
|
261
|
-
def self.serialize_args #:nodoc:
|
262
|
-
@serialize_args ||= if Gem.loaded_specs['nokogiri'].version >= Gem::Version.new('1.3.0')
|
263
|
-
{ :encoding => 'UTF-8' }
|
264
|
-
else
|
265
|
-
'UTF-8'
|
266
|
-
end
|
267
|
-
end
|
268
278
|
def xpath(expression, ns = nil)
|
269
279
|
ns = {} if ns.nil?
|
270
280
|
ns = @namespaces.merge(ns)
|
271
281
|
assert_prefixes!(expression, ns)
|
272
|
-
@element.xpath(expression, ns).map{|node| NokogiriDriver.new(node, ns) }
|
282
|
+
NodeSelection.new(@element.xpath(expression, ns).map{|node| NokogiriDriver.new(node, ns) })
|
273
283
|
end
|
274
284
|
def [](attribute_name)
|
275
285
|
raise ArgumentError.new unless attribute_name.kind_of? String
|
276
286
|
@element[attribute_name]
|
277
287
|
end
|
278
288
|
def to_xml
|
279
|
-
@element.serialize(
|
289
|
+
@element.serialize(:encoding => 'UTF-8')
|
290
|
+
end
|
291
|
+
def to_raw
|
292
|
+
@element.serialize(:encoding => 'UTF-8', :save_with => Nokogiri::XML::Node::SaveOptions::AS_XML)
|
280
293
|
end
|
281
294
|
def to_s
|
282
295
|
if @element.kind_of?(Nokogiri::XML::Text) || @element.kind_of?(Nokogiri::XML::CDATA)
|
@@ -289,9 +302,9 @@ module Handsoap
|
|
289
302
|
return if element.nil?
|
290
303
|
# This looks messy because it is .. Nokogiri's interface is in a flux
|
291
304
|
if element.kind_of?(Nokogiri::XML::CDATA)
|
292
|
-
element.serialize(
|
305
|
+
element.serialize(:encoding => 'UTF-8').gsub(/^<!\[CDATA\[/, "").gsub(/\]\]>$/, "")
|
293
306
|
else
|
294
|
-
element.serialize(
|
307
|
+
element.serialize(:encoding => 'UTF-8').gsub('<', '<').gsub('>', '>').gsub('"', '"').gsub(''', "'").gsub('&', '&')
|
295
308
|
end
|
296
309
|
end
|
297
310
|
end
|