| 146 | | else if (v.first != "<xmlcomment>" && |
| 147 | | v.first != "<xmlattr>") |
| 148 | | { |
| 149 | | throw config_error(std::string("Unknown child node in 'Map'. ") + |
| 150 | | "Expected 'Style' or 'Layer' but got '" + v.first + "'"); |
| 151 | | } |
| 152 | | } |
| 153 | | } |
| 154 | | catch (const boost::property_tree::ptree_bad_path &) |
| 155 | | { |
| 156 | | throw config_error("Not a map file. Node 'Map' not found."); |
| 157 | | } |
| 158 | | } |
| 159 | | |
| 160 | | void map_parser::parse_style( Map & map, ptree const & sty ) |
| 161 | | { |
| 162 | | string name("<missing name>"); |
| 163 | | try |
| 164 | | { |
| 165 | | name = get_attr<string>(sty, "name"); |
| 166 | | feature_type_style style; |
| 167 | | |
| 168 | | ptree::const_iterator ruleIter = sty.begin(); |
| 169 | | ptree::const_iterator endRule = sty.end(); |
| 170 | | |
| 171 | | for (; ruleIter!=endRule; ++ruleIter) |
| 172 | | { |
| 173 | | ptree::value_type const& rule_tag = *ruleIter; |
| 174 | | if (rule_tag.first == "Rule") |
| 175 | | { |
| 176 | | parse_rule( style, rule_tag.second ); |
| 177 | | } |
| 178 | | else if (rule_tag.first != "<xmlcomment>" && |
| 179 | | rule_tag.first != "<xmlattr>" ) |
| 180 | | { |
| 181 | | throw config_error(std::string("Unknown child node in 'Style'.") + |
| 182 | | "Expected 'Rule' but got '" + rule_tag.first + "'"); |
| 183 | | } |
| 184 | | } |
| 185 | | |
| 186 | | map.insert_style(name, style); |
| 187 | | |
| 188 | | } catch (const config_error & ex) { |
| 189 | | if ( ! name.empty() ) { |
| 190 | | ex.append_context(string("in style '") + name + "'"); |
| 191 | | } |
| 192 | | throw; |
| 193 | | } |
| 194 | | } |
| 195 | | |
| 196 | | void map_parser::parse_layer( Map & map, ptree const & lay ) |
| 197 | | { |
| 198 | | std::string name; |
| 199 | | try |
| 200 | | { |
| 201 | | name = get_attr(lay, "name", string("Unnamed")); |
| 202 | | // XXX if no projection is given inherit from map? [DS] |
| 203 | | std::string srs = get_attr(lay, "srs", map.srs()); |
| 204 | | |
| 205 | | Layer lyr(name, srs); |
| 206 | | |
| 207 | | optional<boolean> status = get_opt_attr<boolean>(lay, "status"); |
| 208 | | if (status) |
| 209 | | { |
| 210 | | lyr.setActive( * status ); |
| 211 | | } |
| 212 | | |
| 213 | | optional<boolean> clear_cache = |
| 214 | | get_opt_attr<boolean>(lay, "clear_label_cache"); |
| 215 | | if (clear_cache) |
| 216 | | { |
| 217 | | lyr.set_clear_label_cache( * clear_cache ); |
| 218 | | } |
| 219 | | |
| 220 | | |
| 221 | | ptree::const_iterator itr2 = lay.begin(); |
| 222 | | ptree::const_iterator end2 = lay.end(); |
| 223 | | |
| 224 | | for(; itr2 != end2; ++itr2) |
| 225 | | { |
| 226 | | ptree::value_type const& child = *itr2; |
| 227 | | |
| 228 | | if (child.first == "StyleName") |
| 229 | | { |
| 230 | | // TODO check references [DS] |
| 231 | | lyr.add_style(child.second.data()); |
| 232 | | } |
| 233 | | else if (child.first == "Datasource") |
| 234 | | { |
| | 148 | else if (v.first == "FileSource") |
| | 149 | { |
| | 150 | std::string name = get_attr<string>( v.second, "name"); |
| | 151 | std::string value = get_own<string>( v.second, ""); |
| | 152 | file_sources_[name] = value; |
| | 153 | } |
| | 154 | else if (v.first == "Datasource") |
| | 155 | { |
| | 156 | std::string name = get_attr(v.second, "name", string("Unnamed")); |
| 249 | | else |
| | 171 | else if( paramIter->first != "<xmlattr>" ) |
| | 172 | { |
| | 173 | throw config_error(std::string("Unknown child node in ") + |
| | 174 | "'Datasource'. Expected 'Parameter' but got '" + |
| | 175 | paramIter->first + "'"); |
| | 176 | } |
| | 177 | } |
| | 178 | datasource_templates_[name] = params; |
| | 179 | } |
| | 180 | else if (v.first != "<xmlcomment>" && |
| | 181 | v.first != "<xmlattr>") |
| | 182 | { |
| | 183 | throw config_error(std::string("Unknown child node in 'Map'. ") + |
| | 184 | "Expected 'Style' or 'Layer' but got '" + v.first + "'"); |
| | 185 | } |
| | 186 | } |
| | 187 | } |
| | 188 | catch (const boost::property_tree::ptree_bad_path &) |
| | 189 | { |
| | 190 | throw config_error("Not a map file. Node 'Map' not found."); |
| | 191 | } |
| | 192 | } |
| | 193 | |
| | 194 | void map_parser::parse_style( Map & map, ptree const & sty ) |
| | 195 | { |
| | 196 | string name("<missing name>"); |
| | 197 | try |
| | 198 | { |
| | 199 | name = get_attr<string>(sty, "name"); |
| | 200 | feature_type_style style; |
| | 201 | |
| | 202 | ptree::const_iterator ruleIter = sty.begin(); |
| | 203 | ptree::const_iterator endRule = sty.end(); |
| | 204 | |
| | 205 | for (; ruleIter!=endRule; ++ruleIter) |
| | 206 | { |
| | 207 | ptree::value_type const& rule_tag = *ruleIter; |
| | 208 | if (rule_tag.first == "Rule") |
| | 209 | { |
| | 210 | parse_rule( style, rule_tag.second ); |
| | 211 | } |
| | 212 | else if (rule_tag.first != "<xmlcomment>" && |
| | 213 | rule_tag.first != "<xmlattr>" ) |
| | 214 | { |
| | 215 | throw config_error(std::string("Unknown child node in 'Style'.") + |
| | 216 | "Expected 'Rule' but got '" + rule_tag.first + "'"); |
| | 217 | } |
| | 218 | } |
| | 219 | |
| | 220 | map.insert_style(name, style); |
| | 221 | |
| | 222 | } catch (const config_error & ex) { |
| | 223 | if ( ! name.empty() ) { |
| | 224 | ex.append_context(string("in style '") + name + "'"); |
| | 225 | } |
| | 226 | throw; |
| | 227 | } |
| | 228 | } |
| | 229 | |
| | 230 | void map_parser::parse_layer( Map & map, ptree const & lay ) |
| | 231 | { |
| | 232 | std::string name; |
| | 233 | try |
| | 234 | { |
| | 235 | name = get_attr(lay, "name", string("Unnamed")); |
| | 236 | // XXX if no projection is given inherit from map? [DS] |
| | 237 | std::string srs = get_attr(lay, "srs", map.srs()); |
| | 238 | |
| | 239 | Layer lyr(name, srs); |
| | 240 | |
| | 241 | optional<boolean> status = get_opt_attr<boolean>(lay, "status"); |
| | 242 | if (status) |
| | 243 | { |
| | 244 | lyr.setActive( * status ); |
| | 245 | } |
| | 246 | |
| | 247 | optional<boolean> clear_cache = |
| | 248 | get_opt_attr<boolean>(lay, "clear_label_cache"); |
| | 249 | if (clear_cache) |
| | 250 | { |
| | 251 | lyr.set_clear_label_cache( * clear_cache ); |
| | 252 | } |
| | 253 | |
| | 254 | |
| | 255 | ptree::const_iterator itr2 = lay.begin(); |
| | 256 | ptree::const_iterator end2 = lay.end(); |
| | 257 | |
| | 258 | for(; itr2 != end2; ++itr2) |
| | 259 | { |
| | 260 | ptree::value_type const& child = *itr2; |
| | 261 | |
| | 262 | if (child.first == "StyleName") |
| | 263 | { |
| | 264 | // TODO check references [DS] |
| | 265 | lyr.add_style(child.second.data()); |
| | 266 | } |
| | 267 | else if (child.first == "Datasource") |
| | 268 | { |
| | 269 | parameters params; |
| | 270 | optional<std::string> base = get_opt_attr<std::string>( child.second, "base" ); |
| | 271 | if( base ) |
| | 272 | { |
| | 273 | std::map<std::string,parameters>::const_iterator base_itr = datasource_templates_.find(*base); |
| | 274 | if (base_itr!=datasource_templates_.end()) |
| | 275 | params = base_itr->second; |
| | 276 | } |
| | 277 | |
| | 278 | ptree::const_iterator paramIter = child.second.begin(); |
| | 279 | ptree::const_iterator endParam = child.second.end(); |
| | 280 | for (; paramIter != endParam; ++paramIter) |
| | 281 | { |
| | 282 | ptree const& param = paramIter->second; |
| | 283 | |
| | 284 | if (paramIter->first == "Parameter") |
| | 285 | { |
| | 286 | std::string name = get_attr<string>(param, "name"); |
| | 287 | std::string value = get_own<string>( param, |
| | 288 | "datasource parameter"); |
| | 289 | params[name] = value; |
| | 290 | } |
| | 291 | else if( paramIter->first != "<xmlattr>" ) |