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



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

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

Instance Attribute Details

#acceptObject

Returns the value of attribute accept.



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

def accept
  @accept
end

#cleanCachePathObject

Returns the value of attribute cleanCachePath.



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

def cleanCachePath
  @cleanCachePath
end

#guiObject

Returns the value of attribute gui.



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

def gui
  @gui
end

#newTokenObject

Returns the value of attribute newToken.



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

def newToken
  @newToken
end

#pluginObject

Returns the value of attribute plugin.



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

def plugin
  @plugin
end

#resourcePathObject

Returns the value of attribute resourcePath.



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

def resourcePath
  @resourcePath
end

#storageObject

Returns the value of attribute storage.



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

def storage
  @storage
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

#validTokenObject

Returns the value of attribute validToken.



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

def validToken
  @validToken
end

#wirisCleanCacheTokenObject

Returns the value of attribute wirisCleanCacheToken.



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

def wirisCleanCacheToken
  @wirisCleanCacheToken
end

Instance Method Details

#deleteCacheObject



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

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

#getCacheOutputObject



42
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
# File 'lib/com/wiris/plugin/impl/CleanCacheImpl.rb', line 42

def getCacheOutput()
  if @gui
    output = ""
    output+="<html><head>\r\n"
    output+="<title>WIRIS plugin 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>WIRIS plugin 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



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

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

#init(param) ⇒ Object



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

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



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

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

#validateToken(md5Token, token) ⇒ Object



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

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