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,55 +1,62 @@
1
1
  module WirisPlugin
2
2
  include Wiris
3
- class TextFilterTags
4
- include Wiris
3
+ class TextFilterTags
4
+ include Wiris
5
+
6
+ attr_accessor :in_mathopen
7
+ attr_accessor :in_mathclose
8
+ attr_accessor :in_double_quote
9
+ attr_accessor :out_double_quote
10
+ attr_accessor :in_open
11
+ attr_accessor :out_open
12
+ attr_accessor :in_close
13
+ attr_accessor :out_close
14
+ attr_accessor :in_entity
15
+ attr_accessor :out_entity
16
+ attr_accessor :in_quote
17
+ attr_accessor :out_quote
18
+ attr_accessor :in_appletopen
19
+ attr_accessor :in_appletclose
20
+ attr_accessor :mathTag
21
+ def initialize()
22
+ super()
23
+ end
24
+ def self.newSafeXml()
25
+ tags = TextFilterTags.new()
26
+ tags::in_open = Std::fromCharCode(171)
27
+ tags::in_close = Std::fromCharCode(187)
28
+ tags::in_entity = Std::fromCharCode(167)
29
+ tags::in_quote = "`"
30
+ tags::in_double_quote = Std::fromCharCode(168)
31
+ tags::mathTag = "math"
32
+ tags::init(tags,nil)
33
+ return tags
34
+ end
35
+ def self.newXml(mathNamespace)
36
+ tags = TextFilterTags.new()
37
+ tags::in_open = "<"
38
+ tags::in_close = ">"
39
+ tags::in_entity = "&"
40
+ tags::in_quote = "\'"
41
+ tags::in_double_quote = "\""
42
+ tags::mathTag = "math"
43
+ tags::init(tags,mathNamespace)
44
+ return tags
45
+ end
46
+ def init(tags, mathNamespace)
47
+ if mathNamespace != nil
48
+ tags::mathTag = (mathNamespace + ":") + tags::mathTag
49
+ end
50
+ tags::in_appletopen = @in_open + "APPLET"
51
+ tags::in_appletclose = (@in_open + "/APPLET") + @in_close
52
+ tags::in_mathopen = @in_open + @mathTag
53
+ tags::in_mathclose = ((@in_open + "/") + @mathTag) + @in_close
54
+ tags::out_open = "<"
55
+ tags::out_close = ">"
56
+ tags::out_entity = "&"
57
+ tags::out_quote = "\'"
58
+ tags::out_double_quote = "\""
59
+ end
5
60
 
6
- attr_accessor :in_mathopen
7
- attr_accessor :in_mathclose
8
- attr_accessor :in_double_quote
9
- attr_accessor :out_double_quote
10
- attr_accessor :in_open
11
- attr_accessor :out_open
12
- attr_accessor :in_close
13
- attr_accessor :out_close
14
- attr_accessor :in_entity
15
- attr_accessor :out_entity
16
- attr_accessor :in_quote
17
- attr_accessor :out_quote
18
- attr_accessor :in_appletopen
19
- attr_accessor :in_appletclose
20
- def initialize()
21
- super()
22
- end
23
- def self.newSafeXml()
24
- tags = TextFilterTags.new()
25
- tags::in_open = Std::fromCharCode(171)
26
- tags::in_close = Std::fromCharCode(187)
27
- tags::in_entity = Std::fromCharCode(167)
28
- tags::in_quote = "`"
29
- tags::in_double_quote = Std::fromCharCode(168)
30
- tags::init(tags)
31
- return tags
32
- end
33
- def self.newXml()
34
- tags = TextFilterTags.new()
35
- tags::in_open = "<"
36
- tags::in_close = ">"
37
- tags::in_entity = "&"
38
- tags::in_quote = "\'"
39
- tags::in_double_quote = "\""
40
- tags::init(tags)
41
- return tags
42
- end
43
- def init(tags)
44
- tags::in_appletopen = @in_open+"APPLET"
45
- tags::in_appletclose = (@in_open+"/APPLET")+@in_close
46
- tags::in_mathopen = @in_open+"math"
47
- tags::in_mathclose = (@in_open+"/math")+@in_close
48
- tags::out_open = "<"
49
- tags::out_close = ">"
50
- tags::out_entity = "&"
51
- tags::out_quote = "\'"
52
- tags::out_double_quote = "\""
53
61
  end
54
- end
55
62
  end
@@ -1,118 +1,169 @@
1
1
  module WirisPlugin
2
2
  include Wiris
3
- require('com/wiris/plugin/impl/TextFilter.rb')
4
- require('com/wiris/plugin/impl/HttpImpl.rb')
5
- require('com/wiris/util/sys/IniFile.rb')
6
- require('com/wiris/plugin/api/TextService.rb')
7
- class TextServiceImpl
8
- extend TextServiceInterface
3
+ require('com/wiris/util/json/JsonAPIResponse.rb')
4
+ require('com/wiris/plugin/impl/HttpImpl.rb')
5
+ require('com/wiris/plugin/impl/HttpListener.rb')
6
+ require('com/wiris/util/sys/IniFile.rb')
7
+ require('com/wiris/plugin/api/TextService.rb')
8
+ require('com/wiris/plugin/impl/TextFilter.rb')
9
+ require('com/wiris/util/json/JSon.rb')
10
+ class TextServiceImpl
11
+ extend TextServiceInterface
9
12
 
10
- include Wiris
13
+ extend HttpListenerInterface
11
14
 
12
- attr_accessor :plugin
13
- def initialize(plugin)
14
- super()
15
- @plugin = plugin
16
- end
17
- def service(serviceName,provider)
18
- digest = nil
19
- renderParams = provider::getRenderParameters(@plugin::getConfiguration())
20
- if self.class.hasCache(serviceName)
21
- digest = @plugin::newRender()::computeDigest(nil,renderParams)
22
- store = @plugin::getStorageAndCache()
23
- ext = self.class.getDigestExtension(serviceName,provider)
24
- s = store::retreiveData(digest,ext)
25
- if s!=nil
26
- return Utf8::fromBytes(s)
15
+ include Wiris
16
+
17
+ attr_accessor :plugin
18
+ attr_accessor :serviceName
19
+ attr_accessor :status
20
+ attr_accessor :error
21
+ attr_accessor :data
22
+ def initialize(plugin)
23
+ super()
24
+ self.plugin = plugin
27
25
  end
28
- end
29
- url = @plugin::getImageServiceURL(serviceName,self.class.hasStats(serviceName))
30
- h = HttpImpl.new(url,nil)
31
- @plugin::addReferer(h)
32
- @plugin::addProxy(h)
33
- ha = PropertiesTools::fromProperties(provider::getServiceParameters())
34
- iter = ha::keys()
35
- while iter::hasNext()
36
- k = iter::next()
37
- h::setParameter(k,ha::get(k))
38
- end
39
- h::request(true)
40
- r = h::getData()
41
- if digest!=nil
42
- store = @plugin::getStorageAndCache()
43
- ext = self.class.getDigestExtension(serviceName,provider)
44
- store::storeData(digest,ext,Utf8::toBytes(r))
45
- end
46
- return r
47
- end
48
- def mathml2accessible(mml,lang,param)
49
- if lang!=nil
50
- PropertiesTools::setProperty(param,"lang",lang)
51
- end
52
- PropertiesTools::setProperty(param,"mml",mml)
53
- provider = @plugin::newGenericParamsProvider(param)
54
- return service("mathml2accessible",provider)
55
- end
56
- def mathml2latex(mml)
57
- param = PropertiesTools::newProperties()
58
- PropertiesTools::setProperty(param,"mml",mml)
59
- provider = @plugin::newGenericParamsProvider(param)
60
- return service("mathml2latex",provider)
61
- end
62
- def latex2mathml(latex)
63
- param = PropertiesTools::newProperties()
64
- PropertiesTools::setProperty(param,"latex",latex)
65
- provider = @plugin::newGenericParamsProvider(param)
66
- return service("latex2mathml",provider)
67
- end
68
- def getMathML(digest,latex)
69
- if digest!=nil
70
- content = @plugin::getStorageAndCache()::decodeDigest(digest)
71
- if content!=nil
72
- if StringTools::startsWith(content,"<")
73
- breakline = content::indexOf("\n",0)
74
- return Std::substr(content,0,breakline)
75
- else
76
- iniFile = IniFile::newIniFileFromString(content)
77
- mathml = iniFile::getProperties()::get("mml")
78
- if mathml!=nil
79
- return mathml
26
+ def service(serviceName, provider)
27
+ self.serviceName = serviceName
28
+ digest = nil
29
+ renderParams = provider::getRenderParameters(@plugin::getConfiguration())
30
+ if TextServiceImpl.hasCache(serviceName)
31
+ digest = @plugin::newRender()::computeDigest(nil,renderParams)
32
+ store = @plugin::getStorageAndCache()
33
+ ext = TextServiceImpl.getDigestExtension(serviceName,provider)
34
+ s = store::retreiveData(digest,ext)
35
+ if s != nil
36
+ cachedServiceText = Utf8::fromBytes(s)
37
+ begin
38
+ JSon::decode(cachedServiceText)
39
+ end
40
+ return cachedServiceText
41
+ end
42
+ end
43
+ return jsonResponse(serviceName,provider)::getResponse()
44
+ end
45
+ def jsonResponse(serviceName, provider)
46
+ renderParams = provider::getRenderParameters(@plugin::getConfiguration())
47
+ digest = @plugin::newRender()::computeDigest(nil,renderParams)
48
+ self.serviceName = serviceName
49
+ url = @plugin::getImageServiceURL(serviceName,TextServiceImpl.hasStats(serviceName))
50
+ h = HttpImpl.new(url,self)
51
+ @plugin::addReferer(h)
52
+ @plugin::addProxy(h)
53
+ ha = PropertiesTools::fromProperties(provider::getServiceParameters())
54
+ iter = ha::keys()
55
+ while iter::hasNext()
56
+ k = iter::next()
57
+ h::setParameter(k,ha::get(k))
58
+ end
59
+ h::setParameter("httpstatus","true")
60
+ begin
61
+ h::request(true)
62
+ end
63
+ r = self.data != nil ? self.data : h::getData()
64
+ response = JsonAPIResponse.new()
65
+ if self.status == JsonAPIResponse::STATUS_ERROR
66
+ response::setStatus(JsonAPIResponse::STATUS_ERROR)
67
+ response::addError(self.error)
80
68
  else
81
- return "Error: mathml not found."
69
+ response::setStatus(JsonAPIResponse::STATUS_OK)
70
+ response::addResult("text",r)
71
+ end
72
+ if digest != nil
73
+ store = @plugin::getStorageAndCache()
74
+ ext = TextServiceImpl.getDigestExtension(serviceName,provider)
75
+ store::storeData(digest,ext,Utf8::toBytes(response::getResponse()))
82
76
  end
83
- end
84
- else
85
- return "Error: formula not found."
77
+ return response
86
78
  end
87
- else
88
- if latex!=nil
89
- return latex2mathml(latex)
90
- else
91
- return "Error: no digest or latex has been sent."
79
+ def mathml2accessible(mml, lang, param)
80
+ if lang != nil
81
+ PropertiesTools::setProperty(param,"lang",lang)
82
+ end
83
+ PropertiesTools::setProperty(param,"mml",mml)
84
+ provider = @plugin::newGenericParamsProvider(param)
85
+ reponse = jsonResponse("mathml2accessible",provider)
86
+ if reponse::getStatus() == JsonAPIResponse::STATUS_OK
87
+ result = reponse::getResult()
88
+ return (result::get("text"))
89
+ else
90
+ return "Error converting from mathml to text"
91
+ end
92
92
  end
93
- end
94
- end
95
- def self.hasCache(serviceName)
96
- if (serviceName=="mathml2accessible")
97
- return true
98
- end
99
- return false
100
- end
101
- def self.hasStats(serviceName)
102
- if (serviceName=="latex2mathml")
103
- return true
104
- end
105
- return false
106
- end
107
- def self.getDigestExtension(serviceName,provider)
108
- lang = provider::getParameter("lang","en")
109
- if (lang!=nil)&&(lang::length()==0)
110
- return "en"
111
- end
112
- return lang
113
- end
114
- def filter(str,prop)
115
- return TextFilter.new(@plugin)::filter(str,prop)
93
+ def mathml2latex(mml)
94
+ param = PropertiesTools::newProperties()
95
+ PropertiesTools::setProperty(param,"mml",mml)
96
+ provider = @plugin::newGenericParamsProvider(param)
97
+ return service("mathml2latex",provider)
98
+ end
99
+ def latex2mathml(latex)
100
+ param = PropertiesTools::newProperties()
101
+ PropertiesTools::setProperty(param,"latex",latex)
102
+ provider = @plugin::newGenericParamsProvider(param)
103
+ mathml = service("latex2mathml",provider)
104
+ return mathml::indexOf("Error converting") != -1 ? mathml : latex
105
+ end
106
+ def getMathML(digest, latex)
107
+ if digest != nil
108
+ content = @plugin::getStorageAndCache()::decodeDigest(digest)
109
+ if content != nil
110
+ if StringTools::startsWith(content,"<")
111
+ breakline = content::indexOf("\n",0)
112
+ return Std::substr(content,0,breakline)
113
+ else
114
+ iniFile = IniFile::newIniFileFromString(content)
115
+ mathml = iniFile::getProperties()::get("mml")
116
+ if mathml != nil
117
+ return mathml
118
+ else
119
+ return "Error: mathml not found."
120
+ end
121
+ end
122
+ else
123
+ return "Error: formula not found."
124
+ end
125
+ else
126
+ if latex != nil
127
+ return latex2mathml(latex)
128
+ else
129
+ return "Error: no digest or latex has been sent."
130
+ end
131
+ end
132
+ end
133
+ def self.hasCache(serviceName)
134
+ if (serviceName == "mathml2accessible")
135
+ return true
136
+ end
137
+ return false
138
+ end
139
+ def self.hasStats(serviceName)
140
+ if (serviceName == "latex2mathml")
141
+ return true
142
+ end
143
+ return false
144
+ end
145
+ def self.getDigestExtension(serviceName, provider)
146
+ lang = provider::getParameter("lang","en")
147
+ if (lang != nil) && (lang::length() == 0)
148
+ return "en"
149
+ end
150
+ return lang
151
+ end
152
+ def filter(str, prop)
153
+ return TextFilter.new(@plugin)::filter(str,prop)
154
+ end
155
+ def onData(msg)
156
+ self.status = JsonAPIResponse::STATUS_OK
157
+ end
158
+ def onError(msg)
159
+ if self.serviceName == "mathml2accessible"
160
+ self.status = JsonAPIResponse::STATUS_WARNING
161
+ self.data = "Error converting from MathML to accessible text."
162
+ else
163
+ self.error = msg
164
+ self.status = JsonAPIResponse::STATUS_ERROR
165
+ end
166
+ end
167
+
116
168
  end
117
- end
118
169
  end
@@ -1,8 +1,8 @@
1
1
  module WirisPlugin
2
2
  include Wiris
3
- module StorageAndCacheInterface
4
- def StorageAndCache
5
- return true
6
- end
7
- end
3
+ module StorageAndCacheInterface
4
+ def StorageAndCache
5
+ return true
6
+ end
7
+ end
8
8
  end
@@ -1,536 +1,548 @@
1
1
  module WirisPlugin
2
2
  include Wiris
3
- require('com/wiris/util/json/StringParser.rb')
4
- require('com/wiris/util/json/JSonIntegerFormat.rb')
5
- require('com/wiris/common/WInteger.rb')
6
- require('com/wiris/util/xml/WCharacterBase.rb')
7
- require('com/wiris/util/json/StringParser.rb')
8
- class JSon < StringParser
9
- include Wiris
3
+ require('com/wiris/util/json/StringParser.rb')
4
+ require('com/wiris/util/xml/WCharacterBase.rb')
5
+ require('com/wiris/util/json/JSonIntegerFormat.rb')
6
+ require('com/wiris/common/WInteger.rb')
7
+ require('com/wiris/util/json/StringParser.rb')
8
+ class JSon < StringParser
9
+ include Wiris
10
10
 
11
- def self.sb
12
- @@sb
13
- end
14
- def self.sb=(sb)
15
- @@sb = sb
16
- end
17
- attr_accessor :addNewLines
18
- attr_accessor :depth
19
- attr_accessor :lastDepth
20
- def initialize()
21
- super()
22
- end
23
- def self.encode(o)
24
- js = JSon.new()
25
- return js::encodeObject(o)
26
- end
27
- def encodeObject(o)
28
- sb = StringBuf.new()
29
- @depth = 0
30
- encodeImpl(sb,o)
31
- return sb::toString()
32
- end
33
- def encodeImpl(sb,o)
34
- if TypeTools::isHash(o)
35
- encodeHash(sb,(o))
36
- else
37
- if TypeTools::isArray(o)
38
- encodeArray(sb,(o))
39
- else
40
- if o.instance_of?String
41
- encodeString(sb,(o))
42
- else
43
- if o.instance_of?Integer
44
- encodeInteger(sb,(o))
11
+ def self.sb
12
+ @@sb
13
+ end
14
+ def self.sb=(sb)
15
+ @@sb = sb
16
+ end
17
+ attr_accessor :addNewLines
18
+ attr_accessor :depth
19
+ attr_accessor :lastDepth
20
+ def initialize()
21
+ super()
22
+ end
23
+ def self.encode(o)
24
+ js = JSon.new()
25
+ return js::encodeObject(o)
26
+ end
27
+ def encodeObject(o)
28
+ sb = StringBuf.new()
29
+ @depth = 0
30
+ encodeImpl(sb,o)
31
+ return sb::toString()
32
+ end
33
+ def encodeImpl(sb, o)
34
+ if TypeTools::isHash(o)
35
+ encodeHash(sb,(o))
45
36
  else
46
- if o.instance_of?Long
47
- encodeLong(sb,(o))
48
- else
49
- if o.instance_of?JSonIntegerFormat
50
- encodeIntegerFormat(sb,(o))
37
+ if TypeTools::isArray(o)
38
+ encodeArray(sb,(o))
51
39
  else
52
- if o.instance_of?Boolean
53
- encodeBoolean(sb,(o))
54
- else
55
- if o.instance_of?Double
56
- encodeFloat(sb,(o))
40
+ if o.instance_of?Array
41
+ encodeArrayInt(sb,(o))
57
42
  else
58
- raise Exception,"Impossible to convert to json object of type "+Type::getClass(o).to_s
43
+ if o.instance_of?Array
44
+ encodeArrayDouble(sb,(o))
45
+ else
46
+ if o.instance_of?Array
47
+ encodeArrayBoolean(sb,(o))
48
+ else
49
+ if o.instance_of?String
50
+ encodeString(sb,(o))
51
+ else
52
+ if o.instance_of?Integer
53
+ encodeInteger(sb,(o))
54
+ else
55
+ if o.instance_of?Bignum
56
+ encodeLong(sb,(o))
57
+ else
58
+ if o.instance_of?JSonIntegerFormat
59
+ encodeIntegerFormat(sb,(o))
60
+ else
61
+ if o.instance_of?Boolean
62
+ encodeBoolean(sb,(o))
63
+ else
64
+ if o.instance_of?Double
65
+ encodeFloat(sb,(o))
66
+ else
67
+ raise Exception,"Impossible to convert to json object of type " + Type::getClass(o).to_s
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
59
76
  end
60
- end
61
77
  end
62
- end
63
78
  end
64
- end
65
79
  end
66
- end
67
- end
68
- def encodeHash(sb,h)
69
- newLines = @addNewLines&&(self.class.getDepth(h)>2)
70
- @depth+=1
71
- myDepth = @lastDepth
72
- sb::add("{")
73
- if newLines
74
- newLine(@depth,sb)
75
- end
76
- e = h::keys()
77
- first = true
78
- while e::hasNext()
79
- if first
80
- first = false
81
- else
82
- sb::add(",")
83
- if newLines
84
- newLine(@depth,sb)
85
- end
86
- end
87
- key = e::next()
88
- encodeString(sb,key)
89
- sb::add(":")
90
- encodeImpl(sb,h::get(key))
91
- end
92
- if newLines
93
- newLine(myDepth,sb)
94
- end
95
- sb::add("}")
96
- @depth-=1
97
- end
98
- def encodeArray(sb,v)
99
- newLines = @addNewLines&&(self.class.getDepth(v)>2)
100
- @depth+=1
101
- myDepth = @lastDepth
102
- sb::add("[")
103
- if newLines
104
- newLine(@depth,sb)
105
- end
106
- for i in 0..v::length()-1
107
- o = v::_(i)
108
- if i>0
109
- sb::add(",")
80
+ def encodeHash(sb, h)
81
+ newLines = @addNewLines && (JSon.getDepth(h) > 2)
82
+ @depth+=1
83
+ myDepth = @lastDepth
84
+ sb::add("{")
110
85
  if newLines
111
- newLine(@depth,sb)
86
+ newLine(@depth,sb)
112
87
  end
113
- end
114
- encodeImpl(sb,o)
115
- i+=1
116
- end
117
- if newLines
118
- newLine(myDepth,sb)
119
- end
120
- sb::add("]")
121
- @depth-=1
122
- end
123
- def encodeString(sb,s)
124
- sb::add("\"")
125
- for i in 0..s::length()-1
126
- c = Std::charCodeAt(s,i)
127
- if c==34
128
- sb::add("\\\"")
129
- else
130
- if c==13
131
- sb::add("\\r")
132
- else
133
- if c==10
134
- sb::add("\\n")
135
- else
136
- if c==9
137
- sb::add("\\t")
88
+ e = h::keys()
89
+ first = true
90
+ while e::hasNext()
91
+ if first
92
+ first = false
138
93
  else
139
- if c==92
140
- sb::add("\\\\")
141
- else
142
- sb::add(s::charAt(i))
143
- end
94
+ sb::add(",")
95
+ if newLines
96
+ newLine(@depth,sb)
97
+ end
144
98
  end
145
- end
99
+ key = e::next()
100
+ encodeString(sb,key)
101
+ sb::add(":")
102
+ encodeImpl(sb,h::get(key))
103
+ end
104
+ if newLines
105
+ newLine(myDepth,sb)
146
106
  end
147
- end
148
- i+=1
107
+ sb::add("}")
108
+ @depth-=1
149
109
  end
150
- sb::add("\"")
151
- end
152
- def encodeInteger(sb,i)
153
- sb::add(""+i.to_s)
154
- end
155
- def encodeBoolean(sb,b)
156
- sb::add(b::booleanValue() ? "true" : "false")
157
- end
158
- def encodeFloat(sb,d)
159
- sb::add(TypeTools::floatToString(d))
160
- end
161
- def encodeLong(sb,i)
162
- sb::add(""+i.to_s)
163
- end
164
- def encodeIntegerFormat(sb,i)
165
- sb::add(i::toString())
166
- end
167
- def self.decode(str)
168
- json = JSon.new()
169
- return json::localDecodeString(str)
170
- end
171
- def localDecodeString(str)
172
- init(str)
173
- return localDecode()
174
- end
175
- def localDecode()
176
- skipBlanks()
177
- if c==123
178
- return decodeHash()
179
- else
180
- if c==91
181
- return decodeArray()
182
- else
183
- if c==34
184
- return decodeString()
185
- else
186
- if c==39
187
- return decodeString()
110
+ def encodeArray(sb, v)
111
+ newLines = @addNewLines && (JSon.getDepth(v) > 2)
112
+ @depth+=1
113
+ myDepth = @lastDepth
114
+ sb::add("[")
115
+ if newLines
116
+ newLine(@depth,sb)
117
+ end
118
+ for i in 0..v::length() - 1
119
+ o = v::_(i)
120
+ if i > 0
121
+ sb::add(",")
122
+ if newLines
123
+ newLine(@depth,sb)
124
+ end
125
+ end
126
+ encodeImpl(sb,o)
127
+ i+=1
128
+ end
129
+ if newLines
130
+ newLine(myDepth,sb)
131
+ end
132
+ sb::add("]")
133
+ @depth-=1
134
+ end
135
+ def encodeArrayInt(sb, v)
136
+ v2 = Array.new()
137
+ i = 0
138
+ while i < v::length
139
+ v2::push(v[i])
140
+ i+=1
141
+ end
142
+ self.encodeArray(sb,v2)
143
+ end
144
+ def encodeArrayDouble(sb, v)
145
+ v2 = Array.new()
146
+ i = 0
147
+ while i < v::length
148
+ v2::push(v[i])
149
+ i+=1
150
+ end
151
+ self.encodeArray(sb,v2)
152
+ end
153
+ def encodeArrayBoolean(sb, v)
154
+ v2 = Array.new()
155
+ i = 0
156
+ while i < v::length
157
+ v2::push(v[i])
158
+ i+=1
159
+ end
160
+ self.encodeArray(sb,v2)
161
+ end
162
+ def encodeString(sb, s)
163
+ s = StringTools::replace(s,"\\","\\\\")
164
+ s = StringTools::replace(s,"\"","\\\"")
165
+ s = StringTools::replace(s,"\r","\\r")
166
+ s = StringTools::replace(s,"\n","\\n")
167
+ s = StringTools::replace(s,"\t","\\t")
168
+ sb::add("\"")
169
+ sb::add(s)
170
+ sb::add("\"")
171
+ end
172
+ def encodeInteger(sb, i)
173
+ sb::add("" + i.to_s)
174
+ end
175
+ def encodeBoolean(sb, b)
176
+ sb::add(b::booleanValue() ? "true" : "false")
177
+ end
178
+ def encodeFloat(sb, d)
179
+ sb::add(TypeTools::floatToString(d))
180
+ end
181
+ def encodeLong(sb, i)
182
+ sb::add("" + i.to_s)
183
+ end
184
+ def encodeIntegerFormat(sb, i)
185
+ sb::add(i::toString())
186
+ end
187
+ def self.decode(str)
188
+ json = JSon.new()
189
+ return json::localDecodeString(str)
190
+ end
191
+ def localDecodeString(str)
192
+ init(str)
193
+ return localDecode()
194
+ end
195
+ def localDecode()
196
+ skipBlanks()
197
+ if c == 123
198
+ return decodeHash()
188
199
  else
189
- if (c==45)||((c>=48)&&(c<=58))
190
- return decodeNumber()
191
- else
192
- if ((c==116)||(c==102))||(c==110)
193
- return decodeBooleanOrNull()
200
+ if c == 91
201
+ return decodeArray()
194
202
  else
195
- raise Exception,"Unrecognized char "+c.to_s
203
+ if c == 34
204
+ return decodeString()
205
+ else
206
+ if c == 39
207
+ return decodeString()
208
+ else
209
+ if (c == 45) || ((c >= 48) && (c <= 58))
210
+ return decodeNumber()
211
+ else
212
+ if ((c == 116) || (c == 102)) || (c == 110)
213
+ return decodeBooleanOrNull()
214
+ else
215
+ raise Exception,"Unrecognized char " + c.to_s
216
+ end
217
+ end
218
+ end
219
+ end
196
220
  end
197
- end
198
221
  end
199
- end
200
222
  end
201
- end
202
- end
203
- def decodeBooleanOrNull()
204
- sb = StringBuf.new()
205
- while WCharacterBase::isLetter(c)
206
- sb::addChar(c)
207
- nextToken()
208
- end
209
- word = sb::toString()
210
- if (word=="true")
211
- return Boolean::TRUE
212
- else
213
- if (word=="false")
214
- return Boolean::FALSE
215
- else
216
- if (word=="null")
217
- return nil
218
- else
219
- raise Exception,("Unrecognized keyword \""+word)+"\"."
220
- end
221
- end
222
- end
223
- end
224
- def decodeString()
225
- sb = StringBuf.new()
226
- d = c
227
- nextToken()
228
- while c!=d
229
- if c==92
230
- nextToken()
231
- if c==110
232
- sb::add("\n")
233
- else
234
- if c==114
235
- sb::add("\r")
223
+ def decodeBooleanOrNull()
224
+ sb = StringBuf.new()
225
+ while WCharacterBase::isLetter(c)
226
+ sb::addChar(c)
227
+ nextToken()
228
+ end
229
+ word = sb::toString()
230
+ if (word == "true")
231
+ return Boolean::TRUE
236
232
  else
237
- if c==34
238
- sb::add("\"")
239
- else
240
- if c==39
241
- sb::add("\'")
233
+ if (word == "false")
234
+ return Boolean::FALSE
242
235
  else
243
- if c==116
244
- sb::add("\t")
245
- else
246
- if c==92
247
- sb::add("\\")
236
+ if (word == "null")
237
+ return nil
248
238
  else
249
- if c==117
250
- nextToken()
251
- code = Utf8::uchr(c)
252
- nextToken()
253
- code+=Utf8::uchr(c)
254
- nextToken()
255
- code+=Utf8::uchr(c)
256
- nextToken()
257
- code+=Utf8::uchr(c)
258
- dec = Std::parseInt("0x"+code)
259
- sb::add(Utf8::uchr(dec))
260
- else
261
- raise Exception,("Unknown scape sequence \'\\"+Utf8::uchr(c).to_s)+"\'"
262
- end
239
+ raise Exception,("Unrecognized keyword \"" + word) + "\"."
263
240
  end
264
- end
265
241
  end
266
- end
267
242
  end
268
- end
269
- else
270
- sb::add(Std::fromCharCode(c))
271
- end
272
- nextToken()
273
- end
274
- nextToken()
275
- return sb::toString()
276
- end
277
- def decodeNumber()
278
- sb = StringBuf.new()
279
- hex = false
280
- floating = false
281
- loop do
282
- sb::add(Std::fromCharCode(c))
283
- nextToken()
284
- if c==120
285
- hex = true
286
- sb::add(Std::fromCharCode(c))
287
- nextToken()
288
- end
289
- if ((c==46)||(c==69))||(c==101)
290
- floating = true
291
- end
292
- break if not (((c>=48)&&(c<=58))||(hex&&isHexDigit(c)))||(floating&&((((c==46)||(c==69))||(c==101))||(c==45)))
293
- end
294
- if floating
295
- return Std::parseFloat(sb::toString())
296
- else
297
- return Std::parseInt(sb::toString())
298
- end
299
- end
300
- def decodeHash()
301
- h = Hash.new()
302
- nextToken()
303
- skipBlanks()
304
- if c==125
305
- nextToken()
306
- return h
307
- end
308
- while c!=125
309
- key = decodeString()
310
- skipBlanks()
311
- if c!=58
312
- raise Exception,"Expected \':\'."
313
- end
314
- nextToken()
315
- skipBlanks()
316
- o = localDecode()
317
- h::set(key,o)
318
- skipBlanks()
319
- if c==44
320
- nextToken()
321
- skipBlanks()
322
- else
323
- if c!=125
324
- raise Exception,"Expected \',\' or \'}\'. "+getPositionRepresentation()
325
- end
326
- end
327
- end
328
- nextToken()
329
- return h
330
- end
331
- def decodeArray()
332
- v = Array.new()
333
- nextToken()
334
- skipBlanks()
335
- if c==93
336
- nextToken()
337
- return v
338
- end
339
- while c!=93
340
- o = localDecode()
341
- v::push(o)
342
- skipBlanks()
343
- if c==44
344
- nextToken()
345
- skipBlanks()
346
- else
347
- if c!=93
348
- raise Exception,"Expected \',\' or \']\'."
349
- end
350
- end
351
- end
352
- nextToken()
353
- return v
354
- end
355
- def self.getDepth(o)
356
- if TypeTools::isHash(o)
357
- h = (o)
358
- m = 0
359
- if h::exists("_left_")||h::exists("_right_")
360
- if h::exists("_left_")
361
- m = WInteger::max(getDepth(h::get("_left_")),m)
362
- end
363
- if h::exists("_right_")
364
- m = WInteger::max(getDepth(h::get("_right_")),m)
365
- end
366
- return m
367
- end
368
- iter = h::keys()
369
- while iter::hasNext()
370
- key = iter::next()
371
- m = WInteger::max(getDepth(h::get(key)),m)
372
- end
373
- return m+2
374
- else
375
- if TypeTools::isArray(o)
376
- a = (o)
377
- m = 0
378
- for i in 0..a::length()-1
379
- m = WInteger::max(getDepth(a::_(i)),m)
380
- i+=1
243
+ end
244
+ def decodeString()
245
+ sb = StringBuf.new()
246
+ d = c
247
+ nextToken()
248
+ while c != d
249
+ if c == 92
250
+ nextToken()
251
+ if c == 110
252
+ sb::add("\n")
253
+ else
254
+ if c == 114
255
+ sb::add("\r")
256
+ else
257
+ if c == 34
258
+ sb::add("\"")
259
+ else
260
+ if c == 39
261
+ sb::add("\'")
262
+ else
263
+ if c == 116
264
+ sb::add("\t")
265
+ else
266
+ if c == 92
267
+ sb::add("\\")
268
+ else
269
+ if c == 117
270
+ nextToken()
271
+ code = Utf8::uchr(c)
272
+ nextToken()
273
+ code += Utf8::uchr(c)
274
+ nextToken()
275
+ code += Utf8::uchr(c)
276
+ nextToken()
277
+ code += Utf8::uchr(c)
278
+ dec = Std::parseInt("0x" + code)
279
+ sb::add(Utf8::uchr(dec))
280
+ else
281
+ raise Exception,("Unknown scape sequence \'\\" + Utf8::uchr(c).to_s) + "\'"
282
+ end
283
+ end
284
+ end
285
+ end
286
+ end
287
+ end
288
+ end
289
+ else
290
+ sb::add(Std::fromCharCode(c))
291
+ end
292
+ nextToken()
381
293
  end
382
- return m+1
383
- else
384
- return 1
294
+ nextToken()
295
+ return sb::toString()
385
296
  end
386
- end
387
- end
388
- def setAddNewLines(addNewLines)
389
- @addNewLines = addNewLines
390
- end
391
- def newLine(depth,sb)
392
- sb::add("\r\n")
393
- for i in 0..depth-1
394
- sb::add(" ")
395
- i+=1
297
+ def decodeNumber()
298
+ sb = StringBuf.new()
299
+ hex = false
300
+ floating = false
301
+ loop do
302
+ sb::add(Std::fromCharCode(c))
303
+ nextToken()
304
+ if c == 120
305
+ hex = true
306
+ sb::add(Std::fromCharCode(c))
307
+ nextToken()
308
+ end
309
+ if ((c == 46) || (c == 69)) || (c == 101)
310
+ floating = true
311
+ end
312
+ break if not (((c >= 48) && (c <= 58)) || (hex && JSon.isHexDigit(c))) || (floating && ((((c == 46) || (c == 69)) || (c == 101)) || (c == 45)))
313
+ end
314
+ if floating
315
+ return Std::parseFloat(sb::toString())
316
+ else
317
+ return Std::parseInt(sb::toString())
318
+ end
396
319
  end
397
- @lastDepth = depth
398
- end
399
- def self.getString(o)
400
- return (o)
401
- end
402
- def self.getFloat(n)
403
- if n.instance_of?Double
404
- return (n)
405
- else
406
- if n.instance_of?Integer
407
- return (n)+0.0
408
- else
409
- return 0.0
410
- end
411
- end
412
- end
413
- def self.getInt(n)
414
- if n.instance_of?Double
415
- return (Math::round((n)))
416
- else
417
- if n.instance_of?Integer
418
- return (n)
419
- else
420
- return 0
421
- end
422
- end
423
- end
424
- def self.getBoolean(b)
425
- return ((b))::booleanValue()
426
- end
427
- def self.getArray(a)
428
- return (a)
429
- end
430
- def self.getHash(a)
431
- return (a)
432
- end
433
- def self.compare(a,b,eps)
434
- if TypeTools::isHash(a)
435
- isBHash = TypeTools::isHash(b)
436
- if !isBHash
437
- return false
438
- end
439
- ha = (a)
440
- hb = (b)
441
- it = ha::keys()
442
- itb = hb::keys()
443
- while it::hasNext()
444
- if !itb::hasNext()
445
- return false
446
- end
447
- itb::next()
448
- key = it::next()
449
- if !hb::exists(key)||!compare(ha::get(key),hb::get(key),eps)
450
- return false
451
- end
452
- end
453
- if itb::hasNext()
454
- return false
455
- end
456
- return true
457
- else
458
- if TypeTools::isArray(a)
459
- isBArray = TypeTools::isArray(b)
460
- if !isBArray
461
- return false
462
- end
463
- aa = (a)
464
- ab = (b)
465
- if aa::length()!=ab::length()
466
- return false
467
- end
468
- for i in 0..aa::length()-1
469
- if !compare(aa::_(i),ab::_(i),eps)
470
- return false
471
- end
472
- i+=1
320
+ def decodeHash()
321
+ h = Hash.new()
322
+ nextToken()
323
+ skipBlanks()
324
+ if c == 125
325
+ nextToken()
326
+ return h
327
+ end
328
+ while c != 125
329
+ key = decodeString()
330
+ skipBlanks()
331
+ if c != 58
332
+ raise Exception,"Expected \':\'."
333
+ end
334
+ nextToken()
335
+ skipBlanks()
336
+ o = localDecode()
337
+ h::set(key,o)
338
+ skipBlanks()
339
+ if c == 44
340
+ nextToken()
341
+ skipBlanks()
342
+ else
343
+ if c != 125
344
+ raise Exception,"Expected \',\' or \'}\'. " + getPositionRepresentation()
345
+ end
346
+ end
473
347
  end
474
- return true
475
- else
476
- if a.instance_of?String
477
- if !(b.instance_of?String)
478
- return false
348
+ nextToken()
349
+ return h
350
+ end
351
+ def decodeArray()
352
+ v = Array.new()
353
+ nextToken()
354
+ skipBlanks()
355
+ if c == 93
356
+ nextToken()
357
+ return v
358
+ end
359
+ while c != 93
360
+ o = localDecode()
361
+ v::push(o)
362
+ skipBlanks()
363
+ if c == 44
364
+ nextToken()
365
+ skipBlanks()
366
+ else
367
+ if c != 93
368
+ raise Exception,"Expected \',\' or \']\'."
369
+ end
370
+ end
479
371
  end
480
- return (a==b)
481
- else
482
- if a.instance_of?Integer
483
- if !(b.instance_of?Integer)
484
- return false
485
- end
486
- return (a==b)
372
+ nextToken()
373
+ return v
374
+ end
375
+ def self.getDepth(o)
376
+ if TypeTools::isHash(o)
377
+ h = (o)
378
+ m = 0
379
+ if h::exists("_left_") || h::exists("_right_")
380
+ if h::exists("_left_")
381
+ m = WInteger::max(JSon.getDepth(h::get("_left_")),m)
382
+ end
383
+ if h::exists("_right_")
384
+ m = WInteger::max(JSon.getDepth(h::get("_right_")),m)
385
+ end
386
+ return m
387
+ end
388
+ iter = h::keys()
389
+ while iter::hasNext()
390
+ key = iter::next()
391
+ m = WInteger::max(JSon.getDepth(h::get(key)),m)
392
+ end
393
+ return m + 2
487
394
  else
488
- if a.instance_of?Long
489
- isBLong = b.instance_of?Long
490
- if !isBLong
491
- return false
395
+ if TypeTools::isArray(o)
396
+ a = (o)
397
+ m = 0
398
+ for i in 0..a::length() - 1
399
+ m = WInteger::max(JSon.getDepth(a::_(i)),m)
400
+ i+=1
401
+ end
402
+ return m + 1
403
+ else
404
+ return 1
492
405
  end
493
- return (a==b)
494
- else
495
- if a.instance_of?JSonIntegerFormat
496
- if !(b.instance_of?JSonIntegerFormat)
497
- return false
498
- end
499
- ja = (a)
500
- jb = (b)
501
- return (ja::toString()==jb::toString())
406
+ end
407
+ end
408
+ def setAddNewLines(addNewLines)
409
+ self.addNewLines = addNewLines
410
+ end
411
+ def newLine(depth, sb)
412
+ sb::add("\r\n")
413
+ for i in 0..depth - 1
414
+ sb::add(" ")
415
+ i+=1
416
+ end
417
+ @lastDepth = depth
418
+ end
419
+ def self.getString(o)
420
+ return (o)
421
+ end
422
+ def self.getFloat(n)
423
+ if n.instance_of?Double
424
+ return (n)
425
+ else
426
+ if n.instance_of?Integer
427
+ return (n) + 0.0
428
+ else
429
+ return 0.0
430
+ end
431
+ end
432
+ end
433
+ def self.getInt(n)
434
+ if n.instance_of?Double
435
+ return (Math::round((n)))
436
+ else
437
+ if n.instance_of?Integer
438
+ return (n)
502
439
  else
503
- if a.instance_of?Boolean
504
- if !(b.instance_of?Boolean)
505
- return false
440
+ return 0
441
+ end
442
+ end
443
+ end
444
+ def self.getBoolean(b)
445
+ return ((b))::booleanValue()
446
+ end
447
+ def self.getArray(a)
448
+ return (a)
449
+ end
450
+ def self.getHash(a)
451
+ return (a)
452
+ end
453
+ def self.compare(a, b, eps)
454
+ if TypeTools::isHash(a)
455
+ isBHash = TypeTools::isHash(b)
456
+ if !isBHash
457
+ return false
458
+ end
459
+ ha = (a)
460
+ hb = (b)
461
+ it = ha::keys()
462
+ itb = hb::keys()
463
+ while it::hasNext()
464
+ if !itb::hasNext()
465
+ return false
466
+ end
467
+ itb::next()
468
+ key = it::next()
469
+ if !hb::exists(key) || !JSon.compare(ha::get(key),hb::get(key),eps)
470
+ return false
471
+ end
472
+ end
473
+ if itb::hasNext()
474
+ return false
475
+ end
476
+ return true
477
+ else
478
+ if TypeTools::isArray(a)
479
+ isBArray = TypeTools::isArray(b)
480
+ if !isBArray
481
+ return false
506
482
  end
507
- return (a==b)
508
- else
509
- if a.instance_of?Double
510
- if !(b.instance_of?Double)
483
+ aa = (a)
484
+ ab = (b)
485
+ if aa::length() != ab::length()
511
486
  return false
512
- end
513
- da = getFloat(a)
514
- db = getFloat(b)
515
- return (da>=(db-eps))&&(da<=(db+eps))
516
487
  end
517
- end
488
+ for i in 0..aa::length() - 1
489
+ if !JSon.compare(aa::_(i),ab::_(i),eps)
490
+ return false
491
+ end
492
+ i+=1
493
+ end
494
+ return true
495
+ else
496
+ if a.instance_of?String
497
+ if !(b.instance_of?String)
498
+ return false
499
+ end
500
+ return (a == b)
501
+ else
502
+ if a.instance_of?Integer
503
+ if !(b.instance_of?Integer)
504
+ return false
505
+ end
506
+ return (a == b)
507
+ else
508
+ if a.instance_of?Bignum
509
+ isBLong = b.instance_of?Bignum
510
+ if !isBLong
511
+ return false
512
+ end
513
+ return (a == b)
514
+ else
515
+ if a.instance_of?JSonIntegerFormat
516
+ if !(b.instance_of?JSonIntegerFormat)
517
+ return false
518
+ end
519
+ ja = (a)
520
+ jb = (b)
521
+ return (ja::toString() == jb::toString())
522
+ else
523
+ if a.instance_of?Boolean
524
+ if !(b.instance_of?Boolean)
525
+ return false
526
+ end
527
+ return (a == b)
528
+ else
529
+ if a.instance_of?Double
530
+ if !(b.instance_of?Double)
531
+ return false
532
+ end
533
+ da = JSon.getFloat(a)
534
+ db = JSon.getFloat(b)
535
+ return (da >= (db - eps)) && (da <= (db + eps))
536
+ end
537
+ end
538
+ end
539
+ end
540
+ end
541
+ end
518
542
  end
519
- end
520
543
  end
521
- end
544
+ return true
522
545
  end
523
- end
524
- return true
525
- end
526
- def self.main(args)
527
- s1 = "{\"displays\":[{\"horizontal_axis_values_position\":\"below\",\"vertical_axis_label\":\"\",\"window_width\":450.,\"horizontal_axis_label\":\"\",\"styles\":[{\"color\":\"#9a0000\",\"ref\":\"line1\"},{\"color\":\"#105b5c\",\"ref\":\"conic1\"},{\"color\":\"#a3b017\",\"fixed\":false,\"ref\":\"point1\"},{\"color\":\"#a3b017\",\"fixed\":false,\"ref\":\"point2\"}],\"window_height\":450.,\"height\":21.,\"id\":\"plotter1\",\"grid_y\":true,\"width\":21.,\"grid_x\":true,\"axis_color\":\"#9696ff\",\"vertical_axis_values_position\":\"left\",\"grid_primary_color\":\"#ffc864\",\"background_color\":\"#fffff0\",\"axis_y\":true,\"axis_x\":true,\"center\":[0.,0.]}],\"elements\":[{\"type\":\"line_segment\",\"value-content\":\"<math xmlns=\\\"http://www.w3.org/1998/Math/MathML\\\"><apply><eq></eq><ci>y</ci><ci>x</ci></apply></math>\",\"coordinates\":[[-31.5,-31.5],[31.5,31.5]],\"id\":\"line1\"},{\"type\":\"path\",\"value-content\":\"<math xmlns=\\\"http://www.w3.org/1998/Math/MathML\\\"><apply><eq></eq><apply><plus></plus><apply><times></times><apply><minus></minus><apply><divide></divide><cn>1</cn><cn>4</cn></apply></apply><apply><power></power><ci>x</ci><cn>2</cn></apply></apply><ci>y</ci><cn>4</cn></apply><cn>0</cn></apply></math>\",\"coordinates\":[[9.795918464660645,19.99000358581543],[9.387755393981934,18.032485961914062],[8.979591369628906,16.158267974853516],[8.571428298950195,14.36734676361084],[8.163265228271484,12.659725189208984],[7.755102157592773,11.035402297973633],[7.346938610076904,9.494377136230469],[6.938775539398193,8.036651611328125],[6.530612468719482,6.662224292755127],[6.122448921203613,5.371095180511475],[5.714285850524902,4.163265228271484],[5.306122303009033,3.038733959197998],[4.897959232330322,1.997501015663147],[4.489795684814453,1.0395668745040894],[4.081632614135742,0.1649312824010849],[3.673469305038452,-0.626405656337738],[3.265306234359741,-1.3344439268112183],[2.857142925262451,-1.959183692932129],[2.448979616165161,-2.500624656677246],[2.040816307067871,-2.9587671756744385],[1.6326531171798706,-3.333611011505127],[1.2244898080825806,-3.6251561641693115],[0.8163265585899353,-3.833402633666992],[0.40816327929496765,-3.958350658416748],[0.,-4.],[-0.40816327929496765,-3.958350658416748],[-0.8163265585899353,-3.833402633666992],[-1.2244898080825806,-3.6251561641693115],[-1.6326531171798706,-3.333611011505127],[-2.040816307067871,-2.9587671756744385],[-2.448979616165161,-2.500624656677246],[-2.857142925262451,-1.959183692932129],[-3.265306234359741,-1.3344439268112183],[-3.673469305038452,-0.626405656337738],[-4.081632614135742,0.1649312824010849],[-4.489795684814453,1.0395668745040894],[-4.897959232330322,1.997501015663147],[-5.306122303009033,3.038733959197998],[-5.714285850524902,4.163265228271484],[-6.122448921203613,5.371095180511475],[-6.530612468719482,6.662224292755127],[-6.938775539398193,8.036651611328125],[-7.346938610076904,9.494377136230469],[-7.755102157592773,11.035402297973633],[-8.163265228271484,12.659725189208984],[-8.571428298950195,14.36734676361084],[-8.979591369628906,16.158267974853516],[-9.387755393981934,18.032485961914062],[-9.795918464660645,19.99000358581543],[-10.204081535339355,22.030820846557617]],\"id\":\"conic1\"},{\"type\":\"point\",\"value-content\":\"<math xmlns=\\\"http://www.w3.org/1998/Math/MathML\\\"><vector><apply><plus></plus><apply><times></times><apply><minus></minus><cn>2</cn></apply><apply><root></root><cn>5</cn></apply></apply><cn>2</cn></apply><apply><plus></plus><apply><times></times><apply><minus></minus><cn>2</cn></apply><apply><root></root><cn>5</cn></apply></apply><cn>2</cn></apply></vector></math>\",\"coordinates\":[-2.4721360206604004,-2.4721360206604004],\"id\":\"point1\"},{\"type\":\"point\",\"value-content\":\"<math xmlns=\\\"http://www.w3.org/1998/Math/MathML\\\"><vector><apply><plus></plus><apply><times></times><cn>2</cn><apply><root></root><cn>5</cn></apply></apply><cn>2</cn></apply><apply><plus></plus><apply><times></times><cn>2</cn><apply><root></root><cn>5</cn></apply></apply><cn>2</cn></apply></vector></math>\",\"coordinates\":[6.4721360206604,6.4721360206604],\"id\":\"point2\"}],\"constraints\":[]}"
528
- s2 = "{\"displays\":[{\"horizontal-axis-values-position\":\"below\",\"vertical-axis-label\":\"\",\"window-width\":450.,\"styles\":[{\"color\":\"#9a0000\",\"ref\":\"line1\"},{\"color\":\"#105b5c\",\"ref\":\"conic1\"},{\"color\":\"#a3b017\",\"fixed\":false,\"ref\":\"point1\"},{\"color\":\"#a3b017\",\"fixed\":false,\"ref\":\"point2\"}],\"background-color\":\"#fffff0\",\"height\":21.,\"id\":\"plotter1\",\"grid-y\":true,\"window-height\":450.,\"grid-x\":true,\"width\":21.,\"horizontal-axis-label\":\"\",\"vertical-axis-values-position\":\"left\",\"grid-primary-color\":\"#ffc864\",\"axis-color\":\"#9696ff\",\"axis-y\":true,\"axis-x\":true,\"center\":[0.,0.]}],\"elements\":[{\"type\":\"line_segment\",\"value-content\":\"<math xmlns=\\\"http://www.w3.org/1998/Math/MathML\\\"><apply><eq></eq><ci>y</ci><ci>x</ci></apply></math>\",\"coordinates\":[[-31.5,-31.5],[31.5,31.5]],\"id\":\"line1\"},{\"type\":\"path\",\"value-content\":\"<math xmlns=\\\"http://www.w3.org/1998/Math/MathML\\\"><apply><eq></eq><apply><plus></plus><apply><times></times><apply><minus></minus><apply><divide></divide><cn>1</cn><cn>4</cn></apply></apply><apply><power></power><ci>x</ci><cn>2</cn></apply></apply><ci>y</ci><cn>4</cn></apply><cn>0</cn></apply></math>\",\"coordinates\":[[9.795918464660645,19.99000358581543],[9.387755393981934,18.032485961914062],[8.979591369628906,16.158267974853516],[8.571428298950195,14.36734676361084],[8.163265228271484,12.659725189208984],[7.755102157592773,11.035402297973633],[7.346938610076904,9.494377136230469],[6.938775539398193,8.036651611328125],[6.530612468719482,6.662224292755127],[6.122448921203613,5.371095180511475],[5.714285850524902,4.163265228271484],[5.306122303009033,3.038733959197998],[4.897959232330322,1.997501015663147],[4.489795684814453,1.0395668745040894],[4.081632614135742,0.1649312824010849],[3.673469305038452,-0.626405656337738],[3.265306234359741,-1.3344439268112183],[2.857142925262451,-1.959183692932129],[2.448979616165161,-2.500624656677246],[2.040816307067871,-2.9587671756744385],[1.6326531171798706,-3.333611011505127],[1.2244898080825806,-3.6251561641693115],[0.8163265585899353,-3.833402633666992],[0.40816327929496765,-3.958350658416748],[0.,-4.],[-0.40816327929496765,-3.958350658416748],[-0.8163265585899353,-3.833402633666992],[-1.2244898080825806,-3.6251561641693115],[-1.6326531171798706,-3.333611011505127],[-2.040816307067871,-2.9587671756744385],[-2.448979616165161,-2.500624656677246],[-2.857142925262451,-1.959183692932129],[-3.265306234359741,-1.3344439268112183],[-3.673469305038452,-0.626405656337738],[-4.081632614135742,0.1649312824010849],[-4.489795684814453,1.0395668745040894],[-4.897959232330322,1.997501015663147],[-5.306122303009033,3.038733959197998],[-5.714285850524902,4.163265228271484],[-6.122448921203613,5.371095180511475],[-6.530612468719482,6.662224292755127],[-6.938775539398193,8.036651611328125],[-7.346938610076904,9.494377136230469],[-7.755102157592773,11.035402297973633],[-8.163265228271484,12.659725189208984],[-8.571428298950195,14.36734676361084],[-8.979591369628906,16.158267974853516],[-9.387755393981934,18.032485961914062],[-9.795918464660645,19.99000358581543],[-10.204081535339355,22.030820846557617]],\"id\":\"conic1\"},{\"type\":\"point\",\"value-content\":\"<math xmlns=\\\"http://www.w3.org/1998/Math/MathML\\\"><vector><apply><plus></plus><apply><times></times><apply><minus></minus><cn>2</cn></apply><apply><root></root><cn>5</cn></apply></apply><cn>2</cn></apply><apply><plus></plus><apply><times></times><apply><minus></minus><cn>2</cn></apply><apply><root></root><cn>5</cn></apply></apply><cn>2</cn></apply></vector></math>\",\"coordinates\":[-2.4721360206604004,-2.4721360206604004],\"id\":\"point1\"},{\"type\":\"point\",\"value-content\":\"<math xmlns=\\\"http://www.w3.org/1998/Math/MathML\\\"><vector><apply><plus></plus><apply><times></times><cn>2</cn><apply><root></root><cn>5</cn></apply></apply><cn>2</cn></apply><apply><plus></plus><apply><times></times><cn>2</cn><apply><root></root><cn>5</cn></apply></apply><cn>2</cn></apply></vector></math>\",\"coordinates\":[6.4721360206604,6.4721360206604],\"id\":\"point2\"}],\"constraints\":[]}"
529
- if JSon::compare(JSon::decode(s1),JSon::decode(s2),1.0E-8)
530
- Std::trace("Equal")
531
- else
532
- Std::trace("Not equal")
533
- end
546
+
534
547
  end
535
- end
536
548
  end