Search in sources :

Example 1 with ExpressionQueryResult

use of edu.mit.simile.backstage.model.data.ExpressionQueryResult in project backstage by zepheira.

the class DomLensNode method generateSubcontentAttributes.

protected void generateSubcontentAttributes(Value value, Scriptable result, Database database, SailRepositoryConnection connection) {
    ScriptableArrayBuilder arrayBuilder = new ScriptableArrayBuilder();
    for (SubcontentAttribute a : _subcontentAttributes) {
        DefaultScriptableObject o = new DefaultScriptableObject();
        o.put("name", o, a.name);
        StringBuffer sb = new StringBuffer();
        for (Fragment f : a.fragments) {
            if (f instanceof StringFragment) {
                sb.append(((StringFragment) f).text);
            } else {
                try {
                    boolean first = true;
                    ExpressionQueryResult eqr = ((ExpressionFragment) f).expression.computeOutputOnValue(value, database, connection);
                    if (eqr != null) {
                        TupleQueryResult queryResult = eqr.tupleQuery.evaluate();
                        try {
                            while (queryResult.hasNext()) {
                                BindingSet bindingSet = queryResult.next();
                                Value value2 = bindingSet.getValue(eqr.resultVar.getName());
                                if (first) {
                                    first = false;
                                } else {
                                    sb.append(";");
                                }
                                sb.append(renderInnerValueToText(value2, database, connection));
                            }
                        } finally {
                            queryResult.close();
                        }
                    } else {
                        sb.append(renderInnerValueToText(value, database, connection));
                    }
                } catch (Exception e) {
                    _logger.error("", e);
                }
            }
        }
        o.put("value", o, sb.toString());
        arrayBuilder.add(o);
    }
    result.put("subcontentAttributes", result, arrayBuilder.toArray());
}
Also used : ScriptableArrayBuilder(edu.mit.simile.backstage.util.ScriptableArrayBuilder) BindingSet(org.openrdf.query.BindingSet) DefaultScriptableObject(edu.mit.simile.backstage.util.DefaultScriptableObject) StringFragment(edu.mit.simile.backstage.model.ui.lens.SubcontentAttribute.StringFragment) ExpressionQueryResult(edu.mit.simile.backstage.model.data.ExpressionQueryResult) Value(org.openrdf.model.Value) TupleQueryResult(org.openrdf.query.TupleQueryResult) Fragment(edu.mit.simile.backstage.model.ui.lens.SubcontentAttribute.Fragment) StringFragment(edu.mit.simile.backstage.model.ui.lens.SubcontentAttribute.StringFragment) ExpressionFragment(edu.mit.simile.backstage.model.ui.lens.SubcontentAttribute.ExpressionFragment)

Example 2 with ExpressionQueryResult

use of edu.mit.simile.backstage.model.data.ExpressionQueryResult in project backstage by zepheira.

the class DomLensNode method generateContentWithInnerTemplates.

protected void generateContentWithInnerTemplates(Value value, Scriptable result, Database database, SailRepositoryConnection connection) {
    ScriptableArrayBuilder arrayBuilder = new ScriptableArrayBuilder();
    try {
        ExpressionQueryResult eqr = _contentExpression.computeOutputOnValue(value, database, connection);
        if (eqr != null) {
            TupleQueryResult queryResult = eqr.tupleQuery.evaluate();
            try {
                while (queryResult.hasNext()) {
                    BindingSet bindingSet = queryResult.next();
                    Value value2 = bindingSet.getValue(eqr.resultVar.getName());
                    arrayBuilder.add(generateInnerContentWithInnerTemplates(value2, database, connection));
                }
            } finally {
                queryResult.close();
            }
        } else {
            arrayBuilder.add(generateInnerContentWithInnerTemplates(value, database, connection));
        }
    } catch (Exception e) {
        _logger.error("", e);
    }
    result.put("content", result, arrayBuilder.toArray());
}
Also used : ScriptableArrayBuilder(edu.mit.simile.backstage.util.ScriptableArrayBuilder) BindingSet(org.openrdf.query.BindingSet) ExpressionQueryResult(edu.mit.simile.backstage.model.data.ExpressionQueryResult) Value(org.openrdf.model.Value) TupleQueryResult(org.openrdf.query.TupleQueryResult)

Example 3 with ExpressionQueryResult

use of edu.mit.simile.backstage.model.data.ExpressionQueryResult in project backstage by zepheira.

the class DomLensNode method generateContentAttributes.

protected void generateContentAttributes(Value value, Scriptable result, Database database, SailRepositoryConnection connection) {
    ScriptableArrayBuilder arrayBuilder = new ScriptableArrayBuilder();
    for (ContentAttribute a : _contentAttributes) {
        DefaultScriptableObject o = new DefaultScriptableObject();
        o.put("name", o, a.name);
        try {
            boolean first = true;
            StringBuffer sb = new StringBuffer();
            ExpressionQueryResult eqr = a.expression.computeOutputOnValue(value, database, connection);
            if (eqr != null) {
                TupleQueryResult queryResult = eqr.tupleQuery.evaluate();
                try {
                    while (queryResult.hasNext()) {
                        BindingSet bindingSet = queryResult.next();
                        Value value2 = bindingSet.getValue(eqr.resultVar.getName());
                        if (first) {
                            first = false;
                        } else {
                            sb.append(";");
                        }
                        sb.append(renderInnerValueToText(value2, database, connection));
                    }
                } finally {
                    queryResult.close();
                }
            }
            o.put("value", o, sb.toString());
        } catch (Exception e) {
            _logger.error("", e);
        }
        arrayBuilder.add(o);
    }
    result.put("contentAttributes", result, arrayBuilder.toArray());
}
Also used : ScriptableArrayBuilder(edu.mit.simile.backstage.util.ScriptableArrayBuilder) BindingSet(org.openrdf.query.BindingSet) DefaultScriptableObject(edu.mit.simile.backstage.util.DefaultScriptableObject) ExpressionQueryResult(edu.mit.simile.backstage.model.data.ExpressionQueryResult) Value(org.openrdf.model.Value) TupleQueryResult(org.openrdf.query.TupleQueryResult)

Example 4 with ExpressionQueryResult

use of edu.mit.simile.backstage.model.data.ExpressionQueryResult in project backstage by zepheira.

the class DomLensNode method generateContent.

protected void generateContent(Value value, Scriptable result, Database database, SailRepositoryConnection connection) {
    ScriptableArrayBuilder arrayBuilder = new ScriptableArrayBuilder();
    String valueType = "text";
    try {
        ExpressionQueryResult eqr = _contentExpression.computeOutputOnValue(value, database, connection);
        if (eqr != null) {
            TupleQueryResult queryResult = eqr.tupleQuery.evaluate();
            try {
                while (queryResult.hasNext()) {
                    BindingSet bindingSet = queryResult.next();
                    Value value2 = bindingSet.getValue(eqr.resultVar.getName());
                    arrayBuilder.add(renderInnerValue(value2, database, connection));
                }
            } finally {
                queryResult.close();
            }
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    DefaultScriptableObject o = new DefaultScriptableObject();
    o.put("valueType", o, valueType);
    o.put("values", o, arrayBuilder.toArray());
    result.put("content", result, o);
}
Also used : ScriptableArrayBuilder(edu.mit.simile.backstage.util.ScriptableArrayBuilder) BindingSet(org.openrdf.query.BindingSet) DefaultScriptableObject(edu.mit.simile.backstage.util.DefaultScriptableObject) ExpressionQueryResult(edu.mit.simile.backstage.model.data.ExpressionQueryResult) Value(org.openrdf.model.Value) TupleQueryResult(org.openrdf.query.TupleQueryResult)

Example 5 with ExpressionQueryResult

use of edu.mit.simile.backstage.model.data.ExpressionQueryResult in project backstage by zepheira.

the class DomLensNode method testCondition.

protected boolean testCondition(Value value, Scriptable result, Database database, SailRepositoryConnection connection) {
    if (_conditionTest == null) {
        return true;
    }
    boolean r = false;
    try {
        ExpressionQueryResult eqr = _conditionExpression.computeOutputOnValue(value, database, connection);
        if (eqr != null) {
            TupleQueryResult queryResult = eqr.tupleQuery.evaluate();
            try {
                if ("if-exists".equals(_conditionTest)) {
                    r = queryResult.hasNext();
                } else if ("if".equals(_conditionTest)) {
                    if (queryResult.hasNext()) {
                        BindingSet bindingSet = queryResult.next();
                        Value value2 = bindingSet.getValue(eqr.resultVar.getName());
                        if (value2 instanceof Literal) {
                            r = ((Literal) value2).booleanValue();
                        }
                    }
                }
            } finally {
                queryResult.close();
            }
        } else {
            if (value instanceof Literal) {
                r = ((Literal) value).booleanValue();
            }
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    result.put("condition", result, r);
    return r;
}
Also used : BindingSet(org.openrdf.query.BindingSet) ExpressionQueryResult(edu.mit.simile.backstage.model.data.ExpressionQueryResult) Literal(org.openrdf.model.Literal) Value(org.openrdf.model.Value) TupleQueryResult(org.openrdf.query.TupleQueryResult)

Aggregations

ExpressionQueryResult (edu.mit.simile.backstage.model.data.ExpressionQueryResult)5 Value (org.openrdf.model.Value)5 BindingSet (org.openrdf.query.BindingSet)5 TupleQueryResult (org.openrdf.query.TupleQueryResult)5 ScriptableArrayBuilder (edu.mit.simile.backstage.util.ScriptableArrayBuilder)4 DefaultScriptableObject (edu.mit.simile.backstage.util.DefaultScriptableObject)3 ExpressionFragment (edu.mit.simile.backstage.model.ui.lens.SubcontentAttribute.ExpressionFragment)1 Fragment (edu.mit.simile.backstage.model.ui.lens.SubcontentAttribute.Fragment)1 StringFragment (edu.mit.simile.backstage.model.ui.lens.SubcontentAttribute.StringFragment)1 Literal (org.openrdf.model.Literal)1