lib/rmobio/utils.rb in rmobio-1.1.3 vs lib/rmobio/utils.rb in rmobio-1.1.4

- old
+ new

@@ -1,71 +1,70 @@ -# +# # Copyright (C) 2007 Mobio Networks, Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see <http://www.gnu.org/licenses/>. +# =begin Some summary should go here =end -#require 'rexml/document' +# #require 'rexml/document' require 'open-uri' require 'hpricot' module Rmobio module Utils - #== cachControl - #=== Adding cache control to response header + # #== cachControl #=== Adding cache control to response header def cacheControl(cacheStr='priority=P3;max-age=604800') headers.delete("Cache-Control"); headers["Cache-Control"] = cacheStr; end - #== cacheloader - #=== A utility method to add cache control to images, styles and files - # To add a cache control, edit the configuration file 'cachehints.txt' with - # filename and header. Here is a ample configuration: + # #== cacheloader #=== A utility method to add cache control to images, + # styles and files To add a cache control, edit the configuration file + # 'cachehints.txt' with filename and header. Here is a ample configuration: # # - #<tt>logo.png: priority=P2;max-age=1296000</tt> - # - #<tt>base.rhtml: priority=P2;max-age=1296000</tt> - # - # - # The utility assumes base directory for images files in RAILS_ROOT/public/images - # and other files in RAILS_ROOT/apps/views. + # #<tt>logo.png: priority=P2;max-age=1296000</tt> # + # #<tt>base.rhtml: priority=P2;max-age=1296000</tt> # + # + # The utility assumes base directory for images files in + # RAILS_ROOT/public/images and other files in RAILS_ROOT/apps/views. + # + # # To access the image in your xform, use the following pattern: - #<tt><icon>recipe/loader?name=logo.png</icon></tt> - # To access the style in your xform, use the following pattern: - #<tt><style xmlns="http://www.mobio.com/ext" src="recipe/loader?name=layouts/base.rhtml"/></tt> - # - # where the controller 'recipe' should provide a method 'loader' that calls this - # utility: + # #<tt><icon>recipe/loader?name=logo.png</icon></tt> To access the style in + # your xform, use the following pattern: #<tt><style + # xmlns="http://www.mobio.com/ext" + # src="recipe/loader?name=layouts/base.rhtml"/></tt> + # + # where the controller 'recipe' should provide a method 'loader' that calls + # this utility: # def loader # cacheloader # end # def cacheloader if (name=params[:name]).nil? - # Can't do anything, just return empty content so we don't get - # 'no template' error. + # Can't do anything, just return empty content so we don't get 'no + # template' error. render :text => '' return end # Default cache configuration file @@ -105,24 +104,22 @@ end render :template => name end - #== cacheimg - #=== A utility method to add cache control to images - #=== This utility is deprecated, use cacheloader instead - # To add a cache control for an image file in RAILS_ROOT/public/images, edit - # the configuration file "cachehints.txt with image name and header. Ex: + # #== cacheimg #=== A utility method to add cache control to images #=== + # This utility is deprecated, use cacheloader instead To add a cache control + # for an image file in RAILS_ROOT/public/images, edit the configuration file + # "cachehints.txt with image name and header. Ex: # # logo.png: priority=P2;max-age=1296000 # # To access the image in your xforms, use the following pattern: - # <icon>img?name=logo.png</icon> - # Where the controller should provide an img method that just call this cacheimg utility. - # - # Sample cachehints.txt: - # Skins_176A2-a.png: priority=P2;max-age=1296000 + # <icon>img?name=logo.png</icon> Where the controller should provide an img + # method that just call this cacheimg utility. + # + # Sample cachehints.txt: Skins_176A2-a.png: priority=P2;max-age=1296000 # logo.png: priority=P2;max-age=1296000 # def cacheimg public_folder = File::join RAILS_ROOT, "public/images" filePath = File::join RAILS_ROOT, "public/images", params['name'] @@ -150,44 +147,44 @@ end end render :text => filecontents end - #== backURL(key) - # This utility handles back url to GLP if page is cached. - # It expects params[:burl] or a session key and renders - # the following xml data back to the caller: + # #== backURL(key) This utility handles back url to GLP if page is cached. + # It expects params[:burl] or a session key and renders the following xml + # data back to the caller: # # <data xmlns=""> # <burl>blah blah url</burl> # </data> - # - # The returned instance data <burl> is determined by the following rules: - #* params[:burl] if parameter exists, the url in the session is also updated - #* session[:key] if params[:burl] is nil - #* empty string if none of the above # - # + # The returned instance data <burl> is determined by the following rules: #* + # params[:burl] if parameter exists, the url in the session is also updated + # #* session[:key] if params[:burl] is nil #* empty string if none of the + # above + # + # # To access the backurl from your xfroms, use the following pattern: # - # <xf:instance id="homepage" src="storeBackurl?burl=SOMEURL" /> - # - # Where the controller should provide a "storeBackurl" method that just call this backURL utility: + # <xf:instance id="homepage" src="storeBackurl?burl=SOMEURL" /> + # + # Where the controller should provide a "storeBackurl" method that just call + # this backURL utility: # def storeBackurl # backURL("recipe_burl") - # end + # end # - #=== Parameter - # key => a unique session key to store the burl for the app + # #=== Parameter key => a unique session key to store the burl for the app # def backURL(key) url = backurl_xml(key) headers['Content-Type']='application/xml' render :text => "<data xmlns=\"\">" + url + "</data>" end # end backURLg - # if you want to just return partial backurl without headers and no rendering + # if you want to just return partial backurl without headers and no + # rendering def backurl_xml(key) if params[:burl] url = params[:burl].gsub(/&/,'&amp;') session[key] = url elsif session[key] @@ -206,9 +203,20 @@ logger.debug( header.to_s + ': ' + request.env[header].to_s) end logger.debug("End of Headers...") end - + # Retrieve the domain string from a given uri + def self.get_domain(uri) + uritokens = uri.split('/') + uritokens.each_with_index do |token,index| + if(token == 'w') + @domain = uritokens[index + 1] + RAILS_DEFAULT_LOGGER.debug 'Utils: Setting domain to ' + + @domain + '...' unless not defined? RAILS_DEFAULT_LOGGER + end + end + @domain + end end #end Utils end #end Rmobio include Rmobio::Utils \ No newline at end of file