# encoding: utf-8 #-- # (c) Copyright 2008, 2010 Mikael Lammentausta # See the file LICENSES.txt included with the distribution for # software license details. #++ module Caterpillar # Formulates generic JSR286 portlet XML class Portlet class << self # Creates portlet XML def xml(portlets) session = begin { :key => Caterpillar::Security.get_session_key(), :secret => Caterpillar::Security.get_secret() } rescue nil end xml = self.header portlets.each do |p| xml << self.template(p,session) end xml << self.footer return xml end def debug(config,routes) # :nodoc: routes.select{|r| !r[:name].empty?}.each do |route| puts '%s: %s' % [route[:name], route[:path]] end end # Rails-portlet Java class def portlet_class 'com.celamanzi.liferay.portlets.rails286.Rails286Portlet' end # Rails-portlet Java class for 0.10.0+ def portlet_filter_class 'com.celamanzi.liferay.portlets.rails286.Rails286PortletFilter' end # JSR 286 portlet XML header. Opens portlet-app. def header xml = '' +"\n" xml << '' xml << "\n\n" return xml end # Closes portlet-app. def footer '' + "\n" end # portlet.xml template. # session is a hash containing session key and secret from Rails. def template(portlet,session=nil) # add roles # TODO: move into portlet hash # administrator, power-user, user roles = %w{ administrator } xml = " \n" % portlet[:title] xml << " \n" ### identification xml << " %s\n" % portlet[:name] xml << " %s\n" % self.portlet_class ### supported portlet modes xml << " \n" xml << " text/html\n" xml << " view\n" if portlet[:edit_mode] == true xml << " edit\n" end xml << " \n" ### title for portlet container xml << " \n" xml << " %s\n" % portlet[:title] xml << " \n" ### init parameters, XXX: fails xsd test #=begin # insert session key unless session.nil? xml << " \n"+\ " session_key\n"+\ " #{session[:key]}\n"+\ " \n" end # insert secret unless session.nil? xml << " \n"+\ " secret\n"+\ " #{session[:secret]}\n"+\ " \n" end #=end roles.each do |role| xml << " \n" xml << " #{role}\n" xml << " \n" end xml << " \n\n" ### portlet filters xml << " \n" # the filter reads the settings and sets the portlet session xml << " %s_filter\n" % portlet[:name] xml << " %s\n" % self.portlet_filter_class xml << " RENDER_PHASE\n" xml << " RESOURCE_PHASE\n" # define host, servlet and route (path to be more precise) xml << " \n" xml << " host\n" xml << " %s\n" % portlet[:host] || "" xml << " \n" xml << " \n" xml << " servlet\n" xml << " %s\n" % portlet[:servlet] xml << " \n" xml << " \n" xml << " route\n" xml << " %s\n" % portlet[:path].gsub(/&/,"&") xml << " \n" xml << " \n\n" xml << " \n" xml << " %s_filter\n" % portlet[:name] xml << " %s\n" % portlet[:name] xml << " \n" xml << "\n" end end # static methods end end