1 # The Potlatch module provides helper functions for potlatch and its communication with the server
4 # The AMF class is a set of helper functions for encoding and decoding AMF.
7 # Return two-byte integer
12 # Return four-byte long
14 ((s.getc*256+s.getc)*256+s.getc)*256+s.getc
17 # Return string with two-byte length
23 # Return eight-byte double-precision float
25 a=s.read(8).unpack('G') # G big-endian, E little-endian
29 # Return numeric array
42 while (key=getstring(s))
43 if (key=='') then break end
46 s.getc # skip the 9 'end of object' value
53 when 0; return getdouble(s) # number
54 when 1; return s.getc # boolean
55 when 2; return getstring(s) # string
56 when 3; return getobject(s) # object/hash
57 when 5; return nil # null
58 when 6; return nil # undefined
59 when 8; s.read(4) # mixedArray
60 return getobject(s) # |
61 when 10;return getarray(s) # array
62 else; return nil # error
66 # Envelope data into AMF writeable form
67 def self.putdata(index,n)
68 d =encodestring(index+"/onResult")
69 d+=encodestring("null")
74 # Pack variables as AMF
75 def self.encodevalue(n)
78 a=10.chr+encodelong(n.length)
86 a+=encodestring(k.to_s)+encodevalue(v)
91 when 'Bignum','Fixnum','Float'
100 RAILS_DEFAULT_LOGGER.error("Unexpected Ruby type for AMF conversion: "+n.class.to_s)
104 # Encode string with two-byte length
105 def self.encodestring(n)
106 a,b=n.size.divmod(256)
110 # Encode number as eight-byte double precision float
111 def self.encodedouble(n)
115 # Encode number as four-byte long
116 def self.encodelong(n)
123 # The Potlatch class is a helper for Potlatch
128 # does: reads tag preset menus, colours, and autocomplete config files
129 # out: [0] presets, [1] presetmenus, [2] presetnames,
130 # [3] colours, [4] casing, [5] areas, [6] autotags
133 RAILS_DEFAULT_LOGGER.info(" Message: getpresets")
137 presetmenus={}; presetmenus['point']=[]; presetmenus['way']=[]; presetmenus['POI']=[]
138 presetnames={}; presetnames['point']={}; presetnames['way']={}; presetnames['POI']={}
141 # StringIO.open(txt) do |file|
142 File.open("#{RAILS_ROOT}/config/potlatch/presets.txt") do |file|
143 file.each_line {|line|
145 if (t=~/(\w+)\/(\w+)/) then
148 presetmenus[presettype].push(presetcategory)
149 presetnames[presettype][presetcategory]=["(no preset)"]
150 elsif (t=~/^([\w\s]+):\s?(.+)$/) then
152 presetnames[presettype][presetcategory].push(pre)
154 kv.split(',').each {|a|
155 if (a=~/^(.+)=(.*)$/) then presets[pre][$1]=$2 end
161 # Read colours/styling
162 colours={}; casing={}; areas={}
163 File.open("#{RAILS_ROOT}/config/potlatch/colours.txt") do |file|
164 file.each_line {|line|
166 if (t=~/(\w+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)/) then
168 if ($2!='-') then colours[tag]=$2.hex end
169 if ($3!='-') then casing[tag]=$3.hex end
170 if ($4!='-') then areas[tag]=$4.hex end
175 # Read relations colours/styling
176 relcolours={}; relalphas={}; relwidths={}
177 File.open("#{RAILS_ROOT}/config/potlatch/relation_colours.txt") do |file|
178 file.each_line {|line|
180 if (t=~/(\w+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)/) then
182 if ($2!='-') then relcolours[tag]=$2.hex end
183 if ($3!='-') then relalphas[tag]=$3.to_i end
184 if ($4!='-') then relwidths[tag]=$4.to_i end
190 icon_list=[]; icon_tags={};
191 File.open("#{RAILS_ROOT}/config/potlatch/icon_presets.txt") do |file|
192 file.each_line {|line|
193 (icon,tags)=line.chomp.split("\t")
195 icon_tags[icon]=Hash[*tags.scan(/([^;=]+)=([^;=]+)/).flatten]
201 autotags={}; autotags['point']={}; autotags['way']={}; autotags['POI']={};
202 File.open("#{RAILS_ROOT}/config/potlatch/autocomplete.txt") do |file|
203 file.each_line {|line|
205 if (t=~/^([\w:]+)\/(\w+)\s+(.+)$/) then
206 tag=$1; type=$2; values=$3
207 if values=='-' then autotags[type][tag]=[]
208 else autotags[type][tag]=values.split(',').sort.reverse end
213 [presets,presetmenus,presetnames,colours,casing,areas,autotags,relcolours,relalphas,relwidths,icon_list,{},icon_tags]