wirispluginengine 3.62.0.1322
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 +7 -0
- data/Rakefile +34 -0
- data/app/assets/javascripts/wirispluginengine/WIRISplugins.js +2833 -0
- data/app/controllers/wirispluginengine/application_controller.rb +75 -0
- data/app/helpers/wirispluginengine/application_helper.rb +4 -0
- data/config/routes.rb +4 -0
- data/configuration.ini.dist +104 -0
- data/lib/com/wiris/common/WInteger.rb +57 -0
- data/lib/com/wiris/plugin/api/Cas.rb +8 -0
- data/lib/com/wiris/plugin/api/CleanCache.rb +8 -0
- data/lib/com/wiris/plugin/api/Configuration.rb +8 -0
- data/lib/com/wiris/plugin/api/ConfigurationKeys.rb +96 -0
- data/lib/com/wiris/plugin/api/Editor.rb +8 -0
- data/lib/com/wiris/plugin/api/Filter.rb +8 -0
- data/lib/com/wiris/plugin/api/ImageFormatController.rb +8 -0
- data/lib/com/wiris/plugin/api/ParamsProvider.rb +8 -0
- data/lib/com/wiris/plugin/api/PluginBuilder.rb +79 -0
- data/lib/com/wiris/plugin/api/Render.rb +8 -0
- data/lib/com/wiris/plugin/api/ServiceResourceLoader.rb +8 -0
- data/lib/com/wiris/plugin/api/Test.rb +8 -0
- data/lib/com/wiris/plugin/api/TextService.rb +8 -0
- data/lib/com/wiris/plugin/configuration/ConfigurationUpdater.rb +8 -0
- data/lib/com/wiris/plugin/impl/CasImpl.rb +146 -0
- data/lib/com/wiris/plugin/impl/CleanCacheImpl.rb +111 -0
- data/lib/com/wiris/plugin/impl/ConfigurationImpl.rb +176 -0
- data/lib/com/wiris/plugin/impl/CustomConfigurationUpdater.rb +38 -0
- data/lib/com/wiris/plugin/impl/DefaultConfigurationUpdater.rb +29 -0
- data/lib/com/wiris/plugin/impl/EditorImpl.rb +86 -0
- data/lib/com/wiris/plugin/impl/FileConfigurationUpdater.rb +34 -0
- data/lib/com/wiris/plugin/impl/FileStorageAndCache.rb +59 -0
- data/lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb +144 -0
- data/lib/com/wiris/plugin/impl/GenericParamsProviderImpl.rb +56 -0
- data/lib/com/wiris/plugin/impl/HttpImpl.rb +53 -0
- data/lib/com/wiris/plugin/impl/HttpListener.rb +8 -0
- data/lib/com/wiris/plugin/impl/ImageFormatControllerPng.rb +73 -0
- data/lib/com/wiris/plugin/impl/ImageFormatControllerSvg.rb +34 -0
- data/lib/com/wiris/plugin/impl/PluginBuilderImpl.rb +253 -0
- data/lib/com/wiris/plugin/impl/RenderImpl.rb +280 -0
- data/lib/com/wiris/plugin/impl/ServiceResourceLoaderImpl.rb +52 -0
- data/lib/com/wiris/plugin/impl/TestImpl.rb +166 -0
- data/lib/com/wiris/plugin/impl/TextFilter.rb +211 -0
- data/lib/com/wiris/plugin/impl/TextFilterTags.rb +55 -0
- data/lib/com/wiris/plugin/impl/TextServiceImpl.rb +118 -0
- data/lib/com/wiris/plugin/storage/StorageAndCache.rb +8 -0
- data/lib/com/wiris/util/json/JSon.rb +536 -0
- data/lib/com/wiris/util/json/JSonIntegerFormat.rb +21 -0
- data/lib/com/wiris/util/json/StringParser.rb +61 -0
- data/lib/com/wiris/util/sys/HttpConnection.rb +18 -0
- data/lib/com/wiris/util/sys/HttpConnectionListener.rb +8 -0
- data/lib/com/wiris/util/sys/IniFile.rb +143 -0
- data/lib/com/wiris/util/sys/Store.rb +109 -0
- data/lib/com/wiris/util/xml/SerializableImpl.rb +20 -0
- data/lib/com/wiris/util/xml/WCharacterBase.rb +634 -0
- data/lib/com/wiris/util/xml/WEntities.rb +14 -0
- data/lib/com/wiris/util/xml/WXmlUtils.rb +515 -0
- data/lib/com/wiris/util/xml/XmlSerializer.rb +485 -0
- data/lib/com/wiris/util/xml/XmlWriter.rb +279 -0
- data/lib/loader.rb +12 -0
- data/lib/src-generic/Array.rb +23 -0
- data/lib/src-generic/ArrayInt.rb +32 -0
- data/lib/src-generic/Base64.rb +15 -0
- data/lib/src-generic/BaseCode.rb +94 -0
- data/lib/src-generic/Bytes.rb +50 -0
- data/lib/src-generic/BytesInput.rb +38 -0
- data/lib/src-generic/EReg.rb +56 -0
- data/lib/src-generic/File.rb +36 -0
- data/lib/src-generic/FileLock.rb +27 -0
- data/lib/src-generic/FileSystem.rb +37 -0
- data/lib/src-generic/Hash.rb +43 -0
- data/lib/src-generic/Http.rb +107 -0
- data/lib/src-generic/HttpRequest.rb +25 -0
- data/lib/src-generic/HttpResponse.rb +71 -0
- data/lib/src-generic/Iterator.rb +20 -0
- data/lib/src-generic/Math.rb +15 -0
- data/lib/src-generic/Md5.rb +8 -0
- data/lib/src-generic/Md5Tools.rb +12 -0
- data/lib/src-generic/PropertiesTools.rb +33 -0
- data/lib/src-generic/Reflect.rb +17 -0
- data/lib/src-generic/RubyConfigurationUpdater.rb +45 -0
- data/lib/src-generic/Serializer.rb +85 -0
- data/lib/src-generic/Std.rb +74 -0
- data/lib/src-generic/Storage.rb +153 -0
- data/lib/src-generic/StringBuf.rb +41 -0
- data/lib/src-generic/StringTools.rb +46 -0
- data/lib/src-generic/Timer.rb +7 -0
- data/lib/src-generic/Type.rb +19 -0
- data/lib/src-generic/TypeTools.rb +32 -0
- data/lib/src-generic/Unserializer.rb +73 -0
- data/lib/src-generic/Utf8.rb +27 -0
- data/lib/src-generic/Xml.rb +199 -0
- data/lib/src-generic/extended/Integer.rb +5 -0
- data/lib/src-generic/extended/Math.rb +7 -0
- data/lib/src-generic/extended/Properties.rb +12 -0
- data/lib/src-generic/extended/String.rb +39 -0
- data/lib/src-generic/settings/PlatformSettings.rb +19 -0
- data/lib/wirispluginengine.rb +5 -0
- data/lib/wirispluginengine/engine.rb +5 -0
- data/lib/wirispluginengine/integration/cleancache.rb +8 -0
- data/lib/wirispluginengine/integration/configurationjs.rb +16 -0
- data/lib/wirispluginengine/integration/configurationjson.rb +7 -0
- data/lib/wirispluginengine/integration/createimage.rb +8 -0
- data/lib/wirispluginengine/integration/getmathml.rb +18 -0
- data/lib/wirispluginengine/integration/resource.rb +8 -0
- data/lib/wirispluginengine/integration/service.rb +6 -0
- data/lib/wirispluginengine/integration/showimage.rb +21 -0
- data/lib/wirispluginengine/integration/test.rb +6 -0
- data/lib/wirispluginengine/version.rb +3 -0
- data/resources/VERSION +1 -0
- data/resources/default-configuration.ini +45 -0
- data/resources/tech.txt +1 -0
- data/resources/wirisplugin.css +43 -0
- metadata +182 -0
@@ -0,0 +1,118 @@
|
|
1
|
+
module WirisPlugin
|
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
|
9
|
+
|
10
|
+
include Wiris
|
11
|
+
|
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)
|
27
|
+
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
|
80
|
+
else
|
81
|
+
return "Error: mathml not found."
|
82
|
+
end
|
83
|
+
end
|
84
|
+
else
|
85
|
+
return "Error: formula not found."
|
86
|
+
end
|
87
|
+
else
|
88
|
+
if latex!=nil
|
89
|
+
return latex2mathml(latex)
|
90
|
+
else
|
91
|
+
return "Error: no digest or latex has been sent."
|
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)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,536 @@
|
|
1
|
+
module WirisPlugin
|
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
|
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))
|
45
|
+
else
|
46
|
+
if o.instance_of?Long
|
47
|
+
encodeLong(sb,(o))
|
48
|
+
else
|
49
|
+
if o.instance_of?JSonIntegerFormat
|
50
|
+
encodeIntegerFormat(sb,(o))
|
51
|
+
else
|
52
|
+
if o.instance_of?Boolean
|
53
|
+
encodeBoolean(sb,(o))
|
54
|
+
else
|
55
|
+
if o.instance_of?Double
|
56
|
+
encodeFloat(sb,(o))
|
57
|
+
else
|
58
|
+
raise Exception,"Impossible to convert to json object of type "+Type::getClass(o).to_s
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
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(",")
|
110
|
+
if newLines
|
111
|
+
newLine(@depth,sb)
|
112
|
+
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")
|
138
|
+
else
|
139
|
+
if c==92
|
140
|
+
sb::add("\\\\")
|
141
|
+
else
|
142
|
+
sb::add(s::charAt(i))
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
i+=1
|
149
|
+
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()
|
188
|
+
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()
|
194
|
+
else
|
195
|
+
raise Exception,"Unrecognized char "+c.to_s
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
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")
|
236
|
+
else
|
237
|
+
if c==34
|
238
|
+
sb::add("\"")
|
239
|
+
else
|
240
|
+
if c==39
|
241
|
+
sb::add("\'")
|
242
|
+
else
|
243
|
+
if c==116
|
244
|
+
sb::add("\t")
|
245
|
+
else
|
246
|
+
if c==92
|
247
|
+
sb::add("\\")
|
248
|
+
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
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
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
|
381
|
+
end
|
382
|
+
return m+1
|
383
|
+
else
|
384
|
+
return 1
|
385
|
+
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
|
396
|
+
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
|
473
|
+
end
|
474
|
+
return true
|
475
|
+
else
|
476
|
+
if a.instance_of?String
|
477
|
+
if !(b.instance_of?String)
|
478
|
+
return false
|
479
|
+
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)
|
487
|
+
else
|
488
|
+
if a.instance_of?Long
|
489
|
+
isBLong = b.instance_of?Long
|
490
|
+
if !isBLong
|
491
|
+
return false
|
492
|
+
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())
|
502
|
+
else
|
503
|
+
if a.instance_of?Boolean
|
504
|
+
if !(b.instance_of?Boolean)
|
505
|
+
return false
|
506
|
+
end
|
507
|
+
return (a==b)
|
508
|
+
else
|
509
|
+
if a.instance_of?Double
|
510
|
+
if !(b.instance_of?Double)
|
511
|
+
return false
|
512
|
+
end
|
513
|
+
da = getFloat(a)
|
514
|
+
db = getFloat(b)
|
515
|
+
return (da>=(db-eps))&&(da<=(db+eps))
|
516
|
+
end
|
517
|
+
end
|
518
|
+
end
|
519
|
+
end
|
520
|
+
end
|
521
|
+
end
|
522
|
+
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
|
534
|
+
end
|
535
|
+
end
|
536
|
+
end
|