Stricter re number of arguments for parseXml/Html and clearer err msgs

This commit is contained in:
Owen Stephens 2018-11-21 15:58:59 +00:00
parent 1f023b53af
commit d144a5dccf
5 changed files with 9 additions and 10 deletions

View File

@ -48,7 +48,7 @@ public class InnerHtml implements Function {
@Override
public Object call(Properties bindings, Object[] args) {
if (args.length >= 1) {
if (args.length == 1) {
Object o1 = args[0];
if (o1 != null && o1 instanceof Element) {
return new InnerXml().call(bindings, args, "html");
@ -56,7 +56,7 @@ public class InnerHtml implements Function {
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " failed as the first parameter is not an HTML Element. Please first use parseHtml(string) and select(query) prior to using this function");
}
}
return null;
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a single String as an argument");
}

View File

@ -37,7 +37,6 @@ import java.util.Properties;
import org.json.JSONException;
import org.json.JSONWriter;
import org.jsoup.Jsoup;
import com.google.refine.expr.EvalError;
import com.google.refine.expr.functions.xml.ParseXml;

View File

@ -47,17 +47,17 @@ public class OwnText implements Function {
@Override
public Object call(Properties bindings, Object[] args) {
if (args.length >= 1) {
if (args.length == 1) {
Object o1 = args[0];
if (o1 != null && o1 instanceof Element) {
Element e1 = (Element)o1;
return e1.ownText();
}else{
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " failed as the first parameter is not an HTML Element. Please first use parseHtml(string) and select(query) prior to using this function");
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " failed as the first parameter is not an XML or HTML Element. Please first use parseHtml(string) and select(query) prior to using this function");
}
}
return null;
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a single XML or HTML element as an argument");
}

View File

@ -47,7 +47,7 @@ public class XmlAttr implements Function {
@Override
public Object call(Properties bindings, Object[] args) {
if (args.length >= 2) {
if (args.length == 2) {
Object o1 = args[0];
Object o2 = args[1];
if (o1 != null && o1 instanceof Element) {
@ -59,7 +59,7 @@ public class XmlAttr implements Function {
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " failed as the first parameter is not an XML or HTML Element. Please first use parseXml() or parseHtml() and select() prior to using this function");
}
}
return null;
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects two arguments");
}

View File

@ -47,7 +47,7 @@ public class XmlText implements Function {
@Override
public Object call(Properties bindings, Object[] args) {
if (args.length >= 1) {
if (args.length == 1) {
Object o1 = args[0];
if (o1 != null && o1 instanceof Element) {
Element e1 = (Element)o1;
@ -57,7 +57,7 @@ public class XmlText implements Function {
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " failed as the first parameter is not an XML or HTML Element. Please first use parseXml() or parseHtml() and select(query) prior to using this function");
}
}
return null;
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a single XML or HTML element as an argument");
}