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.
- checksums.yaml +4 -4
- data/Rakefile +34 -34
- data/app/assets/javascripts/wirispluginengine/WIRISplugins.js +1040 -64
- data/app/controllers/wirispluginengine/application_controller.rb +84 -75
- data/app/helpers/wirispluginengine/application_helper.rb +4 -4
- data/config/routes.rb +4 -4
- data/lib/com/wiris/common/WInteger.rb +52 -51
- data/lib/com/wiris/plugin/api/Cas.rb +5 -5
- data/lib/com/wiris/plugin/api/CleanCache.rb +5 -5
- data/lib/com/wiris/plugin/api/Configuration.rb +5 -5
- data/lib/com/wiris/plugin/api/ConfigurationKeys.rb +94 -91
- data/lib/com/wiris/plugin/api/Editor.rb +5 -5
- data/lib/com/wiris/plugin/api/Filter.rb +5 -5
- data/lib/com/wiris/plugin/api/ImageFormatController.rb +5 -5
- data/lib/com/wiris/plugin/api/ParamsProvider.rb +5 -5
- data/lib/com/wiris/plugin/api/PluginBuilder.rb +88 -74
- data/lib/com/wiris/plugin/api/Render.rb +5 -5
- data/lib/com/wiris/plugin/api/ServiceResourceLoader.rb +5 -5
- data/lib/com/wiris/plugin/api/Test.rb +5 -5
- data/lib/com/wiris/plugin/api/TextService.rb +5 -5
- data/lib/com/wiris/plugin/configuration/ConfigurationUpdater.rb +5 -5
- data/lib/com/wiris/plugin/impl/CacheFormulaImpl.rb +15 -0
- data/lib/com/wiris/plugin/impl/CacheImpl.rb +124 -0
- data/lib/com/wiris/plugin/impl/CasImpl.rb +140 -138
- data/lib/com/wiris/plugin/impl/CleanCacheImpl.rb +103 -101
- data/lib/com/wiris/plugin/impl/ConfigurationImpl.rb +165 -166
- data/lib/com/wiris/plugin/impl/CustomConfigurationUpdater.rb +32 -30
- data/lib/com/wiris/plugin/impl/DefaultConfigurationUpdater.rb +24 -22
- data/lib/com/wiris/plugin/impl/EditorImpl.rb +80 -78
- data/lib/com/wiris/plugin/impl/FileConfigurationUpdater.rb +29 -27
- data/lib/com/wiris/plugin/impl/FileStorageAndCache.rb +55 -53
- data/lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb +65 -134
- data/lib/com/wiris/plugin/impl/GenericParamsProviderImpl.rb +50 -48
- data/lib/com/wiris/plugin/impl/HttpImpl.rb +49 -48
- data/lib/com/wiris/plugin/impl/HttpListener.rb +5 -5
- data/lib/com/wiris/plugin/impl/ImageFormatControllerPng.rb +71 -63
- data/lib/com/wiris/plugin/impl/ImageFormatControllerSvg.rb +37 -28
- data/lib/com/wiris/plugin/impl/PluginBuilderImpl.rb +280 -248
- data/lib/com/wiris/plugin/impl/RenderImpl.rb +303 -257
- data/lib/com/wiris/plugin/impl/ServiceResourceLoaderImpl.rb +41 -39
- data/lib/com/wiris/plugin/impl/TestImpl.rb +177 -157
- data/lib/com/wiris/plugin/impl/TextFilter.rb +210 -194
- data/lib/com/wiris/plugin/impl/TextFilterTags.rb +57 -50
- data/lib/com/wiris/plugin/impl/TextServiceImpl.rb +158 -107
- data/lib/com/wiris/plugin/storage/StorageAndCache.rb +5 -5
- data/lib/com/wiris/util/json/JSon.rb +505 -493
- data/lib/com/wiris/util/json/JSonIntegerFormat.rb +17 -16
- data/lib/com/wiris/util/json/JsonAPIResponse.rb +70 -0
- data/lib/com/wiris/util/json/StringParser.rb +57 -56
- data/lib/com/wiris/util/sys/AccessProvider.rb +8 -0
- data/lib/com/wiris/util/sys/Cache.rb +8 -0
- data/lib/com/wiris/util/sys/HttpConnection.rb +14 -13
- data/lib/com/wiris/util/sys/HttpConnectionListener.rb +5 -5
- data/lib/com/wiris/util/sys/HttpSync.rb +28 -0
- data/lib/com/wiris/util/sys/IniFile.rb +132 -131
- data/lib/com/wiris/util/sys/Lock.rb +8 -0
- data/lib/com/wiris/util/sys/LockProvider.rb +8 -0
- data/lib/com/wiris/util/sys/Store.rb +126 -101
- data/lib/com/wiris/util/sys/StoreCache.rb +63 -0
- data/lib/com/wiris/util/sys/TimerProxy.rb +21 -0
- data/lib/com/wiris/util/sys/TimerTask.rb +8 -0
- data/lib/com/wiris/util/type/Arrays.rb +275 -0
- data/lib/com/wiris/util/type/ByteBuffer.rb +69 -0
- data/lib/com/wiris/util/type/Comparator.rb +8 -0
- data/lib/com/wiris/util/type/DataUtils.rb +24 -0
- data/lib/com/wiris/util/type/DoubleTools.rb +14 -0
- data/lib/com/wiris/util/type/HashCache.rb +43 -0
- data/lib/com/wiris/util/type/IntegerTools.rb +32 -0
- data/lib/com/wiris/util/type/Queue.rb +31 -0
- data/lib/com/wiris/util/type/SortArrayByStringLength.rb +26 -0
- data/lib/com/wiris/util/type/SortStringByLength.rb +26 -0
- data/lib/com/wiris/util/type/SortedHash.rb +45 -0
- data/lib/com/wiris/util/type/Stack.rb +31 -0
- data/lib/com/wiris/util/type/StringUtils.rb +56 -0
- data/lib/com/wiris/util/type/Tokenizer.rb +40 -0
- data/lib/com/wiris/util/type/UrlUtils.rb +78 -0
- data/lib/com/wiris/util/xml/ContentHandler.rb +8 -0
- data/lib/com/wiris/util/xml/DefaultHandler.rb +25 -0
- data/lib/com/wiris/util/xml/EntityResolver.rb +8 -0
- data/lib/com/wiris/util/xml/MathMLEntityResolver.rb +19 -0
- data/lib/com/wiris/util/xml/SAXParser.rb +470 -0
- data/lib/com/wiris/util/xml/SerializableImpl.rb +16 -15
- data/lib/com/wiris/util/xml/WCharacterBase.rb +968 -627
- data/lib/com/wiris/util/xml/WEntities.rb +11 -9
- data/lib/com/wiris/util/xml/WXmlUtils.rb +660 -490
- data/lib/com/wiris/util/xml/XmlSerializer.rb +517 -471
- data/lib/com/wiris/util/xml/XmlWriter.rb +260 -262
- data/lib/loader.rb +15 -12
- data/lib/src-generic/Array.rb +22 -22
- data/lib/src-generic/ArrayInt.rb +31 -31
- data/lib/src-generic/Base64.rb +14 -14
- data/lib/src-generic/BaseCode.rb +93 -93
- data/lib/src-generic/Boolean.rb +27 -0
- data/lib/src-generic/Bytes.rb +50 -50
- data/lib/src-generic/BytesInput.rb +37 -37
- data/lib/src-generic/EReg.rb +55 -55
- data/lib/src-generic/File.rb +35 -35
- data/lib/src-generic/FileLock.rb +26 -26
- data/lib/src-generic/FileSystem.rb +37 -37
- data/lib/src-generic/Hash.rb +42 -42
- data/lib/src-generic/Http.rb +111 -107
- data/lib/src-generic/HttpRequest.rb +25 -25
- data/lib/src-generic/HttpResponse.rb +70 -70
- data/lib/src-generic/Iterator.rb +20 -19
- data/lib/src-generic/Math.rb +14 -14
- data/lib/src-generic/Md5.rb +8 -8
- data/lib/src-generic/Md5Tools.rb +11 -11
- data/lib/src-generic/PropertiesTools.rb +32 -32
- data/lib/src-generic/Reflect.rb +16 -16
- data/lib/src-generic/RubyConfigurationUpdater.rb +49 -45
- data/lib/src-generic/Serializer.rb +84 -84
- data/lib/src-generic/Std.rb +74 -74
- data/lib/src-generic/Storage.rb +152 -152
- data/lib/src-generic/StringBuf.rb +40 -40
- data/lib/src-generic/StringTools.rb +44 -46
- data/lib/src-generic/Timer.rb +6 -6
- data/lib/src-generic/Type.rb +18 -18
- data/lib/src-generic/TypeTools.rb +31 -31
- data/lib/src-generic/Unserializer.rb +72 -72
- data/lib/src-generic/Utf8.rb +26 -26
- data/lib/src-generic/Xml.rb +199 -198
- data/lib/src-generic/extended/Integer.rb +5 -5
- data/lib/src-generic/extended/Math.rb +6 -6
- data/lib/src-generic/extended/Properties.rb +11 -11
- data/lib/src-generic/extended/String.rb +38 -38
- data/lib/src-generic/settings/PlatformSettings.rb +18 -18
- data/lib/src-generic/system/HttpProxy.rb +23 -0
- data/lib/src-generic/system/HttpProxyAuth.rb +10 -0
- data/lib/wirispluginengine.rb +5 -5
- data/lib/wirispluginengine/engine.rb +5 -5
- data/lib/wirispluginengine/integration/cleancache.rb +8 -8
- data/lib/wirispluginengine/integration/configurationjs.rb +8 -15
- data/lib/wirispluginengine/integration/configurationjson.rb +6 -6
- data/lib/wirispluginengine/integration/createimage.rb +7 -7
- data/lib/wirispluginengine/integration/getmathml.rb +18 -18
- data/lib/wirispluginengine/integration/resource.rb +8 -8
- data/lib/wirispluginengine/integration/service.rb +5 -5
- data/lib/wirispluginengine/integration/showimage.rb +28 -21
- data/lib/wirispluginengine/integration/test.rb +5 -5
- data/lib/wirispluginengine/integration/testfilter.rb +10 -0
- data/lib/wirispluginengine/version.rb +2 -2
- data/resources/VERSION +1 -1
- data/resources/WEB-INF/web.xml +25 -0
- data/resources/WIRISplugins.js +3809 -0
- data/resources/default-configuration.ini +47 -45
- data/resources/tech.txt +1 -1
- data/resources/wirisplugin.css +43 -42
- metadata +40 -4
- data/configuration.ini.dist +0 -104
@@ -1,55 +1,62 @@
|
|
1
1
|
module WirisPlugin
|
2
2
|
include Wiris
|
3
|
-
|
4
|
-
|
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/
|
4
|
-
require('com/wiris/plugin/impl/HttpImpl.rb')
|
5
|
-
require('com/wiris/
|
6
|
-
require('com/wiris/
|
7
|
-
|
8
|
-
|
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
|
-
|
13
|
+
extend HttpListenerInterface
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
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
|
-
|
84
|
-
else
|
85
|
-
return "Error: formula not found."
|
77
|
+
return response
|
86
78
|
end
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
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,536 +1,548 @@
|
|
1
1
|
module WirisPlugin
|
2
2
|
include Wiris
|
3
|
-
require('com/wiris/util/json/StringParser.rb')
|
4
|
-
require('com/wiris/util/
|
5
|
-
require('com/wiris/
|
6
|
-
require('com/wiris/
|
7
|
-
require('com/wiris/util/json/StringParser.rb')
|
8
|
-
|
9
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
47
|
-
|
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
|
-
|
53
|
-
|
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
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
86
|
+
newLine(@depth,sb)
|
112
87
|
end
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
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
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
end
|
94
|
+
sb::add(",")
|
95
|
+
if newLines
|
96
|
+
newLine(@depth,sb)
|
97
|
+
end
|
144
98
|
end
|
145
|
-
|
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
|
-
|
148
|
-
|
107
|
+
sb::add("}")
|
108
|
+
@depth-=1
|
149
109
|
end
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
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
|
-
|
190
|
-
|
191
|
-
else
|
192
|
-
if ((c==116)||(c==102))||(c==110)
|
193
|
-
return decodeBooleanOrNull()
|
200
|
+
if c == 91
|
201
|
+
return decodeArray()
|
194
202
|
else
|
195
|
-
|
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
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
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
|
-
|
238
|
-
|
239
|
-
else
|
240
|
-
if c==39
|
241
|
-
sb::add("\'")
|
233
|
+
if (word == "false")
|
234
|
+
return Boolean::FALSE
|
242
235
|
else
|
243
|
-
|
244
|
-
|
245
|
-
else
|
246
|
-
if c==92
|
247
|
-
sb::add("\\")
|
236
|
+
if (word == "null")
|
237
|
+
return nil
|
248
238
|
else
|
249
|
-
|
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
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
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
|
-
|
383
|
-
|
384
|
-
return 1
|
294
|
+
nextToken()
|
295
|
+
return sb::toString()
|
385
296
|
end
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
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
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
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
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
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
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
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
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
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
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
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
|
-
|
504
|
-
|
505
|
-
|
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
|
-
|
508
|
-
|
509
|
-
if
|
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
|
-
|
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
|
-
|
544
|
+
return true
|
522
545
|
end
|
523
|
-
|
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
|