use of edu.mit.simile.backstage.util.ScriptableArrayBuilder 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());
}
use of edu.mit.simile.backstage.util.ScriptableArrayBuilder in project backstage by zepheira.
the class BackChannel method getComponentStateArray.
public NativeArray getComponentStateArray() {
ScriptableArrayBuilder states = new ScriptableArrayBuilder();
for (Component c : _componentsChangingState) {
Scriptable state = c.getComponentState();
if (state != null) {
state.put("id", state, c.getID());
states.add(state);
}
}
return states.toArray();
}
use of edu.mit.simile.backstage.util.ScriptableArrayBuilder 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());
}
use of edu.mit.simile.backstage.util.ScriptableArrayBuilder in project backstage by zepheira.
the class ListFacet method getComponentState.
@SuppressWarnings("unchecked")
@Override
public Scriptable getComponentState() {
DefaultScriptableObject result = new DefaultScriptableObject();
ScriptableArrayBuilder facetChoicesWithSelection = new ScriptableArrayBuilder();
int selectionCount = 0;
List<FacetChoice> facetChoices = (List<FacetChoice>) _context.getDatabase().cacheAndRun(getCacheableQueryKey(), new ListFacetCacheableQuery());
if (facetChoices != null) {
for (FacetChoice fc : facetChoices) {
DefaultScriptableObject valueO = new DefaultScriptableObject();
boolean selected = _selection.contains(fc._valueString);
valueO.put("value", valueO, fc._valueString);
valueO.put("count", valueO, fc._count);
valueO.put("label", valueO, fc._label);
valueO.put("selected", valueO, selected);
facetChoicesWithSelection.add(valueO);
if (selected) {
selectionCount++;
}
}
}
result.put("values", result, facetChoicesWithSelection.toArray());
result.put("selectionCount", result, selectionCount);
return result;
}
use of edu.mit.simile.backstage.util.ScriptableArrayBuilder in project backstage by zepheira.
the class DefaultLens method render.
@Override
public void render(URI item, Scriptable result, Database database, SailRepositoryConnection connection) {
result.put("label", result, database.getItemLabel(database.getItemId(item)));
try {
RepositoryResult<Statement> r = connection.getStatements(item, null, null, true, SailUtilities.noContext);
Map<URI, Set<Value>> propertyToValues = new HashMap<URI, Set<Value>>();
try {
while (r.hasNext()) {
Statement s = r.next();
URI predicate = s.getPredicate();
Set<Value> values = propertyToValues.get(predicate);
if (values == null) {
values = new HashSet<Value>();
propertyToValues.put(predicate, values);
}
values.add(s.getObject());
}
} finally {
r.close();
}
DefaultScriptableObject propertiesO = new DefaultScriptableObject();
for (URI property : propertyToValues.keySet()) {
String propertyID = database.getPropertyId(property);
PropertyRecord propertyRecord = database.getPropertyRecord(propertyID);
DefaultScriptableObject o = new DefaultScriptableObject();
o.put("propertyLabel", o, propertyRecord.label);
o.put("valueType", o, propertyRecord.valueType);
ScriptableArrayBuilder valueArrayBuilder = new ScriptableArrayBuilder();
Set<Value> values = propertyToValues.get(property);
if ("item".equals(propertyRecord.valueType)) {
for (Value value : values) {
if (value instanceof URI) {
URI itemURI = (URI) value;
String itemID = database.getItemId(itemURI);
DefaultScriptableObject v = new DefaultScriptableObject();
v.put("id", v, itemID);
v.put("label", v, database.getItemLabel(itemID));
valueArrayBuilder.add(v);
} else {
valueArrayBuilder.add(((Resource) value).stringValue());
}
}
} else {
for (Value value : values) {
valueArrayBuilder.add(Utilities.valueToString(value));
}
}
o.put("values", o, valueArrayBuilder.toArray());
propertiesO.put(propertyID, propertiesO, o);
}
result.put("propertyValues", result, propertiesO);
} catch (Exception e) {
_logger.error("Failed to generate default lens for item " + item, e);
}
}
Aggregations