More error checking.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@54 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
149330fe05
commit
8701d504e6
@ -14,6 +14,7 @@ import org.json.JSONWriter;
|
|||||||
import com.metaweb.gridworks.commands.Command;
|
import com.metaweb.gridworks.commands.Command;
|
||||||
import com.metaweb.gridworks.expr.Evaluable;
|
import com.metaweb.gridworks.expr.Evaluable;
|
||||||
import com.metaweb.gridworks.expr.ExpressionUtils;
|
import com.metaweb.gridworks.expr.ExpressionUtils;
|
||||||
|
import com.metaweb.gridworks.expr.HasFields;
|
||||||
import com.metaweb.gridworks.expr.Parser;
|
import com.metaweb.gridworks.expr.Parser;
|
||||||
import com.metaweb.gridworks.model.Cell;
|
import com.metaweb.gridworks.model.Cell;
|
||||||
import com.metaweb.gridworks.model.Project;
|
import com.metaweb.gridworks.model.Project;
|
||||||
@ -31,8 +32,6 @@ public class PreviewExpressionCommand extends Command {
|
|||||||
int cellIndex = Integer.parseInt(request.getParameter("cellIndex"));
|
int cellIndex = Integer.parseInt(request.getParameter("cellIndex"));
|
||||||
|
|
||||||
String expression = request.getParameter("expression");
|
String expression = request.getParameter("expression");
|
||||||
Evaluable eval = new Parser(expression).getExpression();
|
|
||||||
|
|
||||||
String rowIndicesString = request.getParameter("rowIndices");
|
String rowIndicesString = request.getParameter("rowIndices");
|
||||||
if (rowIndicesString == null) {
|
if (rowIndicesString == null) {
|
||||||
respond(response, "{ \"code\" : \"error\", \"message\" : \"No row indices specified\" }");
|
respond(response, "{ \"code\" : \"error\", \"message\" : \"No row indices specified\" }");
|
||||||
@ -43,8 +42,11 @@ public class PreviewExpressionCommand extends Command {
|
|||||||
int length = rowIndices.length();
|
int length = rowIndices.length();
|
||||||
|
|
||||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Evaluable eval = new Parser(expression).getExpression();
|
||||||
|
|
||||||
writer.key("code"); writer.value("ok");
|
writer.key("code"); writer.value("ok");
|
||||||
writer.key("results"); writer.array();
|
writer.key("results"); writer.array();
|
||||||
|
|
||||||
@ -57,7 +59,7 @@ public class PreviewExpressionCommand extends Command {
|
|||||||
Row row = project.rows.get(rowIndex);
|
Row row = project.rows.get(rowIndex);
|
||||||
if (cellIndex < row.cells.size()) {
|
if (cellIndex < row.cells.size()) {
|
||||||
Cell cell = row.cells.get(cellIndex);
|
Cell cell = row.cells.get(cellIndex);
|
||||||
if (cell.value != null) {
|
if (cell != null && cell.value != null) {
|
||||||
ExpressionUtils.bind(bindings, row, cell);
|
ExpressionUtils.bind(bindings, row, cell);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -69,9 +71,18 @@ public class PreviewExpressionCommand extends Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result != null) {
|
||||||
|
if (result instanceof HasFields) {
|
||||||
|
result = "[object " + result.getClass().getSimpleName() + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
writer.value(result);
|
writer.value(result);
|
||||||
}
|
}
|
||||||
writer.endArray();
|
writer.endArray();
|
||||||
|
} catch (Exception e) {
|
||||||
|
writer.key("code"); writer.value("error");
|
||||||
|
}
|
||||||
|
|
||||||
writer.endObject();
|
writer.endObject();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
respondException(response, e);
|
respondException(response, e);
|
||||||
|
Loading…
Reference in New Issue
Block a user