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,53 @@
|
|
|
1
|
+
module WirisPlugin
|
|
2
|
+
include Wiris
|
|
3
|
+
class HttpImpl < Http
|
|
4
|
+
include Wiris
|
|
5
|
+
|
|
6
|
+
attr_accessor :data
|
|
7
|
+
attr_accessor :listener
|
|
8
|
+
def initialize(url,listener)
|
|
9
|
+
super(url)
|
|
10
|
+
@listener = listener
|
|
11
|
+
end
|
|
12
|
+
def request(post)
|
|
13
|
+
proxy = getProxy()
|
|
14
|
+
if ((proxy!=nil)&&(proxy::host!=nil))&&(proxy::host::length()>0)
|
|
15
|
+
hpa = (proxy::auth)
|
|
16
|
+
if (hpa::user!=nil)&&(hpa::user::length()>0)
|
|
17
|
+
data = Base64.new()::encodeBytes(Bytes::ofString((hpa::user.to_s+":")+hpa::pass.to_s))::toString()
|
|
18
|
+
setHeader("Proxy-Authorization","Basic "+data)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
super(post)
|
|
22
|
+
end
|
|
23
|
+
def onData(data)
|
|
24
|
+
@data = data
|
|
25
|
+
if @listener!=nil
|
|
26
|
+
@listener::onData(data)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
def onError(msg)
|
|
30
|
+
if @listener!=nil
|
|
31
|
+
@listener::onError(msg)
|
|
32
|
+
else
|
|
33
|
+
raise Exception,msg
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
def getData()
|
|
37
|
+
return @data
|
|
38
|
+
end
|
|
39
|
+
def getProxy()
|
|
40
|
+
proxy = Reflect::field(Http,"PROXY")
|
|
41
|
+
if proxy==nil
|
|
42
|
+
return nil
|
|
43
|
+
end
|
|
44
|
+
return (proxy)
|
|
45
|
+
end
|
|
46
|
+
def setProxy(proxy)
|
|
47
|
+
Reflect::setField(Http,"PROXY",proxy)
|
|
48
|
+
end
|
|
49
|
+
def setListener(listener)
|
|
50
|
+
@listener = listener
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
module WirisPlugin
|
|
2
|
+
include Wiris
|
|
3
|
+
require('com/wiris/plugin/api/ImageFormatController.rb')
|
|
4
|
+
class ImageFormatControllerPng
|
|
5
|
+
extend ImageFormatControllerInterface
|
|
6
|
+
|
|
7
|
+
include Wiris
|
|
8
|
+
|
|
9
|
+
def initialize()
|
|
10
|
+
super()
|
|
11
|
+
end
|
|
12
|
+
def getContentType()
|
|
13
|
+
return "image/png"
|
|
14
|
+
end
|
|
15
|
+
def getMetrics(bytes,ref_output)
|
|
16
|
+
output = ref_output
|
|
17
|
+
width = 0
|
|
18
|
+
height = 0
|
|
19
|
+
dpi = 0
|
|
20
|
+
baseline = 0
|
|
21
|
+
bi = BytesInput.new(bytes)
|
|
22
|
+
n = bytes::length()
|
|
23
|
+
alloc = 10
|
|
24
|
+
b = Bytes::alloc(alloc)
|
|
25
|
+
bi::readBytes(b,0,8)
|
|
26
|
+
n-= 8
|
|
27
|
+
while n>0
|
|
28
|
+
len = bi::readInt32()
|
|
29
|
+
typ = bi::readInt32()
|
|
30
|
+
if typ==1229472850
|
|
31
|
+
width = bi::readInt32()
|
|
32
|
+
height = bi::readInt32()
|
|
33
|
+
bi::readInt32()
|
|
34
|
+
bi::readByte()
|
|
35
|
+
else
|
|
36
|
+
if typ==1650545477
|
|
37
|
+
baseline = bi::readInt32()
|
|
38
|
+
else
|
|
39
|
+
if typ==1883789683
|
|
40
|
+
dpi = bi::readInt32()
|
|
41
|
+
dpi = (Math::round(dpi/39.37))
|
|
42
|
+
bi::readInt32()
|
|
43
|
+
bi::readByte()
|
|
44
|
+
else
|
|
45
|
+
if len>alloc
|
|
46
|
+
alloc = len
|
|
47
|
+
b = Bytes::alloc(alloc)
|
|
48
|
+
end
|
|
49
|
+
bi::readBytes(b,0,len)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
bi::readInt32()
|
|
54
|
+
n-= len+12
|
|
55
|
+
end
|
|
56
|
+
if output!=nil
|
|
57
|
+
PropertiesTools::setProperty(output,"width",""+width.to_s)
|
|
58
|
+
PropertiesTools::setProperty(output,"height",""+height.to_s)
|
|
59
|
+
PropertiesTools::setProperty(output,"baseline",""+baseline.to_s)
|
|
60
|
+
if dpi!=96
|
|
61
|
+
PropertiesTools::setProperty(output,"dpi",""+dpi.to_s)
|
|
62
|
+
end
|
|
63
|
+
r = ""
|
|
64
|
+
else
|
|
65
|
+
r = (((("&cw="+width.to_s)+"&ch=")+height.to_s)+"&cb=")+baseline.to_s
|
|
66
|
+
if dpi!=96
|
|
67
|
+
r = (r+"&dpi=")+dpi.to_s
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
return r
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module WirisPlugin
|
|
2
|
+
include Wiris
|
|
3
|
+
require('com/wiris/util/xml/WXmlUtils.rb')
|
|
4
|
+
require('com/wiris/plugin/api/ImageFormatController.rb')
|
|
5
|
+
class ImageFormatControllerSvg
|
|
6
|
+
extend ImageFormatControllerInterface
|
|
7
|
+
|
|
8
|
+
include Wiris
|
|
9
|
+
|
|
10
|
+
def initialize()
|
|
11
|
+
super()
|
|
12
|
+
end
|
|
13
|
+
def getContentType()
|
|
14
|
+
return "image/svg+xml"
|
|
15
|
+
end
|
|
16
|
+
def getMetrics(bytes,ref_output)
|
|
17
|
+
svg = bytes::toString()
|
|
18
|
+
output = ref_output
|
|
19
|
+
svgXml = WXmlUtils::parseXML(svg)
|
|
20
|
+
width = svgXml::firstElement()::get("width")
|
|
21
|
+
height = svgXml::firstElement()::get("height")
|
|
22
|
+
baseline = svgXml::firstElement()::get("wrs:baseline")
|
|
23
|
+
if output!=nil
|
|
24
|
+
PropertiesTools::setProperty(output,"width",""+width)
|
|
25
|
+
PropertiesTools::setProperty(output,"height",""+height)
|
|
26
|
+
PropertiesTools::setProperty(output,"baseline",""+baseline)
|
|
27
|
+
r = ""
|
|
28
|
+
else
|
|
29
|
+
r = (((("&cw="+width)+"&ch=")+height)+"&cb=")+baseline
|
|
30
|
+
end
|
|
31
|
+
return r
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
module WirisPlugin
|
|
2
|
+
include Wiris
|
|
3
|
+
require('com/wiris/plugin/api/ConfigurationKeys.rb')
|
|
4
|
+
require('com/wiris/plugin/api/PluginBuilder.rb')
|
|
5
|
+
require('com/wiris/plugin/impl/FolderTreeStorageAndCache.rb')
|
|
6
|
+
require('com/wiris/plugin/impl/TestImpl.rb')
|
|
7
|
+
require('com/wiris/plugin/impl/ServiceResourceLoaderImpl.rb')
|
|
8
|
+
require('com/wiris/plugin/impl/ImageFormatControllerPng.rb')
|
|
9
|
+
require('com/wiris/plugin/impl/CleanCacheImpl.rb')
|
|
10
|
+
require('com/wiris/plugin/impl/EditorImpl.rb')
|
|
11
|
+
require('com/wiris/plugin/impl/RenderImpl.rb')
|
|
12
|
+
require('com/wiris/plugin/impl/DefaultConfigurationUpdater.rb')
|
|
13
|
+
require('com/wiris/plugin/impl/FileStorageAndCache.rb')
|
|
14
|
+
require('com/wiris/plugin/impl/ImageFormatControllerSvg.rb')
|
|
15
|
+
require('com/wiris/plugin/impl/CasImpl.rb')
|
|
16
|
+
require('com/wiris/plugin/impl/ConfigurationImpl.rb')
|
|
17
|
+
require('com/wiris/plugin/impl/TextServiceImpl.rb')
|
|
18
|
+
require('com/wiris/plugin/impl/GenericParamsProviderImpl.rb')
|
|
19
|
+
require('com/wiris/plugin/api/PluginBuilder.rb')
|
|
20
|
+
class PluginBuilderImpl < PluginBuilder
|
|
21
|
+
include Wiris
|
|
22
|
+
|
|
23
|
+
attr_accessor :configuration
|
|
24
|
+
attr_accessor :store
|
|
25
|
+
attr_accessor :updaterChain
|
|
26
|
+
attr_accessor :storageAndCacheInitObject
|
|
27
|
+
attr_accessor :customParamsProvider
|
|
28
|
+
def initialize()
|
|
29
|
+
super()
|
|
30
|
+
@updaterChain = Array.new()
|
|
31
|
+
@updaterChain::push(DefaultConfigurationUpdater.new())
|
|
32
|
+
ci = ConfigurationImpl.new()
|
|
33
|
+
@configuration = ci
|
|
34
|
+
ci::setPluginBuilderImpl(self)
|
|
35
|
+
end
|
|
36
|
+
def addConfigurationUpdater(conf)
|
|
37
|
+
@updaterChain::push(conf)
|
|
38
|
+
end
|
|
39
|
+
def setCustomParamsProvider(provider)
|
|
40
|
+
@customParamsProvider = provider
|
|
41
|
+
end
|
|
42
|
+
def getCustomParamsProvider()
|
|
43
|
+
return @customParamsProvider
|
|
44
|
+
end
|
|
45
|
+
def setStorageAndCache(store)
|
|
46
|
+
@store = store
|
|
47
|
+
end
|
|
48
|
+
def newRender()
|
|
49
|
+
if (Type::resolveClass("com.wiris.editor.services.PublicServices")!=nil)&&isEditorLicensed()
|
|
50
|
+
return RenderImplIntegratedServices.new(self)
|
|
51
|
+
end
|
|
52
|
+
return RenderImpl.new(self)
|
|
53
|
+
end
|
|
54
|
+
def newAsyncRender()
|
|
55
|
+
return AsyncRenderImpl.new(self)
|
|
56
|
+
end
|
|
57
|
+
def newTest()
|
|
58
|
+
return TestImpl.new(self)
|
|
59
|
+
end
|
|
60
|
+
def newEditor()
|
|
61
|
+
return EditorImpl.new(self)
|
|
62
|
+
end
|
|
63
|
+
def newCas()
|
|
64
|
+
return CasImpl.new(self)
|
|
65
|
+
end
|
|
66
|
+
def newTextService()
|
|
67
|
+
if (Type::resolveClass("com.wiris.editor.services.PublicServices")!=nil)&&isEditorLicensed()
|
|
68
|
+
return TextServiceImplIntegratedServices.new(self)
|
|
69
|
+
end
|
|
70
|
+
return TextServiceImpl.new(self)
|
|
71
|
+
end
|
|
72
|
+
def newAsyncTextService()
|
|
73
|
+
return AsyncTextServiceImpl.new(self)
|
|
74
|
+
end
|
|
75
|
+
def getConfiguration()
|
|
76
|
+
return @configuration
|
|
77
|
+
end
|
|
78
|
+
def getStorageAndCache()
|
|
79
|
+
if @store==nil
|
|
80
|
+
className = @configuration::getProperty(ConfigurationKeys::STORAGE_CLASS,nil)
|
|
81
|
+
if (className==nil)||(className=="FolderTreeStorageAndCache")
|
|
82
|
+
@store = FolderTreeStorageAndCache.new()
|
|
83
|
+
else
|
|
84
|
+
if (className=="FileStorageAndCache")
|
|
85
|
+
@store = FileStorageAndCache.new()
|
|
86
|
+
else
|
|
87
|
+
cls = Type::resolveClass(className)
|
|
88
|
+
if cls==nil
|
|
89
|
+
raise Exception,("Class "+className)+" not found."
|
|
90
|
+
end
|
|
91
|
+
@store = (Type::createInstance(cls,Array.new()))
|
|
92
|
+
if @store==nil
|
|
93
|
+
raise Exception,("Instance from "+cls.to_s)+" cannot be created."
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
initialize_(@store,@configuration::getFullConfiguration())
|
|
98
|
+
end
|
|
99
|
+
return @store
|
|
100
|
+
end
|
|
101
|
+
def initialize_(sac,conf)
|
|
102
|
+
sac::init(@storageAndCacheInitObject,conf)
|
|
103
|
+
end
|
|
104
|
+
def getConfigurationUpdaterChain()
|
|
105
|
+
return @updaterChain
|
|
106
|
+
end
|
|
107
|
+
def setStorageAndCacheInitObject(obj)
|
|
108
|
+
@storageAndCacheInitObject = obj
|
|
109
|
+
end
|
|
110
|
+
def newCleanCache()
|
|
111
|
+
return CleanCacheImpl.new(self)
|
|
112
|
+
end
|
|
113
|
+
def newResourceLoader()
|
|
114
|
+
return ServiceResourceLoaderImpl.new()
|
|
115
|
+
end
|
|
116
|
+
def getImageServiceURL(service,stats)
|
|
117
|
+
config = getConfiguration()
|
|
118
|
+
if Type::resolveClass("com.wiris.editor.services.PublicServices")!=nil
|
|
119
|
+
if (config::getProperty(ConfigurationKeys::SERVICE_HOST,nil)=="www.wiris.net")
|
|
120
|
+
return getConfiguration()::getProperty(ConfigurationKeys::CONTEXT_PATH,"/")+"/editor/editor"
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
protocol = config::getProperty(ConfigurationKeys::SERVICE_PROTOCOL,nil)
|
|
124
|
+
port = config::getProperty(ConfigurationKeys::SERVICE_PORT,nil)
|
|
125
|
+
url = config::getProperty(ConfigurationKeys::INTEGRATION_PATH,nil)
|
|
126
|
+
if (protocol==nil)&&(url!=nil)
|
|
127
|
+
if StringTools::startsWith(url,"https")
|
|
128
|
+
protocol = "https"
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
if protocol==nil
|
|
132
|
+
protocol = "http"
|
|
133
|
+
end
|
|
134
|
+
if port!=nil
|
|
135
|
+
if (protocol=="http")
|
|
136
|
+
if !(port=="80")
|
|
137
|
+
port = ":"+port
|
|
138
|
+
else
|
|
139
|
+
port = ""
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
if (protocol=="https")
|
|
143
|
+
if !(port=="443")
|
|
144
|
+
port = ":"+port
|
|
145
|
+
else
|
|
146
|
+
port = ""
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
else
|
|
150
|
+
port = ""
|
|
151
|
+
end
|
|
152
|
+
domain = config::getProperty(ConfigurationKeys::SERVICE_HOST,nil)
|
|
153
|
+
path = config::getProperty(ConfigurationKeys::SERVICE_PATH,nil)
|
|
154
|
+
if service!=nil
|
|
155
|
+
_end = path::lastIndexOf("/")
|
|
156
|
+
if _end==-1
|
|
157
|
+
path = service
|
|
158
|
+
else
|
|
159
|
+
path = (Std::substr(path,0,_end).to_s+"/")+service
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
if stats
|
|
163
|
+
path = addStats(path)
|
|
164
|
+
end
|
|
165
|
+
return (((protocol+"://")+domain)+port)+path
|
|
166
|
+
end
|
|
167
|
+
def addProxy(h)
|
|
168
|
+
conf = getConfiguration()
|
|
169
|
+
proxyEnabled = conf::getProperty(ConfigurationKeys::HTTPPROXY,"false")
|
|
170
|
+
if (proxyEnabled=="true")
|
|
171
|
+
host = conf::getProperty(ConfigurationKeys::HTTPPROXY_HOST,nil)
|
|
172
|
+
port = Std::parseInt(conf::getProperty(ConfigurationKeys::HTTPPROXY_PORT,"80"))
|
|
173
|
+
if (host!=nil)&&(host::length()>0)
|
|
174
|
+
user = conf::getProperty(ConfigurationKeys::HTTPPROXY_USER,nil)
|
|
175
|
+
pass = conf::getProperty(ConfigurationKeys::HTTPPROXY_PASS,nil)
|
|
176
|
+
h::setProxy(HttpProxy::newHttpProxy(host,port,user,pass))
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
def addReferer(h)
|
|
181
|
+
conf = getConfiguration()
|
|
182
|
+
if (conf::getProperty("wirisexternalplugin","false")=="true")
|
|
183
|
+
h::setHeader("Referer",conf::getProperty(ConfigurationKeys::EXTERNAL_REFERER,"external referer not found"))
|
|
184
|
+
else
|
|
185
|
+
h::setHeader("Referer",conf::getProperty(ConfigurationKeys::REFERER,""))
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
def addCorsHeaders(response,origin)
|
|
189
|
+
conf = getConfiguration()
|
|
190
|
+
if (conf::getProperty("wiriscorsenabled","false")=="true")
|
|
191
|
+
confDir = conf::getProperty(ConfigurationKeys::CONFIGURATION_PATH,nil)
|
|
192
|
+
corsConfFile = confDir+"/corsservers.ini"
|
|
193
|
+
s = Storage::newStorage(corsConfFile)
|
|
194
|
+
if s::exists()
|
|
195
|
+
dir = s::read()
|
|
196
|
+
allowedHosts = Std::split(dir,"\n")
|
|
197
|
+
if allowedHosts::contains_(origin)
|
|
198
|
+
response::setHeader("Access-Control-Allow-Origin",origin)
|
|
199
|
+
end
|
|
200
|
+
else
|
|
201
|
+
response::setHeader("Access-Control-Allow-Origin","*")
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
def addStats(url)
|
|
206
|
+
saveMode = getConfiguration()::getProperty(ConfigurationKeys::SAVE_MODE,"xml")
|
|
207
|
+
externalPlugin = getConfiguration()::getProperty(ConfigurationKeys::EXTERNAL_PLUGIN,"false")
|
|
208
|
+
begin
|
|
209
|
+
version = Storage::newResourceStorage("VERSION")::read()
|
|
210
|
+
end
|
|
211
|
+
begin
|
|
212
|
+
tech = StringTools::replace(Storage::newResourceStorage("tech.txt")::read(),"\n","")
|
|
213
|
+
tech = StringTools::replace(tech,"\r","")
|
|
214
|
+
end
|
|
215
|
+
if url::indexOf("?")!=-1
|
|
216
|
+
return (((((((url+"&stats-mode=")+saveMode)+"&stats-version=")+version)+"&stats-scriptlang=")+tech)+"&external=")+externalPlugin
|
|
217
|
+
else
|
|
218
|
+
return (((((((url+"?stats-mode=")+saveMode)+"&stats-version=")+version)+"&stats-scriptlang=")+tech)+"&external=")+externalPlugin
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
def isEditorLicensed()
|
|
222
|
+
licenseClass = Type::resolveClass("com.wiris.util.sys.License")
|
|
223
|
+
if licenseClass!=nil
|
|
224
|
+
init = Reflect::field(licenseClass,"init")
|
|
225
|
+
initMethodParams = Array.new()
|
|
226
|
+
initMethodParams::push(getConfiguration()::getProperty(ConfigurationKeys::EDITOR_KEY,""))
|
|
227
|
+
initMethodParams::push("")
|
|
228
|
+
initMethodParams::push([4, 5, 9, 10])
|
|
229
|
+
Reflect::callMethod(licenseClass,init,initMethodParams)
|
|
230
|
+
isLicensedMethod = Reflect::field(licenseClass,"isLicensed")
|
|
231
|
+
isLicensedObject = Reflect::callMethod(licenseClass,isLicensedMethod,nil)
|
|
232
|
+
if Type::getClassName(Type::getClass(isLicensedObject))::indexOf("Boolean")!=-1
|
|
233
|
+
isLicensed = Boolean::valueOf(isLicensedObject::toString())
|
|
234
|
+
else
|
|
235
|
+
isLicensed = (isLicensedObject)
|
|
236
|
+
end
|
|
237
|
+
return (isLicensed)
|
|
238
|
+
end
|
|
239
|
+
return false
|
|
240
|
+
end
|
|
241
|
+
def getImageFormatController()
|
|
242
|
+
if (@configuration::getProperty(ConfigurationKeys::IMAGE_FORMAT,"png")=="svg")
|
|
243
|
+
imageFormatController = ImageFormatControllerSvg.new()
|
|
244
|
+
else
|
|
245
|
+
imageFormatController = ImageFormatControllerPng.new()
|
|
246
|
+
end
|
|
247
|
+
return imageFormatController
|
|
248
|
+
end
|
|
249
|
+
def newGenericParamsProvider(properties)
|
|
250
|
+
return GenericParamsProviderImpl.new(properties)
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
end
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
module WirisPlugin
|
|
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
|
|
10
|
+
|
|
11
|
+
include Wiris
|
|
12
|
+
|
|
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
|
|
28
|
+
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)
|
|
56
|
+
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)
|
|
102
|
+
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
|
+
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)))
|
|
126
|
+
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
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
i+=1
|
|
141
|
+
end
|
|
142
|
+
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))
|
|
151
|
+
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"
|
|
174
|
+
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))
|
|
181
|
+
end
|
|
182
|
+
if s!=nil
|
|
183
|
+
jsonResult::set("alt",Utf8::fromBytes(s))
|
|
184
|
+
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()
|
|
238
|
+
else
|
|
239
|
+
if len>alloc
|
|
240
|
+
alloc = len
|
|
241
|
+
b = Bytes::alloc(alloc)
|
|
242
|
+
end
|
|
243
|
+
bi::readBytes(b,0,len)
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
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)
|
|
256
|
+
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
|
|
262
|
+
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
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
end
|