Search in sources :

Example 1 with ExecuteScriptException

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;
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ExecuteScriptException(org.freeplane.plugin.script.ExecuteScriptException)

Example 2 with ExecuteScriptException

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;
}
Also used : FormattedFormula(org.freeplane.features.format.FormattedFormula) FormattedObject(org.freeplane.features.format.FormattedObject) FormattedObject(org.freeplane.features.format.FormattedObject) ExecuteScriptException(org.freeplane.plugin.script.ExecuteScriptException)

Aggregations

ExecuteScriptException (org.freeplane.plugin.script.ExecuteScriptException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 FormattedFormula (org.freeplane.features.format.FormattedFormula)1 FormattedObject (org.freeplane.features.format.FormattedObject)1