Class: WirisPlugin::CasImpl

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CasInterface

Cas

Constructor Details

#initialize(plugin) ⇒ CasImpl

Returns a new instance of CasImpl.



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

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

Instance Attribute Details

#pluginObject

Returns the value of attribute plugin.



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

def plugin
  @plugin
end

Class Method Details

.decodeBase64(imageParameter) ⇒ Object



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

def self.decodeBase64(imageParameter)
  b = Base64.new()
  dataDecoded = b::decodeBytes(Bytes::ofString(imageParameter))
  return dataDecoded
end

Instance Method Details

#cas(mode, language) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/com/wiris/plugin/impl/CasImpl.rb', line 46

def cas(mode,language)
  output = StringBuf.new()
  output::add("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
  config = plugin::getConfiguration()
  availableLanguages = getAvailableCASLanguages(config::getProperty(ConfigurationKeys::CAS_LANGUAGES,nil))
  if (language==nil)||!availableLanguages::contains_(language)
    language = availableLanguages::_(0)
  end
  if (mode!=nil)&&(mode=="applet")
    codebase = StringTools::replace(config::getProperty(ConfigurationKeys::CAS_CODEBASE,nil),"%LANG",language)
    archive = StringTools::replace(config::getProperty(ConfigurationKeys::CAS_ARCHIVE,nil),"%LANG",language)
    className = StringTools::replace(config::getProperty(ConfigurationKeys::CAS_CLASS,nil),"%LANG",language)
    output::add(printCAS(codebase,archive,className))
  else 
    output::add(printCASContainer(config,availableLanguages,language))
  end
  return output::toString()
end

#createCasImage(imageParameter) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/com/wiris/plugin/impl/CasImpl.rb', line 31

def createCasImage(imageParameter)
  output = ""
  contextPath = @plugin::getConfiguration()::getProperty(ConfigurationKeys::CONTEXT_PATH,"/")
  if imageParameter!=nil
    dataDecoded = self.class.decodeBase64(imageParameter)
    digest = Md5::encode(imageParameter)
    store = plugin::getStorageAndCache()
    store::storeData(digest,"png",dataDecoded::getData())
    showImagePath = @plugin::getConfiguration()::getProperty(ConfigurationKeys::SHOWCASIMAGE_PATH,nil)
    output+=RenderImpl::concatPath(contextPath,showImagePath)+StringTools::urlEncode(digest+".png").to_s
  else 
    output+=RenderImpl::concatPath(contextPath,"core/cas.png")
  end
  return output
end

#getAvailableCASLanguages(languageString) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/com/wiris/plugin/impl/CasImpl.rb', line 64

def getAvailableCASLanguages(languageString)
  langs = Std::split(languageString,",")
  availableLanguages = Array.new()
  iter = langs::iterator()
  while iter::hasNext()
    elem = iter::next()
    elem = StringTools::trim(elem)
    availableLanguages::push(elem)
  end
  if availableLanguages::length()==0
    availableLanguages = Array.new()
    availableLanguages::push("")
  end
  return availableLanguages
end

#htmlentities(input, entQuotes) ⇒ Object



130
131
132
133
134
135
136
137
138
139
# File 'lib/com/wiris/plugin/impl/CasImpl.rb', line 130

def htmlentities(input,entQuotes)
  returnValue = StringTools::replace(input,"&","&amp;")
  returnValue = StringTools::replace(returnValue,"<","&lt;")
  returnValue = StringTools::replace(returnValue,">","gt;")
  if entQuotes
    returnValue = StringTools::replace(returnValue,"\"","&quot;")
    return returnValue
  end
  return returnValue
end

#printCAS(codebase, archive, className) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/com/wiris/plugin/impl/CasImpl.rb', line 79

def printCAS(codebase,archive,className)
  output = StringBuf.new()
  output::add("<html><head><style type=\"text/css\">/*<!--*/ html, body { height: 100%; } body { overflow: hidden; margin: 0; } applet { height: 100%; width: 100%; } /*-->*/</style></head>")
  output::add("<body><applet id=\"applet\" alt=\"WIRIS CAS\" codebase=\"")
  output::add(htmlentities(codebase,true))
  output::add("\" archive=\"")
  output::add(htmlentities(archive,true))
  output::add("\" code=\"")
  output::add(htmlentities(className,true))
  output::add("\"><p>You need JAVA&reg; to use WIRIS tools.<br />FREE download from <a target=\"_blank\" href=\"http://www.java.com\">www.java.com</a></p></applet></body></html>")
  return output::toString()
end

#printCASContainer(config, availableLanguages, lang) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/com/wiris/plugin/impl/CasImpl.rb', line 91

def printCASContainer(config,availableLanguages,lang)
  output = StringBuf.new()
  output::add("<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"/><script>")
  output::add("var lang =\'")
  output::add(lang)
  output::add("/strings.js\';")
  output::add(" ")
  output::add(" var scriptsrc =  window.opener._wrs_conf_path + \'/lang/\' + lang;")
  output::add(" var script = document.createElement(\'script\'); ")
  output::add(" script.src = scriptsrc;")
  output::add(" document.head.appendChild(script);")
  output::add("</script><script>")
  output::add("var scriptsrc = window.opener._wrs_conf_path + \'/core/cas.js\'; ")
  output::add(" var script = document.createElement(\'script\'); ")
  output::add(" script.src = scriptsrc;")
  output::add(" document.head.appendChild(script);")
  output::add("</script>")
  output::add("<title>WIRIS CAS</title><style type=\"text/css\">")
  output::add("/*<!--*/ html, body, #optionForm { height: 100%; } body { overflow: hidden; margin: 0; } #controls { width: 100%; } /*-->*/</style></head>")
  output::add("<body><form id=\"optionForm\"><div id=\"appletContainer\"></div><table id=\"controls\"><tr><td>Width</td><td><input name=\"width\" type=\"text\" value=\"")
  output::add(config::getProperty(ConfigurationKeys::CAS_WIDTH,nil))
  output::add("\"/></td><td><input name=\"executeonload\" type=\"checkbox\"/> Calculate on load")
  output::add("</td><td><input name=\"toolbar\" type=\"checkbox\" checked /> Show toolbar</td><td>Language <select id=\"languageList\">")
    for i in 0..availableLanguages::length()-1
      language = htmlentities(availableLanguages::_(i),true)
      output::add("<option value=\"")
      output::add(language)
      output::add("\">")
      output::add(language)
      output::add("</option>")
      i+=1
    end
  output::add("</select></td></tr><tr><td>Height</td><td><input name=\"height\" type=\"text\" value=\"")
  output::add(config::getProperty(ConfigurationKeys::CAS_HEIGHT,nil))
  output::add("\"/></td><td><input name=\"focusonload\" type=\"checkbox\"/> Focus on load</td><td><input name=\"level\" type=\"checkbox\"/>")
  output::add("Elementary mode</td><td></td></tr><tr><td colspan=\"5\"><input id=\"submit\" value=\"Accept\" type=\"button\"/>")
  output::add("<input id=\"cancel\" value=\"Cancel\" type=\"button\"/></td></tr></table></form></body></html>")
  return output::toString()
end

#showCasImage(f, provider) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/com/wiris/plugin/impl/CasImpl.rb', line 16

def showCasImage(f,provider)
  formula = f
  if formula::endsWith(".png")
    formula = Std::substr(formula,0,formula::length()-4)
  end
  store = plugin::getStorageAndCache()
  data = store::retreiveData(formula,"png")
  if data==nil
    data = Storage::newResourceStorage("cas.png")::readBinary()
    if data==nil
      raise Exception,"Missing resource cas.png"
    end
  end
  return data
end