require "ontomde-core"
require "ontomde-inspector/loader.rb"
require "ontomde-core/context.rb"
require "ontomde-uml2"
require "ontomde-uml2-kb"
require "ontomde-uml2-java"
class MtkController < ApplicationController
def post_init
puts "initialize!"
@loader=Crdf_loader.instance
#@loader.loadProfile
@model=@loader.rdf_model
#MtkWebContext::RModel
#@model.init
end
def clear
post_init
@loader.reset
post_init
#MtkWebContext::RModel=Model.new
end
def index
end
def last_generated
post_init
@generated=@model.fileGenerated
end
def auto_complete_for_add_file_
p=params[ "add_file[]" ].to_s
puts "p=#{p}"
@filter_result=Array.new
Dir.glob("#{p}*").each { |f|
puts "f=#{f}"
h=Hash.new
h["to_s"]=f
@filter_result << h
break if @filter_result.length > 10
}
render :inline => "<%= auto_complete_result @filter_result, 'to_s' %>"
end
def auto_complete_for_filter_contains
puts "@@@@@@@@@@@@@@\ncall auto_complete_for_contact_name"
post_init
puts "0 params"
params.each{|p,v|
puts "auto #{p}-->#{v}"
}
puts "1 params"
filter=params[ :filter ][:contains].to_s
filter=/#{filter}/
#puts "params.raw_post=#{params.raw_post} size=#{@model.size}"
@filter_result=Array.new
@model.each_value { |res|
#puts "filter=#{filter} #{res.to_s} #{res.class.name}"
if (res.to_s =~ filter)
h=Hash.new
h["to_s"]="^#{res.to_s}$"
@filter_result << h
break if @filter_result.length > 10
end
}
#puts "filter!, #{filter} #{@filter_result.length}"
render :inline => "<%= auto_complete_result @filter_result, 'to_s' %>"
#render :partials => contact
end
def search_form
post_init
end
def search
post_init
params.each {|k,v|
puts("params #{k} --> #{v.class} #{v}")
}
filter=params[:filter][:contains].to_s
puts "filter=#{filter}"
filter=/#{filter}/
search_result=@model.reject { |key,res|
#puts "filter=#{filter} #{res.to_s} #{res.class.name}"
!(res.to_s =~ filter)
}
if search_result.size == 1
search_result.each { |key,res|
redirect_to :action => "show", :uri => key
}
else
@search_result=search_result
@filter=filter
#@model=m
render :action=> "search_result"
end
end
def search_result
post_init
filter=params[ "filter[x]" ].to_s
filter=/#{filter}/
@model=m
@search_result=@model.reject { |key,res|
#puts "filter=#{filter} #{res.to_s} #{res.class.name}"
!(res.to_s =~ filter)
}
render :action=> "search_result"
end
def show
post_init
#m=session[:rdfModel]
#model=MtkWebContext::RModel
#model.init
uri=params["uri"]
obj=@model[uri]
if obj==nil
puts "object not found (uri=#{uri})!!!!"
#@model=model.reject { false }
@uri=uri
render :action=> "not_found"
puts "object not found!!!!"
return
end
puts "object found (uri=#{uri})!!!!"
onglet_actif=params["onglet"]
onglet_actif="" if onglet_actif.nil?
show_obj(obj,onglet_actif)
end
def show_obj(obj,onglet_actif)
#out="
# uri=#{uri}
# model=#{@model==nil ? 'nil' : 'model loaded'}
# obj=#{obj==nil ? 'nil' : 'objet loaded'}
#"
puts "obj.class.name=#{obj.class.name}"
methods=Hash.new
vides=Array.new
erreurs=Array.new
onglets=Set.new
onglets << ""
on_demand=%w{ rdfx_clone }
black_list=%w{to_enum enum_for extended_by instance_values instance_variables object_id private_methods public_methods rdf_model to_a to_yaml to_yaml_style to_yaml_properties instance_eval instance_values private_methods object_id decode_b require_gem protected_methods silence_stderr enable_warnings ext_ instance_exec method_missing silence_stream silence_warnings singleton_methods subclasses_of to_json with_options stringify_keys symbolize_keys to_hash to_options to_set to_xml with_indifferent_access init_notUsed require_gem_with_options require_library_or_gem }
on_demand.reject!{ |elt| params["on_demand"]==elt }
obj.methods.find_all { |a|
#puts "operation:#{a} one=#{(a.to_s=~/^.*_one[0]$/)and true}"
a =~/^[a-zA-Z]+_[_a-zA-Z0-9]*\??$/ and !black_list.include?(a) and !on_demand.include?(a) and !(a=~/^.*_xxxone[0]$/) #and ! a=~ "_dot"
}.sort{|a,b| a<=>b}.each {|m|
#puts "operation=#{m} !!!!!!!!!!!!!!!!!!!!!!!!!!!!"
#if(on_demand.include?(a)
r=nil
sos=@model.mtk_stringWriteSession() {
begin
r=eval("obj.#{m}")
#puts " post eval"
rescue Warning =>warn
if m=~/.*_one$/
erreurs.push(m)
next
end
puts"warn=#{warn.message}"
r="Warning:"+warn.message.split(/:/,4)[3]
puts " rescue"
rescue StandardError =>boom
puts " rescue eval (!!)"
puts "boom #{boom.to_s}"
erreurs.push(m)
next
end
}
puts "sos=#{sos}/#{sos.to_s} #{sos.class.name}"
r=sos.to_s if sos!=nil
if(r==nil)
vides.push(m)
next
end
r=[r] if !r.respond_to?(:each)
if(r.length<=0)
vides.push(m)
else
#on ajoute m
prefix=m.split(/_/,3)[0]
onglets << prefix
methods[m]=r
end
}
@obj=obj
@methods=methods
@vides=vides
#@model=@model
@erreurs=erreurs
@on_demand=on_demand
@onglets=onglets
@onglet_actif=onglet_actif
end
def loadLocalRDFUpdateFile
post_init
fn=params["file"]
puts "\"File\"=\"#{fn}\""
@loader.addModelFile(fn)
#@model.loadModelFromFile(fn)
@model.mtk_context(:build => '../build/') {
@model.java_generate
}
render_text < "setup_form"
end
def setup_form
post_init
@activeProfiles=@loader.activeProfiles
@availableProfiles=@loader.availableProfiles
@sourceFiles=@loader.sourceFiles
end
def setup_change
post_init
add_file=params["add_file[]"]
if !add_file.nil? && add_file.length>0
puts "add_file=#{add_file}"
@loader.addModelFile(add_file)
end
key=1000
@loader.availableProfiles.each { |prof|
key=key+1
puts "!!!!!!!!"
puts params["check_#{key}"]
puts params["check_#{key}"]=="1"
if params["check_#{key}"]=="1"
puts "add #{prof}"
@loader.activeProfiles.add(prof)
else
puts "delete #{prof}"
@loader.activeProfiles.delete(prof)
end
}
redirect_to :action => "setup_form"
end
# essai pdf
def pdf
require "pdf/writer"
_pdf = PDF::Writer.new
_pdf.select_font "Times-Roman"
_pdf.text "Hello, Ruby.", :font_size => 72, :justification => :center
send_data _pdf.render, :filename => "hello.pdf",
:type => "application/pdf"
end
def model
post_init
show_obj(@model,"")
#render :action=> "show"
end
def dot
uri=params["uri"]
method=params["method"]
post_init
obj=@model[uri]
fn="#{Dir.tmpdir}/#{method}-#{obj.object_id}"
obj.mtk_writeSession("#{fn}.dot") {
obj.instance_eval(method)
}
cmd="dot -Tgif -o#{fn}.gif #{fn}.dot"
system(cmd)
send_file "#{fn}.gif", :type => 'image/gif', :disposition => 'inline'
end
end