validate properties on xml objects. fixes #6

This commit is contained in:
Konstantin Käfer 2011-02-07 14:56:11 -05:00
parent 59fe61267f
commit d6255165c7
3 changed files with 16 additions and 27 deletions

View File

@ -186,10 +186,6 @@ carto.Parser = function Parser(env) {
this.env = env = env || {};
this.env.filename = this.env.filename || null;
this.env.error = function(e) {
if (!env.errors) env.errors = [];
env.errors.push(e);
};
//
// The Parser
@ -318,7 +314,7 @@ carto.Parser = function Parser(env) {
return function(env) {
env.error = function(e) {
if (!env.errors) env.errors = [];
env.errors.push(e);
env.errors.push(root.makeError(e));
};
env.errors = [];
env.frames = env.frames || [];
@ -326,10 +322,6 @@ carto.Parser = function Parser(env) {
// call populates Invalid-caused errors
var definitions = this.flatten([], [], env);
definitions.sort(specificitySort);
env.errors = env.errors.map(function(e) {
_.extend(e, root.makeError(e));
return e;
});
return definitions;
};
})();

View File

@ -315,7 +315,7 @@ carto.Renderer = function Renderer(env) {
var key = r.rules[i].name;
if (!(key in tree.Reference.data.symbolizers.map)) {
throw {
message: 'Attribute ' + key + ' not allowed for Map.',
message: 'Rule ' + key + ' not allowed for Map.',
index: r.rules[i].index
};
}
@ -390,7 +390,14 @@ carto.Renderer = function Renderer(env) {
Step(
function() {
var group = this.group();
var map_properties = that.getMapProperties(rulesets, env);
try {
var map_properties = that.getMapProperties(rulesets, env);
} catch(err) {
env.error(err);
callback(env.errors);
return;
}
if (!map_properties.srs) {
map_properties.srs = 'srs="+proj=merc +a=6378137 ' +
@ -429,21 +436,11 @@ carto.Renderer = function Renderer(env) {
output.push('</Map>');
env.errors.map(function(e) {
if (!e.line && e.index && e.filename) {
var matches = stylesheets.filter(function(s) {
return s[0] == e.filename;
});
if (matches.length && matches[0][1]) {
return _.extend(e, matches[0][1].makeError(e));
}
}
});
callback(env.errors.length ?
env.errors :
null,
output.join('\n'));
if (env.errors.length) {
callback(env.errors);
} else {
callback(null, output.join('\n'))
}
}
);
},

View File

@ -31,7 +31,7 @@ tree.Rule.prototype.toString = function() {
tree.Rule.prototype.toXML = function(env) {
if (!tree.Reference.validSelector(this.name)) {
return env.error({
message: "Unrecognized selector: " + this.name,
message: "Unrecognized rule: " + this.name,
index: this.index,
type: 'syntax',
filename: this.filename