Search in sources :

Example 1 with Fragment

use of edu.mit.simile.backstage.model.ui.lens.SubcontentAttribute.Fragment 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)

Aggregations

ExpressionQueryResult (edu.mit.simile.backstage.model.data.ExpressionQueryResult)1 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 DefaultScriptableObject (edu.mit.simile.backstage.util.DefaultScriptableObject)1 ScriptableArrayBuilder (edu.mit.simile.backstage.util.ScriptableArrayBuilder)1 Value (org.openrdf.model.Value)1 BindingSet (org.openrdf.query.BindingSet)1 TupleQueryResult (org.openrdf.query.TupleQueryResult)1