Package edu.mit.simile.backstage.util

Examples of edu.mit.simile.backstage.util.ScriptableArrayBuilder


    protected Object internalRun() {
            _logger.debug("> internalRun");
          Database database = _context.getDatabase();
         
          DefaultScriptableObject result = new DefaultScriptableObject();
          ScriptableArrayBuilder itemIDs = new ScriptableArrayBuilder();
          ScriptableArrayBuilder lenses = new ScriptableArrayBuilder();
         
          int count = 0;
         
          try {
              SailRepositoryConnection connection = (SailRepositoryConnection)
                  database.getRepository().getConnection();
             
              try {
                  TupleQuery query = _builder.makeTupleQuery(_itemVar, connection);
                  TupleQueryResult queryResult = query.evaluate();
                  try {
                      while (queryResult.hasNext()) {
                          BindingSet bindingSet = queryResult.next();
                          Value v = bindingSet.getValue(_itemVar.getName());
                          if (v instanceof URI) {
                              if (count < 20) {
                                String itemID = database.getItemId((URI) v);
                                  itemIDs.add(itemID);
                                  lenses.add(_context.generateLens(itemID));
                              }
                              count++;
                          }
                      }
                  } finally {
                      queryResult.close();
                  }
              } finally {
                  connection.close();
              }
          } catch (Exception e) {
              _logger.error("Error querying for restricted items", e);
          }
         
          result.put("count", result, count);
          result.put("items", result, itemIDs.toArray());
          result.put("lenses", result, lenses.toArray());
     
            _logger.debug("< internalRun");
          return result;
    }
View Full Code Here


   
    result.put("content", result, arrayBuilder.toArray());
  }
 
  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();
  }
View Full Code Here

    }
    return arrayBuilder.toArray();
  }
 
  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);
  }
View Full Code Here

       
    result.put("content", result, o);
  }
 
  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());
  }
View Full Code Here

   
    result.put("contentAttributes", result, arrayBuilder.toArray());
  }
 
  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());
  }
View Full Code Here

       
            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);
View Full Code Here

    @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;
    }
View Full Code Here

        generateContentWithInnerTemplates(value, result, database, connection);
      } else {
        generateContent(value, result, database, connection);
      }
    } else if (_children != null) {
      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);
        }
      }
     
      result.put("children", result, arrayBuilder.toArray());
    }
  }
View Full Code Here

   
    return r;
  }
 
  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());
  }
View Full Code Here

    public boolean hasComponentUpdates() {
        return _componentUpdates.size() > 0;
    }
   
    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();
    }
View Full Code Here

TOP

Related Classes of edu.mit.simile.backstage.util.ScriptableArrayBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.