rho-tau-extensions 6.2.0 → 7.1.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/libs/crosswalk/ext/platform/android/Rakefile +19 -1
  3. data/libs/enterprise-barcode/ext/platform/android/adds/lib/aarch64/liballbarcode.a +0 -0
  4. data/libs/enterprise-barcode/ext/platform/android/adds/lib/armeabi/liballbarcode.a +0 -0
  5. data/libs/enterprise-barcode/ext/platform/android/adds/lib/x86/liballbarcode.a +0 -0
  6. data/libs/enterprise-barcode/ext/platform/android/allbarcode.jar +0 -0
  7. data/libs/fcm-push-18/ext.yml +20 -0
  8. data/libs/fcm-push-18/ext/android/AndroidManifest.rb +10 -0
  9. data/libs/fcm-push-18/ext/android/ApplicationManifestAdds.erb +39 -0
  10. data/libs/fcm-push-18/ext/android/Rakefile +187 -0
  11. data/libs/fcm-push-18/ext/android/ext_java.files +3 -0
  12. data/libs/fcm-push-18/ext/android/ext_native.files +1 -0
  13. data/libs/fcm-push-18/ext/android/jni/src/fcmpushclient.cpp +215 -0
  14. data/libs/fcm-push-18/ext/android/jni/src/fcmpushclient.h +74 -0
  15. data/libs/fcm-push-18/ext/android/res/res/values/fireBaseValues.xml +5 -0
  16. data/libs/fcm-push-18/ext/android/src/com/rhomobile/rhodes/fcm/FCMFacade.java +164 -0
  17. data/libs/fcm-push-18/ext/android/src/com/rhomobile/rhodes/fcm/FCMIntentService.java +219 -0
  18. data/libs/fcm-push-18/ext/android/src/com/rhomobile/rhodes/fcm/FCMListener.java +88 -0
  19. data/libs/fcm-push-18/ext/build +16 -0
  20. data/libs/fcm-push-18/ext/build.bat +8 -0
  21. data/libs/fcm-push-18/ext/fcm.xml +9 -0
  22. data/libs/fcm-push-18/ext/iphone/ApplePush_Prefix.pch +7 -0
  23. data/libs/fcm-push-18/ext/iphone/Firebase.h +68 -0
  24. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseAnalytics.framework/FirebaseAnalytics +0 -0
  25. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseAnalytics.framework/Headers/FIRAnalytics+AppDelegate.h +62 -0
  26. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseAnalytics.framework/Headers/FIRAnalytics.h +115 -0
  27. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseAnalytics.framework/Headers/FIRAnalyticsConfiguration.h +1 -0
  28. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseAnalytics.framework/Headers/FIRAnalyticsSwiftNameSupport.h +13 -0
  29. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseAnalytics.framework/Headers/FIRApp.h +1 -0
  30. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseAnalytics.framework/Headers/FIRConfiguration.h +1 -0
  31. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseAnalytics.framework/Headers/FIREventNames.h +389 -0
  32. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseAnalytics.framework/Headers/FIROptions.h +1 -0
  33. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseAnalytics.framework/Headers/FIRParameterNames.h +485 -0
  34. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseAnalytics.framework/Headers/FIRUserPropertyNames.h +15 -0
  35. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseAnalytics.framework/Headers/FirebaseAnalytics.h +10 -0
  36. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseAnalytics.framework/Modules/module.modulemap +10 -0
  37. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseCore.framework/FirebaseCore +0 -0
  38. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseCore.framework/Headers/FIRAnalyticsConfiguration.h +52 -0
  39. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseCore.framework/Headers/FIRApp.h +130 -0
  40. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseCore.framework/Headers/FIRConfiguration.h +78 -0
  41. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseCore.framework/Headers/FIRLoggerLevel.h +35 -0
  42. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseCore.framework/Headers/FIROptions.h +133 -0
  43. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseCore.framework/Headers/FirebaseCore.h +5 -0
  44. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseCore.framework/Modules/module.modulemap +7 -0
  45. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseCoreDiagnostics.framework/FirebaseCoreDiagnostics +0 -0
  46. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseCoreDiagnostics.framework/Modules/module.modulemap +6 -0
  47. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseInstanceID.framework/FirebaseInstanceID +0 -0
  48. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseInstanceID.framework/Headers/FIRInstanceID.h +276 -0
  49. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseInstanceID.framework/Headers/FirebaseInstanceID.h +1 -0
  50. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseInstanceID.framework/Modules/module.modulemap +7 -0
  51. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseMessaging.framework/FirebaseMessaging +0 -0
  52. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseMessaging.framework/Headers/FIRMessaging.h +508 -0
  53. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseMessaging.framework/Headers/FirebaseMessaging.h +1 -0
  54. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseMessaging.framework/Modules/module.modulemap +8 -0
  55. data/libs/fcm-push-18/ext/iphone/Frameworks/FirebaseNanoPB.framework/FirebaseNanoPB +0 -0
  56. data/libs/fcm-push-18/ext/iphone/Frameworks/GoogleToolboxForMac.framework/GoogleToolboxForMac +0 -0
  57. data/libs/fcm-push-18/ext/iphone/Frameworks/GoogleToolboxForMac.framework/Modules/module.modulemap +5 -0
  58. data/libs/fcm-push-18/ext/iphone/Frameworks/Protobuf.framework/Modules/module.modulemap +5 -0
  59. data/libs/fcm-push-18/ext/iphone/Frameworks/Protobuf.framework/Protobuf +0 -0
  60. data/libs/fcm-push-18/ext/iphone/Frameworks/nanopb.framework/Modules/module.modulemap +5 -0
  61. data/libs/fcm-push-18/ext/iphone/Frameworks/nanopb.framework/nanopb +0 -0
  62. data/libs/fcm-push-18/ext/iphone/Rakefile +81 -0
  63. data/libs/fcm-push-18/ext/iphone/fcm-push.xcodeproj/project.pbxproj +370 -0
  64. data/libs/fcm-push-18/ext/iphone/impl/PushNotificationsReceiver.h +28 -0
  65. data/libs/fcm-push-18/ext/iphone/impl/PushNotificationsReceiver.m +27 -0
  66. data/libs/fcm-push-18/ext/iphone/impl/PushNotificationsReceiver.mm +234 -0
  67. data/libs/fcm-push-18/ext/iphone/impl/applePushSetup.c +10 -0
  68. data/libs/fcm-push-18/ext/iphone/impl/applepushclient.h +69 -0
  69. data/libs/fcm-push-18/ext/iphone/impl/applepushclient.mm +164 -0
  70. data/libs/fcm-push-18/ext/iphone/impl/readme.txt +7 -0
  71. data/libs/fcm-push-18/ext/platform/iphone/impl/readme.txt +7 -0
  72. data/libs/nodejs/ext/platform/android/jxCore/jx.h +17 -1
  73. data/libs/nodejs/ext/platform/android/jxCore/libcares_arm.a +0 -0
  74. data/libs/nodejs/ext/platform/android/jxCore/libcares_ia32.a +0 -0
  75. data/libs/nodejs/ext/platform/android/jxCore/libcares_x64.a +0 -0
  76. data/libs/nodejs/ext/platform/android/jxCore/libchrome_zlib_arm.a +0 -0
  77. data/libs/nodejs/ext/platform/android/jxCore/libchrome_zlib_ia32.a +0 -0
  78. data/libs/nodejs/ext/platform/android/jxCore/libchrome_zlib_x64.a +0 -0
  79. data/libs/nodejs/ext/platform/android/jxCore/libhttp_parser_arm.a +0 -0
  80. data/libs/nodejs/ext/platform/android/jxCore/libhttp_parser_ia32.a +0 -0
  81. data/libs/nodejs/ext/platform/android/jxCore/libhttp_parser_x64.a +0 -0
  82. data/libs/nodejs/ext/platform/android/jxCore/libjx_arm.a +0 -0
  83. data/libs/nodejs/ext/platform/android/jxCore/libjx_ia32.a +0 -0
  84. data/libs/nodejs/ext/platform/android/jxCore/libjx_x64.a +0 -0
  85. data/libs/nodejs/ext/platform/android/jxCore/libopenssl_arm.a +0 -0
  86. data/libs/nodejs/ext/platform/android/jxCore/libopenssl_ia32.a +0 -0
  87. data/libs/nodejs/ext/platform/android/jxCore/libopenssl_x64.a +0 -0
  88. data/libs/nodejs/ext/platform/android/jxCore/libsqlite3_arm.a +0 -0
  89. data/libs/nodejs/ext/platform/android/jxCore/libsqlite3_ia32.a +0 -0
  90. data/libs/nodejs/ext/platform/android/jxCore/libsqlite3_x64.a +0 -0
  91. data/libs/nodejs/ext/platform/android/jxCore/libuv_arm.a +0 -0
  92. data/libs/nodejs/ext/platform/android/jxCore/libuv_ia32.a +0 -0
  93. data/libs/nodejs/ext/platform/android/jxCore/libuv_x64.a +0 -0
  94. data/libs/nodejs/ext/platform/android/jxCore/libv8_base_arm.a +0 -0
  95. data/libs/nodejs/ext/platform/android/jxCore/libv8_base_ia32.a +0 -0
  96. data/libs/nodejs/ext/platform/android/jxCore/libv8_base_x64.a +0 -0
  97. data/libs/nodejs/ext/platform/android/jxCore/libv8_nosnapshot_arm.a +0 -0
  98. data/libs/nodejs/ext/platform/android/jxCore/libv8_nosnapshot_ia32.a +0 -0
  99. data/libs/nodejs/ext/platform/android/jxCore/libv8_nosnapshot_x64.a +0 -0
  100. data/libs/nodejs/ext/platform/iphone/jxCore/jx.h +17 -1
  101. data/libs/nodejs/ext/platform/iphone/jxCore/libcares.a +0 -0
  102. data/libs/nodejs/ext/platform/iphone/jxCore/libchrome_zlib.a +0 -0
  103. data/libs/nodejs/ext/platform/iphone/jxCore/libhttp_parser.a +0 -0
  104. data/libs/nodejs/ext/platform/iphone/jxCore/libjx.a +0 -0
  105. data/libs/nodejs/ext/platform/iphone/jxCore/libmozjs.a +0 -0
  106. data/libs/nodejs/ext/platform/iphone/jxCore/libopenssl.a +0 -0
  107. data/libs/nodejs/ext/platform/iphone/jxCore/libsqlite3.a +0 -0
  108. data/libs/nodejs/ext/platform/iphone/jxCore/libuv.a +0 -0
  109. data/libs/rexml-edge/rexml/attlistdecl.rb +63 -0
  110. data/libs/rexml-edge/rexml/attribute.rb +192 -0
  111. data/libs/rexml-edge/rexml/cdata.rb +68 -0
  112. data/libs/rexml-edge/rexml/child.rb +97 -0
  113. data/libs/rexml-edge/rexml/comment.rb +80 -0
  114. data/libs/rexml-edge/rexml/doctype.rb +270 -0
  115. data/libs/rexml-edge/rexml/document.rb +291 -0
  116. data/libs/rexml-edge/rexml/dtd/attlistdecl.rb +11 -0
  117. data/libs/rexml-edge/rexml/dtd/dtd.rb +47 -0
  118. data/libs/rexml-edge/rexml/dtd/elementdecl.rb +18 -0
  119. data/libs/rexml-edge/rexml/dtd/entitydecl.rb +57 -0
  120. data/libs/rexml-edge/rexml/dtd/notationdecl.rb +40 -0
  121. data/libs/rexml-edge/rexml/element.rb +1241 -0
  122. data/libs/rexml-edge/rexml/encoding.rb +51 -0
  123. data/libs/rexml-edge/rexml/entity.rb +174 -0
  124. data/libs/rexml-edge/rexml/formatters/default.rb +112 -0
  125. data/libs/rexml-edge/rexml/formatters/pretty.rb +142 -0
  126. data/libs/rexml-edge/rexml/formatters/transitive.rb +58 -0
  127. data/libs/rexml-edge/rexml/functions.rb +418 -0
  128. data/libs/rexml-edge/rexml/instruction.rb +71 -0
  129. data/libs/rexml-edge/rexml/light/node.rb +196 -0
  130. data/libs/rexml-edge/rexml/namespace.rb +48 -0
  131. data/libs/rexml-edge/rexml/node.rb +76 -0
  132. data/libs/rexml-edge/rexml/output.rb +30 -0
  133. data/libs/rexml-edge/rexml/parent.rb +166 -0
  134. data/libs/rexml-edge/rexml/parseexception.rb +52 -0
  135. data/libs/rexml-edge/rexml/parsers/baseparser.rb +533 -0
  136. data/libs/rexml-edge/rexml/parsers/lightparser.rb +59 -0
  137. data/libs/rexml-edge/rexml/parsers/pullparser.rb +197 -0
  138. data/libs/rexml-edge/rexml/parsers/sax2parser.rb +273 -0
  139. data/libs/rexml-edge/rexml/parsers/streamparser.rb +61 -0
  140. data/libs/rexml-edge/rexml/parsers/treeparser.rb +101 -0
  141. data/libs/rexml-edge/rexml/parsers/ultralightparser.rb +57 -0
  142. data/libs/rexml-edge/rexml/parsers/xpathparser.rb +657 -0
  143. data/libs/rexml-edge/rexml/quickpath.rb +266 -0
  144. data/libs/rexml-edge/rexml/rexml.rb +32 -0
  145. data/libs/rexml-edge/rexml/sax2listener.rb +98 -0
  146. data/libs/rexml-edge/rexml/security.rb +28 -0
  147. data/libs/rexml-edge/rexml/source.rb +297 -0
  148. data/libs/rexml-edge/rexml/streamlistener.rb +93 -0
  149. data/libs/rexml-edge/rexml/syncenumerator.rb +33 -0
  150. data/libs/rexml-edge/rexml/text.rb +426 -0
  151. data/libs/rexml-edge/rexml/undefinednamespaceexception.rb +9 -0
  152. data/libs/rexml-edge/rexml/validation/relaxng.rb +539 -0
  153. data/libs/rexml-edge/rexml/validation/validation.rb +144 -0
  154. data/libs/rexml-edge/rexml/validation/validationexception.rb +10 -0
  155. data/libs/rexml-edge/rexml/xmldecl.rb +116 -0
  156. data/libs/rexml-edge/rexml/xmltokens.rb +85 -0
  157. data/libs/rexml-edge/rexml/xpath.rb +81 -0
  158. data/libs/rexml-edge/rexml/xpath_parser.rb +704 -0
  159. data/version +1 -1
  160. metadata +118 -2
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: false
2
+ require 'rexml/validation/validationexception'
3
+
4
+ module REXML
5
+ module Validation
6
+ module Validator
7
+ NILEVENT = [ nil ]
8
+ def reset
9
+ @current = @root
10
+ @root.reset
11
+ @root.previous = true
12
+ @attr_stack = []
13
+ self
14
+ end
15
+ def dump
16
+ puts @root.inspect
17
+ end
18
+ def validate( event )
19
+ @attr_stack = [] unless defined? @attr_stack
20
+ match = @current.next(event)
21
+ raise ValidationException.new( "Validation error. Expected: "+
22
+ @current.expected.join( " or " )+" from #{@current.inspect} "+
23
+ " but got #{Event.new( event[0], event[1] ).inspect}" ) unless match
24
+ @current = match
25
+
26
+ # Check for attributes
27
+ case event[0]
28
+ when :start_element
29
+ @attr_stack << event[2]
30
+ begin
31
+ sattr = [:start_attribute, nil]
32
+ eattr = [:end_attribute]
33
+ text = [:text, nil]
34
+ k, = event[2].find { |key,value|
35
+ sattr[1] = key
36
+ m = @current.next( sattr )
37
+ if m
38
+ # If the state has text children...
39
+ if m.matches?( eattr )
40
+ @current = m
41
+ else
42
+ text[1] = value
43
+ m = m.next( text )
44
+ text[1] = nil
45
+ return false unless m
46
+ @current = m if m
47
+ end
48
+ m = @current.next( eattr )
49
+ if m
50
+ @current = m
51
+ true
52
+ else
53
+ false
54
+ end
55
+ else
56
+ false
57
+ end
58
+ }
59
+ event[2].delete(k) if k
60
+ end while k
61
+ when :end_element
62
+ attrs = @attr_stack.pop
63
+ raise ValidationException.new( "Validation error. Illegal "+
64
+ " attributes: #{attrs.inspect}") if attrs.length > 0
65
+ end
66
+ end
67
+ end
68
+
69
+ class Event
70
+ def initialize(event_type, event_arg=nil )
71
+ @event_type = event_type
72
+ @event_arg = event_arg
73
+ end
74
+
75
+ attr_reader :event_type
76
+ attr_accessor :event_arg
77
+
78
+ def done?
79
+ @done
80
+ end
81
+
82
+ def single?
83
+ return (@event_type != :start_element and @event_type != :start_attribute)
84
+ end
85
+
86
+ def matches?( event )
87
+ return false unless event[0] == @event_type
88
+ case event[0]
89
+ when nil
90
+ return true
91
+ when :start_element
92
+ return true if event[1] == @event_arg
93
+ when :end_element
94
+ return true
95
+ when :start_attribute
96
+ return true if event[1] == @event_arg
97
+ when :end_attribute
98
+ return true
99
+ when :end_document
100
+ return true
101
+ when :text
102
+ return (@event_arg.nil? or @event_arg == event[1])
103
+ =begin
104
+ when :processing_instruction
105
+ false
106
+ when :xmldecl
107
+ false
108
+ when :start_doctype
109
+ false
110
+ when :end_doctype
111
+ false
112
+ when :externalentity
113
+ false
114
+ when :elementdecl
115
+ false
116
+ when :entity
117
+ false
118
+ when :attlistdecl
119
+ false
120
+ when :notationdecl
121
+ false
122
+ when :end_doctype
123
+ false
124
+ =end
125
+ else
126
+ false
127
+ end
128
+ end
129
+
130
+ def ==( other )
131
+ return false unless other.kind_of? Event
132
+ @event_type == other.event_type and @event_arg == other.event_arg
133
+ end
134
+
135
+ def to_s
136
+ inspect
137
+ end
138
+
139
+ def inspect
140
+ "#{@event_type.inspect}( #@event_arg )"
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: false
2
+ module REXML
3
+ module Validation
4
+ class ValidationException < RuntimeError
5
+ def initialize msg
6
+ super
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: false
2
+ require 'rexml/encoding'
3
+ require 'rexml/source'
4
+
5
+ module REXML
6
+ # NEEDS DOCUMENTATION
7
+ class XMLDecl < Child
8
+ include Encoding
9
+
10
+ DEFAULT_VERSION = "1.0";
11
+ DEFAULT_ENCODING = "UTF-8";
12
+ DEFAULT_STANDALONE = "no";
13
+ START = '<\?xml';
14
+ STOP = '\?>';
15
+
16
+ attr_accessor :version, :standalone
17
+ attr_reader :writeencoding, :writethis
18
+
19
+ def initialize(version=DEFAULT_VERSION, encoding=nil, standalone=nil)
20
+ @writethis = true
21
+ @writeencoding = !encoding.nil?
22
+ if version.kind_of? XMLDecl
23
+ super()
24
+ @version = version.version
25
+ self.encoding = version.encoding
26
+ @writeencoding = version.writeencoding
27
+ @standalone = version.standalone
28
+ else
29
+ super()
30
+ @version = version
31
+ self.encoding = encoding
32
+ @standalone = standalone
33
+ end
34
+ @version = DEFAULT_VERSION if @version.nil?
35
+ end
36
+
37
+ def clone
38
+ XMLDecl.new(self)
39
+ end
40
+
41
+ # indent::
42
+ # Ignored. There must be no whitespace before an XML declaration
43
+ # transitive::
44
+ # Ignored
45
+ # ie_hack::
46
+ # Ignored
47
+ def write(writer, indent=-1, transitive=false, ie_hack=false)
48
+ return nil unless @writethis or writer.kind_of? Output
49
+ writer << START.sub(/\\/u, '')
50
+ writer << " #{content encoding}"
51
+ writer << STOP.sub(/\\/u, '')
52
+ end
53
+
54
+ def ==( other )
55
+ other.kind_of?(XMLDecl) and
56
+ other.version == @version and
57
+ other.encoding == self.encoding and
58
+ other.standalone == @standalone
59
+ end
60
+
61
+ def xmldecl version, encoding, standalone
62
+ @version = version
63
+ self.encoding = encoding
64
+ @standalone = standalone
65
+ end
66
+
67
+ def node_type
68
+ :xmldecl
69
+ end
70
+
71
+ alias :stand_alone? :standalone
72
+ alias :old_enc= :encoding=
73
+
74
+ def encoding=( enc )
75
+ if enc.nil?
76
+ self.old_enc = "UTF-8"
77
+ @writeencoding = false
78
+ else
79
+ self.old_enc = enc
80
+ @writeencoding = true
81
+ end
82
+ self.dowrite
83
+ end
84
+
85
+ # Only use this if you do not want the XML declaration to be written;
86
+ # this object is ignored by the XML writer. Otherwise, instantiate your
87
+ # own XMLDecl and add it to the document.
88
+ #
89
+ # Note that XML 1.1 documents *must* include an XML declaration
90
+ def XMLDecl.default
91
+ rv = XMLDecl.new( "1.0" )
92
+ rv.nowrite
93
+ rv
94
+ end
95
+
96
+ def nowrite
97
+ @writethis = false
98
+ end
99
+
100
+ def dowrite
101
+ @writethis = true
102
+ end
103
+
104
+ def inspect
105
+ START.sub(/\\/u, '') + " ... " + STOP.sub(/\\/u, '')
106
+ end
107
+
108
+ private
109
+ def content(enc)
110
+ rv = "version='#@version'"
111
+ rv << " encoding='#{enc}'" if @writeencoding || enc !~ /\Autf-8\z/i
112
+ rv << " standalone='#@standalone'" if @standalone
113
+ rv
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: false
2
+ module REXML
3
+ # Defines a number of tokens used for parsing XML. Not for general
4
+ # consumption.
5
+ module XMLTokens
6
+ # From http://www.w3.org/TR/REC-xml/#sec-common-syn
7
+ #
8
+ # [4] NameStartChar ::=
9
+ # ":" |
10
+ # [A-Z] |
11
+ # "_" |
12
+ # [a-z] |
13
+ # [#xC0-#xD6] |
14
+ # [#xD8-#xF6] |
15
+ # [#xF8-#x2FF] |
16
+ # [#x370-#x37D] |
17
+ # [#x37F-#x1FFF] |
18
+ # [#x200C-#x200D] |
19
+ # [#x2070-#x218F] |
20
+ # [#x2C00-#x2FEF] |
21
+ # [#x3001-#xD7FF] |
22
+ # [#xF900-#xFDCF] |
23
+ # [#xFDF0-#xFFFD] |
24
+ # [#x10000-#xEFFFF]
25
+ name_start_chars = [
26
+ ":",
27
+ "A-Z",
28
+ "_",
29
+ "a-z",
30
+ "\\u00C0-\\u00D6",
31
+ "\\u00D8-\\u00F6",
32
+ "\\u00F8-\\u02FF",
33
+ "\\u0370-\\u037D",
34
+ "\\u037F-\\u1FFF",
35
+ "\\u200C-\\u200D",
36
+ "\\u2070-\\u218F",
37
+ "\\u2C00-\\u2FEF",
38
+ "\\u3001-\\uD7FF",
39
+ "\\uF900-\\uFDCF",
40
+ "\\uFDF0-\\uFFFD",
41
+ "\\u{10000}-\\u{EFFFF}",
42
+ ]
43
+ # From http://www.w3.org/TR/REC-xml/#sec-common-syn
44
+ #
45
+ # [4a] NameChar ::=
46
+ # NameStartChar |
47
+ # "-" |
48
+ # "." |
49
+ # [0-9] |
50
+ # #xB7 |
51
+ # [#x0300-#x036F] |
52
+ # [#x203F-#x2040]
53
+ name_chars = name_start_chars + [
54
+ "\\-",
55
+ "\\.",
56
+ "0-9",
57
+ "\\u00B7",
58
+ "\\u0300-\\u036F",
59
+ "\\u203F-\\u2040",
60
+ ]
61
+ NAME_START_CHAR = "[#{name_start_chars.join('')}]"
62
+ NAME_CHAR = "[#{name_chars.join('')}]"
63
+ NAMECHAR = NAME_CHAR # deprecated. Use NAME_CHAR instead.
64
+
65
+ # From http://www.w3.org/TR/xml-names11/#NT-NCName
66
+ #
67
+ # [6] NCNameStartChar ::= NameStartChar - ':'
68
+ ncname_start_chars = name_start_chars - [":"]
69
+ # From http://www.w3.org/TR/xml-names11/#NT-NCName
70
+ #
71
+ # [5] NCNameChar ::= NameChar - ':'
72
+ ncname_chars = name_chars - [":"]
73
+ NCNAME_STR = "[#{ncname_start_chars.join('')}][#{ncname_chars.join('')}]*"
74
+ NAME_STR = "(?:#{NCNAME_STR}:)?#{NCNAME_STR}"
75
+
76
+ NAME = "(#{NAME_START_CHAR}#{NAME_CHAR}*)"
77
+ NMTOKEN = "(?:#{NAME_CHAR})+"
78
+ NMTOKENS = "#{NMTOKEN}(\\s+#{NMTOKEN})*"
79
+ REFERENCE = "(?:&#{NAME};|&#\\d+;|&#x[0-9a-fA-F]+;)"
80
+
81
+ #REFERENCE = "(?:#{ENTITYREF}|#{CHARREF})"
82
+ #ENTITYREF = "&#{NAME};"
83
+ #CHARREF = "&#\\d+;|&#x[0-9a-fA-F]+;"
84
+ end
85
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: false
2
+ require 'rexml/functions'
3
+ require 'rexml/xpath_parser'
4
+
5
+ module REXML
6
+ # Wrapper class. Use this class to access the XPath functions.
7
+ class XPath
8
+ include Functions
9
+ # A base Hash object, supposing to be used when initializing a
10
+ # default empty namespaces set, but is currently unused.
11
+ # TODO: either set the namespaces=EMPTY_HASH, or deprecate this.
12
+ EMPTY_HASH = {}
13
+
14
+ # Finds and returns the first node that matches the supplied xpath.
15
+ # element::
16
+ # The context element
17
+ # path::
18
+ # The xpath to search for. If not supplied or nil, returns the first
19
+ # node matching '*'.
20
+ # namespaces::
21
+ # If supplied, a Hash which defines a namespace mapping.
22
+ # variables::
23
+ # If supplied, a Hash which maps $variables in the query
24
+ # to values. This can be used to avoid XPath injection attacks
25
+ # or to automatically handle escaping string values.
26
+ #
27
+ # XPath.first( node )
28
+ # XPath.first( doc, "//b"} )
29
+ # XPath.first( node, "a/x:b", { "x"=>"http://doofus" } )
30
+ # XPath.first( node, '/book/publisher/text()=$publisher', {}, {"publisher"=>"O'Reilly"})
31
+ def XPath::first element, path=nil, namespaces=nil, variables={}
32
+ raise "The namespaces argument, if supplied, must be a hash object." unless namespaces.nil? or namespaces.kind_of?(Hash)
33
+ raise "The variables argument, if supplied, must be a hash object." unless variables.kind_of?(Hash)
34
+ parser = XPathParser.new
35
+ parser.namespaces = namespaces
36
+ parser.variables = variables
37
+ path = "*" unless path
38
+ element = [element] unless element.kind_of? Array
39
+ parser.parse(path, element).flatten[0]
40
+ end
41
+
42
+ # Iterates over nodes that match the given path, calling the supplied
43
+ # block with the match.
44
+ # element::
45
+ # The context element
46
+ # path::
47
+ # The xpath to search for. If not supplied or nil, defaults to '*'
48
+ # namespaces::
49
+ # If supplied, a Hash which defines a namespace mapping
50
+ # variables::
51
+ # If supplied, a Hash which maps $variables in the query
52
+ # to values. This can be used to avoid XPath injection attacks
53
+ # or to automatically handle escaping string values.
54
+ #
55
+ # XPath.each( node ) { |el| ... }
56
+ # XPath.each( node, '/*[@attr='v']' ) { |el| ... }
57
+ # XPath.each( node, 'ancestor::x' ) { |el| ... }
58
+ # XPath.each( node, '/book/publisher/text()=$publisher', {}, {"publisher"=>"O'Reilly"}) \
59
+ # {|el| ... }
60
+ def XPath::each element, path=nil, namespaces=nil, variables={}, &block
61
+ raise "The namespaces argument, if supplied, must be a hash object." unless namespaces.nil? or namespaces.kind_of?(Hash)
62
+ raise "The variables argument, if supplied, must be a hash object." unless variables.kind_of?(Hash)
63
+ parser = XPathParser.new
64
+ parser.namespaces = namespaces
65
+ parser.variables = variables
66
+ path = "*" unless path
67
+ element = [element] unless element.kind_of? Array
68
+ parser.parse(path, element).each( &block )
69
+ end
70
+
71
+ # Returns an array of nodes matching a given XPath.
72
+ def XPath::match element, path=nil, namespaces=nil, variables={}
73
+ parser = XPathParser.new
74
+ parser.namespaces = namespaces
75
+ parser.variables = variables
76
+ path = "*" unless path
77
+ element = [element] unless element.kind_of? Array
78
+ parser.parse(path,element)
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,704 @@
1
+ # frozen_string_literal: false
2
+ require 'rexml/namespace'
3
+ require 'rexml/xmltokens'
4
+ require 'rexml/attribute'
5
+ require 'rexml/syncenumerator'
6
+ require 'rexml/parsers/xpathparser'
7
+
8
+ class Object
9
+ # provides a unified +clone+ operation, for REXML::XPathParser
10
+ # to use across multiple Object types
11
+ def dclone
12
+ clone
13
+ end
14
+ end
15
+ class Symbol
16
+ # provides a unified +clone+ operation, for REXML::XPathParser
17
+ # to use across multiple Object types
18
+ def dclone ; self ; end
19
+ end
20
+ class Fixnum
21
+ # provides a unified +clone+ operation, for REXML::XPathParser
22
+ # to use across multiple Object types
23
+ def dclone ; self ; end
24
+ end
25
+ class Float
26
+ # provides a unified +clone+ operation, for REXML::XPathParser
27
+ # to use across multiple Object types
28
+ def dclone ; self ; end
29
+ end
30
+ class Array
31
+ # provides a unified +clone+ operation, for REXML::XPathParser
32
+ # to use across multiple Object+ types
33
+ def dclone
34
+ klone = self.clone
35
+ klone.clear
36
+ self.each{|v| klone << v.dclone}
37
+ klone
38
+ end
39
+ end
40
+
41
+ module REXML
42
+ # You don't want to use this class. Really. Use XPath, which is a wrapper
43
+ # for this class. Believe me. You don't want to poke around in here.
44
+ # There is strange, dark magic at work in this code. Beware. Go back! Go
45
+ # back while you still can!
46
+ class XPathParser
47
+ include XMLTokens
48
+ LITERAL = /^'([^']*)'|^"([^"]*)"/u
49
+
50
+ def initialize( )
51
+ @parser = REXML::Parsers::XPathParser.new
52
+ @namespaces = nil
53
+ @variables = {}
54
+ end
55
+
56
+ def namespaces=( namespaces={} )
57
+ Functions::namespace_context = namespaces
58
+ @namespaces = namespaces
59
+ end
60
+
61
+ def variables=( vars={} )
62
+ Functions::variables = vars
63
+ @variables = vars
64
+ end
65
+
66
+ def parse path, nodeset
67
+ path_stack = @parser.parse( path )
68
+ match( path_stack, nodeset )
69
+ end
70
+
71
+ def get_first path, nodeset
72
+ path_stack = @parser.parse( path )
73
+ first( path_stack, nodeset )
74
+ end
75
+
76
+ def predicate path, nodeset
77
+ path_stack = @parser.parse( path )
78
+ expr( path_stack, nodeset )
79
+ end
80
+
81
+ def []=( variable_name, value )
82
+ @variables[ variable_name ] = value
83
+ end
84
+
85
+
86
+ # Performs a depth-first (document order) XPath search, and returns the
87
+ # first match. This is the fastest, lightest way to return a single result.
88
+ #
89
+ # FIXME: This method is incomplete!
90
+ def first( path_stack, node )
91
+ return nil if path.size == 0
92
+
93
+ case path[0]
94
+ when :document
95
+ # do nothing
96
+ return first( path[1..-1], node )
97
+ when :child
98
+ for c in node.children
99
+ r = first( path[1..-1], c )
100
+ return r if r
101
+ end
102
+ when :qname
103
+ name = path[2]
104
+ if node.name == name
105
+ return node if path.size == 3
106
+ return first( path[3..-1], node )
107
+ else
108
+ return nil
109
+ end
110
+ when :descendant_or_self
111
+ r = first( path[1..-1], node )
112
+ return r if r
113
+ for c in node.children
114
+ r = first( path, c )
115
+ return r if r
116
+ end
117
+ when :node
118
+ return first( path[1..-1], node )
119
+ when :any
120
+ return first( path[1..-1], node )
121
+ end
122
+ return nil
123
+ end
124
+
125
+
126
+ def match( path_stack, nodeset )
127
+ r = expr( path_stack, nodeset )
128
+ r
129
+ end
130
+
131
+ private
132
+
133
+
134
+ # Returns a String namespace for a node, given a prefix
135
+ # The rules are:
136
+ #
137
+ # 1. Use the supplied namespace mapping first.
138
+ # 2. If no mapping was supplied, use the context node to look up the namespace
139
+ def get_namespace( node, prefix )
140
+ if @namespaces
141
+ return @namespaces[prefix] || ''
142
+ else
143
+ return node.namespace( prefix ) if node.node_type == :element
144
+ return ''
145
+ end
146
+ end
147
+
148
+
149
+ # Expr takes a stack of path elements and a set of nodes (either a Parent
150
+ # or an Array and returns an Array of matching nodes
151
+ ALL = [ :attribute, :element, :text, :processing_instruction, :comment ]
152
+ ELEMENTS = [ :element ]
153
+ def expr( path_stack, nodeset, context=nil )
154
+ node_types = ELEMENTS
155
+ return nodeset if path_stack.length == 0 || nodeset.length == 0
156
+ while path_stack.length > 0
157
+ if nodeset.length == 0
158
+ path_stack.clear
159
+ return []
160
+ end
161
+ case (op = path_stack.shift)
162
+ when :document
163
+ nodeset = [ nodeset[0].root_node ]
164
+
165
+ when :qname
166
+ prefix = path_stack.shift
167
+ name = path_stack.shift
168
+ nodeset.delete_if do |node|
169
+ # FIXME: This DOUBLES the time XPath searches take
170
+ ns = get_namespace( node, prefix )
171
+ if node.node_type == :element
172
+ if node.name == name
173
+ end
174
+ end
175
+ !(node.node_type == :element and
176
+ node.name == name and
177
+ node.namespace == ns )
178
+ end
179
+ node_types = ELEMENTS
180
+
181
+ when :any
182
+ nodeset.delete_if { |node| !node_types.include?(node.node_type) }
183
+
184
+ when :self
185
+ # This space left intentionally blank
186
+
187
+ when :processing_instruction
188
+ target = path_stack.shift
189
+ nodeset.delete_if do |node|
190
+ (node.node_type != :processing_instruction) or
191
+ ( target!='' and ( node.target != target ) )
192
+ end
193
+
194
+ when :text
195
+ nodeset.delete_if { |node| node.node_type != :text }
196
+
197
+ when :comment
198
+ nodeset.delete_if { |node| node.node_type != :comment }
199
+
200
+ when :node
201
+ # This space left intentionally blank
202
+ node_types = ALL
203
+
204
+ when :child
205
+ new_nodeset = []
206
+ nt = nil
207
+ nodeset.each do |node|
208
+ nt = node.node_type
209
+ new_nodeset += node.children if nt == :element or nt == :document
210
+ end
211
+ nodeset = new_nodeset
212
+ node_types = ELEMENTS
213
+
214
+ when :literal
215
+ return path_stack.shift
216
+
217
+ when :attribute
218
+ new_nodeset = []
219
+ case path_stack.shift
220
+ when :qname
221
+ prefix = path_stack.shift
222
+ name = path_stack.shift
223
+ for element in nodeset
224
+ if element.node_type == :element
225
+ attrib = element.attribute( name, get_namespace(element, prefix) )
226
+ new_nodeset << attrib if attrib
227
+ end
228
+ end
229
+ when :any
230
+ for element in nodeset
231
+ if element.node_type == :element
232
+ new_nodeset += element.attributes.to_a
233
+ end
234
+ end
235
+ end
236
+ nodeset = new_nodeset
237
+
238
+ when :parent
239
+ nodeset = nodeset.collect{|n| n.parent}.compact
240
+ #nodeset = expr(path_stack.dclone, nodeset.collect{|n| n.parent}.compact)
241
+ node_types = ELEMENTS
242
+
243
+ when :ancestor
244
+ new_nodeset = []
245
+ nodeset.each do |node|
246
+ while node.parent
247
+ node = node.parent
248
+ new_nodeset << node unless new_nodeset.include? node
249
+ end
250
+ end
251
+ nodeset = new_nodeset
252
+ node_types = ELEMENTS
253
+
254
+ when :ancestor_or_self
255
+ new_nodeset = []
256
+ nodeset.each do |node|
257
+ if node.node_type == :element
258
+ new_nodeset << node
259
+ while ( node.parent )
260
+ node = node.parent
261
+ new_nodeset << node unless new_nodeset.include? node
262
+ end
263
+ end
264
+ end
265
+ nodeset = new_nodeset
266
+ node_types = ELEMENTS
267
+
268
+ when :predicate
269
+ new_nodeset = []
270
+ subcontext = { :size => nodeset.size }
271
+ pred = path_stack.shift
272
+ nodeset.each_with_index { |node, index|
273
+ subcontext[ :node ] = node
274
+ subcontext[ :index ] = index+1
275
+ pc = pred.dclone
276
+ result = expr( pc, [node], subcontext )
277
+ result = result[0] if result.kind_of? Array and result.length == 1
278
+ if result.kind_of? Numeric
279
+ new_nodeset << node if result == (index+1)
280
+ elsif result.instance_of? Array
281
+ if result.size > 0 and result.inject(false) {|k,s| s or k}
282
+ new_nodeset << node if result.size > 0
283
+ end
284
+ else
285
+ new_nodeset << node if result
286
+ end
287
+ }
288
+ nodeset = new_nodeset
289
+ =begin
290
+ predicate = path_stack.shift
291
+ ns = nodeset.clone
292
+ result = expr( predicate, ns )
293
+ if result.kind_of? Array
294
+ nodeset = result.zip(ns).collect{|m,n| n if m}.compact
295
+ else
296
+ nodeset = result ? nodeset : []
297
+ end
298
+ =end
299
+
300
+ when :descendant_or_self
301
+ rv = descendant_or_self( path_stack, nodeset )
302
+ path_stack.clear
303
+ nodeset = rv
304
+ node_types = ELEMENTS
305
+
306
+ when :descendant
307
+ results = []
308
+ nt = nil
309
+ nodeset.each do |node|
310
+ nt = node.node_type
311
+ results += expr( path_stack.dclone.unshift( :descendant_or_self ),
312
+ node.children ) if nt == :element or nt == :document
313
+ end
314
+ nodeset = results
315
+ node_types = ELEMENTS
316
+
317
+ when :following_sibling
318
+ results = []
319
+ nodeset.each do |node|
320
+ next if node.parent.nil?
321
+ all_siblings = node.parent.children
322
+ current_index = all_siblings.index( node )
323
+ following_siblings = all_siblings[ current_index+1 .. -1 ]
324
+ results += expr( path_stack.dclone, following_siblings )
325
+ end
326
+ nodeset = results
327
+
328
+ when :preceding_sibling
329
+ results = []
330
+ nodeset.each do |node|
331
+ next if node.parent.nil?
332
+ all_siblings = node.parent.children
333
+ current_index = all_siblings.index( node )
334
+ preceding_siblings = all_siblings[ 0, current_index ].reverse
335
+ results += preceding_siblings
336
+ end
337
+ nodeset = results
338
+ node_types = ELEMENTS
339
+
340
+ when :preceding
341
+ new_nodeset = []
342
+ nodeset.each do |node|
343
+ new_nodeset += preceding( node )
344
+ end
345
+ nodeset = new_nodeset
346
+ node_types = ELEMENTS
347
+
348
+ when :following
349
+ new_nodeset = []
350
+ nodeset.each do |node|
351
+ new_nodeset += following( node )
352
+ end
353
+ nodeset = new_nodeset
354
+ node_types = ELEMENTS
355
+
356
+ when :namespace
357
+ new_nodeset = []
358
+ prefix = path_stack.shift
359
+ nodeset.each do |node|
360
+ if (node.node_type == :element or node.node_type == :attribute)
361
+ if @namespaces
362
+ namespaces = @namespaces
363
+ elsif (node.node_type == :element)
364
+ namespaces = node.namespaces
365
+ else
366
+ namespaces = node.element.namesapces
367
+ end
368
+ if (node.namespace == namespaces[prefix])
369
+ new_nodeset << node
370
+ end
371
+ end
372
+ end
373
+ nodeset = new_nodeset
374
+
375
+ when :variable
376
+ var_name = path_stack.shift
377
+ return @variables[ var_name ]
378
+
379
+ # :and, :or, :eq, :neq, :lt, :lteq, :gt, :gteq
380
+ # TODO: Special case for :or and :and -- not evaluate the right
381
+ # operand if the left alone determines result (i.e. is true for
382
+ # :or and false for :and).
383
+ when :eq, :neq, :lt, :lteq, :gt, :gteq, :or
384
+ left = expr( path_stack.shift, nodeset.dup, context )
385
+ right = expr( path_stack.shift, nodeset.dup, context )
386
+ res = equality_relational_compare( left, op, right )
387
+ return res
388
+
389
+ when :and
390
+ left = expr( path_stack.shift, nodeset.dup, context )
391
+ return [] unless left
392
+ if left.respond_to?(:inject) and !left.inject(false) {|a,b| a | b}
393
+ return []
394
+ end
395
+ right = expr( path_stack.shift, nodeset.dup, context )
396
+ res = equality_relational_compare( left, op, right )
397
+ return res
398
+
399
+ when :div
400
+ left = Functions::number(expr(path_stack.shift, nodeset, context)).to_f
401
+ right = Functions::number(expr(path_stack.shift, nodeset, context)).to_f
402
+ return (left / right)
403
+
404
+ when :mod
405
+ left = Functions::number(expr(path_stack.shift, nodeset, context )).to_f
406
+ right = Functions::number(expr(path_stack.shift, nodeset, context )).to_f
407
+ return (left % right)
408
+
409
+ when :mult
410
+ left = Functions::number(expr(path_stack.shift, nodeset, context )).to_f
411
+ right = Functions::number(expr(path_stack.shift, nodeset, context )).to_f
412
+ return (left * right)
413
+
414
+ when :plus
415
+ left = Functions::number(expr(path_stack.shift, nodeset, context )).to_f
416
+ right = Functions::number(expr(path_stack.shift, nodeset, context )).to_f
417
+ return (left + right)
418
+
419
+ when :minus
420
+ left = Functions::number(expr(path_stack.shift, nodeset, context )).to_f
421
+ right = Functions::number(expr(path_stack.shift, nodeset, context )).to_f
422
+ return (left - right)
423
+
424
+ when :union
425
+ left = expr( path_stack.shift, nodeset, context )
426
+ right = expr( path_stack.shift, nodeset, context )
427
+ return (left | right)
428
+
429
+ when :neg
430
+ res = expr( path_stack, nodeset, context )
431
+ return -(res.to_f)
432
+
433
+ when :not
434
+ when :function
435
+ func_name = path_stack.shift.tr('-','_')
436
+ arguments = path_stack.shift
437
+ subcontext = context ? nil : { :size => nodeset.size }
438
+
439
+ res = []
440
+ cont = context
441
+ nodeset.each_with_index { |n, i|
442
+ if subcontext
443
+ subcontext[:node] = n
444
+ subcontext[:index] = i
445
+ cont = subcontext
446
+ end
447
+ arg_clone = arguments.dclone
448
+ args = arg_clone.collect { |arg|
449
+ expr( arg, [n], cont )
450
+ }
451
+ Functions.context = cont
452
+ res << Functions.send( func_name, *args )
453
+ }
454
+ return res
455
+
456
+ end
457
+ end # while
458
+ return nodeset
459
+ end
460
+
461
+
462
+ ##########################################################
463
+ # FIXME
464
+ # The next two methods are BAD MOJO!
465
+ # This is my achilles heel. If anybody thinks of a better
466
+ # way of doing this, be my guest. This really sucks, but
467
+ # it is a wonder it works at all.
468
+ # ########################################################
469
+
470
+ def descendant_or_self( path_stack, nodeset )
471
+ rs = []
472
+ d_o_s( path_stack, nodeset, rs )
473
+ document_order(rs.flatten.compact)
474
+ #rs.flatten.compact
475
+ end
476
+
477
+ def d_o_s( p, ns, r )
478
+ nt = nil
479
+ ns.each_index do |i|
480
+ n = ns[i]
481
+ x = expr( p.dclone, [ n ] )
482
+ nt = n.node_type
483
+ d_o_s( p, n.children, x ) if nt == :element or nt == :document and n.children.size > 0
484
+ r.concat(x) if x.size > 0
485
+ end
486
+ end
487
+
488
+
489
+ # Reorders an array of nodes so that they are in document order
490
+ # It tries to do this efficiently.
491
+ #
492
+ # FIXME: I need to get rid of this, but the issue is that most of the XPath
493
+ # interpreter functions as a filter, which means that we lose context going
494
+ # in and out of function calls. If I knew what the index of the nodes was,
495
+ # I wouldn't have to do this. Maybe add a document IDX for each node?
496
+ # Problems with mutable documents. Or, rewrite everything.
497
+ def document_order( array_of_nodes )
498
+ new_arry = []
499
+ array_of_nodes.each { |node|
500
+ node_idx = []
501
+ np = node.node_type == :attribute ? node.element : node
502
+ while np.parent and np.parent.node_type == :element
503
+ node_idx << np.parent.index( np )
504
+ np = np.parent
505
+ end
506
+ new_arry << [ node_idx.reverse, node ]
507
+ }
508
+ new_arry.sort{ |s1, s2| s1[0] <=> s2[0] }.collect{ |s| s[1] }
509
+ end
510
+
511
+
512
+ def recurse( nodeset, &block )
513
+ for node in nodeset
514
+ yield node
515
+ recurse( node, &block ) if node.node_type == :element
516
+ end
517
+ end
518
+
519
+
520
+
521
+ # Builds a nodeset of all of the preceding nodes of the supplied node,
522
+ # in reverse document order
523
+ # preceding:: includes every element in the document that precedes this node,
524
+ # except for ancestors
525
+ def preceding( node )
526
+ ancestors = []
527
+ p = node.parent
528
+ while p
529
+ ancestors << p
530
+ p = p.parent
531
+ end
532
+
533
+ acc = []
534
+ p = preceding_node_of( node )
535
+ while p
536
+ if ancestors.include? p
537
+ ancestors.delete(p)
538
+ else
539
+ acc << p
540
+ end
541
+ p = preceding_node_of( p )
542
+ end
543
+ acc
544
+ end
545
+
546
+ def preceding_node_of( node )
547
+ psn = node.previous_sibling_node
548
+ if psn.nil?
549
+ if node.parent.nil? or node.parent.class == Document
550
+ return nil
551
+ end
552
+ return node.parent
553
+ #psn = preceding_node_of( node.parent )
554
+ end
555
+ while psn and psn.kind_of? Element and psn.children.size > 0
556
+ psn = psn.children[-1]
557
+ end
558
+ psn
559
+ end
560
+
561
+ def following( node )
562
+ acc = []
563
+ p = next_sibling_node( node )
564
+ while p
565
+ acc << p
566
+ p = following_node_of( p )
567
+ end
568
+ acc
569
+ end
570
+
571
+ def following_node_of( node )
572
+ if node.kind_of? Element and node.children.size > 0
573
+ return node.children[0]
574
+ end
575
+ return next_sibling_node(node)
576
+ end
577
+
578
+ def next_sibling_node(node)
579
+ psn = node.next_sibling_node
580
+ while psn.nil?
581
+ if node.parent.nil? or node.parent.class == Document
582
+ return nil
583
+ end
584
+ node = node.parent
585
+ psn = node.next_sibling_node
586
+ end
587
+ return psn
588
+ end
589
+
590
+ def norm b
591
+ case b
592
+ when true, false
593
+ return b
594
+ when 'true', 'false'
595
+ return Functions::boolean( b )
596
+ when /^\d+(\.\d+)?$/
597
+ return Functions::number( b )
598
+ else
599
+ return Functions::string( b )
600
+ end
601
+ end
602
+
603
+ def equality_relational_compare( set1, op, set2 )
604
+ if set1.kind_of? Array and set2.kind_of? Array
605
+ if set1.size == 1 and set2.size == 1
606
+ set1 = set1[0]
607
+ set2 = set2[0]
608
+ elsif set1.size == 0 or set2.size == 0
609
+ nd = set1.size==0 ? set2 : set1
610
+ rv = nd.collect { |il| compare( il, op, nil ) }
611
+ return rv
612
+ else
613
+ res = []
614
+ SyncEnumerator.new( set1, set2 ).each { |i1, i2|
615
+ i1 = norm( i1 )
616
+ i2 = norm( i2 )
617
+ res << compare( i1, op, i2 )
618
+ }
619
+ return res
620
+ end
621
+ end
622
+ # If one is nodeset and other is number, compare number to each item
623
+ # in nodeset s.t. number op number(string(item))
624
+ # If one is nodeset and other is string, compare string to each item
625
+ # in nodeset s.t. string op string(item)
626
+ # If one is nodeset and other is boolean, compare boolean to each item
627
+ # in nodeset s.t. boolean op boolean(item)
628
+ if set1.kind_of? Array or set2.kind_of? Array
629
+ if set1.kind_of? Array
630
+ a = set1
631
+ b = set2
632
+ else
633
+ a = set2
634
+ b = set1
635
+ end
636
+
637
+ case b
638
+ when true, false
639
+ return a.collect {|v| compare( Functions::boolean(v), op, b ) }
640
+ when Numeric
641
+ return a.collect {|v| compare( Functions::number(v), op, b )}
642
+ when /^\d+(\.\d+)?$/
643
+ b = Functions::number( b )
644
+ return a.collect {|v| compare( Functions::number(v), op, b )}
645
+ else
646
+ b = Functions::string( b )
647
+ return a.collect { |v| compare( Functions::string(v), op, b ) }
648
+ end
649
+ else
650
+ # If neither is nodeset,
651
+ # If op is = or !=
652
+ # If either boolean, convert to boolean
653
+ # If either number, convert to number
654
+ # Else, convert to string
655
+ # Else
656
+ # Convert both to numbers and compare
657
+ s1 = set1.to_s
658
+ s2 = set2.to_s
659
+ if s1 == 'true' or s1 == 'false' or s2 == 'true' or s2 == 'false'
660
+ set1 = Functions::boolean( set1 )
661
+ set2 = Functions::boolean( set2 )
662
+ else
663
+ if op == :eq or op == :neq
664
+ if s1 =~ /^\d+(\.\d+)?$/ or s2 =~ /^\d+(\.\d+)?$/
665
+ set1 = Functions::number( s1 )
666
+ set2 = Functions::number( s2 )
667
+ else
668
+ set1 = Functions::string( set1 )
669
+ set2 = Functions::string( set2 )
670
+ end
671
+ else
672
+ set1 = Functions::number( set1 )
673
+ set2 = Functions::number( set2 )
674
+ end
675
+ end
676
+ return compare( set1, op, set2 )
677
+ end
678
+ return false
679
+ end
680
+
681
+ def compare a, op, b
682
+ case op
683
+ when :eq
684
+ a == b
685
+ when :neq
686
+ a != b
687
+ when :lt
688
+ a < b
689
+ when :lteq
690
+ a <= b
691
+ when :gt
692
+ a > b
693
+ when :gteq
694
+ a >= b
695
+ when :and
696
+ a and b
697
+ when :or
698
+ a or b
699
+ else
700
+ false
701
+ end
702
+ end
703
+ end
704
+ end