Class: WirisPlugin::PluginBuilderImpl

Inherits:
PluginBuilder show all
Includes:
Wiris
Defined in:
lib/com/wiris/plugin/impl/PluginBuilderImpl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from PluginBuilder

getInstance, newInstance, pb, pb=

Constructor Details

#initializePluginBuilderImpl

Returns a new instance of PluginBuilderImpl.



37
38
39
40
41
42
43
44
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 37

def initialize()
    super()
    @updaterChain = Array.new()
    @updaterChain::push(DefaultConfigurationUpdater.new())
    ci = ConfigurationImpl.new()
    @configuration = ci
    ci::setPluginBuilderImpl(self)
end

Instance Attribute Details

#accessProviderObject

Returns the value of attribute accessProvider.



36
37
38
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 36

def accessProvider
  @accessProvider
end

#configurationObject

Returns the value of attribute configuration.



25
26
27
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 25

def configuration
  @configuration
end

#customParamsProviderObject

Returns the value of attribute customParamsProvider.



34
35
36
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 34

def customParamsProvider
  @customParamsProvider
end

#storageAndCacheCacheFormulaObjectObject

Returns the value of attribute storageAndCacheCacheFormulaObject.



32
33
34
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 32

def storageAndCacheCacheFormulaObject
  @storageAndCacheCacheFormulaObject
end

#storageAndCacheCacheObjectObject

Returns the value of attribute storageAndCacheCacheObject.



30
31
32
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 30

def storageAndCacheCacheObject
  @storageAndCacheCacheObject
end

#storageAndCacheInitObjectObject

Returns the value of attribute storageAndCacheInitObject.



28
29
30
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 28

def storageAndCacheInitObject
  @storageAndCacheInitObject
end

#storeObject

Returns the value of attribute store.



26
27
28
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 26

def store
  @store
end

#updaterChainObject

Returns the value of attribute updaterChain.



27
28
29
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 27

def updaterChain
  @updaterChain
end

Instance Method Details

#addConfigurationUpdater(conf) ⇒ Object



45
46
47
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 45

def addConfigurationUpdater(conf)
    @updaterChain::push(conf)
end

#addCorsHeaders(response, origin) ⇒ Object



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 215

def addCorsHeaders(response, origin)
    conf = self.getConfiguration()
    if (conf::getProperty("wiriscorsenabled","false") == "true")
        confDir = conf::getProperty(ConfigurationKeys::CONFIGURATION_PATH,nil)
        corsConfFile = confDir + "/corsservers.ini"
        s = Storage::newStorage(corsConfFile)
        if s::exists()
            dir = s::read()
            allowedHosts = Std::split(dir,"\n")
            if allowedHosts::contains_(origin)
                response::setHeader("Access-Control-Allow-Origin",origin)
            end
        else 
            response::setHeader("Access-Control-Allow-Origin","*")
        end
    end
end

#addProxy(h) ⇒ Object



194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 194

def addProxy(h)
    conf = self.getConfiguration()
    proxyEnabled = conf::getProperty(ConfigurationKeys::HTTPPROXY,"false")
    if (proxyEnabled == "true")
        host = conf::getProperty(ConfigurationKeys::HTTPPROXY_HOST,nil)
        port = Std::parseInt(conf::getProperty(ConfigurationKeys::HTTPPROXY_PORT,"80"))
        if (host != nil) && (host::length() > 0)
            user = conf::getProperty(ConfigurationKeys::HTTPPROXY_USER,nil)
            pass = conf::getProperty(ConfigurationKeys::HTTPPROXY_PASS,nil)
            h::setProxy(HttpProxy::newHttpProxy(host,port,user,pass))
        end
    end
end

#addReferer(h) ⇒ Object



207
208
209
210
211
212
213
214
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 207

def addReferer(h)
    conf = self.getConfiguration()
    if (conf::getProperty("wirisexternalplugin","false") == "true")
        h::setHeader("Referer",conf::getProperty(ConfigurationKeys::EXTERNAL_REFERER,"external referer not found"))
    else 
        h::setHeader("Referer",conf::getProperty(ConfigurationKeys::REFERER,""))
    end
end

#addStats(url) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 232

def addStats(url)
    saveMode = self.getConfiguration()::getProperty(ConfigurationKeys::SAVE_MODE,"xml")
    externalPlugin = self.getConfiguration()::getProperty(ConfigurationKeys::EXTERNAL_PLUGIN,"false")
    begin
    version = Storage::newResourceStorage("VERSION")::read()
    end
    begin
    tech = StringTools::replace(Storage::newResourceStorage("tech.txt")::read(),"\n","")
    tech = StringTools::replace(tech,"\r","")
    end
    if url::indexOf("?") != -1
        return (((((((url + "&stats-mode=") + saveMode) + "&stats-version=") + version) + "&stats-scriptlang=") + tech) + "&external=") + externalPlugin
    else 
        return (((((((url + "?stats-mode=") + saveMode) + "&stats-version=") + version) + "&stats-scriptlang=") + tech) + "&external=") + externalPlugin
    end
end

#getAccessProviderObject



57
58
59
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 57

def getAccessProvider()
    return self.accessProvider
end

#getConfigurationObject



90
91
92
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 90

def getConfiguration()
    return @configuration
end

#getConfigurationUpdaterChainObject



125
126
127
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 125

def getConfigurationUpdaterChain()
    return @updaterChain
end

#getCustomParamsProviderObject



51
52
53
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 51

def getCustomParamsProvider()
    return self.customParamsProvider
end

#getImageFormatControllerObject



268
269
270
271
272
273
274
275
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 268

def getImageFormatController()
    if (@configuration::getProperty(ConfigurationKeys::IMAGE_FORMAT,"png") == "svg")
        imageFormatController = ImageFormatControllerSvg.new()
    else 
        imageFormatController = ImageFormatControllerPng.new()
    end
    return imageFormatController
end

#getImageServiceURL(service, stats) ⇒ Object



143
144
145
146
147
148
149
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
188
189
190
191
192
193
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 143

def getImageServiceURL(service, stats)
    config = getConfiguration()
    if Type::resolveClass("com.wiris.editor.services.PublicServices") != nil
        if (config::getProperty(ConfigurationKeys::SERVICE_HOST,nil) == "www.wiris.net")
            return self.getConfiguration()::getProperty(ConfigurationKeys::CONTEXT_PATH,"/") + "/editor/editor"
        end
    end
    protocol = config::getProperty(ConfigurationKeys::SERVICE_PROTOCOL,nil)
    port = config::getProperty(ConfigurationKeys::SERVICE_PORT,nil)
    url = config::getProperty(ConfigurationKeys::INTEGRATION_PATH,nil)
    if (protocol == nil) && (url != nil)
        if StringTools::startsWith(url,"https")
            protocol = "https"
        end
    end
    if protocol == nil
        protocol = "http"
    end
    if port != nil
        if (protocol == "http")
            if !(port == "80")
                port = ":" + port
            else 
                port = ""
            end
        end
        if (protocol == "https")
            if !(port == "443")
                port = ":" + port
            else 
                port = ""
            end
        end
    else 
        port = ""
    end
    domain = config::getProperty(ConfigurationKeys::SERVICE_HOST,nil)
    path = config::getProperty(ConfigurationKeys::SERVICE_PATH,nil)
    if service != nil
        _end = path::lastIndexOf("/")
        if _end == -1
            path = service
        else 
            path = (Std::substr(path,0,_end).to_s + "/") + service
        end
    end
    if stats
        path = addStats(path)
    end
    return (((protocol + "://") + domain) + port) + path
end

#getStorageAndCacheObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 93

def getStorageAndCache()
    if @store == nil
        className = @configuration::getProperty(ConfigurationKeys::STORAGE_CLASS,nil)
        if (className == nil) || (className == "FolderTreeStorageAndCache")
            @store = FolderTreeStorageAndCache.new()
        else 
            if (className == "FileStorageAndCache")
                @store = FileStorageAndCache.new()
            else 
                cls = Type::resolveClass(className)
                if cls == nil
                    raise Exception,("Class " + className) + " not found."
                end
                @store = (Type::createInstance(cls,Array.new()))
                if @store == nil
                    raise Exception,("Instance from " + cls.to_s) + " cannot be created."
                end
            end
        end
        initialize_(@store,@configuration::getFullConfiguration())
    end
    return @store
end

#initialize_(sac, conf) ⇒ Object



116
117
118
119
120
121
122
123
124
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 116

def initialize_(sac, conf)
    if @storageAndCacheCacheObject == nil
        @storageAndCacheCacheObject = CacheImpl.new(conf)
    end
    if @storageAndCacheCacheFormulaObject == nil
        @storageAndCacheCacheFormulaObject = CacheFormulaImpl.new(conf)
    end
    sac::init(@storageAndCacheInitObject,conf,@storageAndCacheCacheObject,@storageAndCacheCacheFormulaObject)
end

#isEditorLicensedObject



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 248

def isEditorLicensed()
    licenseClass = Type::resolveClass("com.wiris.util.sys.License")
    if licenseClass != nil
        init = Reflect::field(licenseClass,"init")
        initMethodParams = Array.new()
        initMethodParams::push(self.getConfiguration()::getProperty(ConfigurationKeys::EDITOR_KEY,""))
        initMethodParams::push("")
        initMethodParams::push([4, 5, 9, 10])
        Reflect::callMethod(licenseClass,init,initMethodParams)
        isLicensedMethod = Reflect::field(licenseClass,"isLicensed")
        isLicensedObject = Reflect::callMethod(licenseClass,isLicensedMethod,nil)
        if Type::getClassName(Type::getClass(isLicensedObject))::indexOf("Boolean") != -1
            isLicensed = Boolean::valueOf(isLicensedObject::toString())
        else 
            isLicensed = (isLicensedObject)
        end
        return (isLicensed)
    end
    return false
end

#newAsyncRenderObject



69
70
71
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 69

def newAsyncRender()
    return AsyncRenderImpl.new(self)
end

#newAsyncTextServiceObject



87
88
89
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 87

def newAsyncTextService()
    return AsyncTextServiceImpl.new(self)
end

#newCasObject



78
79
80
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 78

def newCas()
    return CasImpl.new(self)
end

#newCleanCacheObject



137
138
139
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 137

def newCleanCache()
    return CleanCacheImpl.new(self)
end

#newEditorObject



75
76
77
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 75

def newEditor()
    return EditorImpl.new(self)
end

#newGenericParamsProvider(properties) ⇒ Object



276
277
278
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 276

def newGenericParamsProvider(properties)
    return GenericParamsProviderImpl.new(properties)
end

#newRenderObject



63
64
65
66
67
68
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 63

def newRender()
    if (Type::resolveClass("com.wiris.editor.services.PublicServices") != nil) && isEditorLicensed()
        return RenderImplIntegratedServices.new(self)
    end
    return RenderImpl.new(self)
end

#newResourceLoaderObject



140
141
142
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 140

def newResourceLoader()
    return ServiceResourceLoaderImpl.new()
end

#newTestObject



72
73
74
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 72

def newTest()
    return TestImpl.new(self)
end

#newTextServiceObject



81
82
83
84
85
86
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 81

def newTextService()
    if (Type::resolveClass("com.wiris.editor.services.PublicServices") != nil) && isEditorLicensed()
        return TextServiceImplIntegratedServices.new(self)
    end
    return TextServiceImpl.new(self)
end

#setAccessProvider(provider) ⇒ Object



54
55
56
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 54

def setAccessProvider(provider)
    self.accessProvider = provider
end

#setCustomParamsProvider(provider) ⇒ Object



48
49
50
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 48

def setCustomParamsProvider(provider)
    self.customParamsProvider = provider
end

#setStorageAndCache(store) ⇒ Object



60
61
62
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 60

def setStorageAndCache(store)
    self.store = store
end

#setStorageAndCacheCacheFormulaObject(cacheFormula) ⇒ Object



134
135
136
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 134

def setStorageAndCacheCacheFormulaObject(cacheFormula)
    @storageAndCacheCacheFormulaObject = cacheFormula
end

#setStorageAndCacheCacheObject(cache) ⇒ Object



131
132
133
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 131

def setStorageAndCacheCacheObject(cache)
    @storageAndCacheCacheObject = cache
end

#setStorageAndCacheInitObject(obj) ⇒ Object



128
129
130
# File 'lib/com/wiris/plugin/impl/PluginBuilderImpl.rb', line 128

def setStorageAndCacheInitObject(obj)
    @storageAndCacheInitObject = obj
end