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)+encodevalue(v)
91 when 'Bignum','Fixnum','Float'
96 RAILS_DEFAULT_LOGGER.error("Unexpected Ruby type for AMF conversion: "+n.class.to_s)
100 # Encode string with two-byte length
101 def self.encodestring(n)
102 a,b=n.size.divmod(256)
106 # Encode number as eight-byte double precision float
107 def self.encodedouble(n)
111 # Encode number as four-byte long
112 def self.encodelong(n)
119 # The Potlatch class is a helper for Potlatch
124 # does: reads tag preset menus, colours, and autocomplete config files
125 # out: [0] presets, [1] presetmenus, [2] presetnames,
126 # [3] colours, [4] casing, [5] areas, [6] autotags
129 RAILS_DEFAULT_LOGGER.info(" Message: getpresets")
133 presetmenus={}; presetmenus['point']=[]; presetmenus['way']=[]; presetmenus['POI']=[]
134 presetnames={}; presetnames['point']={}; presetnames['way']={}; presetnames['POI']={}
137 # StringIO.open(txt) do |file|
138 File.open("#{RAILS_ROOT}/config/potlatch/presets.txt") do |file|
139 file.each_line {|line|
141 if (t=~/(\w+)\/(\w+)/) then
144 presetmenus[presettype].push(presetcategory)
145 presetnames[presettype][presetcategory]=["(no preset)"]
146 elsif (t=~/^(.+):\s?(.+)$/) then
148 presetnames[presettype][presetcategory].push(pre)
150 kv.split(',').each {|a|
151 if (a=~/^(.+)=(.*)$/) then presets[pre][$1]=$2 end
157 # Read colours/styling
158 colours={}; casing={}; areas={}
159 File.open("#{RAILS_ROOT}/config/potlatch/colours.txt") do |file|
160 file.each_line {|line|
162 if (t=~/(\w+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)/) then
164 if ($2!='-') then colours[tag]=$2.hex end
165 if ($3!='-') then casing[tag]=$3.hex end
166 if ($4!='-') then areas[tag]=$4.hex end
171 # Read relations colours/styling
172 relcolours={}; relalphas={}; relwidths={}
173 File.open("#{RAILS_ROOT}/config/potlatch/relation_colours.txt") do |file|
174 file.each_line {|line|
176 if (t=~/(\w+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)/) then
178 if ($2!='-') then relcolours[tag]=$2.hex end
179 if ($3!='-') then relalphas[tag]=$3.to_i end
180 if ($4!='-') then relwidths[tag]=$4.to_i end
186 autotags={}; autotags['point']={}; autotags['way']={}; autotags['POI']={};
187 File.open("#{RAILS_ROOT}/config/potlatch/autocomplete.txt") do |file|
188 file.each_line {|line|
190 if (t=~/^(\w+)\/(\w+)\s+(.+)$/) then
191 tag=$1; type=$2; values=$3
192 if values=='-' then autotags[type][tag]=[]
193 else autotags[type][tag]=values.split(',').sort.reverse end
198 [presets,presetmenus,presetnames,colours,casing,areas,autotags,relcolours,relalphas,relwidths]