Search in sources :

Example 6 with ScriptableArrayBuilder

use of edu.mit.simile.backstage.util.ScriptableArrayBuilder 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 7 with ScriptableArrayBuilder

use of edu.mit.simile.backstage.util.ScriptableArrayBuilder in project backstage by zepheira.

the class DomLensNode method generateInnerContentWithInnerTemplates.

protected Object generateInnerContentWithInnerTemplates(Value value, Database database, SailRepositoryConnection connection) {
    ScriptableArrayBuilder arrayBuilder = new ScriptableArrayBuilder();
    for (LensNode node : _children) {
        if (node instanceof StringLensNode) {
            arrayBuilder.add("");
        } else {
            DefaultScriptableObject o = new DefaultScriptableObject();
            ((DomLensNode) node).render(value, o, database, connection);
            arrayBuilder.add(o);
        }
    }
    return arrayBuilder.toArray();
}
Also used : ScriptableArrayBuilder(edu.mit.simile.backstage.util.ScriptableArrayBuilder) DefaultScriptableObject(edu.mit.simile.backstage.util.DefaultScriptableObject)

Example 8 with ScriptableArrayBuilder

use of edu.mit.simile.backstage.util.ScriptableArrayBuilder 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)

Aggregations

ScriptableArrayBuilder (edu.mit.simile.backstage.util.ScriptableArrayBuilder)8 DefaultScriptableObject (edu.mit.simile.backstage.util.DefaultScriptableObject)6 Value (org.openrdf.model.Value)5 ExpressionQueryResult (edu.mit.simile.backstage.model.data.ExpressionQueryResult)4 BindingSet (org.openrdf.query.BindingSet)4 TupleQueryResult (org.openrdf.query.TupleQueryResult)4 PropertyRecord (edu.mit.simile.backstage.model.data.Database.PropertyRecord)1 Component (edu.mit.simile.backstage.model.ui.Component)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 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Scriptable (org.mozilla.javascript.Scriptable)1 Statement (org.openrdf.model.Statement)1 URI (org.openrdf.model.URI)1 ProjectionElemList (org.openrdf.query.algebra.ProjectionElemList)1