Class: WirisPlugin::CleanCacheImpl

Inherits:
Object
  • Object
show all
Extended by:
CleanCacheInterface
Includes:
Wiris
Defined in:
lib/com/wiris/plugin/impl/CleanCacheImpl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CleanCacheInterface

CleanCache

Constructor Details

#initialize(pb) ⇒ CleanCacheImpl

Returns a new instance of CleanCacheImpl.



22
23
24
25
# File 'lib/com/wiris/plugin/impl/CleanCacheImpl.rb', line 22

def initialize(pb)
    super()
    @plugin = pb
end

Instance Attribute Details

#acceptObject

Returns the value of attribute accept.



17
18
19
# File 'lib/com/wiris/plugin/impl/CleanCacheImpl.rb', line 17

def accept
  @accept
end

#cleanCachePathObject

Returns the value of attribute cleanCachePath.



20
21
22
# File 'lib/com/wiris/plugin/impl/CleanCacheImpl.rb', line 20

def cleanCachePath
  @cleanCachePath
end

#guiObject

Returns the value of attribute gui.



18
19
20
# File 'lib/com/wiris/plugin/impl/CleanCacheImpl.rb', line 18

def gui
  @gui
end

#newTokenObject

Returns the value of attribute newToken.



14
15
16
# File 'lib/com/wiris/plugin/impl/CleanCacheImpl.rb', line 14

def newToken
  @newToken
end

#pluginObject

Returns the value of attribute plugin.



12
13
14
# File 'lib/com/wiris/plugin/impl/CleanCacheImpl.rb', line 12

def plugin
  @plugin
end

#resourcePathObject

Returns the value of attribute resourcePath.



21
22
23
# File 'lib/com/wiris/plugin/impl/CleanCacheImpl.rb', line 21

def resourcePath
  @resourcePath
end

#storageObject

Returns the value of attribute storage.



19
20
21
# File 'lib/com/wiris/plugin/impl/CleanCacheImpl.rb', line 19

def storage
  @storage
end

#tokenObject

Returns the value of attribute token.



13
14
15
# File 'lib/com/wiris/plugin/impl/CleanCacheImpl.rb', line 13

def token
  @token
end

#validTokenObject

Returns the value of attribute validToken.



16
17
18
# File 'lib/com/wiris/plugin/impl/CleanCacheImpl.rb', line 16

def validToken
  @validToken
end

#wirisCleanCacheTokenObject

Returns the value of attribute wirisCleanCacheToken.



15
16
17
# File 'lib/com/wiris/plugin/impl/CleanCacheImpl.rb', line 15

def wirisCleanCacheToken
  @wirisCleanCacheToken
end

Instance Method Details

#deleteCacheObject



40
41
42
# File 'lib/com/wiris/plugin/impl/CleanCacheImpl.rb', line 40

def deleteCache()
    @storage::deleteCache()
end

#getCacheOutputObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/com/wiris/plugin/impl/CleanCacheImpl.rb', line 43

def getCacheOutput()
    if @gui
        output = ""
        output += "<html><head>\r\n"
        output += "<title>MathType integration clean cache service</title><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />\r\n"
        output += ("<link rel=stylesheet type=text/css href=" + @resourcePath) + "?resourcefile=wirisplugin.css />"
        output += "</head>"
        output += "<div class=wirismaincontainer>"
        output += "<body class=wirisplugincleancache>"
        output += "<h2 class=wirisplugincleancache>MathType integration clean cache service</h2>\r\n"
        output += "<div class=wirisplugincleancacheform>"
        if @wirisCleanCacheToken != nil
            output += ("<form action=" + @cleanCachePath) + " method=post>"
            output += "<span class=wirisplugincleancachetextform> Security token </span><input type=password autocomplete=off name=token>"
            output += "<input type=\"submit\" value=\"Submit\">"
            output += "</form>"
        end
        output += ("<form action=" + @cleanCachePath) + " method=post>"
        output += "<span class=wirisplugincleancachetextform> Generate token </span> <input type=text name=newtoken>"
        output += "<input type=\"submit\" value=\"Submit\">"
        output += "</form>"
        output += "</div>"
        output += "<div class=wirisplugincleancacheresults>"
        if (@token != nil) && !@validToken
            output += "<span class=wirisplugincleancachewarning> Invalid Token </span>"
        else 
            if @validToken && (@token != nil)
                output += "<span class=wirisplugincleancachewarning> Cache deleted successfully </span>"
            else 
                if @newToken != nil
                    output += " Your new token is: <br>"
                    output += ("<span class=wirisplugincleancachewarning>" + Md5::encode(@newToken).to_s) + "</span> <br>"
                    output += " Please copy it to your configuration.ini file <br>"
                    output += " For more information see <a href=http://www.wiris.com/plugins/docs/resources/configuration-table style=text-decoration:none>Server configuration file documentation</a>"
                end
            end
        end
        output += "</div>"
        output += "</div>"
        return output
    else 
        jsonOutput = Hash.new()
        if !@validToken
            jsonOutput::set("status","error")
        else 
            jsonOutput::set("status","ok")
        end
        return JSon::encode(jsonOutput)
    end
end

#getContentTypeObject



93
94
95
96
97
98
99
# File 'lib/com/wiris/plugin/impl/CleanCacheImpl.rb', line 93

def getContentType()
    if !@gui
        return "application/json"
    else 
        return "text/html charset=UTF-8"
    end
end

#init(param) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/com/wiris/plugin/impl/CleanCacheImpl.rb', line 26

def init(param)
    @storage = @plugin::getStorageAndCache()
    @token = param::getParameter("token",nil)
    @newToken = param::getParameter("newtoken",nil)
    @wirisCleanCacheToken = @plugin::getConfiguration()::getProperty(ConfigurationKeys::CLEAN_CACHE_TOKEN,nil)
    @accept = (param::getParameter("accept",nil) != nil) && (param::getParameter("accept","") == "application/json") ? true : false
    @gui = isGui()
    @validToken = validateToken(@wirisCleanCacheToken,@token)
    @cleanCachePath = @plugin::getConfiguration()::getProperty(ConfigurationKeys::CLEAN_CACHE_PATH,"")
    @resourcePath = @plugin::getConfiguration()::getProperty(ConfigurationKeys::RESOURCE_PATH,"")
    if (@token != nil) && @validToken
        deleteCache()
    end
end

#isGuiObject



107
108
109
110
# File 'lib/com/wiris/plugin/impl/CleanCacheImpl.rb', line 107

def isGui()
    wirisCacheGui = (@plugin::getConfiguration()::getProperty(ConfigurationKeys::CLEAN_CACHE_GUI,"false") == "true")
    return wirisCacheGui && !@accept
end

#validateToken(md5Token, token) ⇒ Object



100
101
102
103
104
105
106
# File 'lib/com/wiris/plugin/impl/CleanCacheImpl.rb', line 100

def validateToken(md5Token, token)
    if (token != nil) && (md5Token != nil)
        return (md5Token == Md5Tools::encodeString(token))
    else 
        return false
    end
end