Skip to content

Commit 94ce061

Browse files
fixed some bugeens
1 parent 987559b commit 94ce061

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

lib/viewer/documentFrame.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,38 @@ DocumentFrame.prototype.setErrors = function(errors, frameconf){
153153
for(var i = 0; i<errors.length; i++){
154154
addRuleForVio(frameconf, errors[i])
155155
}
156-
this.applyRules(false, frameconf);
156+
var myfilt = function(frame, rule){
157+
if(rule.errors()){
158+
frame.errors = frame.errors ? frame.errors.concat(rule.errors()) : rule.errors();
159+
}
160+
}
161+
this.applyRules(false, frameconf, myfilt);
157162
}
158163

159164
DocumentFrame.prototype.clearErrors = function(frameconf){
160-
frameconf.all().errors(false)
161-
this.applyRules(false, frameconf)
165+
frameconf.all()
166+
var myfilt = function(frame, rule){
167+
if(frame.errors) delete(frame.errors)
168+
}
169+
this.applyRules(false, frameconf, myfilt)
170+
frameconf.rules = []
162171
}
163172

164173
function addRuleForVio(docview, error){
165-
let prop = (error['api:property'] ? error['api:property']["@value"] : false)
166-
let subj = (error['api:subject'] ? error['api:subject']["@value"] : false)
167-
let val = (error['api:value'] ? error['api:value']["@value"] : false)
168-
let type = (error['api:type'] ? error['api:type']["@value"] : false)
174+
let prop = (error['vio:property'] ? error['vio:property']["@value"] : false)
175+
let subj = (error['vio:subject'] ? error['vio:subject']["@value"] : false)
176+
let msg = (error['vio:message'] ? error['vio:message']["@value"] : false)
177+
let val = (error['api:value'] ? error['api:value'] : false)
178+
if(val && val[0] == '"' && val[val.length-1] == '"')
179+
val = val.substring(1, val.length-1)
180+
let type = (error['api:type'] ? error['api:type'] : false)
169181
if(type && val){ //api:BadCast
170-
docview.data().value(val).range(type).errors([error])
182+
docview.data().value(val).type(type).errors([error])
183+
}
184+
if(prop && subj){//untypedInstanceViolation
185+
let shrt = FrameHelper.shorten(subj)
186+
if(shrt.substring(0, 5) == "woql:") shrt == shrt.substring(5)
187+
docview.data().property(prop).value(shrt, subj).errors([error])
171188
}
172189
}
173190

lib/viewer/frameRule.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ FrameRule.prototype.range = function(...prop){
102102
return this;
103103
}
104104

105+
/**
106+
* Specifies that only one from among the list of range types will match
107+
*/
108+
FrameRule.prototype.value = function(...prop){
109+
if(!prop || prop.length == 0) return this.pattern.value;
110+
this.pattern.value = prop;
111+
return this;
112+
}
113+
114+
105115
/**
106116
* Specifies that only frames of the specified depth will match the rule
107117
*/
@@ -404,8 +414,8 @@ FramePattern.prototype.checkProperty = function (rtype, frame) {
404414
*/
405415
FramePattern.prototype.checkType = function (rtype, frame) {
406416
if(rtype == "object") var vs = frame.subjectClass();
407-
else var vs = frame.range();
408-
if(!Array.isArray(this.type)) this.type = [this.type];
417+
else var vs = typeof frame.range == "function" ? frame.range() : frame.range;
418+
if(!Array.isArray(this.type)) this.type = [this.type];
409419
if(this.type.indexOf(vs) === -1) return false;
410420
return true;
411421
}
@@ -423,7 +433,7 @@ FramePattern.prototype.checkValue = function (rtype, frame) {
423433
if (typeof this.value !== 'object' || !this.value.length) this.value = [this.value];
424434
for (let i = 0; i < this.value.length; i++) {
425435
if (rtype == 'data') {
426-
if (this.valuesMatch(frame.value(), this.value[i])) {
436+
if (this.valuesMatch(frame.get(), this.value[i])) {
427437
return true;
428438
}
429439
} else if (rtype == 'property') {

0 commit comments

Comments
 (0)