wirispluginengine 3.62.0.1322 → 7.14.0.1422

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.
Files changed (149) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +34 -34
  3. data/app/assets/javascripts/wirispluginengine/WIRISplugins.js +1040 -64
  4. data/app/controllers/wirispluginengine/application_controller.rb +84 -75
  5. data/app/helpers/wirispluginengine/application_helper.rb +4 -4
  6. data/config/routes.rb +4 -4
  7. data/lib/com/wiris/common/WInteger.rb +52 -51
  8. data/lib/com/wiris/plugin/api/Cas.rb +5 -5
  9. data/lib/com/wiris/plugin/api/CleanCache.rb +5 -5
  10. data/lib/com/wiris/plugin/api/Configuration.rb +5 -5
  11. data/lib/com/wiris/plugin/api/ConfigurationKeys.rb +94 -91
  12. data/lib/com/wiris/plugin/api/Editor.rb +5 -5
  13. data/lib/com/wiris/plugin/api/Filter.rb +5 -5
  14. data/lib/com/wiris/plugin/api/ImageFormatController.rb +5 -5
  15. data/lib/com/wiris/plugin/api/ParamsProvider.rb +5 -5
  16. data/lib/com/wiris/plugin/api/PluginBuilder.rb +88 -74
  17. data/lib/com/wiris/plugin/api/Render.rb +5 -5
  18. data/lib/com/wiris/plugin/api/ServiceResourceLoader.rb +5 -5
  19. data/lib/com/wiris/plugin/api/Test.rb +5 -5
  20. data/lib/com/wiris/plugin/api/TextService.rb +5 -5
  21. data/lib/com/wiris/plugin/configuration/ConfigurationUpdater.rb +5 -5
  22. data/lib/com/wiris/plugin/impl/CacheFormulaImpl.rb +15 -0
  23. data/lib/com/wiris/plugin/impl/CacheImpl.rb +124 -0
  24. data/lib/com/wiris/plugin/impl/CasImpl.rb +140 -138
  25. data/lib/com/wiris/plugin/impl/CleanCacheImpl.rb +103 -101
  26. data/lib/com/wiris/plugin/impl/ConfigurationImpl.rb +165 -166
  27. data/lib/com/wiris/plugin/impl/CustomConfigurationUpdater.rb +32 -30
  28. data/lib/com/wiris/plugin/impl/DefaultConfigurationUpdater.rb +24 -22
  29. data/lib/com/wiris/plugin/impl/EditorImpl.rb +80 -78
  30. data/lib/com/wiris/plugin/impl/FileConfigurationUpdater.rb +29 -27
  31. data/lib/com/wiris/plugin/impl/FileStorageAndCache.rb +55 -53
  32. data/lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb +65 -134
  33. data/lib/com/wiris/plugin/impl/GenericParamsProviderImpl.rb +50 -48
  34. data/lib/com/wiris/plugin/impl/HttpImpl.rb +49 -48
  35. data/lib/com/wiris/plugin/impl/HttpListener.rb +5 -5
  36. data/lib/com/wiris/plugin/impl/ImageFormatControllerPng.rb +71 -63
  37. data/lib/com/wiris/plugin/impl/ImageFormatControllerSvg.rb +37 -28
  38. data/lib/com/wiris/plugin/impl/PluginBuilderImpl.rb +280 -248
  39. data/lib/com/wiris/plugin/impl/RenderImpl.rb +303 -257
  40. data/lib/com/wiris/plugin/impl/ServiceResourceLoaderImpl.rb +41 -39
  41. data/lib/com/wiris/plugin/impl/TestImpl.rb +177 -157
  42. data/lib/com/wiris/plugin/impl/TextFilter.rb +210 -194
  43. data/lib/com/wiris/plugin/impl/TextFilterTags.rb +57 -50
  44. data/lib/com/wiris/plugin/impl/TextServiceImpl.rb +158 -107
  45. data/lib/com/wiris/plugin/storage/StorageAndCache.rb +5 -5
  46. data/lib/com/wiris/util/json/JSon.rb +505 -493
  47. data/lib/com/wiris/util/json/JSonIntegerFormat.rb +17 -16
  48. data/lib/com/wiris/util/json/JsonAPIResponse.rb +70 -0
  49. data/lib/com/wiris/util/json/StringParser.rb +57 -56
  50. data/lib/com/wiris/util/sys/AccessProvider.rb +8 -0
  51. data/lib/com/wiris/util/sys/Cache.rb +8 -0
  52. data/lib/com/wiris/util/sys/HttpConnection.rb +14 -13
  53. data/lib/com/wiris/util/sys/HttpConnectionListener.rb +5 -5
  54. data/lib/com/wiris/util/sys/HttpSync.rb +28 -0
  55. data/lib/com/wiris/util/sys/IniFile.rb +132 -131
  56. data/lib/com/wiris/util/sys/Lock.rb +8 -0
  57. data/lib/com/wiris/util/sys/LockProvider.rb +8 -0
  58. data/lib/com/wiris/util/sys/Store.rb +126 -101
  59. data/lib/com/wiris/util/sys/StoreCache.rb +63 -0
  60. data/lib/com/wiris/util/sys/TimerProxy.rb +21 -0
  61. data/lib/com/wiris/util/sys/TimerTask.rb +8 -0
  62. data/lib/com/wiris/util/type/Arrays.rb +275 -0
  63. data/lib/com/wiris/util/type/ByteBuffer.rb +69 -0
  64. data/lib/com/wiris/util/type/Comparator.rb +8 -0
  65. data/lib/com/wiris/util/type/DataUtils.rb +24 -0
  66. data/lib/com/wiris/util/type/DoubleTools.rb +14 -0
  67. data/lib/com/wiris/util/type/HashCache.rb +43 -0
  68. data/lib/com/wiris/util/type/IntegerTools.rb +32 -0
  69. data/lib/com/wiris/util/type/Queue.rb +31 -0
  70. data/lib/com/wiris/util/type/SortArrayByStringLength.rb +26 -0
  71. data/lib/com/wiris/util/type/SortStringByLength.rb +26 -0
  72. data/lib/com/wiris/util/type/SortedHash.rb +45 -0
  73. data/lib/com/wiris/util/type/Stack.rb +31 -0
  74. data/lib/com/wiris/util/type/StringUtils.rb +56 -0
  75. data/lib/com/wiris/util/type/Tokenizer.rb +40 -0
  76. data/lib/com/wiris/util/type/UrlUtils.rb +78 -0
  77. data/lib/com/wiris/util/xml/ContentHandler.rb +8 -0
  78. data/lib/com/wiris/util/xml/DefaultHandler.rb +25 -0
  79. data/lib/com/wiris/util/xml/EntityResolver.rb +8 -0
  80. data/lib/com/wiris/util/xml/MathMLEntityResolver.rb +19 -0
  81. data/lib/com/wiris/util/xml/SAXParser.rb +470 -0
  82. data/lib/com/wiris/util/xml/SerializableImpl.rb +16 -15
  83. data/lib/com/wiris/util/xml/WCharacterBase.rb +968 -627
  84. data/lib/com/wiris/util/xml/WEntities.rb +11 -9
  85. data/lib/com/wiris/util/xml/WXmlUtils.rb +660 -490
  86. data/lib/com/wiris/util/xml/XmlSerializer.rb +517 -471
  87. data/lib/com/wiris/util/xml/XmlWriter.rb +260 -262
  88. data/lib/loader.rb +15 -12
  89. data/lib/src-generic/Array.rb +22 -22
  90. data/lib/src-generic/ArrayInt.rb +31 -31
  91. data/lib/src-generic/Base64.rb +14 -14
  92. data/lib/src-generic/BaseCode.rb +93 -93
  93. data/lib/src-generic/Boolean.rb +27 -0
  94. data/lib/src-generic/Bytes.rb +50 -50
  95. data/lib/src-generic/BytesInput.rb +37 -37
  96. data/lib/src-generic/EReg.rb +55 -55
  97. data/lib/src-generic/File.rb +35 -35
  98. data/lib/src-generic/FileLock.rb +26 -26
  99. data/lib/src-generic/FileSystem.rb +37 -37
  100. data/lib/src-generic/Hash.rb +42 -42
  101. data/lib/src-generic/Http.rb +111 -107
  102. data/lib/src-generic/HttpRequest.rb +25 -25
  103. data/lib/src-generic/HttpResponse.rb +70 -70
  104. data/lib/src-generic/Iterator.rb +20 -19
  105. data/lib/src-generic/Math.rb +14 -14
  106. data/lib/src-generic/Md5.rb +8 -8
  107. data/lib/src-generic/Md5Tools.rb +11 -11
  108. data/lib/src-generic/PropertiesTools.rb +32 -32
  109. data/lib/src-generic/Reflect.rb +16 -16
  110. data/lib/src-generic/RubyConfigurationUpdater.rb +49 -45
  111. data/lib/src-generic/Serializer.rb +84 -84
  112. data/lib/src-generic/Std.rb +74 -74
  113. data/lib/src-generic/Storage.rb +152 -152
  114. data/lib/src-generic/StringBuf.rb +40 -40
  115. data/lib/src-generic/StringTools.rb +44 -46
  116. data/lib/src-generic/Timer.rb +6 -6
  117. data/lib/src-generic/Type.rb +18 -18
  118. data/lib/src-generic/TypeTools.rb +31 -31
  119. data/lib/src-generic/Unserializer.rb +72 -72
  120. data/lib/src-generic/Utf8.rb +26 -26
  121. data/lib/src-generic/Xml.rb +199 -198
  122. data/lib/src-generic/extended/Integer.rb +5 -5
  123. data/lib/src-generic/extended/Math.rb +6 -6
  124. data/lib/src-generic/extended/Properties.rb +11 -11
  125. data/lib/src-generic/extended/String.rb +38 -38
  126. data/lib/src-generic/settings/PlatformSettings.rb +18 -18
  127. data/lib/src-generic/system/HttpProxy.rb +23 -0
  128. data/lib/src-generic/system/HttpProxyAuth.rb +10 -0
  129. data/lib/wirispluginengine.rb +5 -5
  130. data/lib/wirispluginengine/engine.rb +5 -5
  131. data/lib/wirispluginengine/integration/cleancache.rb +8 -8
  132. data/lib/wirispluginengine/integration/configurationjs.rb +8 -15
  133. data/lib/wirispluginengine/integration/configurationjson.rb +6 -6
  134. data/lib/wirispluginengine/integration/createimage.rb +7 -7
  135. data/lib/wirispluginengine/integration/getmathml.rb +18 -18
  136. data/lib/wirispluginengine/integration/resource.rb +8 -8
  137. data/lib/wirispluginengine/integration/service.rb +5 -5
  138. data/lib/wirispluginengine/integration/showimage.rb +28 -21
  139. data/lib/wirispluginengine/integration/test.rb +5 -5
  140. data/lib/wirispluginengine/integration/testfilter.rb +10 -0
  141. data/lib/wirispluginengine/version.rb +2 -2
  142. data/resources/VERSION +1 -1
  143. data/resources/WEB-INF/web.xml +25 -0
  144. data/resources/WIRISplugins.js +3809 -0
  145. data/resources/default-configuration.ini +47 -45
  146. data/resources/tech.txt +1 -1
  147. data/resources/wirisplugin.css +43 -42
  148. metadata +40 -4
  149. data/configuration.ini.dist +0 -104
@@ -1,7 +1,7 @@
1
- module Wiris
2
- class Timer
3
- def self.stamp()
4
- return Time.now.to_f
5
- end
6
- end
1
+ module Wiris
2
+ class Timer
3
+ def self.stamp()
4
+ return Time.now.to_f
5
+ end
6
+ end
7
7
  end
@@ -1,19 +1,19 @@
1
- module Wiris
2
- class Type
3
- def self.resolveClass(name)
4
- name = name.to_s
5
- name = name.split(".").last
6
- return Object.const_get("Wiris::" + name)
7
- rescue Exception => exc
8
- return nil
9
- end
10
-
11
- def self.getClass(o)
12
- return o.class.name
13
- end
14
-
15
- def self.createInstance(cls, args)
16
- return cls.new()
17
- end
18
- end
1
+ module Wiris
2
+ class Type
3
+ def self.resolveClass(name)
4
+ name = name.to_s
5
+ name = name.split(".").last
6
+ return Object.const_get("Wiris::" + name)
7
+ rescue Exception => exc
8
+ return nil
9
+ end
10
+
11
+ def self.getClass(o)
12
+ return o.class.name
13
+ end
14
+
15
+ def self.createInstance(cls, args)
16
+ return cls.new()
17
+ end
18
+ end
19
19
  end
@@ -1,32 +1,32 @@
1
- module Wiris
2
- class TypeTools
3
-
4
- def self.floatToString(float)
5
- return float.to_s
6
- end
7
-
8
- def self.isFloating(str)
9
- Float(str) rescue false
10
- end
11
-
12
- def self.isInteger(str)
13
- Integer(str) rescue false
14
- end
15
-
16
- def self.isIdentifierPart(int)
17
- return (int.chr.match(/^[[:alpha:]]$/) ? true : false) || (int.chr.match(/^[[:digit:]]$/) ? true : false) || int.chr == '_'
18
- end
19
-
20
- def self.isIdentifierStart(int)
21
- return (int.chr.match(/^[[:alpha:]]$/) ? true : false) || int.chr == '_'
22
- end
23
-
24
- def self.isArray(o)
25
- return o.instance_of? Array
26
- end
27
-
28
- def self.isHash(o)
29
- return o.instance_of? Hash
30
- end
31
- end
1
+ module Wiris
2
+ class TypeTools
3
+
4
+ def self.floatToString(float)
5
+ return float.to_s
6
+ end
7
+
8
+ def self.isFloating(str)
9
+ Float(str) rescue false
10
+ end
11
+
12
+ def self.isInteger(str)
13
+ Integer(str) rescue false
14
+ end
15
+
16
+ def self.isIdentifierPart(int)
17
+ return (int.chr.match(/^[[:alpha:]]$/) ? true : false) || (int.chr.match(/^[[:digit:]]$/) ? true : false) || int.chr == '_'
18
+ end
19
+
20
+ def self.isIdentifierStart(int)
21
+ return (int.chr.match(/^[[:alpha:]]$/) ? true : false) || int.chr == '_'
22
+ end
23
+
24
+ def self.isArray(o)
25
+ return o.instance_of? Array
26
+ end
27
+
28
+ def self.isHash(o)
29
+ return o.instance_of? Hash
30
+ end
31
+ end
32
32
  end
@@ -1,73 +1,73 @@
1
- module Wiris
2
- class Unserializer
3
- def buf
4
- @buf
5
- end
6
-
7
- def pos
8
- @pos
9
- end
10
-
11
- def initialize(s)
12
- @buf = s
13
- @pos = 0
14
- end
15
-
16
- def self.run(s)
17
- return Unserializer.new(s).unserialize()
18
- end
19
-
20
- def unserialize()
21
- c = Std.charCodeAt(buf, @pos)
22
- @pos += 1
23
- case c
24
- when 0x61 # 'a' for Array
25
- a = Array.new()
26
- while(true)
27
- t = Std.charCodeAt(buf, @pos)
28
- if (t == 0x68) # 'h'
29
- @pos += 1
30
- break
31
- end
32
- if (t == 0x75) # 'u'
33
- @pos += 1
34
- n = readDigits()
35
- a._(a.length()-(n-1), nil)
36
- else
37
- a.push(unserialize())
38
- end
39
- end
40
- return a
41
- when 0x69 # 'i' for integer
42
- return readDigits()
43
- when 0x7a # 'z'
44
- return 0
45
- when 0x6e #n
46
- return nil
47
- else
48
- raise Exception,'Object class not implemented: " ' + Std.fromCharCode(c) + "."
49
- end
50
- end
51
-
52
- def readDigits()
53
- n = 0
54
- c = Std.charCodeAt(buf,@pos)
55
- minus = false
56
- if c == 0x2d # '-'
57
- minus = true
58
- @pos += 1
59
- c = Std.charCodeAt(buf,@pos)
60
- end
61
- while (c>=0x30 && c<=0x39)
62
- n = n*10 + (c-0x30)
63
- @pos += 1
64
- if (@pos >= buf.length())
65
- break
66
- end
67
- c= Std.charCodeAt(buf,@pos)
68
- end
69
- ret = (minus ? -n : n)
70
- return ret
71
- end
72
- end
1
+ module Wiris
2
+ class Unserializer
3
+ def buf
4
+ @buf
5
+ end
6
+
7
+ def pos
8
+ @pos
9
+ end
10
+
11
+ def initialize(s)
12
+ @buf = s
13
+ @pos = 0
14
+ end
15
+
16
+ def self.run(s)
17
+ return Unserializer.new(s).unserialize()
18
+ end
19
+
20
+ def unserialize()
21
+ c = Std.charCodeAt(buf, @pos)
22
+ @pos += 1
23
+ case c
24
+ when 0x61 # 'a' for Array
25
+ a = Array.new()
26
+ while(true)
27
+ t = Std.charCodeAt(buf, @pos)
28
+ if (t == 0x68) # 'h'
29
+ @pos += 1
30
+ break
31
+ end
32
+ if (t == 0x75) # 'u'
33
+ @pos += 1
34
+ n = readDigits()
35
+ a._(a.length()-(n-1), nil)
36
+ else
37
+ a.push(unserialize())
38
+ end
39
+ end
40
+ return a
41
+ when 0x69 # 'i' for integer
42
+ return readDigits()
43
+ when 0x7a # 'z'
44
+ return 0
45
+ when 0x6e #n
46
+ return nil
47
+ else
48
+ raise Exception,'Object class not implemented: " ' + Std.fromCharCode(c) + "."
49
+ end
50
+ end
51
+
52
+ def readDigits()
53
+ n = 0
54
+ c = Std.charCodeAt(buf,@pos)
55
+ minus = false
56
+ if c == 0x2d # '-'
57
+ minus = true
58
+ @pos += 1
59
+ c = Std.charCodeAt(buf,@pos)
60
+ end
61
+ while (c>=0x30 && c<=0x39)
62
+ n = n*10 + (c-0x30)
63
+ @pos += 1
64
+ if (@pos >= buf.length())
65
+ break
66
+ end
67
+ c= Std.charCodeAt(buf,@pos)
68
+ end
69
+ ret = (minus ? -n : n)
70
+ return ret
71
+ end
72
+ end
73
73
  end
@@ -1,27 +1,27 @@
1
- module Wiris
2
- class Utf8
3
- def self.toBytes(str)
4
- return str.force_encoding("UTF-8").bytes.to_a
5
- end
6
-
7
- def self.fromBytes(bytes)
8
- return bytes.pack("C*")
9
- end
10
-
11
- def self.charCodeAt(s, index)
12
- return s.codepoints.to_a[index]
13
- end
14
-
15
- def self.uchr(code)
16
- return code.chr(Encoding::UTF_8)
17
- end
18
-
19
- def self.getLength(s)
20
- return s.length
21
- end
22
-
23
- def self.charAt(s, i)
24
- return s[i]
25
- end
26
- end
1
+ module Wiris
2
+ class Utf8
3
+ def self.toBytes(str)
4
+ return str.force_encoding("UTF-8").bytes.to_a
5
+ end
6
+
7
+ def self.fromBytes(bytes)
8
+ return bytes.pack("C*")
9
+ end
10
+
11
+ def self.charCodeAt(s, index)
12
+ return s.codepoints.to_a[index]
13
+ end
14
+
15
+ def self.uchr(code)
16
+ return code.chr(Encoding::UTF_8)
17
+ end
18
+
19
+ def self.getLength(s)
20
+ return s.length
21
+ end
22
+
23
+ def self.charAt(s, i)
24
+ return s[i]
25
+ end
26
+ end
27
27
  end
@@ -1,199 +1,200 @@
1
- require "rexml/document"
2
- module Wiris
3
- class Xml
4
- include REXML
5
- include Comparable
6
- @node
7
- @nodeName
8
- @nodeType
9
- Element = :element
10
- PCData = :text
11
- CData = :text
12
-
13
- def node=(node)
14
- @node=node
15
- end
16
- def node
17
- @node
18
- end
19
-
20
- def nodeName=(nodeName)
21
- @nodeName=nodeName
22
- end
23
- def nodeName
24
- @nodeName
25
- end
26
-
27
- def nodeType=(nodeType)
28
- @nodeType=nodeType
29
- end
30
- def nodeType
31
- @nodeType
32
- end
33
-
34
- def initialize(node)
35
- @node =node
36
- @nodeType = node.node_type
37
- if node.class == REXML::CData
38
- @nodeType = :text
39
- end
40
- if (@nodeType == :text)
41
- @nodeName = :text
42
- elsif (@nodeType == :text)
43
- @nodeName = :text
44
- else
45
- @nodeName = node.name
46
- end
47
-
48
- end
49
- def self.parse(xml)
50
- return Xml.new REXML::Document.new xml
51
- end
52
-
53
- def iterator()
54
- return XmlIterator.new(@node.each)
55
- end
56
-
57
- def elements()
58
- childElements = Array.new
59
- node = nil
60
- if (self.firstChild() != nil)
61
- node = self.firstChild().node
62
- end
63
-
64
- while (!node.nil?)
65
- if (node.node_type == :element)
66
- childElements.push(node)
67
- end
68
- node = node.next_sibling
69
- end
70
- # return XmlIterator.new(childElements.each)
71
- return XmlIterator.new childElements.each
72
- end
73
-
74
- def attributes()
75
- atts = Array.new;
76
- if @node.attributes.nil?
77
- return Iterator.new
78
- end
79
-
80
- @node.attributes.each_attribute { |attr|
81
- atts.push(attr.expanded_name)
82
- }
83
-
84
- return Iterator.new atts.each
85
- end
86
-
87
- def get(attributeName)
88
- return @node.attributes[attributeName]
89
- end
90
-
91
- def remove(attributeName)
92
- if !@node.attributes[attributeName].nil?
93
- @node.attributes.delete attributeName
94
- end
95
- end
96
-
97
- def set(attributeName, attributeValue)
98
- newAtrribute = REXML::Attribute.new(attributeName, attributeValue);
99
- @node.attributes.add(newAtrribute)
100
- end
101
-
102
- def parent_()
103
- if @node.parent.nil?
104
- return nil
105
- end
106
- return Xml.new @node.parent
107
- end
108
-
109
- def firstChild()
110
- if defined?(@node.each_child).nil? || @node.each_child.count == 0
111
- return nil
112
- end
113
-
114
- return Xml.new @node.each_child.next
115
- end
116
-
117
- def firstElement()
118
- @node.each_recursive {|e|
119
- if e.class == REXML::Element
120
- return Xml.new e
121
- end
122
- }
123
- return nil
124
- end
125
-
126
- def addChild(x)
127
- @node << x.node
128
- end
129
-
130
- def insertChild(x, pos)
131
- if pos < 0
132
- end
133
- # On ruby first index starts at 1.
134
- # Check if node has childs, if not insert node directly.
135
- if @node.elements[1].nil?
136
- xmlparsed.firstChild.addChild(x)
137
- else
138
- @node.insert_before(@node.elements[1], x.node)
139
- end
140
- end
141
- def removeChild(x)
142
- remove = @node == x.node.parent
143
- if remove
144
- x.node.remove
145
- end
146
- end
147
-
148
- def self.createDocument()
149
- return Xml.new REXML::Document.new
150
- end
151
-
152
- def createElement_(name)
153
- elementNode = REXML::Element.new name
154
- return Xml.new elementNode
155
- end
156
-
157
- def createPCData_(text)
158
- textNode = Text.new text
159
- return Xml.new textNode
160
- end
161
-
162
- def getNodeValue_()
163
- if (@node.node_type == :text || @node.node_type == :node)
164
- return @node.value
165
- else
166
- return @node.text
167
- end
168
- end
169
-
170
- def createCData_(text)
171
- elem = REXML::CData.new(text)
172
- return Xml.new elem
173
- end
174
-
175
- def toString()
176
- return @node.to_s
177
- end
178
- end
179
-
180
-
181
- class XmlIterator < Enumerator
182
- def initialize(enum)
183
- super(enum)
184
- end
185
- alias enumeratornext next
186
- def next
187
- Xml.new self.enumeratornext
188
- end
189
-
190
- def hasNext()
191
- begin
192
- self.peek
193
- return true
194
- rescue StopIteration
195
- return false
196
- end
197
- end
198
- end
1
+ require "rexml/document"
2
+ module Wiris
3
+ class Xml
4
+ include REXML
5
+ include Comparable
6
+ @node
7
+ @nodeName
8
+ @nodeType
9
+ Element = :element
10
+ PCData = :text
11
+ CData = :text
12
+
13
+ def node=(node)
14
+ @node=node
15
+ end
16
+ def node
17
+ @node
18
+ end
19
+
20
+ def nodeName=(nodeName)
21
+ @nodeName=nodeName
22
+ end
23
+ def nodeName
24
+ @nodeName
25
+ end
26
+
27
+ def nodeType=(nodeType)
28
+ @nodeType=nodeType
29
+ end
30
+ def nodeType
31
+ @nodeType
32
+ end
33
+
34
+ def initialize(node)
35
+ @node =node
36
+ @nodeType = node.node_type
37
+ if node.class == REXML::CData
38
+ @nodeType = :text
39
+ end
40
+ if (@nodeType == :text)
41
+ @nodeName = :text
42
+ elsif (@nodeType == :text)
43
+ @nodeName = :text
44
+ else
45
+ @nodeName = node.name
46
+ end
47
+
48
+ end
49
+ def self.parse(xml)
50
+ return Xml.new REXML::Document.new xml
51
+ end
52
+
53
+ def iterator()
54
+ return XmlIterator.new(@node.each)
55
+ end
56
+
57
+ def elements()
58
+ childElements = Array.new
59
+ node = nil
60
+ if (self.firstChild() != nil)
61
+ node = self.firstChild().node
62
+ end
63
+
64
+ while (!node.nil?)
65
+ if (node.node_type == :element)
66
+ childElements.push(node)
67
+ end
68
+ node = node.next_sibling
69
+ end
70
+ # return XmlIterator.new(childElements.each)
71
+ return XmlIterator.new childElements.each
72
+ end
73
+
74
+ def attributes()
75
+ atts = Array.new;
76
+ if @node.attributes.nil?
77
+ return Iterator.new
78
+ end
79
+
80
+ @node.attributes.each_attribute { |attr|
81
+ atts.push(attr.expanded_name)
82
+ }
83
+
84
+ return Iterator.new atts.each
85
+ end
86
+
87
+ def get(attributeName)
88
+ return @node.attributes[attributeName]
89
+ end
90
+
91
+ def remove(attributeName)
92
+ if !@node.attributes[attributeName].nil?
93
+ @node.attributes.delete attributeName
94
+ end
95
+ end
96
+
97
+ def set(attributeName, attributeValue)
98
+ newAtrribute = REXML::Attribute.new(attributeName, attributeValue);
99
+ @node.attributes.add(newAtrribute)
100
+ end
101
+
102
+ def parent_()
103
+ if @node.parent.nil?
104
+ return nil
105
+ end
106
+ return Xml.new @node.parent
107
+ end
108
+
109
+ def firstChild()
110
+ if defined?(@node.each_child).nil? || @node.each_child.count == 0
111
+ return nil
112
+ end
113
+
114
+ return Xml.new @node.each_child.next
115
+ end
116
+
117
+ def firstElement()
118
+ @node.each_recursive {|e|
119
+ if e.class == REXML::Element
120
+ return Xml.new e
121
+ end
122
+ }
123
+ return nil
124
+ end
125
+
126
+ def addChild(x)
127
+ @node << x.node
128
+ end
129
+
130
+ def insertChild(x, pos)
131
+ if pos < 0
132
+ end
133
+ # On ruby first index starts at 1.
134
+ # Check if node has childs, if not insert node directly.
135
+ if @node.elements[1].nil?
136
+ xmlparsed.firstChild.addChild(x)
137
+ else
138
+ @node.insert_before(@node.elements[1], x.node)
139
+ end
140
+ end
141
+ def removeChild(x)
142
+ remove = @node == x.node.parent
143
+ if remove
144
+ x.node.remove
145
+ end
146
+ end
147
+
148
+ def self.createDocument()
149
+ return Xml.new REXML::Document.new
150
+ end
151
+
152
+ def createElement_(name)
153
+ elementNode = REXML::Element.new name
154
+ return Xml.new elementNode
155
+ end
156
+
157
+ def createPCData_(text)
158
+ textNode = Text.new text
159
+ return Xml.new textNode
160
+ end
161
+
162
+ def getNodeValue_()
163
+ if (@node.node_type == :text || @node.node_type == :node)
164
+ return @node.value
165
+ else
166
+ return @node.text
167
+ end
168
+ end
169
+
170
+ def createCData_(text)
171
+ elem = REXML::CData.new(text)
172
+ return Xml.new elem
173
+ end
174
+
175
+ def toString()
176
+ return @node.to_s
177
+ end
178
+ end
179
+
180
+
181
+ class XmlIterator < Enumerator
182
+ @enumeration
183
+ def initialize(enum)
184
+ @enumeration = enum.map
185
+ end
186
+
187
+ def next
188
+ Xml.new @enumeration.next
189
+ end
190
+
191
+ def hasNext()
192
+ begin
193
+ @enumeration.peek
194
+ return true
195
+ rescue StopIteration
196
+ return false
197
+ end
198
+ end
199
+ end
199
200
  end