use of org.freeplane.plugin.script.ExecuteScriptException in project freeplane by freeplane.
the class ScriptCondition method checkNode.
@Override
public boolean checkNode(final NodeModel node) {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final PrintStream printStream = new PrintStream(out);
final Object result;
try {
result = script.setOutStream(printStream).execute(node);
if (result instanceof Boolean)
return (Boolean) result;
if (result instanceof Number)
return ((Number) result).doubleValue() != 0;
printStream.println(this + ": got '" + result + "' for " + node);
printStream.close();
final String info = TextUtils.format(SCRIPT_FILTER_ERROR_RESOURCE, createDescription(), node.toString(), String.valueOf(result));
setErrorStatus(info);
} catch (ExecuteScriptException e) {
printStream.close();
final String info = TextUtils.format(SCRIPT_FILTER_EXECUTE_ERROR_RESOURCE, createDescription(), node.toString(), e.getMessage());
setErrorStatus(info);
}
return false;
}
use of org.freeplane.plugin.script.ExecuteScriptException in project freeplane by freeplane.
the class FormulaTextTransformer method transformContent.
public Object transformContent(TextController textController, final Object obj, final NodeModel node, Object transformedExtension) {
if (obj instanceof FormattedFormula) {
final FormattedFormula formattedFormula = (FormattedFormula) obj;
final Object evaluationResult = transformContent(textController, formattedFormula.getObject(), node, transformedExtension);
return new FormattedObject(evaluationResult, formattedFormula.getPattern());
}
if (!(obj instanceof String)) {
return obj;
}
if (textController.isTextFormattingDisabled(node))
return obj;
final String text = obj.toString();
if (!FormulaUtils.containsFormulaCheckHTML(text)) {
return obj;
}
final String plainText = HtmlUtils.htmlToPlain(text);
// starting a new ScriptContext in evalIfScript
final Object result = FormulaUtils.evalIfScript(node, null, plainText);
if (result == null) {
throw new ExecuteScriptException("got null result from evaluating " + node.getID() + ", text='" + plainText.substring(1) + "'");
}
return result;
}
Aggregations