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,280 +1,326 @@
1
1
  module WirisPlugin
2
2
  include Wiris
3
- require('com/wiris/plugin/api/ConfigurationKeys.rb')
4
- require('com/wiris/plugin/impl/HttpImpl.rb')
5
- require('com/wiris/util/sys/IniFile.rb')
6
- require('com/wiris/util/json/JSon.rb')
7
- require('com/wiris/plugin/api/Render.rb')
8
- class RenderImpl
9
- extend RenderInterface
3
+ require('com/wiris/plugin/api/ConfigurationKeys.rb')
4
+ require('com/wiris/plugin/impl/HttpImpl.rb')
5
+ require('com/wiris/util/sys/IniFile.rb')
6
+ require('com/wiris/plugin/api/Render.rb')
7
+ require('com/wiris/util/type/UrlUtils.rb')
8
+ require('com/wiris/util/json/JSon.rb')
9
+ require('com/wiris/plugin/api/Render.rb')
10
+ class RenderImpl
11
+ extend RenderInterface
10
12
 
11
- include Wiris
13
+ include Wiris
12
14
 
13
- attr_accessor :plugin
14
- def initialize(plugin)
15
- super()
16
- @plugin = plugin
17
- end
18
- def computeDigest(mml,param)
19
- ss = getEditorParametersList()
20
- renderParams = Hash.new()
21
- for i in 0..ss::length-1
22
- key = ss[i]
23
- value = PropertiesTools::getProperty(param,key)
24
- if value!=nil
25
- renderParams::set(key,value)
26
- end
27
- i+=1
15
+ attr_accessor :plugin
16
+ def initialize(plugin)
17
+ super()
18
+ self.plugin = plugin
28
19
  end
29
- if mml!=nil
30
- renderParams::set("mml",mml)
31
- end
32
- s = IniFile::propertiesToString(renderParams)
33
- return @plugin::getStorageAndCache()::codeDigest(s)
34
- end
35
- def createImage(mml,provider,ref_output)
36
- output = ref_output
37
- if mml==nil
38
- raise Exception,"Missing parameter \'mml\'."
39
- end
40
- digest = computeDigest(mml,provider::getRenderParameters(@plugin::getConfiguration()))
41
- contextPath = @plugin::getConfiguration()::getProperty(ConfigurationKeys::CONTEXT_PATH,"/")
42
- showImagePath = @plugin::getConfiguration()::getProperty(ConfigurationKeys::SHOWIMAGE_PATH,nil)
43
- saveMode = @plugin::getConfiguration()::getProperty(ConfigurationKeys::SAVE_MODE,"xml")
44
- s = ""
45
- if (provider::getParameter("metrics","false")=="true")
46
- s = getMetrics(digest,output)
47
- end
48
- a = ""
49
- if (provider::getParameter("accessible","false")=="true")
50
- lang = provider::getParameter("lang","en")
51
- text = safeMath2Accessible(mml,lang,provider::getParameters())
52
- if output==nil
53
- a = "&text="+StringTools::urlEncode(text).to_s
54
- else
55
- PropertiesTools::setProperty(output,"alt",text)
20
+ def computeDigest(mml, param)
21
+ ss = getEditorParametersList()
22
+ renderParams = Hash.new()
23
+ for i in 0..ss::length - 1
24
+ key = ss[i]
25
+ value = PropertiesTools::getProperty(param,key)
26
+ if value != nil
27
+ renderParams::set(key,value)
28
+ end
29
+ i+=1
30
+ end
31
+ if mml != nil
32
+ renderParams::set("mml",mml)
33
+ end
34
+ s = IniFile::propertiesToString(renderParams)
35
+ return @plugin::getStorageAndCache()::codeDigest(s)
56
36
  end
57
- end
58
- rparam = ""
59
- if provider::getParameter("refererquery",nil)!=nil
60
- refererquery = provider::getParameter("refererquery","")
61
- rparam = "&refererquery="+refererquery
62
- end
63
- if (provider::getParameter("base64",nil)!=nil)||(saveMode=="base64")
64
- bs = showImage(digest,nil,provider)
65
- by = Bytes::ofData(bs)
66
- b64 = Base64.new()::encodeBytes(by)
67
- imageContentType = @plugin::getImageFormatController()::getContentType()
68
- return (("data:"+imageContentType)+";base64,")+b64::toString().to_s
69
- else
70
- return (((self.class.concatPath(contextPath,showImagePath)+StringTools::urlEncode(digest).to_s)+s)+a)+rparam
71
- end
72
- end
73
- def showImage(digest,mml,provider)
74
- if (digest==nil)&&(mml==nil)
75
- raise Exception,"Missing parameters \'formula\' or \'mml\'."
76
- end
77
- if (digest!=nil)&&(mml!=nil)
78
- raise Exception,"Only one parameter \'formula\' or \'mml\' is valid."
79
- end
80
- atts = false
81
- if ((digest==nil)&&(mml!=nil))&&(provider!=nil)
82
- digest = computeDigest(mml,provider::getRenderParameters(@plugin::getConfiguration()))
83
- end
84
- formula = @plugin::getStorageAndCache()::decodeDigest(digest)
85
- if formula==nil
86
- raise Exception,"Formula associated to digest not found."
87
- end
88
- if formula::startsWith("<")
89
- raise Exception,"Not implemented."
90
- end
91
- iniFile = IniFile::newIniFileFromString(formula)
92
- renderParams = iniFile::getProperties()
93
- ss = getEditorParametersList()
94
- if provider!=nil
95
- renderParameters = provider::getRenderParameters(@plugin::getConfiguration())
96
- for i in 0..ss::length-1
97
- key = ss[i]
98
- value = PropertiesTools::getProperty(renderParameters,key)
99
- if value!=nil
100
- atts = true
101
- renderParams::set(key,value)
37
+ def createImage(mml, provider, ref_output)
38
+ output = ref_output
39
+ if mml == nil
40
+ raise Exception,"Missing parameter \'mml\'."
41
+ end
42
+ digest = computeDigest(mml,provider::getRenderParameters(@plugin::getConfiguration()))
43
+ contextPath = @plugin::getConfiguration()::getProperty(ConfigurationKeys::CONTEXT_PATH,"/")
44
+ showImagePath = @plugin::getConfiguration()::getProperty(ConfigurationKeys::SHOWIMAGE_PATH,nil)
45
+ saveMode = @plugin::getConfiguration()::getProperty(ConfigurationKeys::SAVE_MODE,"xml")
46
+ s = ""
47
+ if (provider::getParameter("metrics","false") == "true")
48
+ s = getMetrics(digest,output)
49
+ end
50
+ a = ""
51
+ if (provider::getParameter("accessible","false") == "true")
52
+ lang = provider::getParameter("lang","en")
53
+ text = safeMath2Accessible(mml,lang,provider::getParameters())
54
+ if output == nil
55
+ a = "&text=" + UrlUtils::urlComponentEncode(text)
56
+ else
57
+ PropertiesTools::setProperty(output,"alt",text)
58
+ end
59
+ end
60
+ rparam = ""
61
+ if provider::getParameter("refererquery",nil) != nil
62
+ refererquery = provider::getParameter("refererquery","")
63
+ rparam = "&refererquery=" + refererquery
64
+ end
65
+ if output != nil
66
+ PropertiesTools::setProperty(output,"role","math")
67
+ end
68
+ if (provider::getParameter("base64",nil) != nil) || (saveMode == "base64")
69
+ bs = showImage(digest,nil,provider)
70
+ by = Bytes::ofData(bs)
71
+ b64 = Base64.new()::encodeBytes(by)
72
+ imageContentType = @plugin::getImageFormatController()::getContentType()
73
+ return (("data:" + imageContentType) + ";base64,") + b64::toString().to_s
74
+ else
75
+ return (((RenderImpl.concatPath(contextPath,showImagePath) + UrlUtils::urlComponentEncode(digest)) + s) + a) + rparam
102
76
  end
103
- i+=1
104
- end
105
- end
106
- if atts
107
- if mml!=nil
108
- digest = computeDigest(mml,PropertiesTools::toProperties(renderParams))
109
- else
110
- digest = computeDigest(renderParams::get("mml"),PropertiesTools::toProperties(renderParams))
111
77
  end
112
- end
113
- store = @plugin::getStorageAndCache()
114
- bs = nil
115
- bs = store::retreiveData(digest,@plugin::getConfiguration()::getProperty("wirisimageformat","png"))
116
- if bs==nil
117
- if @plugin::getConfiguration()::getProperty(ConfigurationKeys::EDITOR_PARAMS,nil)!=nil
118
- json = JSon::decode(@plugin::getConfiguration()::getProperty(ConfigurationKeys::EDITOR_PARAMS,nil))
119
- decodedHash = (json)
120
- keys = decodedHash::keys()
121
- notAllowedParams = Std::split(ConfigurationKeys::EDITOR_PARAMETERS_NOTRENDER_LIST,",")
122
- while keys::hasNext()
123
- key = keys::next()
124
- if !notAllowedParams::contains_(key)
125
- renderParams::set(key,(decodedHash::get(key)))
78
+ def showImage(digest, mml, provider)
79
+ if (digest == nil) && (mml == nil)
80
+ raise Exception,"Missing parameters \'formula\' or \'mml\'."
126
81
  end
127
- end
128
- else
129
- for i in 0..ss::length-1
130
- key = ss[i]
131
- if !renderParams::exists(key)
132
- confKey = ConfigurationKeys::imageConfigProperties::get(key)
133
- if confKey!=nil
134
- value = @plugin::getConfiguration()::getProperty(confKey,nil)
135
- if value!=nil
136
- renderParams::set(key,value)
137
- end
82
+ if (digest != nil) && (mml != nil)
83
+ raise Exception,"Only one parameter \'formula\' or \'mml\' is valid."
84
+ end
85
+ atts = false
86
+ if ((digest == nil) && (mml != nil)) && (provider != nil)
87
+ digest = computeDigest(mml,provider::getRenderParameters(@plugin::getConfiguration()))
88
+ end
89
+ formula = @plugin::getStorageAndCache()::decodeDigest(digest)
90
+ if formula == nil
91
+ raise Exception,"Formula associated to digest not found."
92
+ end
93
+ if formula::startsWith("<")
94
+ raise Exception,"Not implemented."
95
+ end
96
+ iniFile = IniFile::newIniFileFromString(formula)
97
+ renderParams = iniFile::getProperties()
98
+ ss = getEditorParametersList()
99
+ if provider != nil
100
+ renderParameters = provider::getRenderParameters(@plugin::getConfiguration())
101
+ for i in 0..ss::length - 1
102
+ key = ss[i]
103
+ value = PropertiesTools::getProperty(renderParameters,key)
104
+ if value != nil
105
+ atts = true
106
+ renderParams::set(key,value)
107
+ end
108
+ i+=1
109
+ end
110
+ end
111
+ if atts
112
+ if mml != nil
113
+ digest = computeDigest(mml,PropertiesTools::toProperties(renderParams))
114
+ else
115
+ digest = computeDigest(renderParams::get("mml"),PropertiesTools::toProperties(renderParams))
116
+ end
117
+ end
118
+ store = @plugin::getStorageAndCache()
119
+ bs = nil
120
+ bs = store::retreiveData(digest,@plugin::getConfiguration()::getProperty("wirisimageformat","png"))
121
+ if bs == nil
122
+ if @plugin::getConfiguration()::getProperty(ConfigurationKeys::EDITOR_PARAMS,nil) != nil
123
+ json = JSon::decode(@plugin::getConfiguration()::getProperty(ConfigurationKeys::EDITOR_PARAMS,nil))
124
+ decodedHash = (json)
125
+ keys = decodedHash::keys()
126
+ notAllowedParams = Std::split(ConfigurationKeys::EDITOR_PARAMETERS_NOTRENDER_LIST,",")
127
+ while keys::hasNext()
128
+ key = keys::next()
129
+ if !notAllowedParams::contains_(key)
130
+ renderParams::set(key,(decodedHash::get(key)))
131
+ end
132
+ end
133
+ else
134
+ for i in 0..ss::length - 1
135
+ key = ss[i]
136
+ if !renderParams::exists(key)
137
+ confKey = ConfigurationKeys::imageConfigProperties::get(key)
138
+ if confKey != nil
139
+ value = @plugin::getConfiguration()::getProperty(confKey,nil)
140
+ if value != nil
141
+ renderParams::set(key,value)
142
+ end
143
+ end
144
+ end
145
+ i+=1
146
+ end
147
+ end
148
+ renderParams::set("format",@plugin::getConfiguration()::getProperty("wirisimageformat","png"))
149
+ h = HttpImpl.new(@plugin::getImageServiceURL(nil,true),nil)
150
+ @plugin::addReferer(h)
151
+ @plugin::addProxy(h)
152
+ iter = renderParams::keys()
153
+ while iter::hasNext()
154
+ key = iter::next()
155
+ h::setParameter(key,renderParams::get(key))
156
+ end
157
+ h::request(true)
158
+ b = Bytes::ofString(h::getData())
159
+ store::storeData(digest,@plugin::getConfiguration()::getProperty("wirisimageformat","png"),b::getData())
160
+ bs = b::getData()
161
+ end
162
+ return bs
163
+ end
164
+ def showImageJson(digest, lang)
165
+ jsonResult = self.showImageHash(digest,lang)
166
+ if jsonResult != nil
167
+ jsonSb = StringBuf.new()
168
+ iter = jsonResult::keys()
169
+ jsonSb::add("{\"status\":\"ok\",\"result\":{")
170
+ while iter::hasNext()
171
+ key = (iter::next())
172
+ value = (jsonResult::get(key))
173
+ value = StringTools::replace(value,"\\","\\\\")
174
+ value = StringTools::replace(value,"\"","\\\"")
175
+ value = StringTools::replace(value,"\r","\\r")
176
+ value = StringTools::replace(value,"\n","\\n")
177
+ value = StringTools::replace(value,"\t","\\t")
178
+ jsonSb::add((((("\"" + key) + "\":") + "\"") + value) + "\"")
179
+ if iter::hasNext()
180
+ jsonSb::add(",")
181
+ end
138
182
  end
139
- end
140
- i+=1
183
+ jsonSb::add("}}")
184
+ return jsonSb::toString()
185
+ else
186
+ return "{\"status\":\"warning\"}"
141
187
  end
142
188
  end
143
- renderParams::set("format",@plugin::getConfiguration()::getProperty("wirisimageformat","png"))
144
- h = HttpImpl.new(@plugin::getImageServiceURL(nil,true),nil)
145
- @plugin::addReferer(h)
146
- @plugin::addProxy(h)
147
- iter = renderParams::keys()
148
- while iter::hasNext()
149
- key = iter::next()
150
- h::setParameter(key,renderParams::get(key))
189
+ def showImageHash(digest, lang)
190
+ imageFormat = @plugin::getConfiguration()::getProperty("wirisimageformat","png")
191
+ store = @plugin::getStorageAndCache()
192
+ bs = nil
193
+ bs = store::retreiveData(digest,imageFormat)
194
+ if bs != nil
195
+ jsonResult = Hash.new()
196
+ content = Bytes::ofData(bs)
197
+ if (imageFormat == "png")
198
+ content = Base64.new()::encodeBytes(content)
199
+ end
200
+ metrics = PropertiesTools::newProperties()
201
+ self.getMetrics(digest,metrics)
202
+ if lang == nil
203
+ lang = "en"
204
+ end
205
+ s = store::retreiveData(digest,lang)
206
+ hashMetrics = PropertiesTools::fromProperties(metrics)
207
+ keys = hashMetrics::keys()
208
+ while keys::hasNext()
209
+ currentKey = keys::next()
210
+ jsonResult::set(currentKey,hashMetrics::get(currentKey))
211
+ end
212
+ if s != nil
213
+ cachedServiceText = Utf8::fromBytes(s)
214
+ b = StringTools::endsWith(cachedServiceText,"}") && StringTools::startsWith(cachedServiceText,"{")
215
+ if b
216
+ decodedJson = (JSon::decode(cachedServiceText))
217
+ jsonErrors = (decodedJson::get("errors"))
218
+ if jsonErrors == nil
219
+ result = (decodedJson::get("result"))
220
+ if result != nil
221
+ jsonResult::set("alt",(result::get("text")))
222
+ end
223
+ else
224
+ jsonResult::set("alt","Error converting from MathML to accessible text.")
225
+ end
226
+ else
227
+ jsonResult::set("alt",cachedServiceText)
228
+ end
229
+ end
230
+ jsonResult::set("content",content::toString())
231
+ jsonResult::set("format",imageFormat)
232
+ jsonResult::set("role","math")
233
+ return jsonResult
234
+ else
235
+ return nil
236
+ end
151
237
  end
152
- h::request(true)
153
- b = Bytes::ofString(h::getData())
154
- store::storeData(digest,@plugin::getConfiguration()::getProperty("wirisimageformat","png"),b::getData())
155
- bs = b::getData()
156
- end
157
- return bs
158
- end
159
- def showImageJson(digest,lang)
160
- imageFormat = @plugin::getConfiguration()::getProperty("wirisimageformat","png")
161
- store = @plugin::getStorageAndCache()
162
- bs = nil
163
- bs = store::retreiveData(digest,imageFormat)
164
- jsonOutput = Hash.new()
165
- if bs!=nil
166
- jsonOutput::set("status","ok")
167
- jsonResult = Hash.new()
168
- by = Bytes::ofData(bs)
169
- b64 = Base64.new()::encodeBytes(by)
170
- metrics = PropertiesTools::newProperties()
171
- getMetrics(digest,metrics)
172
- if lang==nil
173
- lang = "en"
238
+ def getMathml(digest)
239
+ return nil
174
240
  end
175
- s = store::retreiveData(digest,lang)
176
- hashMetrics = PropertiesTools::fromProperties(metrics)
177
- keys = hashMetrics::keys()
178
- while keys::hasNext()
179
- currentKey = keys::next()
180
- jsonResult::set(currentKey,hashMetrics::get(currentKey))
241
+ def getEditorParametersList()
242
+ pl = @plugin::getConfiguration()::getProperty(ConfigurationKeys::EDITOR_PARAMETERS_LIST,ConfigurationKeys::EDITOR_PARAMETERS_DEFAULT_LIST)
243
+ return pl::split(",")
181
244
  end
182
- if s!=nil
183
- jsonResult::set("alt",Utf8::fromBytes(s))
245
+ def getMetrics(digest, ref_output)
246
+ output = ref_output
247
+ begin
248
+ bs = showImage(digest,nil,nil)
249
+ end
250
+ b = Bytes::ofData(bs)
251
+ return @plugin::getImageFormatController()::getMetrics(b,output)
184
252
  end
185
- jsonResult::set("base64",b64::toString())
186
- jsonResult::set("format",imageFormat)
187
- jsonOutput::set("result",jsonResult)
188
- else
189
- jsonOutput::set("status","warning")
190
- end
191
- return JSon::encode(jsonOutput)
192
- end
193
- def getMathml(digest)
194
- return nil
195
- end
196
- def getEditorParametersList()
197
- pl = @plugin::getConfiguration()::getProperty(ConfigurationKeys::EDITOR_PARAMETERS_LIST,ConfigurationKeys::EDITOR_PARAMETERS_DEFAULT_LIST)
198
- return pl::split(",")
199
- end
200
- def getMetrics(digest,ref_output)
201
- output = ref_output
202
- begin
203
- bs = showImage(digest,nil,nil)
204
- end
205
- b = Bytes::ofData(bs)
206
- return @plugin::getImageFormatController()::getMetrics(b,output)
207
- end
208
- def getMetricsFromBytes(bs,ref_output)
209
- output = ref_output
210
- width = 0
211
- height = 0
212
- dpi = 0
213
- baseline = 0
214
- bys = Bytes::ofData(bs)
215
- bi = BytesInput.new(bys)
216
- n = bys::length()
217
- alloc = 10
218
- b = Bytes::alloc(alloc)
219
- bi::readBytes(b,0,8)
220
- n-= 8
221
- while n>0
222
- len = bi::readInt32()
223
- typ = bi::readInt32()
224
- if typ==1229472850
225
- width = bi::readInt32()
226
- height = bi::readInt32()
227
- bi::readInt32()
228
- bi::readByte()
229
- else
230
- if typ==1650545477
231
- baseline = bi::readInt32()
232
- else
233
- if typ==1883789683
234
- dpi = bi::readInt32()
235
- dpi = (Math::round(dpi/39.37))
236
- bi::readInt32()
237
- bi::readByte()
253
+ def getMetricsFromBytes(bs, ref_output)
254
+ output = ref_output
255
+ width = 0
256
+ height = 0
257
+ dpi = 0
258
+ baseline = 0
259
+ bys = Bytes::ofData(bs)
260
+ bi = BytesInput.new(bys)
261
+ n = bys::length()
262
+ alloc = 10
263
+ b = Bytes::alloc(alloc)
264
+ bi::readBytes(b,0,8)
265
+ n -= 8
266
+ while n > 0
267
+ len = bi::readInt32()
268
+ typ = bi::readInt32()
269
+ if typ == 1229472850
270
+ width = bi::readInt32()
271
+ height = bi::readInt32()
272
+ bi::readInt32()
273
+ bi::readByte()
274
+ else
275
+ if typ == 1650545477
276
+ baseline = bi::readInt32()
277
+ else
278
+ if typ == 1883789683
279
+ dpi = bi::readInt32()
280
+ dpi = (Math::round(dpi/39.37))
281
+ bi::readInt32()
282
+ bi::readByte()
283
+ else
284
+ if len > alloc
285
+ alloc = len
286
+ b = Bytes::alloc(alloc)
287
+ end
288
+ bi::readBytes(b,0,len)
289
+ end
290
+ end
291
+ end
292
+ bi::readInt32()
293
+ n -= len + 12
294
+ end
295
+ if output != nil
296
+ PropertiesTools::setProperty(output,"width","" + width.to_s)
297
+ PropertiesTools::setProperty(output,"height","" + height.to_s)
298
+ PropertiesTools::setProperty(output,"baseline","" + baseline.to_s)
299
+ if dpi != 96
300
+ PropertiesTools::setProperty(output,"dpi","" + dpi.to_s)
301
+ end
302
+ r = ""
238
303
  else
239
- if len>alloc
240
- alloc = len
241
- b = Bytes::alloc(alloc)
242
- end
243
- bi::readBytes(b,0,len)
304
+ r = (((("&cw=" + width.to_s) + "&ch=") + height.to_s) + "&cb=") + baseline.to_s
305
+ if dpi != 96
306
+ r = (r + "&dpi=") + dpi.to_s
307
+ end
244
308
  end
245
- end
309
+ return r
246
310
  end
247
- bi::readInt32()
248
- n-= len+12
249
- end
250
- if output!=nil
251
- PropertiesTools::setProperty(output,"width",""+width.to_s)
252
- PropertiesTools::setProperty(output,"height",""+height.to_s)
253
- PropertiesTools::setProperty(output,"baseline",""+baseline.to_s)
254
- if dpi!=96
255
- PropertiesTools::setProperty(output,"dpi",""+dpi.to_s)
311
+ def safeMath2Accessible(mml, lang, param)
312
+ begin
313
+ text = @plugin::newTextService()::mathml2accessible(mml,lang,param)
314
+ return text
315
+ end
256
316
  end
257
- r = ""
258
- else
259
- r = (((("&cw="+width.to_s)+"&ch=")+height.to_s)+"&cb=")+baseline.to_s
260
- if dpi!=96
261
- r = (r+"&dpi=")+dpi.to_s
317
+ def self.concatPath(s1, s2)
318
+ if s1::lastIndexOf("/") == (s1::length() - 1)
319
+ return s1 + s2
320
+ else
321
+ return (s1 + "/") + s2
322
+ end
262
323
  end
263
- end
264
- return r
265
- end
266
- def safeMath2Accessible(mml,lang,param)
267
- begin
268
- text = @plugin::newTextService()::mathml2accessible(mml,lang,param)
269
- return text
270
- end
271
- end
272
- def self.concatPath(s1,s2)
273
- if s1::lastIndexOf("/")==(s1::length()-1)
274
- return s1+s2
275
- else
276
- return (s1+"/")+s2
277
- end
324
+
278
325
  end
279
- end
280
326
  end