Exemplo n.º 1
0
  private static void addContextNodeToBuffer(StringBuffer buffer, ContextNode contextNode) {

    buffer.append("{\n");
    buffer.append("type: \"context\",\n");
    buffer.append("name: \"" + contextNode.getXDIAddress() + "\",\n");
    buffer.append(
        "arc: \"" + (contextNode.isRootContextNode() ? "" : contextNode.getXDIArc()) + "\",\n");
    buffer.append("root: " + XdiAbstractRoot.isValid(contextNode) + ",\n");
    buffer.append("contents: [\n");

    for (Iterator<ContextNode> innerContextNodes = contextNode.getContextNodes();
        innerContextNodes.hasNext(); ) {

      ContextNode innerContextNode = innerContextNodes.next();
      addContextNodeToBuffer(buffer, innerContextNode);
      if (innerContextNodes.hasNext() || contextNode.containsLiteralNode()) buffer.append(",");
      buffer.append("\n");
    }

    if (contextNode.containsLiteralNode()) {

      buffer.append("{\n");
      buffer.append("type: \"literal\",\n");
      buffer.append("name: \"\\\"" + contextNode.getLiteralNode().getLiteralData() + "\\\"\",\n");
      buffer.append("arc: \"&\"\n");
      buffer.append("}\n");
    }

    buffer.append("],\n");

    buffer.append("rel: [");
    for (Iterator<Relation> relations = contextNode.getRelations(); relations.hasNext(); ) {

      Relation relation = relations.next();

      buffer.append("{\n");
      buffer.append("type: \"relation\",\n");
      buffer.append("arc: \"" + relation.getXDIAddress() + "\",\n");
      buffer.append("target: \"" + relation.getTargetXDIAddress() + "\"\n");
      buffer.append("}");
      if (relations.hasNext()) buffer.append(",");
      buffer.append("\n");
    }
    buffer.append("]");

    buffer.append("}\n");
  }