Class: Caterpillar::Liferay
- Inherits:
-
Object
- Object
- Caterpillar::Liferay
- Defined in:
- lib/caterpillar/liferay.rb
Overview
Creates liferay-portlet XML and liferay-display XML. The latter optionally combines your production portlet display configuration.
See www.liferay.com/web/guest/community/wiki/-/wiki/Main/Liferay-portlet.xml
Supported portlet.xml tags: (*) stands for non-configurable
<portlet-name>
<icon> (*)
<instanceable> (*; always true)
5.1.x -specific:
<header-portal-javascript>
5.2.0 -specific:
<footer-portal-javascript>
<control-panel-entry-category>
<control-panel-entry-weight> (*; always 99.0)
TODO:
<footer-portlet-javascript>
<header-portlet-css>
<use-default-template>
<private-request-attributes>
<private-session-attributes>
<render-weight>
<restore-current-view>
Instance Attribute Summary collapse
-
#deploy_dir ⇒ Object
The directory where to deploy.
-
#root ⇒ Object
the installation directory.
-
#server ⇒ Object
server type: - ‘Tomcat’ - ‘JBoss/Tomcat’.
-
#server_dir ⇒ Object
the name of the JBoss server directory.
-
#version ⇒ Object
Liferay version.
Instance Method Summary collapse
-
#analyze(type = :native) ⇒ Object
Reads Liferay portlet descriptor XML files and parses them with Hpricot.
-
#display_xml(portlets) ⇒ Object
liferay-display XML.
-
#initialize(version = nil) ⇒ Liferay
constructor
Liferay version is given as a String, eg.
-
#name ⇒ Object
The name of the portal.
-
#portletapp_xml(portlets) ⇒ Object
liferay-portlet XML.
-
#skip_fixture_tables ⇒ Object
tables that are skipped when creating fixtures.
-
#WEB_INF ⇒ Object
The location of Liferay’s WEB-INF folder, relative to installation directory (@root).
Constructor Details
#initialize(version = nil) ⇒ Liferay
Liferay version is given as a String, eg. ‘5.2.2’.
63 64 65 66 67 68 |
# File 'lib/caterpillar/liferay.rb', line 63 def initialize(version=nil) @version = version || '6.0.6' @root = '/usr/local/liferay-portal-6.0.6/tomcat-6.0.29' @server = 'Tomcat' @deploy_dir = nil end |
Instance Attribute Details
#deploy_dir ⇒ Object
The directory where to deploy. By default, it is based on the servlet container name and the confured location of its root. It can also be defined from the configuration file: portlet.container.deploy_dir = ‘/opt/myDeployDir’
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/caterpillar/liferay.rb', line 80 def deploy_dir return @deploy_dir if @deploy_dir # user configuration case @server when 'Tomcat' raise 'Configure container root directory' unless @root return File.join(@root,'webapps') when 'JBoss/Tomcat' raise "Please configure deploy directory for JBoss." end end |
#root ⇒ Object
the installation directory
48 49 50 |
# File 'lib/caterpillar/liferay.rb', line 48 def root @root end |
#server ⇒ Object
server type:
- 'Tomcat'
- 'JBoss/Tomcat'
53 54 55 |
# File 'lib/caterpillar/liferay.rb', line 53 def server @server end |
#server_dir ⇒ Object
the name of the JBoss server directory
56 57 58 |
# File 'lib/caterpillar/liferay.rb', line 56 def server_dir @server_dir end |
#version ⇒ Object
Liferay version
45 46 47 |
# File 'lib/caterpillar/liferay.rb', line 45 def version @version end |
Instance Method Details
#analyze(type = :native) ⇒ Object
Reads Liferay portlet descriptor XML files and parses them with Hpricot.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/caterpillar/liferay.rb', line 115 def analyze(type=:native) require 'hpricot' return nil unless type==:native portlets = [] f=File.open(self.WEB_INF+'/portlet-custom.xml','r') custom_xml = Hpricot.XML(f.read) f.close f=File.open(self.WEB_INF+'/liferay-portlet.xml','r') portlet_xml = Hpricot.XML(f.read) f.close f=File.open(self.WEB_INF+'/liferay-display.xml','r') display_xml = Hpricot.XML(f.read) f.close (custom_xml/'portlet').each do |portlet| _p = { :id => (portlet/'portlet-name').innerHTML, :title => (portlet/'display-name').innerHTML } # search portlet metadata portlet_xml.search("//portlet-name").each do |p| if p.innerHTML==_p[:id] _p.update(:name => (p/"../struts-path").text) # is the portlet instanceable? # it seems that if undefined, the default is "false" _p.update(:instanceable => (p/"../instanceable").text=='true') end end # search the category - horribly ineffective. # the categories is an Array where each raising index is a new subcategory display_xml.search("display/category").each do |c| if (c/"//portlet[@id='#{_p[:id]}']").any? # the portlet is in this category categories = [c['name']] # child categories c.search("category").each do |child| categories << child['name'] end if categories.size > 1 _p.update(:categories => categories) else _p.update(:category => categories.first) end end end portlets << _p end return portlets end |
#display_xml(portlets) ⇒ Object
liferay-display XML
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/caterpillar/liferay.rb', line 198 def display_xml(portlets) liferay_display_file = File.join(self.WEB_INF,'liferay-display.xml') # read existing configuration _doc = REXML::Document.new File.new(liferay_display_file) display = _doc.root doc = REXML::Document.new doc << REXML::XMLDecl.new('1.0', 'utf-8') doc << REXML::DocType.new('display', 'PUBLIC '+\ '"-//Liferay//DTD Display %s//EN" ' % (self.dtd_version) +\ '"http://www.liferay.com/dtd/liferay-display_%s.dtd"' % self.dtd_version.gsub('.','_') ) doc << display # include portlets Util.categorize(portlets).each_pair do |category_name, portlets| category = nil display.each_element {|e| if e.attributes['name'] == category_name.to_s then category = e; break end} unless category category = REXML::Element.new('category', display) category.attributes['name'] = category_name.to_s end portlets.each do |portlet| if category.has_elements? # unless he holds does not add again category.each_element do |e| unless e.attributes['id'] == portlet[:name] category.add_element 'portlet', {'id' => portlet[:name]} break end end else category.add_element 'portlet', {'id' => portlet[:name]} end end end return Util.xml_to_s(doc) end |
#name ⇒ Object
The name of the portal. Used in STDOUT messages.
71 72 73 |
# File 'lib/caterpillar/liferay.rb', line 71 def name 'Liferay' end |
#portletapp_xml(portlets) ⇒ Object
liferay-portlet XML
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/caterpillar/liferay.rb', line 176 def portletapp_xml(portlets) doc = REXML::Document.new doc << REXML::XMLDecl.new('1.0', 'utf-8') doc << REXML::DocType.new('liferay-portlet-app', 'PUBLIC '+\ '"-//Liferay//DTD Portlet Application %s//EN" ' % (self.dtd_version) +\ '"http://www.liferay.com/dtd/liferay-portlet-app_%s.dtd"' % self.dtd_version.gsub('.','_') ) app = REXML::Element.new('liferay-portlet-app', doc) portlets.each do |portlet| # <portlet> app.elements << self.portlet_element(portlet) end # define role-mappers only once, at the end roles.each {|role| app.elements << role} return Util.xml_to_s(doc) end |
#skip_fixture_tables ⇒ Object
tables that are skipped when creating fixtures
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
# File 'lib/caterpillar/liferay.rb', line 321 def skip_fixture_tables %w{ cyrususer cyrusvirtual documentlibrary_fsentry documentlibrary_binval documentlibrary_node documentlibrary_prop documentlibrary_refs expandocolumn expandorow expandotable expandovalue image chat_entry chat_status journalcontentsearch mbban membershiprequest orglabor passwordpolicyrel passwordpolicy passwordtracker pluginsetting quartz_blob_triggers quartz_calendars quartz_cron_triggers quartz_fired_triggers quartz_job_details quartz_job_listeners quartz_locks quartz_paused_trigger_grps quartz_scheduler_state quartz_simple_triggers quartz_trigger_listeners quartz_triggers ratingsentry ratingsstats region scframeworkversion scframeworkversi_scproductvers schema_migrations sclicenses_scproductentries sclicense scproductentry scproductscreenshot scproductversion servicecomponent sessions shoppingcart shoppingcategory shoppingcoupon shoppingitemfield shoppingitemprice shoppingitem shoppingorderitem shoppingorder subscription tasksproposal tasksreview webdavprops website } end |
#WEB_INF ⇒ Object
The location of Liferay’s WEB-INF folder, relative to installation directory (@root). This is where the XML files are housed.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/caterpillar/liferay.rb', line 97 def WEB_INF raise 'Configure container root directory' unless @root case @server when 'Tomcat' return File.join(@root, %w{webapps ROOT WEB-INF}) when 'JBoss/Tomcat' # user should configure server_dir !! unless @server_dir raise 'Please configure server_dir for JBoss/Tomcat' end return File.join(@root, @server_dir, 'WEB-INF') end end |